v4 preprocessor/macro: cosmetic changes in the stack used for nested includes
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1720 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
ceee9628ed
commit
818e571fdc
|
@ -48,10 +48,12 @@ using namespace std;
|
|||
class MacroFlex : public MacroFlexLexer
|
||||
{
|
||||
private:
|
||||
//! The stack of scanner states
|
||||
/*! We could have used instead yypush_buffer_state() and yypop_buffer_state(),
|
||||
but those functions do not exist in Flex 2.5.4 */
|
||||
stack<struct yy_buffer_state *> state_stack;
|
||||
//! The stack used to handle (possibly nested) includes
|
||||
/*! Keeps track of buffer state and associated location, as they were just before switching to
|
||||
included file.
|
||||
Note that we could have used yypush_buffer_state() and yypop_buffer_state()
|
||||
instead of a stack for buffer states, but those functions do not exist in Flex 2.5.4 */
|
||||
stack<pair<struct yy_buffer_state *, Macro::parser::location_type> > include_stack;
|
||||
|
||||
public:
|
||||
MacroFlex(istream* in = 0, ostream* out = 0);
|
||||
|
@ -89,9 +91,6 @@ public:
|
|||
//! Pointer to keep track of the input file stream currently scanned
|
||||
ifstream *ifs;
|
||||
|
||||
//! Stack of locations used for (possibly nested) includes
|
||||
stack<Macro::parser::location_type> loc_stack;
|
||||
|
||||
//! Name of main file being parsed
|
||||
string file;
|
||||
|
||||
|
|
|
@ -68,20 +68,19 @@ typedef Macro::parser::token token;
|
|||
driver.ifs = new ifstream(yytext, ios::binary);
|
||||
if (driver.ifs->fail())
|
||||
driver.error(*yylloc, "Could not open " + string(yytext));
|
||||
// Save old location
|
||||
// Save old buffer state and location
|
||||
/* We don't use yypush_buffer_state(), since it doesn't exist in
|
||||
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
|
||||
example with yypush_buffer_state()) */
|
||||
yylloc->step();
|
||||
driver.loc_stack.push(*yylloc);
|
||||
include_stack.push(make_pair(YY_CURRENT_BUFFER, *yylloc));
|
||||
// Reset location
|
||||
yylloc->begin.filename = yylloc->end.filename = new string(yytext);
|
||||
yylloc->begin.line = yylloc->end.line = 1;
|
||||
yylloc->begin.column = yylloc->end.column = 0;
|
||||
// Display @line
|
||||
// Output @line information
|
||||
*yyout << "@line \"" << *yylloc->begin.filename << "\" 1" << endl;
|
||||
// Switch to new buffer
|
||||
/* We don't use yypush_buffer_state(), since it doesn't exist in
|
||||
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
|
||||
example with yypush_buffer_state()) */
|
||||
state_stack.push(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(yy_create_buffer(driver.ifs, YY_BUF_SIZE));
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
|
@ -142,22 +141,22 @@ typedef Macro::parser::token token;
|
|||
|
||||
|
||||
<<EOF>> {
|
||||
/* We don't use yypop_buffer_state(), since it doesn't exist in
|
||||
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
|
||||
example with yypop_buffer_state()) */
|
||||
// Quit lexer if end of main file
|
||||
if (state_stack.empty())
|
||||
if (include_stack.empty())
|
||||
{
|
||||
yyterminate();
|
||||
}
|
||||
// Else restore old flex buffer
|
||||
/* We don't use yypop_buffer_state(), since it doesn't exist in
|
||||
Flex 2.5.4 (see Flex 2.5.33 info file - section 11 - for code
|
||||
example with yypop_buffer_state()) */
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(state_stack.top());
|
||||
state_stack.pop();
|
||||
yy_switch_to_buffer(include_stack.top().first);
|
||||
// And restore old location
|
||||
delete yylloc->begin.filename;
|
||||
*yylloc = driver.loc_stack.top();
|
||||
driver.loc_stack.pop();
|
||||
*yylloc = include_stack.top().second;
|
||||
// Remove top of stack
|
||||
include_stack.pop();
|
||||
BEGIN(END_INCLUDE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue