# HG changeset patch # User John W. Eaton # Date 1328468035 18000 # Node ID 8d1ae996c12228f429ae09b6a3f1584107f18f2b # Parent 19078011cdc30075740cf93e63569900440cd341 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. diff -r 19078011cdc3 -r 8d1ae996c122 src/Makefile.am --- a/src/Makefile.am Sun Feb 05 13:16:07 2012 -0500 +++ b/src/Makefile.am Sun Feb 05 13:53:55 2012 -0500 @@ -284,6 +284,7 @@ ops.h \ pager.h \ parse.h \ + parse-private.h \ pr-output.h \ procstream.h \ profiler.h \ diff -r 19078011cdc3 -r 8d1ae996c122 src/lex.ll --- a/src/lex.ll Sun Feb 05 13:16:07 2012 -0500 +++ b/src/lex.ll Sun Feb 05 13:53:55 2012 -0500 @@ -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; diff -r 19078011cdc3 -r 8d1ae996c122 src/oct-parse.yy --- a/src/oct-parse.yy Sun Feb 05 13:16:07 2012 -0500 +++ b/src/oct-parse.yy Sun Feb 05 13:53:55 2012 -0500 @@ -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 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) diff -r 19078011cdc3 -r 8d1ae996c122 src/parse.h --- a/src/parse.h Sun Feb 05 13:16:07 2012 -0500 +++ b/src/parse.h Sun Feb 05 13:53:55 2012 -0500 @@ -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 symtab_context; - // Name of the current class when we are parsing class methods or // constructors. extern std::string current_class_name; diff -r 19078011cdc3 -r 8d1ae996c122 test/Makefile.am --- a/test/Makefile.am Sun Feb 05 13:16:07 2012 -0500 +++ b/test/Makefile.am Sun Feb 05 13:53:55 2012 -0500 @@ -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 diff -r 19078011cdc3 -r 8d1ae996c122 test/bug-35448/fA.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-35448/fA.m Sun Feb 05 13:53:55 2012 -0500 @@ -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 diff -r 19078011cdc3 -r 8d1ae996c122 test/bug-35448/fB.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-35448/fB.m Sun Feb 05 13:53:55 2012 -0500 @@ -0,0 +1,4 @@ +# fB.m +function y = fB (x) + y = x; +endfunction diff -r 19078011cdc3 -r 8d1ae996c122 test/bug-35448/fC.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-35448/fC.m Sun Feb 05 13:53:55 2012 -0500 @@ -0,0 +1,4 @@ +# fC.m +function y = fC (x) + y = x; +endfunction diff -r 19078011cdc3 -r 8d1ae996c122 test/bug-35448/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-35448/module.mk Sun Feb 05 13:53:55 2012 -0500 @@ -0,0 +1,7 @@ +bug_35448_FCN_FILES = \ + bug-35448/fA.m \ + bug-35448/fB.m \ + bug-35448/fC.m \ + class-concat/test_bug_35448.m + +FCN_FILES += $(bug_35448_FCN_FILES) diff -r 19078011cdc3 -r 8d1ae996c122 test/bug-35448/test_bug_35448.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-35448/test_bug_35448.m Sun Feb 05 13:53:55 2012 -0500 @@ -0,0 +1,11 @@ +%!test +%! global gfun +%! gfun = @fB; +%! y = fA (e); +%! assert (y, e); + +%!test +%! global gfun +%! gfun = @fC; +%! y = fA (e); +%! assert (y, e);