preprocessor: take care of extra exos in external functions
parent
ef640070c2
commit
5fb6667f86
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2014 Dynare Team
|
* Copyright (C) 2003-2015 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -50,6 +50,12 @@ DataTree::~DataTree()
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table)
|
||||||
|
{
|
||||||
|
external_functions_table.reindex(symbol_table, orig_symbol_table);
|
||||||
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
DataTree::AddNonNegativeConstant(const string &value)
|
DataTree::AddNonNegativeConstant(const string &value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -238,6 +238,8 @@ public:
|
||||||
void writePowerDerivCHeader(ostream &output) const;
|
void writePowerDerivCHeader(ostream &output) const;
|
||||||
//! Write getPowerDeriv
|
//! Write getPowerDeriv
|
||||||
void writePowerDeriv(ostream &output, bool use_dll) const;
|
void writePowerDeriv(ostream &output, bool use_dll) const;
|
||||||
|
//! reindex external functions
|
||||||
|
void reindexExternalFunctions(SymbolTable &orig_symbol_table);
|
||||||
//! Thrown when trying to access an unknown variable by deriv_id
|
//! Thrown when trying to access an unknown variable by deriv_id
|
||||||
class UnknownDerivIDException
|
class UnknownDerivIDException
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2010-2011 Dynare Team
|
* Copyright (C) 2010-2015 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "ExternalFunctionsTable.hh"
|
#include "ExternalFunctionsTable.hh"
|
||||||
#include "SymbolTable.hh"
|
|
||||||
|
|
||||||
ExternalFunctionsTable::ExternalFunctionsTable()
|
ExternalFunctionsTable::ExternalFunctionsTable()
|
||||||
{
|
{
|
||||||
|
@ -115,3 +114,44 @@ ExternalFunctionsTable::addExternalFunction(int symb_id, const external_function
|
||||||
|
|
||||||
externalFunctionTable[symb_id] = external_function_options_chng;
|
externalFunctionTable[symb_id] = external_function_options_chng;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExternalFunctionsTable::reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table)
|
||||||
|
{
|
||||||
|
external_function_table_type orig_externalFunctionTable = externalFunctionTable;
|
||||||
|
externalFunctionTable.clear();
|
||||||
|
for (external_function_table_type::const_iterator it = orig_externalFunctionTable.begin();
|
||||||
|
it != orig_externalFunctionTable.end(); it++)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
external_function_options new_external_function_options;
|
||||||
|
if (it->second.firstDerivSymbID == eExtFunNotSet ||
|
||||||
|
it->second.firstDerivSymbID == eExtFunSetButNoNameProvided)
|
||||||
|
new_external_function_options.firstDerivSymbID = it->second.firstDerivSymbID;
|
||||||
|
else
|
||||||
|
new_external_function_options.firstDerivSymbID =
|
||||||
|
new_symbol_table.getID(orig_symbol_table.getName(it->second.firstDerivSymbID));
|
||||||
|
|
||||||
|
if (it->second.secondDerivSymbID == eExtFunNotSet ||
|
||||||
|
it->second.secondDerivSymbID == eExtFunSetButNoNameProvided)
|
||||||
|
new_external_function_options.secondDerivSymbID = it->second.secondDerivSymbID;
|
||||||
|
else
|
||||||
|
new_external_function_options.secondDerivSymbID =
|
||||||
|
new_symbol_table.getID(orig_symbol_table.getName(it->second.secondDerivSymbID));
|
||||||
|
new_external_function_options.nargs = it->second.nargs;
|
||||||
|
bool new_track_nargs = true;
|
||||||
|
if (it->second.nargs == eExtFunNotSet)
|
||||||
|
{
|
||||||
|
new_track_nargs = false;
|
||||||
|
new_external_function_options.nargs = eExtFunSetDefaultNargs;
|
||||||
|
}
|
||||||
|
addExternalFunction(new_symbol_table.getID(orig_symbol_table.getName(it->first)),
|
||||||
|
new_external_function_options,
|
||||||
|
new_track_nargs);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
cerr << "Error: problem encountered when reindexing external functions table." << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2010-2011 Dynare Team
|
* Copyright (C) 2010-2015 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -27,6 +27,8 @@ using namespace std;
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "SymbolTable.hh"
|
||||||
|
|
||||||
enum ExternalFunctionSetOrNot
|
enum ExternalFunctionSetOrNot
|
||||||
{
|
{
|
||||||
eExtFunSetButNoNameProvided = -2, //! Signifies that the derivative is obtained from the top-level function
|
eExtFunSetButNoNameProvided = -2, //! Signifies that the derivative is obtained from the top-level function
|
||||||
|
@ -76,6 +78,8 @@ public:
|
||||||
inline int getSecondDerivSymbID(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
|
//! Returns the total number of unique external functions declared or used in the .mod file
|
||||||
inline int get_total_number_of_unique_model_block_external_functions() const;
|
inline int get_total_number_of_unique_model_block_external_functions() const;
|
||||||
|
//! Reindex external function table (after removal of extra exo)
|
||||||
|
void reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
|
|
|
@ -1419,6 +1419,7 @@ ModelTree::reindex(SymbolTable &orig_symbol_table)
|
||||||
reindexEquations(orig_symbol_table);
|
reindexEquations(orig_symbol_table);
|
||||||
reindexTrendSymbolsMap(orig_symbol_table);
|
reindexTrendSymbolsMap(orig_symbol_table);
|
||||||
reindexNonstationarySymbolsMap(orig_symbol_table);
|
reindexNonstationarySymbolsMap(orig_symbol_table);
|
||||||
|
reindexExternalFunctions(orig_symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue