diff libinterp/parse-tree/oct-parse.in.yy @ 24037:21915520ac7b

use more direct method for non-local symbol access (bug #38236) * pt-id.h, pd-id.cc (tree_evaluator::get_current_scope): New function. * symtab.h, symtab.cc (symbol_table::symbol_reference): Delete class. (symbol_table::dummy_symbol_record): Delete static data member. * oct-lvalue.h, oct-lvalue.cc (octave_lvalue::sym): Use symbol_record, not symbol_reference. Change all uses. (octave_lvalue::black_hole): New data member. (octave_lvalue:is_black_hole): Use it. (octave_lvalue::mark_black_hole): New function. * pt-eval.cc (tree_identifier::sym): Use symbol_record, not symbol_reference. Change all uses. (tree_black_hole::lvalue): Explicitly mark retval as black_hole. (tree_evaluator::visit_tree_identifier): Adapt to tree_identifier::symbol returning symbol_record, not symbol_reference. * oct-parse.in.yy (push_script_symtab, begin_file): New non-terminals. (file): Use begin_file to start script and classdef files. Use separate symbol table scope when parsing scripts. * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::m_scope): Move here from octave_user_fcn. (octave_user_code::scope): Likewise. (octave_user_script::octave_user_script): New argument scope. (octave_user_script::call): Add symbol_table::scope::unbind_script_symbols to unwind_protect frame. Call scope::bind_script_symbols to access evaluation scope. (octave_user_function::octave_user_function): Pass scope argument to octave_user_code base class. * symtab.h, symtab.cc (symbol_record_rep::m_fwd_rep): New data member. Change member functions to forward to secondary rep if it is defined. (symbol_record::bind_fwd_rep, symbol_record_rep::bind_fwd_rep, symbol_record::unbind_fwd_rep, symbol_record_rep::unbind_fwd_rep): New functions. (scope::bind_script_symbols, scope::unbind_script_symbols): New functions. (scope::varval, scope::global_varval, scope::top_level_varval): Now const. (scope::update_nest): Set forwarding rep for nonlocal symbol. (scope::look_nonlocal): Likewise.
author John W. Eaton <jwe@octave.org>
date Wed, 13 Sep 2017 17:10:51 -0400
parents 4b0e0cae49db
children 840882c82e22
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy	Wed Sep 13 16:42:14 2017 -0700
+++ b/libinterp/parse-tree/oct-parse.in.yy	Wed Sep 13 17:10:51 2017 -0400
@@ -230,7 +230,8 @@
 %token<dummy_type> '(' ')' '[' ']' '{' '}' '.' ',' ';' '@' '\n'
 
 // Nonterminals we construct.
-%type <dummy_type> indirect_ref_op decl_param_init push_fcn_symtab
+%type <dummy_type> indirect_ref_op decl_param_init
+%type <dummy_type> push_fcn_symtab push_script_symtab begin_file
 %type <dummy_type> param_list_beg param_list_end stmt_begin parse_error
 %type <dummy_type> parsing_local_fcns
 %type <comment_type> stash_comment
@@ -1438,7 +1439,19 @@
                   { parser.m_parsing_local_functions = true; }
                 ;
 
-file            : INPUT_FILE opt_nl opt_list END_OF_INPUT
+push_script_symtab : // empty
+                  {
+                    $$ = 0;
+
+                    lexer.symtab_context.push (new octave::symbol_table::scope ());
+                  }
+                ;
+
+begin_file      : push_script_symtab INPUT_FILE
+                  { $$ = 0; }
+                ;
+
+file            : begin_file opt_nl opt_list END_OF_INPUT
                   {
                     YYUSE ($2);
 
@@ -1450,6 +1463,9 @@
                         // been stored in the symbol table or in
                         // base_parser::m_primary_fcn_ptr.
 
+                        // Unused symbol table context.
+                        lexer.symtab_context.pop ();
+
                         delete $3;
                       }
                     else
@@ -1464,12 +1480,15 @@
 
                     $$ = nullptr;
                   }
-                | INPUT_FILE opt_nl classdef parsing_local_fcns opt_sep opt_fcn_list END_OF_INPUT
+                | begin_file opt_nl classdef parsing_local_fcns opt_sep opt_fcn_list END_OF_INPUT
                   {
                     YYUSE ($2);
                     YYUSE ($5);
                     YYUSE ($6);
 
+                    // Unused symbol table context.
+                    lexer.symtab_context.pop ();
+
                     if (lexer.reading_classdef_file)
                       parser.m_classdef_object = $3;
 
@@ -3216,8 +3235,10 @@
     octave_user_script *script
       = new octave_user_script (m_lexer.fcn_file_full_name,
                                 m_lexer.fcn_file_name,
+                                m_lexer.symtab_context.curr_scope (),
                                 cmds, m_lexer.help_text);
 
+    m_lexer.symtab_context.pop ();
     m_lexer.help_text = "";
 
     sys::time now;