Preprocessor: minor refactoring and documentation of ExprNode::writeOutput() methods
parent
30ea396a08
commit
35a20551a6
|
@ -139,11 +139,17 @@ ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID>
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ExprNode::writeOutput(ostream &output)
|
ExprNode::writeOutput(ostream &output) const
|
||||||
{
|
{
|
||||||
writeOutput(output, oMatlabOutsideModel, temporary_terms_type());
|
writeOutput(output, oMatlabOutsideModel, temporary_terms_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type) const
|
||||||
|
{
|
||||||
|
writeOutput(output, output_type, temporary_terms_type());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const
|
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const
|
||||||
{
|
{
|
||||||
|
@ -2152,13 +2158,6 @@ BinaryOpNode::collectTemporary_terms(const temporary_terms_type &temporary_terms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const
|
|
||||||
{
|
|
||||||
deriv_node_temp_terms_type tef_terms;
|
|
||||||
writeOutput(output, output_type, temporary_terms, tef_terms);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
const temporary_terms_type &temporary_terms,
|
const temporary_terms_type &temporary_terms,
|
||||||
|
|
|
@ -172,14 +172,23 @@ public:
|
||||||
/*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */
|
/*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
|
|
||||||
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
|
//! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions
|
||||||
|
/*!
|
||||||
|
\param[in] output the output stream
|
||||||
|
\param[in] output_type the type of output (MATLAB, C, LaTeX...)
|
||||||
|
\param[in] temporary_terms the nodes that are marked as temporary terms
|
||||||
|
\param[in,out] tef_terms the set of already written external function nodes
|
||||||
|
*/
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, deriv_node_temp_terms_type &tef_terms) const = 0;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, deriv_node_temp_terms_type &tef_terms) const = 0;
|
||||||
|
|
||||||
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
||||||
void writeOutput(ostream &output);
|
void writeOutput(ostream &output) const;
|
||||||
|
|
||||||
//! Overloads main writeOutput method to pass an empty value to the tef_terms argument
|
//! Writes output of node (with no temporary terms)
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
void writeOutput(ostream &output, ExprNodeOutputType output_type) const;
|
||||||
|
|
||||||
|
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
|
||||||
|
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||||
|
|
||||||
//! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms
|
//! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
@ -491,7 +500,6 @@ public:
|
||||||
virtual void prepareForDerivation();
|
virtual void prepareForDerivation();
|
||||||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, deriv_node_temp_terms_type &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, deriv_node_temp_terms_type &tef_terms) const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
const temporary_terms_type &temporary_terms,
|
const temporary_terms_type &temporary_terms,
|
||||||
|
|
|
@ -1064,7 +1064,7 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
|
||||||
|
|
||||||
output << symbol_table.getName(id) << " = ";
|
output << symbol_table.getName(id) << " = ";
|
||||||
// Use an empty set for the temporary terms
|
// Use an empty set for the temporary terms
|
||||||
value->writeOutput(output, output_type, temporary_terms_type());
|
value->writeOutput(output, output_type);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1226,7 +1226,7 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output
|
||||||
output << "\\begin{equation*}" << endl
|
output << "\\begin{equation*}" << endl
|
||||||
<< symbol_table.getName(id) << " = ";
|
<< symbol_table.getName(id) << " = ";
|
||||||
// Use an empty set for the temporary terms
|
// Use an empty set for the temporary terms
|
||||||
value->writeOutput(output, output_type, temporary_terms_type());
|
value->writeOutput(output, output_type);
|
||||||
output << endl << "\\end{equation*}" << endl;
|
output << endl << "\\end{equation*}" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1234,7 +1234,8 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output
|
||||||
{
|
{
|
||||||
output << "\\begin{equation}" << endl
|
output << "\\begin{equation}" << endl
|
||||||
<< "% Equation " << eq+1 << endl;
|
<< "% Equation " << eq+1 << endl;
|
||||||
equations[eq]->writeOutput(output, output_type, temporary_terms_type());
|
// Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found
|
||||||
|
dynamic_cast<ExprNode *>(equations[eq])->writeOutput(output, output_type);
|
||||||
output << endl << "\\end{equation}" << endl;
|
output << endl << "\\end{equation}" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue