From 35a20551a6986419ec9c2a5dabb9137e8267d556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 9 Mar 2010 12:16:32 +0100 Subject: [PATCH] Preprocessor: minor refactoring and documentation of ExprNode::writeOutput() methods --- preprocessor/ExprNode.cc | 15 +++++++-------- preprocessor/ExprNode.hh | 18 +++++++++++++----- preprocessor/ModelTree.cc | 7 ++++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index d64a00f9a..e330d29e3 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -139,11 +139,17 @@ ExprNode::normalizeEquation(int var_endo, vector } void -ExprNode::writeOutput(ostream &output) +ExprNode::writeOutput(ostream &output) const { writeOutput(output, oMatlabOutsideModel, temporary_terms_type()); } +void +ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type) const +{ + writeOutput(output, output_type, temporary_terms_type()); +} + void 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 BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, diff --git a/preprocessor/ExprNode.hh b/preprocessor/ExprNode.hh index 7f9e1c4c5..13cfd4305 100644 --- a/preprocessor/ExprNode.hh +++ b/preprocessor/ExprNode.hh @@ -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 */ virtual void computeTemporaryTerms(map &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; //! 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 - virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const; + //! Writes output of node (with no temporary terms) + 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 virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, @@ -491,7 +500,6 @@ public: virtual void prepareForDerivation(); virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const; virtual void computeTemporaryTerms(map &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 writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, diff --git a/preprocessor/ModelTree.cc b/preprocessor/ModelTree.cc index 44452c16b..2bcce6150 100644 --- a/preprocessor/ModelTree.cc +++ b/preprocessor/ModelTree.cc @@ -1064,7 +1064,7 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t output << symbol_table.getName(id) << " = "; // Use an empty set for the temporary terms - value->writeOutput(output, output_type, temporary_terms_type()); + value->writeOutput(output, output_type); output << ";" << endl; } } @@ -1226,7 +1226,7 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output output << "\\begin{equation*}" << endl << symbol_table.getName(id) << " = "; // 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; } @@ -1234,7 +1234,8 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output { output << "\\begin{equation}" << 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(equations[eq])->writeOutput(output, output_type); output << endl << "\\end{equation}" << endl; }