diff --git a/dynare++/parser/cc/dynamic_atoms.cpp b/dynare++/parser/cc/dynamic_atoms.cpp index f02b580af..ca6b6dcd2 100644 --- a/dynare++/parser/cc/dynamic_atoms.cpp +++ b/dynare++/parser/cc/dynamic_atoms.cpp @@ -341,6 +341,12 @@ int DynamicAtoms::index(const char* name, int ll) const return -1; } +bool DynamicAtoms::is_referenced(const char* name) const +{ + Tvarmap::const_iterator it = vars.find(name); + return it != vars.end(); +} + const DynamicAtoms::Tlagmap& DynamicAtoms::lagmap(const char* name) const { Tvarmap::const_iterator it = vars.find(name); diff --git a/dynare++/parser/cc/dynamic_atoms.h b/dynare++/parser/cc/dynamic_atoms.h index 03cb0411f..7d44d6dcc 100644 --- a/dynare++/parser/cc/dynamic_atoms.h +++ b/dynare++/parser/cc/dynamic_atoms.h @@ -182,6 +182,9 @@ namespace ogp { /** Return index of the variable described by the variable * name and lag/lead. If it doesn't exist, return -1. */ int index(const char* name, int ll) const; + /** Return true if a variable is referenced, i.e. it has lag + * map. */ + bool is_referenced(const char* name) const; /** Return the lag map for the variable name. */ const Tlagmap& lagmap(const char* name) const; /** Return the variable name for the tree index. It throws an diff --git a/dynare++/parser/cc/static_atoms.cpp b/dynare++/parser/cc/static_atoms.cpp index 0151cade6..7276cc0c9 100644 --- a/dynare++/parser/cc/static_atoms.cpp +++ b/dynare++/parser/cc/static_atoms.cpp @@ -41,15 +41,14 @@ void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tin register_name(name); int tnew = otree.add_nulary(); assign(name, tnew); - try { - const DynamicAtoms::Tlagmap& lmap = da.lagmap(name); + if (da.is_referenced(name)) { + const DynamicAtoms::Tlagmap& lmap = da.lagmap(name); for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { int told = (*it).second; tmap.insert(Tintintmap::value_type(told, tnew)); } - } catch (const ogu::Exception& e) { - } + } } } diff --git a/dynare++/src/dynare_atoms.cpp b/dynare++/src/dynare_atoms.cpp index e0121d530..c1ae58bc4 100644 --- a/dynare++/src/dynare_atoms.cpp +++ b/dynare++/src/dynare_atoms.cpp @@ -135,22 +135,19 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const // set parameteres for (unsigned int i = 0; i < atoms.get_params().size(); i++) { - try { + if (atoms.is_referenced(atoms.get_params()[i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_params()[i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { int t = (*it).second; et.set_nulary(t, paramvals[i]); } - } catch (const ogu::Exception& e) { - // ignore non-referenced parameters; there is no - // lagmap for them } } // set endogenous for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) { - try { + if (atoms.is_referenced(atoms.get_endovars()[outer_i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_endovars()[outer_i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { @@ -165,15 +162,12 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const else et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]); } - } catch (const ogu::Exception& e) { - // ignore non-referenced endogenous variables; there is no - // lagmap for them } } // set exogenous for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) { - try { + if (atoms.is_referenced(atoms.get_exovars()[outer_i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_exovars()[outer_i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { @@ -184,8 +178,6 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const et.set_nulary(t, xx[i]); } } - } catch (const ogu::Exception& e) { - // ignore non-referenced variables } } }