Commit 18836437 authored by sebastien's avatar sebastien
Browse files

trunk preprocessor: fixed bug in the macro-processor, when the body of a @#for loop is empty


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2399 ac1d8469-bf42-47a9-8791-bf33cf982152
parent b62649a6
......@@ -56,13 +56,15 @@ private:
istream *input;
struct yy_buffer_state *buffer;
const Macro::parser::location_type yylloc;
const bool is_for_context;
const string for_body;
const Macro::parser::location_type for_body_loc;
ScanContext(istream *input_arg, struct yy_buffer_state *buffer_arg,
Macro::parser::location_type &yylloc_arg, const string &for_body_arg,
Macro::parser::location_type &yylloc_arg, bool is_for_context_arg,
const string &for_body_arg,
Macro::parser::location_type &for_body_loc_arg) :
input(input_arg), buffer(buffer_arg), yylloc(yylloc_arg), for_body(for_body_arg),
for_body_loc(for_body_loc_arg) { }
input(input_arg), buffer(buffer_arg), yylloc(yylloc_arg), is_for_context(is_for_context_arg),
for_body(for_body_arg), for_body_loc(for_body_loc_arg) { }
};
//! The stack used to keep track of nested scanning contexts
......@@ -75,7 +77,9 @@ private:
//! Should we omit the @#line statements ?
const bool no_line_macro;
//! If current context is the body of a loop, contains the string of the loop body. Empty otherwise.
//! True iff current context is the body of a loop
bool is_for_context;
//! If current context is the body of a loop, contains the string of the loop body
string for_body;
//! If current context is the body of a loop, contains the location of the beginning of the body
Macro::parser::location_type for_body_loc;
......
......@@ -203,6 +203,7 @@ CONT \\\\
// Save old buffer state and location
save_context(yylloc);
is_for_context = true;
for_body = for_body_tmp;
for_body_loc = for_body_loc_tmp;
......@@ -298,7 +299,7 @@ CONT \\\\
/* If we are not in a loop body, or if the loop has terminated,
pop a context */
if (for_body.empty() || !iter_loop(driver, yylloc))
if (!is_for_context || !iter_loop(driver, yylloc))
restore_context(yylloc);
}
......@@ -328,7 +329,8 @@ MacroFlex::output_line(Macro::parser::location_type *yylloc) const
void
MacroFlex::save_context(Macro::parser::location_type *yylloc)
{
context_stack.push(ScanContext(input, YY_CURRENT_BUFFER, *yylloc, for_body, for_body_loc));
context_stack.push(ScanContext(input, YY_CURRENT_BUFFER, *yylloc, is_for_context,
for_body, for_body_loc));
}
void
......@@ -337,6 +339,7 @@ MacroFlex::restore_context(Macro::parser::location_type *yylloc)
input = context_stack.top().input;
yy_switch_to_buffer(context_stack.top().buffer);
*yylloc = context_stack.top().yylloc;
is_for_context = context_stack.top().is_for_context;
for_body = context_stack.top().for_body;
for_body_loc = context_stack.top().for_body_loc;
// Remove top of stack
......@@ -359,6 +362,7 @@ MacroFlex::create_include_context(string *filename, Macro::parser::location_type
yylloc->begin.line = yylloc->end.line = 1;
yylloc->begin.column = yylloc->end.column = 0;
// We are not in a loop body
is_for_context = false;
for_body.clear();
// Output @#line information
output_line(yylloc);
......@@ -373,6 +377,7 @@ MacroFlex::create_then_context(Macro::parser::location_type *yylloc)
input = new stringstream(then_body_tmp);
*yylloc = then_body_loc_tmp;
yylloc->begin.filename = yylloc->end.filename = new string(*then_body_loc_tmp.begin.filename);
is_for_context = false;
for_body.clear();
output_line(yylloc);
yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
......@@ -385,6 +390,7 @@ MacroFlex::create_else_context(Macro::parser::location_type *yylloc)
input = new stringstream(else_body_tmp);
*yylloc = else_body_loc_tmp;
yylloc->begin.filename = yylloc->end.filename = new string(*else_body_loc_tmp.begin.filename);
is_for_context = false;
for_body.clear();
output_line(yylloc);
yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
......
Markdown is supported
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