Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
preprocessor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
preprocessor
Commits
baccf9e8
Commit
baccf9e8
authored
14 years ago
by
Sébastien Villemot
Browse files
Options
Downloads
Patches
Plain Diff
Preprocessor: minor refactoring of ParsingDriver::add_model_var_or_external_function
parent
e74c2835
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ParsingDriver.cc
+15
-28
15 additions, 28 deletions
ParsingDriver.cc
with
15 additions
and
28 deletions
ParsingDriver.cc
+
15
−
28
View file @
baccf9e8
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include
<iostream>
#include
<iostream>
#include
<cassert>
#include
<cassert>
#include
<sstream>
#include
<sstream>
#include
<cmath>
#include
"ParsingDriver.hh"
#include
"ParsingDriver.hh"
#include
"Statement.hh"
#include
"Statement.hh"
...
@@ -1765,68 +1766,54 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
...
@@ -1765,68 +1766,54 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
{
{
if
(
!
in_model_block
)
if
(
!
in_model_block
)
{
{
if
(
(
int
)
stack_external_function_args
.
top
().
size
()
>
0
)
if
(
stack_external_function_args
.
top
().
size
()
>
0
)
error
(
"A variable
cannot take arguments."
);
error
(
string
(
"Symbol "
)
+
*
function_name
+
string
(
"
cannot take arguments."
)
)
;
else
else
return
add_expression_variable
(
function_name
);
return
add_expression_variable
(
function_name
);
}
}
else
else
{
// e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode)
{
// e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode)
if
(
(
int
)
stack_external_function_args
.
top
().
size
()
!=
1
)
if
(
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)."
);
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
<
NumConstNode
*>
(
stack_external_function_args
.
top
().
front
());
NumConstNode
*
numNode
=
dynamic_cast
<
NumConstNode
*>
(
stack_external_function_args
.
top
().
front
());
UnaryOpNode
*
unaryNode
=
dynamic_cast
<
UnaryOpNode
*>
(
stack_external_function_args
.
top
().
front
());
UnaryOpNode
*
unaryNode
=
dynamic_cast
<
UnaryOpNode
*>
(
stack_external_function_args
.
top
().
front
());
if
(
numNode
==
NULL
&&
unaryNode
==
NULL
)
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
;
eval_context_t
ectmp
;
int
model_var_arg
;
double
model_var_arg
;
double
model_var_arg_dbl
;
if
(
unaryNode
==
NULL
)
if
(
unaryNode
==
NULL
)
{
{
try
try
{
{
model_var_arg
=
(
int
)
numNode
->
eval
(
ectmp
);
model_var_arg
=
numNode
->
eval
(
ectmp
);
}
}
catch
(
ExprNode
::
EvalException
&
e
)
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
else
if
(
unaryNode
->
get_op_code
()
!=
oUminus
)
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
else
{
{
try
try
{
{
model_var_arg
=
(
int
)
unaryNode
->
eval
(
ectmp
);
model_var_arg
=
unaryNode
->
eval
(
ectmp
);
}
catch
(
ExprNode
::
EvalException
&
e
)
{
}
try
{
model_var_arg_dbl
=
unaryNode
->
eval
(
ectmp
);
}
}
catch
(
ExprNode
::
EvalException
&
e
)
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
if
(
model_var_arg
!=
floor
(
model_var_arg
))
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)."
)
)
;
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
();
stack_external_function_args
.
pop
();
delete
function_name
;
delete
function_name
;
return
nid
;
return
nid
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment