diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 782c38321d47c92271619a64fe173e439b76c483..a96bbe6fe19aafa6ec93f59429c138b9301f9494 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -18,6 +18,7 @@ */ #include <cstdlib> +#include <cassert> #include <iostream> #include <sstream> @@ -897,11 +898,7 @@ PlannerObjectiveStatement::~PlannerObjectiveStatement() void PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct) { - if (model_tree->equation_number() != 1) - { - cerr << "ERROR: planer_objective: should have only one equation!" << endl; - exit(EXIT_FAILURE); - } + assert(model_tree->equation_number() == 1); } void diff --git a/DataTree.cc b/DataTree.cc index d7469dff40c9b96d916a2bdf8018c633c379ae17..b240e5fbb18aee4bae76db4576fcb2a425e86bbd 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -18,6 +18,7 @@ */ #include <cstdlib> +#include <cassert> #include <iostream> #include "DataTree.hh" @@ -73,11 +74,7 @@ DataTree::AddVariableInternal(const string &name, int lag) NodeID DataTree::AddVariable(const string &name, int lag) { - if (lag != 0) - { - cerr << "DataTree::AddVariable: a non-zero lag is forbidden here!" << endl; - exit(EXIT_FAILURE); - } + assert(lag == 0); return AddVariableInternal(name, lag); } @@ -422,11 +419,7 @@ DataTree::AddLocalVariable(const string &name, NodeID value) throw (LocalVariabl { int id = symbol_table.getID(name); - if (symbol_table.getType(id) != eModelLocalVariable) - { - cerr << "Symbol " << name << " is not a model local variable!" << endl; - exit(EXIT_FAILURE); - } + assert(symbol_table.getType(id) == eModelLocalVariable); // Throw an exception if symbol already declared map<int, NodeID>::iterator it = local_variables_table.find(id); @@ -441,11 +434,7 @@ DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> & { int id = symbol_table.getID(function_name); - if (symbol_table.getType(id) != eUnknownFunction) - { - cerr << "Symbol " << function_name << " is not a function name!" << endl; - exit(EXIT_FAILURE); - } + assert(symbol_table.getType(id) == eUnknownFunction); return new UnknownFunctionNode(*this, id, arguments); } diff --git a/DynamicModel.cc b/DynamicModel.cc index 9a425b809cb7b94f0dbe3a401e757c3ffaa40487..cdf434387af8bab779e50e9f27f9f76e4980edb8 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -19,6 +19,7 @@ #include <cmath> #include <cstdlib> +#include <cassert> #include "DynamicModel.hh" @@ -2153,11 +2154,7 @@ void DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, const eval_context_type &eval_context, bool no_tmp_terms) { - if (!jacobianExo && (hessian || thirdDerivatives || paramsDerivatives)) - { - cerr << "DynamicModel::computingPass: computing 2nd or 3rd order derivatives imply computing 1st derivatives w.r. to exogenous" << endl; - exit(EXIT_FAILURE); - } + assert(jacobianExo || !(hessian || thirdDerivatives || paramsDerivatives)); // Computes dynamic jacobian columns computeDynJacobianCols(jacobianExo); diff --git a/ExprNode.cc b/ExprNode.cc index 170ab263c4db4d6739b045c7c118f7c07aeed209..500abf2f34122d68d2aec15bf524eaa8a703425f 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -21,6 +21,7 @@ #include <iterator> #include <algorithm> +#include <cassert> #include <cmath> #include "ExprNode.hh" @@ -186,11 +187,7 @@ VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg, datatree.variable_node_map[make_pair(symb_id, lag)] = this; // It makes sense to allow a lead/lag on parameters: during steady state calibration, endogenous and parameters can be swapped - if ((type == eModelLocalVariable || type == eModFileLocalVariable || type == eUnknownFunction) && lag != 0) - { - cerr << "Attempt to construct a VariableNode for local variable or unknown function with non-zero lead/lag" << endl; - exit(EXIT_FAILURE); - } + assert(lag == 0 || (type != eModelLocalVariable && type != eModFileLocalVariable && type != eUnknownFunction)); // Fill in non_null_derivatives switch(type) @@ -359,11 +356,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << "x" << LPAR(output_type) << i << RPAR(output_type); break; case oMatlabOutsideModel: - if (lag != 0) - { - cerr << "VariableNode::writeOutput: lag != 0 for exogenous variable outside model scope!" << endl; - exit(EXIT_FAILURE); - } + assert(lag == 0); output << "oo_.exo_steady_state" << "(" << i << ")"; break; } @@ -397,11 +390,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << "x" << LPAR(output_type) << i << RPAR(output_type); break; case oMatlabOutsideModel: - if (lag != 0) - { - cerr << "VariableNode::writeOutput: lag != 0 for exogenous determistic variable outside model scope!" << endl; - exit(EXIT_FAILURE); - } + assert(lag == 0); output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")"; break; } @@ -1439,7 +1428,6 @@ BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const arg2->collectEndogenous(result); } - void BinaryOpNode::collectExogenous(set<pair<int, int> > &result) const { @@ -1729,11 +1717,8 @@ void TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const { - if (!OFFSET(output_type)) - { - cerr << "TrinaryOpNode not implemented for C output" << endl; - exit(EXIT_FAILURE); - } + // TrinaryOpNode not implemented for C output + assert(OFFSET(output_type)); // If current node is a temporary term temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this)); diff --git a/ModFile.cc b/ModFile.cc index 043e40244d066ced5118bb31680ad9472e7ce3ff..e775d43332fbd666fbe04a5ffe593e066439b8d2 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -154,7 +154,7 @@ ModFile::computingPass(bool no_tmp_terms) { if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) { - cerr << "Incorrect order option..." << endl; + cerr << "ERROR: Incorrect order option..." << endl; exit(EXIT_FAILURE); } bool hessian = mod_file_struct.order_option >= 2; diff --git a/ModelTree.cc b/ModelTree.cc index fbdef3ea68f5736d55b6409d535240eeb03c0afd..708ac4f5bdcc2ecb9ad5cc84168aa11d045eadad 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -17,7 +17,7 @@ * along with Dynare. If not, see <http://www.gnu.org/licenses/>. */ -#include <cstdlib> +#include <cassert> #include <iostream> #include "ModelTree.hh" @@ -217,12 +217,7 @@ void ModelTree::addEquation(NodeID eq) { BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq); - - if (beq == NULL || beq->get_op_code() != oEqual) - { - cerr << "ModelTree::addEquation: you didn't provide an equal node!" << endl; - exit(EXIT_FAILURE); - } + assert(beq != NULL && beq->get_op_code() == oEqual); equations.push_back(beq); } diff --git a/NumericalConstants.cc b/NumericalConstants.cc index 3c89d5f79f3a000f00e1b45acf39d14f86fce5a4..eacb3434d3e6e21342eb95c5411e93da1b2ff966 100644 --- a/NumericalConstants.cc +++ b/NumericalConstants.cc @@ -18,6 +18,7 @@ */ #include <cstdlib> +#include <cassert> #include <iostream> #include "NumericalConstants.hh" @@ -26,15 +27,11 @@ int NumericalConstants::AddConstant(const string &iConst) { map<string, int>::iterator iter = numConstantsIndex.find(iConst); - //cout << "iConst=" << iConst << "\n" ; + if (iter != numConstantsIndex.end()) return iter->second; - if (atof(iConst.c_str()) < 0) - { - cerr << "Can't handle a negative constant..!" << endl; - exit(EXIT_FAILURE); - } + assert(atof(iConst.c_str()) >= 0); int id = (int) mNumericalConstants.size(); mNumericalConstants.push_back(iConst); @@ -45,13 +42,8 @@ NumericalConstants::AddConstant(const string &iConst) string NumericalConstants::get(int ID) const { - if (ID < (int) mNumericalConstants.size()) - return mNumericalConstants[ID]; - else - { - cerr << "Unknown constant" << endl; - exit(EXIT_FAILURE); - } + assert(ID >= 0 && ID < (int) mNumericalConstants.size()); + return mNumericalConstants[ID]; } double