diff libinterp/parse-tree/oct-parse.in.yy @ 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 a4af67e0d22c
children 11115c237231
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy	Fri Mar 15 14:52:02 2013 -0400
+++ b/libinterp/parse-tree/oct-parse.in.yy	Sat Mar 16 02:02:43 2013 -0400
@@ -68,7 +68,6 @@
 #include "toplev.h"
 #include "pager.h"
 #include "parse.h"
-#include "parse-private.h"
 #include "pt-all.h"
 #include "pt-eval.h"
 #include "symtab.h"
@@ -98,9 +97,6 @@
 // TRUE means we printed messages about reading startup files.
 bool reading_startup_message_printed = false;
 
-// Keep track of symbol table information when parsing functions.
-symtab_context parser_symtab_context;
-
 // List of autoloads (function -> file mapping).
 static std::map<std::string, std::string> autoload_map;
 
@@ -123,9 +119,7 @@
   do \
     { \
       yyerrok; \
-      if (! parser_symtab_context.empty ()) \
-        parser_symtab_context.pop (); \
-      if ((interactive || forced_interactive)   \
+      if ((interactive || forced_interactive) \
           && ! lexer.input_from_eval_string ()) \
         YYACCEPT; \
       else \
@@ -1000,16 +994,16 @@
                     if (parser.max_fcn_depth < parser.curr_fcn_depth)
                       parser.max_fcn_depth = parser.curr_fcn_depth;
 
-                    parser_symtab_context.push ();
-
-                    symbol_table::set_scope (symbol_table::alloc_scope ());
-
-                    parser.function_scopes.push_back (symbol_table::current_scope ());
+                    lexer.symtab_context.push (symbol_table::alloc_scope ());
+
+                    parser.function_scopes.push_back
+                     (lexer.symtab_context.curr_scope ());
 
                     if (! lexer.reading_script_file
                         && parser.curr_fcn_depth == 1
                         && ! parser.parsing_subfunctions)
-                      parser.primary_fcn_scope = symbol_table::current_scope ();
+                      parser.primary_fcn_scope
+                        = lexer.symtab_context.curr_scope ();
 
                     if (lexer.reading_script_file
                         && parser.curr_fcn_depth > 1)
@@ -1027,8 +1021,7 @@
 
                     if (lexer.looking_at_function_handle)
                       {
-                        parser_symtab_context.push ();
-                        symbol_table::set_scope (symbol_table::alloc_scope ());
+                        lexer.symtab_context.push (symbol_table::alloc_scope ());
                         lexer.looking_at_function_handle--;
                         lexer.looking_at_anon_fcn_args = true;
                       }
@@ -1892,12 +1885,12 @@
 
   tree_parameter_list *ret_list = 0;
 
-  symbol_table::scope_id fcn_scope = symbol_table::current_scope ();
-
-  if (parser_symtab_context.empty ())
+  symbol_table::scope_id fcn_scope = lexer.symtab_context.curr_scope ();
+
+  if (lexer.symtab_context.empty ())
     panic_impossible ();
 
-  parser_symtab_context.pop ();
+  lexer.symtab_context.pop ();
 
   stmt->set_print_flag (false);
 
@@ -2579,7 +2572,7 @@
   body->append (end_fcn_stmt);
 
   octave_user_function *fcn
-    = new octave_user_function (symbol_table::current_scope (),
+    = new octave_user_function (lexer.symtab_context.curr_scope (),
                                 param_list, 0, body);
 
   if (fcn)
@@ -2770,10 +2763,10 @@
 void
 octave_base_parser::recover_from_parsing_function (void)
 {
-  if (parser_symtab_context.empty ())
+  if (lexer.symtab_context.empty ())
     panic_impossible ();
 
-  parser_symtab_context.pop ();
+  lexer.symtab_context.pop ();
 
   if (lexer.reading_fcn_file && curr_fcn_depth == 1
       && ! parsing_subfunctions)