Commit 84ba1aff authored by sebastien's avatar sebastien
Browse files

trunk preprocessor: use assert() function at several places


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2642 ac1d8469-bf42-47a9-8791-bf33cf982152
parent bc86ddc1
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <cstdlib> #include <cstdlib>
#include <cassert>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
...@@ -897,11 +898,7 @@ PlannerObjectiveStatement::~PlannerObjectiveStatement() ...@@ -897,11 +898,7 @@ PlannerObjectiveStatement::~PlannerObjectiveStatement()
void void
PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct) PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
if (model_tree->equation_number() != 1) assert(model_tree->equation_number() == 1);
{
cerr << "ERROR: planer_objective: should have only one equation!" << endl;
exit(EXIT_FAILURE);
}
} }
void void
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <cstdlib> #include <cstdlib>
#include <cassert>
#include <iostream> #include <iostream>
#include "DataTree.hh" #include "DataTree.hh"
...@@ -73,11 +74,7 @@ DataTree::AddVariableInternal(const string &name, int lag) ...@@ -73,11 +74,7 @@ DataTree::AddVariableInternal(const string &name, int lag)
NodeID NodeID
DataTree::AddVariable(const string &name, int lag) DataTree::AddVariable(const string &name, int lag)
{ {
if (lag != 0) assert(lag == 0);
{
cerr << "DataTree::AddVariable: a non-zero lag is forbidden here!" << endl;
exit(EXIT_FAILURE);
}
return AddVariableInternal(name, lag); return AddVariableInternal(name, lag);
} }
...@@ -422,11 +419,7 @@ DataTree::AddLocalVariable(const string &name, NodeID value) throw (LocalVariabl ...@@ -422,11 +419,7 @@ DataTree::AddLocalVariable(const string &name, NodeID value) throw (LocalVariabl
{ {
int id = symbol_table.getID(name); int id = symbol_table.getID(name);
if (symbol_table.getType(id) != eModelLocalVariable) assert(symbol_table.getType(id) == eModelLocalVariable);
{
cerr << "Symbol " << name << " is not a model local variable!" << endl;
exit(EXIT_FAILURE);
}
// Throw an exception if symbol already declared // Throw an exception if symbol already declared
map<int, NodeID>::iterator it = local_variables_table.find(id); map<int, NodeID>::iterator it = local_variables_table.find(id);
...@@ -441,11 +434,7 @@ DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> & ...@@ -441,11 +434,7 @@ DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> &
{ {
int id = symbol_table.getID(function_name); int id = symbol_table.getID(function_name);
if (symbol_table.getType(id) != eUnknownFunction) assert(symbol_table.getType(id) == eUnknownFunction);
{
cerr << "Symbol " << function_name << " is not a function name!" << endl;
exit(EXIT_FAILURE);
}
return new UnknownFunctionNode(*this, id, arguments); return new UnknownFunctionNode(*this, id, arguments);
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cassert>
#include "DynamicModel.hh" #include "DynamicModel.hh"
...@@ -2153,11 +2154,7 @@ void ...@@ -2153,11 +2154,7 @@ void
DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives,
const eval_context_type &eval_context, bool no_tmp_terms) const eval_context_type &eval_context, bool no_tmp_terms)
{ {
if (!jacobianExo && (hessian || thirdDerivatives || paramsDerivatives)) assert(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);
}
// Computes dynamic jacobian columns // Computes dynamic jacobian columns
computeDynJacobianCols(jacobianExo); computeDynJacobianCols(jacobianExo);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cmath> #include <cmath>
#include "ExprNode.hh" #include "ExprNode.hh"
...@@ -186,11 +187,7 @@ VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg, ...@@ -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; 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 // 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) assert(lag == 0 || (type != eModelLocalVariable && type != eModFileLocalVariable && type != eUnknownFunction));
{
cerr << "Attempt to construct a VariableNode for local variable or unknown function with non-zero lead/lag" << endl;
exit(EXIT_FAILURE);
}
// Fill in non_null_derivatives // Fill in non_null_derivatives
switch(type) switch(type)
...@@ -359,11 +356,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -359,11 +356,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
output << "x" << LPAR(output_type) << i << RPAR(output_type); output << "x" << LPAR(output_type) << i << RPAR(output_type);
break; break;
case oMatlabOutsideModel: case oMatlabOutsideModel:
if (lag != 0) assert(lag == 0);
{
cerr << "VariableNode::writeOutput: lag != 0 for exogenous variable outside model scope!" << endl;
exit(EXIT_FAILURE);
}
output << "oo_.exo_steady_state" << "(" << i << ")"; output << "oo_.exo_steady_state" << "(" << i << ")";
break; break;
} }
...@@ -397,11 +390,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -397,11 +390,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
output << "x" << LPAR(output_type) << i << RPAR(output_type); output << "x" << LPAR(output_type) << i << RPAR(output_type);
break; break;
case oMatlabOutsideModel: case oMatlabOutsideModel:
if (lag != 0) assert(lag == 0);
{
cerr << "VariableNode::writeOutput: lag != 0 for exogenous determistic variable outside model scope!" << endl;
exit(EXIT_FAILURE);
}
output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")"; output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")";
break; break;
} }
...@@ -1439,7 +1428,6 @@ BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const ...@@ -1439,7 +1428,6 @@ BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
arg2->collectEndogenous(result); arg2->collectEndogenous(result);
} }
void void
BinaryOpNode::collectExogenous(set<pair<int, int> > &result) const BinaryOpNode::collectExogenous(set<pair<int, int> > &result) const
{ {
...@@ -1729,11 +1717,8 @@ void ...@@ -1729,11 +1717,8 @@ void
TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const const temporary_terms_type &temporary_terms) const
{ {
if (!OFFSET(output_type)) // TrinaryOpNode not implemented for C output
{ assert(OFFSET(output_type));
cerr << "TrinaryOpNode not implemented for C output" << endl;
exit(EXIT_FAILURE);
}
// If current node is a temporary term // If current node is a temporary term
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this)); temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
......
...@@ -154,7 +154,7 @@ ModFile::computingPass(bool no_tmp_terms) ...@@ -154,7 +154,7 @@ ModFile::computingPass(bool no_tmp_terms)
{ {
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) 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); exit(EXIT_FAILURE);
} }
bool hessian = mod_file_struct.order_option >= 2; bool hessian = mod_file_struct.order_option >= 2;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* along with Dynare. If not, see <http://www.gnu.org/licenses/>. * along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cstdlib> #include <cassert>
#include <iostream> #include <iostream>
#include "ModelTree.hh" #include "ModelTree.hh"
...@@ -217,12 +217,7 @@ void ...@@ -217,12 +217,7 @@ void
ModelTree::addEquation(NodeID eq) ModelTree::addEquation(NodeID eq)
{ {
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq); BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
assert(beq != NULL && beq->get_op_code() == oEqual);
if (beq == NULL || beq->get_op_code() != oEqual)
{
cerr << "ModelTree::addEquation: you didn't provide an equal node!" << endl;
exit(EXIT_FAILURE);
}
equations.push_back(beq); equations.push_back(beq);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <cstdlib> #include <cstdlib>
#include <cassert>
#include <iostream> #include <iostream>
#include "NumericalConstants.hh" #include "NumericalConstants.hh"
...@@ -26,15 +27,11 @@ int ...@@ -26,15 +27,11 @@ int
NumericalConstants::AddConstant(const string &iConst) NumericalConstants::AddConstant(const string &iConst)
{ {
map<string, int>::iterator iter = numConstantsIndex.find(iConst); map<string, int>::iterator iter = numConstantsIndex.find(iConst);
//cout << "iConst=" << iConst << "\n" ;
if (iter != numConstantsIndex.end()) if (iter != numConstantsIndex.end())
return iter->second; return iter->second;
if (atof(iConst.c_str()) < 0) assert(atof(iConst.c_str()) >= 0);
{
cerr << "Can't handle a negative constant..!" << endl;
exit(EXIT_FAILURE);
}
int id = (int) mNumericalConstants.size(); int id = (int) mNumericalConstants.size();
mNumericalConstants.push_back(iConst); mNumericalConstants.push_back(iConst);
...@@ -45,13 +42,8 @@ NumericalConstants::AddConstant(const string &iConst) ...@@ -45,13 +42,8 @@ NumericalConstants::AddConstant(const string &iConst)
string string
NumericalConstants::get(int ID) const NumericalConstants::get(int ID) const
{ {
if (ID < (int) mNumericalConstants.size()) assert(ID >= 0 && ID < (int) mNumericalConstants.size());
return mNumericalConstants[ID]; return mNumericalConstants[ID];
else
{
cerr << "Unknown constant" << endl;
exit(EXIT_FAILURE);
}
} }
double double
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment