comparison 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
comparison
equal deleted inserted replaced
16319:54c4b4b58a24 16320:09f0cb9cac7d
40 40
41 class 41 class
42 lexical_feedback 42 lexical_feedback
43 { 43 {
44 public: 44 public:
45
46 // Track symbol table information when parsing functions.
47
48 class symbol_table_context
49 {
50 public:
51
52 symbol_table_context (void)
53 : frame_stack (), init_scope (symbol_table::current_scope ())
54 {
55 push (init_scope);
56 }
57
58 void clear (void)
59 {
60 while (! frame_stack.empty ())
61 frame_stack.pop ();
62
63 push (init_scope);
64 }
65
66 bool empty (void) const { return frame_stack.empty (); }
67
68 void pop (void)
69 {
70 frame_stack.pop ();
71 }
72
73 void push (symbol_table::scope_id scope)
74 {
75 frame_stack.push (scope);
76 }
77
78 void push (void)
79 {
80 push (symbol_table::current_scope ());
81 }
82
83 symbol_table::scope_id curr_scope (void) const
84 {
85 return frame_stack.top ();
86 }
87
88 private:
89
90 std::stack<symbol_table::scope_id> frame_stack;
91
92 symbol_table::scope_id init_scope;
93 };
45 94
46 // Track nesting of square brackets, curly braces, and parentheses. 95 // Track nesting of square brackets, curly braces, and parentheses.
47 96
48 class bbp_nesting_level 97 class bbp_nesting_level
49 { 98 {
231 looping (0), defining_func (0), looking_at_function_handle (0), 280 looping (0), defining_func (0), looking_at_function_handle (0),
232 block_comment_nesting_level (0), token_count (0), 281 block_comment_nesting_level (0), token_count (0),
233 current_input_line (), comment_text (), help_text (), 282 current_input_line (), comment_text (), help_text (),
234 fcn_file_name (), fcn_file_full_name (), looking_at_object_index (), 283 fcn_file_name (), fcn_file_full_name (), looking_at_object_index (),
235 parsed_function_name (), pending_local_variables (), 284 parsed_function_name (), pending_local_variables (),
236 nesting_level (), tokens () 285 symtab_context (), nesting_level (), tokens ()
237 { 286 {
238 init (); 287 init ();
239 } 288 }
240 289
241 ~lexical_feedback (void); 290 ~lexical_feedback (void);
372 // current_function_level > 0 421 // current_function_level > 0
373 std::stack<bool> parsed_function_name; 422 std::stack<bool> parsed_function_name;
374 423
375 // set of identifiers that might be local variable names. 424 // set of identifiers that might be local variable names.
376 std::set<std::string> pending_local_variables; 425 std::set<std::string> pending_local_variables;
426
427 // Track current symbol table scope and context.
428 symbol_table_context symtab_context;
377 429
378 // is the closest nesting level a square bracket, squiggly brace, 430 // is the closest nesting level a square bracket, squiggly brace,
379 // a paren, or an anonymous function body? 431 // a paren, or an anonymous function body?
380 bbp_nesting_level nesting_level; 432 bbp_nesting_level nesting_level;
381 433