From 188364377224738cd8374ee27dd864cdd47d7a43 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 5 Feb 2009 15:54:09 +0000 Subject: [PATCH] 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 --- macro/MacroDriver.hh | 12 ++++++++---- macro/MacroFlex.ll | 10 ++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh index 549c6573..d5669188 100644 --- a/macro/MacroDriver.hh +++ b/macro/MacroDriver.hh @@ -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; diff --git a/macro/MacroFlex.ll b/macro/MacroFlex.ll index df8000e4..6ea48752 100644 --- a/macro/MacroFlex.ll +++ b/macro/MacroFlex.ll @@ -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));