Preprocessor: minor cosmetic changes related to external functions
parent
0b1888bc84
commit
d860763122
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 +
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue