comparison 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
comparison
equal deleted inserted replaced
24036:2932a325930c 24037:21915520ac7b
228 // %token VARARGIN VARARGOUT 228 // %token VARARGIN VARARGOUT
229 229
230 %token<dummy_type> '(' ')' '[' ']' '{' '}' '.' ',' ';' '@' '\n' 230 %token<dummy_type> '(' ')' '[' ']' '{' '}' '.' ',' ';' '@' '\n'
231 231
232 // Nonterminals we construct. 232 // Nonterminals we construct.
233 %type <dummy_type> indirect_ref_op decl_param_init push_fcn_symtab 233 %type <dummy_type> indirect_ref_op decl_param_init
234 %type <dummy_type> push_fcn_symtab push_script_symtab begin_file
234 %type <dummy_type> param_list_beg param_list_end stmt_begin parse_error 235 %type <dummy_type> param_list_beg param_list_end stmt_begin parse_error
235 %type <dummy_type> parsing_local_fcns 236 %type <dummy_type> parsing_local_fcns
236 %type <comment_type> stash_comment 237 %type <comment_type> stash_comment
237 %type <tok_val> function_beg classdef_beg 238 %type <tok_val> function_beg classdef_beg
238 %type <punct_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep 239 %type <punct_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep
1436 parsing_local_fcns 1437 parsing_local_fcns
1437 : // empty 1438 : // empty
1438 { parser.m_parsing_local_functions = true; } 1439 { parser.m_parsing_local_functions = true; }
1439 ; 1440 ;
1440 1441
1441 file : INPUT_FILE opt_nl opt_list END_OF_INPUT 1442 push_script_symtab : // empty
1443 {
1444 $$ = 0;
1445
1446 lexer.symtab_context.push (new octave::symbol_table::scope ());
1447 }
1448 ;
1449
1450 begin_file : push_script_symtab INPUT_FILE
1451 { $$ = 0; }
1452 ;
1453
1454 file : begin_file opt_nl opt_list END_OF_INPUT
1442 { 1455 {
1443 YYUSE ($2); 1456 YYUSE ($2);
1444 1457
1445 if (lexer.reading_fcn_file) 1458 if (lexer.reading_fcn_file)
1446 { 1459 {
1447 // Delete the dummy statement_list we created 1460 // Delete the dummy statement_list we created
1448 // after parsing the function. Any function 1461 // after parsing the function. Any function
1449 // definitions found in the file have already 1462 // definitions found in the file have already
1450 // been stored in the symbol table or in 1463 // been stored in the symbol table or in
1451 // base_parser::m_primary_fcn_ptr. 1464 // base_parser::m_primary_fcn_ptr.
1465
1466 // Unused symbol table context.
1467 lexer.symtab_context.pop ();
1452 1468
1453 delete $3; 1469 delete $3;
1454 } 1470 }
1455 else 1471 else
1456 { 1472 {
1462 parser.make_script ($3, end_of_script); 1478 parser.make_script ($3, end_of_script);
1463 } 1479 }
1464 1480
1465 $$ = nullptr; 1481 $$ = nullptr;
1466 } 1482 }
1467 | INPUT_FILE opt_nl classdef parsing_local_fcns opt_sep opt_fcn_list END_OF_INPUT 1483 | begin_file opt_nl classdef parsing_local_fcns opt_sep opt_fcn_list END_OF_INPUT
1468 { 1484 {
1469 YYUSE ($2); 1485 YYUSE ($2);
1470 YYUSE ($5); 1486 YYUSE ($5);
1471 YYUSE ($6); 1487 YYUSE ($6);
1488
1489 // Unused symbol table context.
1490 lexer.symtab_context.pop ();
1472 1491
1473 if (lexer.reading_classdef_file) 1492 if (lexer.reading_classdef_file)
1474 parser.m_classdef_object = $3; 1493 parser.m_classdef_object = $3;
1475 1494
1476 $$ = nullptr; 1495 $$ = nullptr;
3214 cmds->append (end_script); 3233 cmds->append (end_script);
3215 3234
3216 octave_user_script *script 3235 octave_user_script *script
3217 = new octave_user_script (m_lexer.fcn_file_full_name, 3236 = new octave_user_script (m_lexer.fcn_file_full_name,
3218 m_lexer.fcn_file_name, 3237 m_lexer.fcn_file_name,
3238 m_lexer.symtab_context.curr_scope (),
3219 cmds, m_lexer.help_text); 3239 cmds, m_lexer.help_text);
3220 3240
3241 m_lexer.symtab_context.pop ();
3221 m_lexer.help_text = ""; 3242 m_lexer.help_text = "";
3222 3243
3223 sys::time now; 3244 sys::time now;
3224 3245
3225 script->stash_fcn_file_time (now); 3246 script->stash_fcn_file_time (now);