comparison src/oct-parse.yy @ 14329:8d1ae996c122

also save and restore symbol table context in parser (bug #35448) * parse-private.h: New file to define new symtab_context class. * Makefile.am (octinclude_HEADERS): Include it in the list. * lex.ll, oct-parse.yy: Include parse-private.h. * lex.ll (reset_parser): Clear parser_symtab_context. * parse.h (symtab_context): Delete variable declaration. * oct-parse.yy (symtab_context): Delete variable definition. (parser_symtab_context): New variable. (ABORT_PARSE, make_anon_fcn_handle, recover_from_parsing_function): Pop parser_symtab_context. (push_fcn_symtab, param_list_beg): Push parser_symtab_context.
author John W. Eaton <jwe@octave.org>
date Sun, 05 Feb 2012 13:53:55 -0500
parents 9e3983c8963c
children 97883071e8e4
comparison
equal deleted inserted replaced
14328:19078011cdc3 14329:8d1ae996c122
66 #include "ov-usr-fcn.h" 66 #include "ov-usr-fcn.h"
67 #include "ov-null-mat.h" 67 #include "ov-null-mat.h"
68 #include "toplev.h" 68 #include "toplev.h"
69 #include "pager.h" 69 #include "pager.h"
70 #include "parse.h" 70 #include "parse.h"
71 #include "parse-private.h"
71 #include "pt-all.h" 72 #include "pt-all.h"
72 #include "pt-eval.h" 73 #include "pt-eval.h"
73 #include "symtab.h" 74 #include "symtab.h"
74 #include "token.h" 75 #include "token.h"
75 #include "unwind-prot.h" 76 #include "unwind-prot.h"
124 125
125 // Have we found an explicit end to a function? 126 // Have we found an explicit end to a function?
126 static bool endfunction_found = false; 127 static bool endfunction_found = false;
127 128
128 // Keep track of symbol table information when parsing functions. 129 // Keep track of symbol table information when parsing functions.
129 std::stack<symbol_table::scope_id> symtab_context; 130 symtab_context parser_symtab_context;
130 131
131 // Name of the current class when we are parsing class methods or 132 // Name of the current class when we are parsing class methods or
132 // constructors. 133 // constructors.
133 std::string current_class_name; 134 std::string current_class_name;
134 135
363 #define ABORT_PARSE \ 364 #define ABORT_PARSE \
364 do \ 365 do \
365 { \ 366 { \
366 global_command = 0; \ 367 global_command = 0; \
367 yyerrok; \ 368 yyerrok; \
368 if (! symtab_context.empty ()) \ 369 if (! parser_symtab_context.empty ()) \
369 { \ 370 parser_symtab_context.pop (); \
370 symbol_table::set_scope (symtab_context.top ()); \
371 symtab_context.pop (); \
372 } \
373 if (interactive || forced_interactive) \ 371 if (interactive || forced_interactive) \
374 YYACCEPT; \ 372 YYACCEPT; \
375 else \ 373 else \
376 YYABORT; \ 374 YYABORT; \
377 } \ 375 } \
1222 current_function_depth++; 1220 current_function_depth++;
1223 1221
1224 if (max_function_depth < current_function_depth) 1222 if (max_function_depth < current_function_depth)
1225 max_function_depth = current_function_depth; 1223 max_function_depth = current_function_depth;
1226 1224
1227 symtab_context.push (symbol_table::current_scope ()); 1225 parser_symtab_context.push ();
1226
1228 symbol_table::set_scope (symbol_table::alloc_scope ()); 1227 symbol_table::set_scope (symbol_table::alloc_scope ());
1229 1228
1230 if (! reading_script_file && current_function_depth == 1 1229 if (! reading_script_file && current_function_depth == 1
1231 && ! parsing_subfunctions) 1230 && ! parsing_subfunctions)
1232 primary_fcn_scope = symbol_table::current_scope (); 1231 primary_fcn_scope = symbol_table::current_scope ();
1244 { 1243 {
1245 lexer_flags.looking_at_parameter_list = true; 1244 lexer_flags.looking_at_parameter_list = true;
1246 1245
1247 if (lexer_flags.looking_at_function_handle) 1246 if (lexer_flags.looking_at_function_handle)
1248 { 1247 {
1249 symtab_context.push (symbol_table::current_scope ()); 1248 parser_symtab_context.push ();
1250 symbol_table::set_scope (symbol_table::alloc_scope ()); 1249 symbol_table::set_scope (symbol_table::alloc_scope ());
1251 lexer_flags.looking_at_function_handle--; 1250 lexer_flags.looking_at_function_handle--;
1252 lexer_flags.looking_at_anon_fcn_args = true; 1251 lexer_flags.looking_at_anon_fcn_args = true;
1253 } 1252 }
1254 } 1253 }
2122 2121
2123 tree_parameter_list *ret_list = 0; 2122 tree_parameter_list *ret_list = 0;
2124 2123
2125 symbol_table::scope_id fcn_scope = symbol_table::current_scope (); 2124 symbol_table::scope_id fcn_scope = symbol_table::current_scope ();
2126 2125
2127 if (symtab_context.empty ()) 2126 if (parser_symtab_context.empty ())
2128 panic_impossible (); 2127 panic_impossible ();
2129 2128
2130 symbol_table::set_scope (symtab_context.top ()); 2129 parser_symtab_context.pop ();
2131
2132 symtab_context.pop ();
2133 2130
2134 stmt->set_print_flag (false); 2131 stmt->set_print_flag (false);
2135 2132
2136 tree_statement_list *body = new tree_statement_list (stmt); 2133 tree_statement_list *body = new tree_statement_list (stmt);
2137 2134
2970 } 2967 }
2971 2968
2972 static void 2969 static void
2973 recover_from_parsing_function (void) 2970 recover_from_parsing_function (void)
2974 { 2971 {
2975 if (symtab_context.empty ()) 2972 if (parser_symtab_context.empty ())
2976 panic_impossible (); 2973 panic_impossible ();
2977 2974
2978 symbol_table::set_scope (symtab_context.top ()); 2975 parser_symtab_context.pop ();
2979 symtab_context.pop ();
2980 2976
2981 if (reading_fcn_file && current_function_depth == 1 2977 if (reading_fcn_file && current_function_depth == 1
2982 && ! parsing_subfunctions) 2978 && ! parsing_subfunctions)
2983 parsing_subfunctions = true; 2979 parsing_subfunctions = true;
2984 2980