diff --git a/DataTree.hh b/DataTree.hh index 3c10cc92a6e6fb2ca4f3404b698537c8c7c7a2f2..6b20e7e6cd2c4e7173f372d44d380a3c9e44e36f 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -181,8 +181,9 @@ public: //! Adds a model local variable with its value void AddLocalVariable(const string &name, NodeID value) throw (LocalVariableException); //! Adds an external function node - /*! \todo Use a map to share identical nodes */ NodeID AddExternalFunction(const string &function_name, const vector<NodeID> &arguments); + //! Adds an external function node + /*! \todo Use a map to share identical nodes */ NodeID AddExternalFunction(int symb_id, const vector<NodeID> &arguments); //! Adds an external function node for the first derivative of an external function NodeID AddFirstDerivExternalFunctionNode(int top_level_symb_id, const vector<NodeID> &arguments, int input_index); diff --git a/DynareBison.yy b/DynareBison.yy index ea8c2ba99979bd0bb14457ade49fa1c106254c85..4eed5b49861960e0a6e81ec7d301f37e98b25435 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -579,6 +579,7 @@ comma_hand_side : hand_side { driver.add_external_function_arg($1); } | comma_hand_side COMMA hand_side { driver.add_external_function_arg($3); } + ; expectation_input : signed_integer | VAROBS { string *varobs = new string("varobs"); $$ = varobs; } diff --git a/ExternalFunctionsTable.cc b/ExternalFunctionsTable.cc index 9cc7c9ce33a8b0f52e4df5122e59e923e3a6d5a9..28044a6d924a3173751be6300a0d52d74cffaa7f 100644 --- a/ExternalFunctionsTable.cc +++ b/ExternalFunctionsTable.cc @@ -28,24 +28,24 @@ ExternalFunctionsTable::ExternalFunctionsTable() { -}; +} void -ExternalFunctionsTable::addExternalFunction(const int symb_id, const external_function_options external_function_options_arg) +ExternalFunctionsTable::addExternalFunction(int symb_id, const external_function_options &external_function_options_arg) { assert(symb_id >= 0); if (external_function_options_arg.secondDerivSymbID > eExtFunNotSet && external_function_options_arg.firstDerivSymbID == eExtFunNotSet) { - cerr << "If the second derivative is provided to the external_function() command," - << "the first derivative must also be provided." << endl; + cerr << "ERROR: If the second derivative is provided to the external_function() command," + << "the first derivative must also be provided" << endl; exit(EXIT_FAILURE); } if (external_function_options_arg.nargs <= 0) { - cerr << "The number of arguments passed to an external function must be > 0." << endl; + cerr << "ERROR: The number of arguments passed to an external function must be > 0" << endl; exit(EXIT_FAILURE); } diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index 867c68e580961dd71daad181b0105fd3ef707b9e..e1d19cf91bd2f88fcc3a42960207dd0b3bb6f4e6 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -65,64 +65,55 @@ private: public: ExternalFunctionsTable(); //! Adds an external function to the table as well as its derivative functions - void addExternalFunction(const int symb_id, const external_function_options external_function_options_arg); + void addExternalFunction(int symb_id, const external_function_options &external_function_options_arg); //! See if the function exists in the External Functions Table - inline bool exists(const int symb_id) const; + inline bool exists(int symb_id) const; //! Get the number of arguments for a given external function - inline int getNargs(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException); + inline int getNargs( int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Get the symbol_id of the first derivative function - inline int getFirstDerivSymbID(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException); + inline int getFirstDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Get the symbol_id of the second derivative function - inline int getSecondDerivSymbID(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException); + inline int getSecondDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Returns the total number of unique external functions declared or used in the .mod file - inline int get_total_number_of_unique_external_functions(); + inline int get_total_number_of_unique_external_functions() const; }; inline bool -ExternalFunctionsTable::exists(const int symb_id) const +ExternalFunctionsTable::exists(int symb_id) const { external_function_table_type::const_iterator iter = externalFunctionTable.find(symb_id); return (iter != externalFunctionTable.end()); } inline int -ExternalFunctionsTable::getNargs(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException) +ExternalFunctionsTable::getNargs(int symb_id) const throw (UnknownExternalFunctionSymbolIDException) { if (exists(symb_id)) return externalFunctionTable.find(symb_id)->second.nargs; else - { - cout << "In get_nargs(): id: " << symb_id << endl; - throw UnknownExternalFunctionSymbolIDException(symb_id); - } + throw UnknownExternalFunctionSymbolIDException(symb_id); } inline int -ExternalFunctionsTable::getFirstDerivSymbID(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException) +ExternalFunctionsTable::getFirstDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException) { if (exists(symb_id)) return externalFunctionTable.find(symb_id)->second.firstDerivSymbID; else - { - cout << "In getFirstDerivSymbID(): id: " << symb_id << endl; - throw UnknownExternalFunctionSymbolIDException(symb_id); - } + throw UnknownExternalFunctionSymbolIDException(symb_id); } inline int -ExternalFunctionsTable::getSecondDerivSymbID(const int symb_id) const throw (UnknownExternalFunctionSymbolIDException) +ExternalFunctionsTable::getSecondDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException) { if (exists(symb_id)) return externalFunctionTable.find(symb_id)->second.secondDerivSymbID; else - { - cout << "In getSecondDerivSymbID(): id: " << symb_id << endl; - throw UnknownExternalFunctionSymbolIDException(symb_id); - } + throw UnknownExternalFunctionSymbolIDException(symb_id); } inline int -ExternalFunctionsTable::get_total_number_of_unique_external_functions() +ExternalFunctionsTable::get_total_number_of_unique_external_functions() const { return externalFunctionTable.size(); } diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 088e09200f621eb95b2a1838a5097c539f8810d8..a07298bc8fc1f5f044f5b54dc05c46d9736959c7 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -110,7 +110,7 @@ ParsingDriver::warning(const string &m) } void -ParsingDriver::declare_symbol(const string *name, const SymbolType type, const string *tex_name) +ParsingDriver::declare_symbol(const string *name, SymbolType type, const string *tex_name) { try { @@ -1743,8 +1743,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name) { // e.g. this function has already been referenced (either ad hoc or through the external_function() statement // => check that the information matches previously declared info int symb_id = mod_file->symbol_table.getID(*function_name); - if (!mod_file->external_functions_table.exists(symb_id)) - error("In ParsingDriver::add_external_function()(1) Please report to Dynare Team."); + assert(mod_file->external_functions_table.exists(symb_id)); if ((int)(stack_external_function_args.top().size()) != mod_file->external_functions_table.getNargs(symb_id)) error("The number of arguments passed to " + *function_name + diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 7177fee0cb9ed0413f64bb73bee9502803242fdb..20e92508c28ab9210782e78afea538bd20aa6241 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -79,7 +79,7 @@ private: void check_symbol_existence(const string &name); //! Helper to add a symbol declaration - void declare_symbol(const string *name, const SymbolType type, const string *tex_name); + void declare_symbol(const string *name, SymbolType type, const string *tex_name); //! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name void optim_options_helper(const string &name); @@ -162,6 +162,8 @@ private: ExternalFunctionsTable::external_function_options current_external_function_options; //! reset the values for temporary storage void reset_current_external_function_options(); + //! Adds a model lagged variable to ModelTree and VariableTable + NodeID add_model_variable(int symb_id, int lag); //! The mod file representation constructed by this ParsingDriver ModFile *mod_file; @@ -226,8 +228,6 @@ public: NodeID add_inf_constant(); //! Adds a model variable to ModelTree and VariableTable NodeID add_model_variable(string *name); - //! Adds a model lagged variable to ModelTree and VariableTable - NodeID add_model_variable(int symb_id, int lag); //! Adds an Expression's variable NodeID add_expression_variable(string *name); //! Adds a "periods" statement