preprocessor: external functions bug fix: fixes the case where an external function is contained in a local variable that’s used in an equation with leads/lags that require auxiliary equations. Closes #916
parent
5ac2683b32
commit
2ab8e2a122
|
@ -308,6 +308,12 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
output << datatree.num_constants.get(id);
|
||||
}
|
||||
|
||||
bool
|
||||
NumConstNode::containsExternalFunction() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double
|
||||
NumConstNode::eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException)
|
||||
{
|
||||
|
@ -571,6 +577,12 @@ VariableNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, t
|
|||
datatree.local_variables_table[symb_id]->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
|
||||
}
|
||||
|
||||
bool
|
||||
VariableNode::containsExternalFunction() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -1714,6 +1726,12 @@ UnaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, te
|
|||
arg->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
|
||||
}
|
||||
|
||||
bool
|
||||
UnaryOpNode::containsExternalFunction() const
|
||||
{
|
||||
return arg->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -2885,6 +2903,13 @@ BinaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, t
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BinaryOpNode::containsExternalFunction() const
|
||||
{
|
||||
return arg1->containsExternalFunction()
|
||||
|| arg2->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -3963,6 +3988,14 @@ TrinaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms,
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TrinaryOpNode::containsExternalFunction() const
|
||||
{
|
||||
return arg1->containsExternalFunction()
|
||||
|| arg2->containsExternalFunction()
|
||||
|| arg3->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -4626,6 +4659,12 @@ AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType outp
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
AbstractExternalFunctionNode::containsExternalFunction() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg,
|
||||
int symb_id_arg,
|
||||
const vector<expr_t> &arguments_arg) :
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2014 Dynare Team
|
||||
* Copyright (C) 2007-2015 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -187,6 +187,9 @@ public:
|
|||
*/
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
|
||||
//! returns true if the expr node contains an external function
|
||||
virtual bool containsExternalFunction() const = 0;
|
||||
|
||||
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
||||
void writeOutput(ostream &output) const;
|
||||
|
||||
|
@ -441,6 +444,7 @@ public:
|
|||
};
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
|
||||
|
@ -486,6 +490,7 @@ public:
|
|||
VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg);
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count,
|
||||
temporary_terms_t &temporary_terms,
|
||||
|
@ -552,6 +557,7 @@ public:
|
|||
virtual void prepareForDerivation();
|
||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
|
@ -630,6 +636,7 @@ public:
|
|||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
|
@ -724,6 +731,7 @@ public:
|
|||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
|
@ -795,6 +803,7 @@ public:
|
|||
virtual void prepareForDerivation();
|
||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2014 Dynare Team
|
||||
* Copyright (C) 2003-2015 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -1927,9 +1927,16 @@ void StaticModel::writeAuxVarRecursiveDefinitions(const string &basename) const
|
|||
<< "% from model file (.mod)" << endl
|
||||
<< endl;
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
temporary_terms_t temporary_terms;
|
||||
for (int i = 0; i < (int) aux_equations.size(); i++)
|
||||
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction())
|
||||
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oMatlabStaticModel,
|
||||
temporary_terms, tef_terms);
|
||||
|
||||
for (int i = 0; i < (int) aux_equations.size(); i++)
|
||||
{
|
||||
dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output, oMatlabStaticModel);
|
||||
dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output, oMatlabStaticModel, temporary_terms, tef_terms);
|
||||
output << ";" << endl;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue