diff --git a/DynamicModel.cc b/DynamicModel.cc index ecd0881b..87239eea 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -3427,9 +3427,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const dynamic_model.AddLocalVariable(it->first, it->second->cloneDynamic(dynamic_model)); // Convert equations - for (vector::const_iterator it = equations.begin(); - it != equations.end(); it++) - dynamic_model.addEquation((*it)->cloneDynamic(dynamic_model)); + for (size_t i = 0; i < equations.size(); i++) + dynamic_model.addEquation(equations[i]->cloneDynamic(dynamic_model), equations_lineno[i]); // Convert auxiliary equations for (deque::const_iterator it = aux_equations.begin(); @@ -3437,18 +3436,18 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const dynamic_model.addAuxEquation((*it)->cloneDynamic(dynamic_model)); // Convert static_only equations - for (vector::const_iterator it = static_only_equations.begin(); - it != static_only_equations.end(); it++) - dynamic_model.addStaticOnlyEquation((*it)->cloneDynamic(dynamic_model)); + for (size_t i = 0; i < static_only_equations.size(); i++) + dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model), + static_only_equations_lineno[i]); } void DynamicModel::replaceMyEquations(DynamicModel &dynamic_model) const { dynamic_model.equations.clear(); - for (vector::const_iterator it = equations.begin(); - it != equations.end(); it++) - dynamic_model.addEquation((*it)->cloneDynamic(dynamic_model)); + for (size_t i = 0; i < equations.size(); i++) + dynamic_model.addEquation(equations[i]->cloneDynamic(dynamic_model), + equations_lineno[i]); } void @@ -3468,7 +3467,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) // Add Planner Objective to equations to include in computeDerivIDs assert(static_model.equations.size() == 1); - addEquation(static_model.equations[0]->cloneDynamic(*this)); + addEquation(static_model.equations[0]->cloneDynamic(*this), static_model.equations_lineno[0]); // Get max endo lead and max endo lag set > dynvars; @@ -3513,7 +3512,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) } equations.clear(); - addEquation(AddEqual(lagrangian, Zero)); + addEquation(AddEqual(lagrangian, Zero), -1); computeDerivIDs(); //Compute derivatives and overwrite equations @@ -3527,7 +3526,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) // Add new equations equations.clear(); for (int i = 0; i < (int) neweqs.size(); i++) - addEquation(neweqs[i]); + addEquation(neweqs[i], -1); } void @@ -3559,11 +3558,11 @@ DynamicModel::toStatic(StaticModel &static_model) const // If yes, replace it by an equation marked [static] if (is_dynamic_only) { - static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model)); + static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]); static_only_index++; } else - static_model.addEquation(equations[i]->toStatic(static_model)); + static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]); } // Convert auxiliary equations @@ -3795,7 +3794,8 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog if (fabs(nearZero) > ZERO_BAND) { - cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " w.r.t. trend variable " + cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line " + << equations_lineno[eq] << ") w.r.t. trend variable " << symbol_table.getName(it->first.first) << " and endogenous variable " << symbol_table.getName(endogit->first.first) << " is not null. " << endl; exit(EXIT_FAILURE); @@ -4075,7 +4075,7 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model // Add new equations for (int i = 0; i < (int) neweqs.size(); i++) - addEquation(neweqs[i]); + addEquation(neweqs[i], -1); // Order of auxiliary variable definition equations: // - expectation (entered before this function is called) @@ -4135,7 +4135,7 @@ DynamicModel::substituteExpectation(bool partial_information_model) // Add new equations for (int i = 0; i < (int) neweqs.size(); i++) - addEquation(neweqs[i]); + addEquation(neweqs[i], -1); // Add the new set of equations at the *beginning* of aux_equations copy(neweqs.rbegin(), neweqs.rend(), front_inserter(aux_equations)); @@ -4256,12 +4256,13 @@ DynamicModel::isModelLocalVariableUsed() const } void -DynamicModel::addStaticOnlyEquation(expr_t eq) +DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) { BinaryOpNode *beq = dynamic_cast(eq); assert(beq != NULL && beq->get_op_code() == oEqual); static_only_equations.push_back(beq); + static_only_equations_lineno.push_back(lineno); } size_t diff --git a/DynamicModel.hh b/DynamicModel.hh index 5f32ed11..07716efe 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -35,6 +35,9 @@ private: /*! They will be used in toStatic() to replace equations marked as [dynamic] */ vector static_only_equations; + //! Stores line numbers of equations declared as [static] + vector static_only_equations_lineno; + typedef map, int> deriv_id_table_t; //! Maps a pair (symbol_id, lag) to a deriv ID deriv_id_table_t deriv_id_table; @@ -237,7 +240,7 @@ public: void replaceMyEquations(DynamicModel &dynamic_model) const; //! Adds an equation marked as [static] - void addStaticOnlyEquation(expr_t eq); + void addStaticOnlyEquation(expr_t eq, int lineno); //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; diff --git a/ModelTree.cc b/ModelTree.cc index f51eeb6f..5daf09df 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -270,7 +270,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m } catch (ExprNode::EvalException &e) { - cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl; + cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " (line " << equations_lineno[eq] << ") and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl; Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms); cerr << endl; exit(EXIT_FAILURE); @@ -1376,21 +1376,22 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output } void -ModelTree::addEquation(expr_t eq) +ModelTree::addEquation(expr_t eq, int lineno) { BinaryOpNode *beq = dynamic_cast(eq); assert(beq != NULL && beq->get_op_code() == oEqual); equations.push_back(beq); + equations_lineno.push_back(lineno); } void -ModelTree::addEquation(expr_t eq, vector > &eq_tags) +ModelTree::addEquation(expr_t eq, int lineno, vector > &eq_tags) { int n = equation_number(); for (size_t i = 0; i < eq_tags.size(); i++) equation_tags.push_back(make_pair(n, eq_tags[i])); - addEquation(eq); + addEquation(eq, lineno); } void diff --git a/ModelTree.hh b/ModelTree.hh index 30afd27d..ffdb02ac 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -54,6 +54,9 @@ protected: //! Stores declared and generated auxiliary equations vector equations; + //! Stores line numbers of declared equations; -1 means undefined + vector equations_lineno; + //! Only stores generated auxiliary equations, in an order meaningful for evaluation deque aux_equations; @@ -295,10 +298,10 @@ public: 3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables default value = 0 */ int mfs; - //! Declare a node as an equation of the model - void addEquation(expr_t eq); + //! Declare a node as an equation of the model; also give its line number + void addEquation(expr_t eq, int lineno); //! Declare a node as an equation of the model, also giving its tags - void addEquation(expr_t eq, vector > &eq_tags); + void addEquation(expr_t eq, int lineno, vector > &eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations void addAuxEquation(expr_t eq); //! Returns the number of equations in the model diff --git a/ParsingDriver.cc b/ParsingDriver.cc index f4bf3a75..58311c0e 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -1741,7 +1741,7 @@ ParsingDriver::end_planner_objective(expr_t expr) { // Add equation corresponding to expression expr_t eq = model_tree->AddEqual(expr, model_tree->Zero); - model_tree->addEquation(eq); + model_tree->addEquation(eq, location.begin.line); mod_file->addStatement(new PlannerObjectiveStatement(dynamic_cast(model_tree))); @@ -1988,10 +1988,10 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) if (!id->isInStaticForm()) error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators"); - dynamic_model->addStaticOnlyEquation(id); + dynamic_model->addStaticOnlyEquation(id, location.begin.line); } else - model_tree->addEquation(id, eq_tags); + model_tree->addEquation(id, location.begin.line, eq_tags); eq_tags.clear(); return id;