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 @@
*/
#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
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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));
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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
......
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