Mercurial > octave
diff libinterp/parse-tree/lex.ll @ 23602:214cb58ccc1c
use pointer to scope instead of scope id
Eliminate symbol table scope ID and the global list of all scopes
indexed by numeric ID. Function scope data is now only accessible
from the function itself, or by asking a scope for its parent scope
(if it exists).
The top-level and global scopes are now regular data members of the
symbol table class instead of being static.
Symbol table scopes are now created in the lexer when parsing a
function begins and stored in the function object when finishing the
construction of function object. If an error occurs while parsing a
function, the list of any pending scopes is deleted.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 14 Jun 2017 11:53:34 -0400 |
parents | 5cb3a2bb5e1e |
children | 91c8f006ed8b |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll Sun Jun 11 16:57:00 2017 -0400 +++ b/libinterp/parse-tree/lex.ll Wed Jun 14 11:53:34 2017 -0400 @@ -2081,46 +2081,29 @@ namespace octave { - lexical_feedback::symbol_table_context::~symbol_table_context (void) - { - clear (); - } - void lexical_feedback::symbol_table_context::clear (void) { - symbol_table& symtab - = octave::__get_symbol_table__ ("lexical_feedback::symbol_table_context::push"); - while (! frame_stack.empty ()) { - symbol_table::scope_id sid = curr_scope (); - - if (sid > 0) - { - // FIXME: for now we need to ensure that the scope_id has a - // scope object associated with it. Calling clear_variables - // should do that for us. In the future, this should not be - // necessary. - symtab.clear_variables (sid); - - symtab.erase_scope (sid); - } + symbol_table::scope *scope = curr_scope (); + + delete scope; frame_stack.pop_front (); } } void - lexical_feedback::symbol_table_context::push (void) + lexical_feedback::symbol_table_context::pop (void) { - symbol_table& symtab - = octave::__get_symbol_table__ ("lexical_feedback::symbol_table_context::push"); - - push (symtab.current_scope ()); + if (empty ()) + panic_impossible (); + + frame_stack.pop_front (); } - symbol_table::scope_id + symbol_table::scope * lexical_feedback::symbol_table_context::curr_scope (void) const { if (empty ()) @@ -2134,12 +2117,12 @@ return frame_stack.front (); } - symbol_table::scope_id + symbol_table::scope * lexical_feedback::symbol_table_context::parent_scope (void) const { size_t sz = size (); - return sz > 1 ? frame_stack[1] : (sz == 1 ? frame_stack[0] : -1); + return sz > 1 ? frame_stack[1] : (sz == 1 ? frame_stack[0] : 0); } lexical_feedback::~lexical_feedback (void) @@ -2541,11 +2524,9 @@ bool base_lexer::is_variable (const std::string& name, - symbol_table::scope_id scope) + symbol_table::scope *scope) { - symbol_table& symtab = octave::__get_symbol_table__ ("base_lexer::is_variable"); - - return (symtab.is_variable (name, scope) + return ((scope && scope->is_variable (name)) || (pending_local_variables.find (name) != pending_local_variables.end ())); } @@ -3171,13 +3152,14 @@ // Find the token in the symbol table. - symbol_table::scope_id sid = symtab_context.curr_scope (); - - symbol_table& symtab - = octave::__get_symbol_table__ ("base_lexer::handle_identifier"); - - token *tok = new token (NAME, &(symtab.insert (ident, sid)), - input_line_number, current_input_column); + symbol_table::scope *scope = symtab_context.curr_scope (); + + symbol_table::symbol_record sr + = (scope + ? scope->insert (ident) + : symbol_table::symbol_record (scope, ident)); + + token *tok = new token (NAME, sr, input_line_number, current_input_column); // The following symbols are handled specially so that things like // @@ -3187,7 +3169,7 @@ // function call with the argument "+1". if (at_beginning_of_statement - && (! (is_variable (ident, sid) + && (! (is_variable (ident, scope) || ident == "e" || ident == "pi" || ident == "I" || ident == "i" || ident == "J" || ident == "j" @@ -3358,11 +3340,8 @@ case NAME: { token *tok_val = current_token (); - symbol_table::symbol_record *sr = tok_val->sym_rec (); - std::cerr << "NAME"; - if (sr) - std::cerr << " [" << sr->name () << "]"; - std::cerr << "\n"; + symbol_table::symbol_record sr = tok_val->sym_rec (); + std::cerr << "NAME [" << sr.name () << "]\n"; } break;