Mercurial > hg > octave-nkf
diff libinterp/parse-tree/lex.h @ 16320:09f0cb9cac7d
don't modify symbol table scope in the parser
* symtab.h (symbol_table::insert): Accept scope as argument.
* lex.h (symbol_table_context): New class.
(octave_lexer::symtab_context: New data member.
* parse-private.h: Delete.
* parse.h, oct-parse.in.yy (parser_symtab_context): Delete global
variable and all uses.
* lex.ll (octave_lexer::reset): Clear symtab_context.
(octave_base_lexer::handle_superclass_identifier,
octave_base_lexer::handle_meta_identifier,
octave_base_lexer::handle_identifier): Get current symbol table scope
for parsing from symtab_context. Use it to insert new variables in
the symbol table.
* oct-parse.in.yy (ABORT_PARSE): Don't pop symtab_context.
(push_fcn_symtab, param_list_beg): Push newly allocated scope on the
symtab_context stack. Don't modify symbol table scope.
(make_anon_fcn_handle): Get function scope from symtab_context instead
of the symbol table. Pop symtab_context.
(start_function): Get function scope from symtab_context instead
of the symbol table.
(octave_base_parser::recover_from_parsing_function):
Pop symtab_context.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 16 Mar 2013 02:02:43 -0400 |
parents | 0925d1f6875e |
children | 6bfd8dbd7d3c |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -43,6 +43,55 @@ { public: + // Track symbol table information when parsing functions. + + class symbol_table_context + { + public: + + symbol_table_context (void) + : frame_stack (), init_scope (symbol_table::current_scope ()) + { + push (init_scope); + } + + void clear (void) + { + while (! frame_stack.empty ()) + frame_stack.pop (); + + push (init_scope); + } + + bool empty (void) const { return frame_stack.empty (); } + + void pop (void) + { + frame_stack.pop (); + } + + void push (symbol_table::scope_id scope) + { + frame_stack.push (scope); + } + + void push (void) + { + push (symbol_table::current_scope ()); + } + + symbol_table::scope_id curr_scope (void) const + { + return frame_stack.top (); + } + + private: + + std::stack<symbol_table::scope_id> frame_stack; + + symbol_table::scope_id init_scope; + }; + // Track nesting of square brackets, curly braces, and parentheses. class bbp_nesting_level @@ -233,7 +282,7 @@ current_input_line (), comment_text (), help_text (), fcn_file_name (), fcn_file_full_name (), looking_at_object_index (), parsed_function_name (), pending_local_variables (), - nesting_level (), tokens () + symtab_context (), nesting_level (), tokens () { init (); } @@ -375,6 +424,9 @@ // set of identifiers that might be local variable names. std::set<std::string> pending_local_variables; + // Track current symbol table scope and context. + symbol_table_context symtab_context; + // is the closest nesting level a square bracket, squiggly brace, // a paren, or an anonymous function body? bbp_nesting_level nesting_level;