From baccf9e8f5fda07ff7b42e8df4dedcdd7656aea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 13 Jan 2011 19:10:16 +0100 Subject: [PATCH] Preprocessor: minor refactoring of ParsingDriver::add_model_var_or_external_function --- ParsingDriver.cc | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/ParsingDriver.cc b/ParsingDriver.cc index b0638406..99a7e33d 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "ParsingDriver.hh" #include "Statement.hh" @@ -1765,68 +1766,54 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in { if (!in_model_block) { - if ((int)stack_external_function_args.top().size() > 0) - error("A variable cannot take arguments."); + if (stack_external_function_args.top().size() > 0) + error(string("Symbol ") + *function_name + string(" cannot take arguments.")); else return add_expression_variable(function_name); } else { // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode) - if ((int)stack_external_function_args.top().size() != 1) - error("A model variable is being treated as if it were a function (i.e., has received more than one argument)."); + if (stack_external_function_args.top().size() != 1) + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., has received more than one argument).")); NumConstNode *numNode = dynamic_cast(stack_external_function_args.top().front()); UnaryOpNode *unaryNode = dynamic_cast(stack_external_function_args.top().front()); if (numNode == NULL && unaryNode == NULL) - error("A model variable is being treated as if it were a function (i.e., takes an argument that is not an integer)."); + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); eval_context_t ectmp; - int model_var_arg; - double model_var_arg_dbl; + double model_var_arg; if (unaryNode == NULL) { try { - model_var_arg = (int)numNode->eval(ectmp); + model_var_arg = numNode->eval(ectmp); } catch (ExprNode::EvalException &e) { + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); } - try - { - model_var_arg_dbl = numNode->eval(ectmp); - } - catch (ExprNode::EvalException &e) - { - } - } else if (unaryNode->get_op_code() != oUminus) - error("A model variable is being treated as if it were a function (i.e., takes an argument that is not an integer)."); + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); else { try { - model_var_arg = (int)unaryNode->eval(ectmp); - } - catch (ExprNode::EvalException &e) - { - } - try - { - model_var_arg_dbl = unaryNode->eval(ectmp); + model_var_arg = unaryNode->eval(ectmp); } catch (ExprNode::EvalException &e) { + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); } } - if ((double) model_var_arg != model_var_arg_dbl) //make 100% sure int cast didn't lose info - error("A model variable is being treated as if it were a function (i.e., takes an argument that is not an integer)."); + if (model_var_arg != floor(model_var_arg)) + error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); - nid = add_model_variable(mod_file->symbol_table.getID(*function_name), model_var_arg); + nid = add_model_variable(mod_file->symbol_table.getID(*function_name), (int) model_var_arg); stack_external_function_args.pop(); delete function_name; return nid;