From 711a4f62a2ba46e80436a11cb7ad65a7a3bc8771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 24 Feb 2014 15:37:55 +0100 Subject: [PATCH] Small improvements to external functions code. --- preprocessor/DataTree.hh | 8 +++++++- preprocessor/ExprNode.cc | 24 ++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/preprocessor/DataTree.hh b/preprocessor/DataTree.hh index 3540a86de..9ef440f8a 100644 --- a/preprocessor/DataTree.hh +++ b/preprocessor/DataTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -68,10 +68,16 @@ protected: binary_op_node_map_t binary_op_node_map; typedef map, expr_t>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_t; trinary_op_node_map_t trinary_op_node_map; + + // (arguments, symb_id) -> ExternalFunctionNode typedef map, int>, ExternalFunctionNode *> external_function_node_map_t; external_function_node_map_t external_function_node_map; + + // ((arguments, deriv_idx), symb_id) -> FirstDerivExternalFunctionNode typedef map, int>, int>, FirstDerivExternalFunctionNode *> first_deriv_external_function_node_map_t; first_deriv_external_function_node_map_t first_deriv_external_function_node_map; + + // ((arguments, (deriv_idx1, deriv_idx2)), symb_id) -> SecondDerivExternalFunctionNode typedef map, pair >, int>, SecondDerivExternalFunctionNode *> second_deriv_external_function_node_map_t; second_deriv_external_function_node_map_t second_deriv_external_function_node_map; diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index 6639416fe..11d23a6d3 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2013 Dynare Team + * Copyright (C) 2007-2014 Dynare Team * * This file is part of Dynare. * @@ -4935,12 +4935,10 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType return; } - int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); + const int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); - int tmpIndx = inputIndex; - if (IS_C(output_type)) - tmpIndx = tmpIndx - 1; + const int tmpIndx = inputIndex - ARRAY_SUBSCRIPT_OFFSET(output_type); if (first_deriv_symb_id == symb_id) output << "TEFD_" << getIndxInTefTerms(symb_id, tef_terms) @@ -4982,15 +4980,14 @@ FirstDerivExternalFunctionNode::compile(ostream &CompileCode, unsigned int &inst int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); - int tmpIndx = inputIndex; if (!lhs_rhs) { - FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx); + FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex); fldtefd.write(CompileCode, instruction_number); } else { - FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx); + FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex); fstptefd.write(CompileCode, instruction_number); } } @@ -5193,16 +5190,11 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType return; } - int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); + const int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); - int tmpIndex1 = inputIndex1; - int tmpIndex2 = inputIndex2; - if (IS_C(output_type)) - { - tmpIndex1 = tmpIndex1 - 1; - tmpIndex2 = tmpIndex2 - 1; - } + const int tmpIndex1 = inputIndex1 - ARRAY_SUBSCRIPT_OFFSET(output_type); + const int tmpIndex2 = inputIndex2 - ARRAY_SUBSCRIPT_OFFSET(output_type); int indx = getIndxInTefTerms(symb_id, tef_terms); if (second_deriv_symb_id == symb_id)