Mercurial > hg > octave-terminal
changeset 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 | 19078011cdc3 |
children | 23782766da08 |
files | src/Makefile.am src/lex.ll src/oct-parse.yy src/parse.h test/Makefile.am test/bug-35448/fA.m test/bug-35448/fB.m test/bug-35448/fC.m test/bug-35448/module.mk test/bug-35448/test_bug_35448.m |
diffstat | 10 files changed, 51 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am +++ b/src/Makefile.am @@ -284,6 +284,7 @@ ops.h \ pager.h \ parse.h \ + parse-private.h \ pr-output.h \ procstream.h \ profiler.h \
--- a/src/lex.ll +++ b/src/lex.ll @@ -68,6 +68,7 @@ #include "lex.h" #include "ov.h" #include "parse.h" +#include "parse-private.h" #include "pt-all.h" #include "symtab.h" #include "token.h" @@ -1113,8 +1114,7 @@ parser_end_of_input = false; - while (! symtab_context.empty ()) - symtab_context.pop (); + parser_symtab_context.clear (); // We do want a prompt by default. promptflag = 1;
--- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -68,6 +68,7 @@ #include "toplev.h" #include "pager.h" #include "parse.h" +#include "parse-private.h" #include "pt-all.h" #include "pt-eval.h" #include "symtab.h" @@ -126,7 +127,7 @@ static bool endfunction_found = false; // Keep track of symbol table information when parsing functions. -std::stack<symbol_table::scope_id> symtab_context; +symtab_context parser_symtab_context; // Name of the current class when we are parsing class methods or // constructors. @@ -365,11 +366,8 @@ { \ global_command = 0; \ yyerrok; \ - if (! symtab_context.empty ()) \ - { \ - symbol_table::set_scope (symtab_context.top ()); \ - symtab_context.pop (); \ - } \ + if (! parser_symtab_context.empty ()) \ + parser_symtab_context.pop (); \ if (interactive || forced_interactive) \ YYACCEPT; \ else \ @@ -1224,7 +1222,8 @@ if (max_function_depth < current_function_depth) max_function_depth = current_function_depth; - symtab_context.push (symbol_table::current_scope ()); + parser_symtab_context.push (); + symbol_table::set_scope (symbol_table::alloc_scope ()); if (! reading_script_file && current_function_depth == 1 @@ -1246,7 +1245,7 @@ if (lexer_flags.looking_at_function_handle) { - symtab_context.push (symbol_table::current_scope ()); + parser_symtab_context.push (); symbol_table::set_scope (symbol_table::alloc_scope ()); lexer_flags.looking_at_function_handle--; lexer_flags.looking_at_anon_fcn_args = true; @@ -2124,12 +2123,10 @@ symbol_table::scope_id fcn_scope = symbol_table::current_scope (); - if (symtab_context.empty ()) + if (parser_symtab_context.empty ()) panic_impossible (); - symbol_table::set_scope (symtab_context.top ()); - - symtab_context.pop (); + parser_symtab_context.pop (); stmt->set_print_flag (false); @@ -2972,11 +2969,10 @@ static void recover_from_parsing_function (void) { - if (symtab_context.empty ()) + if (parser_symtab_context.empty ()) panic_impossible (); - symbol_table::set_scope (symtab_context.top ()); - symtab_context.pop (); + parser_symtab_context.pop (); if (reading_fcn_file && current_function_depth == 1 && ! parsing_subfunctions)
--- a/src/parse.h +++ b/src/parse.h @@ -62,9 +62,6 @@ // TRUE means input is coming from startup file. extern bool input_from_startup_file; -// Keep track of symbol table information when parsing functions. -extern std::stack<symbol_table::scope_id> symtab_context; - // Name of the current class when we are parsing class methods or // constructors. extern std::string current_class_name;
--- a/test/Makefile.am +++ b/test/Makefile.am @@ -49,6 +49,7 @@ test_unwind.m \ test_while.m +include bug-35448/module.mk include classes/module.mk include class-concat/module.mk include ctor-vs-method/module.mk
new file mode 100644 --- /dev/null +++ b/test/bug-35448/fA.m @@ -0,0 +1,10 @@ +# fA.m +function y = fA (x, f) + global gfun + if nargin < 2 + y = fA (x, gfun); + else + w = feval (f, x); + y = feval (@fB, w); + endif +endfunction
new file mode 100644 --- /dev/null +++ b/test/bug-35448/fB.m @@ -0,0 +1,4 @@ +# fB.m +function y = fB (x) + y = x; +endfunction
new file mode 100644 --- /dev/null +++ b/test/bug-35448/fC.m @@ -0,0 +1,4 @@ +# fC.m +function y = fC (x) + y = x; +endfunction