changeset 11464:21b5284fa78d

avoid error when parsing nested functions
author John W. Eaton <jwe@octave.org>
date Sun, 09 Jan 2011 14:33:55 -0500
parents ae96756561d0
children fb98284fcc20
files src/ChangeLog src/lex.h src/lex.ll src/oct-parse.yy
diffstat 4 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2011-01-09  John W. Eaton  <jwe@octave.org>
+
+	* lex.h, lex.ll, oct-parse.yy (lexer_flags::parsed_function_name):
+	Declare to be std::stack<bool> instead of bool.  Change all uses.
+	Bug #32083.
+
 2011-01-08  Konstantinos Poulios  <logari81@googlemail.com>
 
 	* gl-render.cc (opengl_renderer::draw_axes): Revert positionmode
--- a/src/lex.h
+++ b/src/lex.h
@@ -25,6 +25,7 @@
 #define octave_lex_h 1
 
 #include <list>
+#include <stack>
 
 // FIXME -- these input buffer things should be members of a
 // parser input stream class.
@@ -117,9 +118,10 @@
   // structure element.
   bool looking_at_indirect_ref;
 
-  // TRUE means that we've already seen the name of this function.
-  // Should only matter if current_function_level > 0
-  bool parsed_function_name;
+  // If the top of the stack is TRUE, then we've already seen the name
+  // of the current function.  Should only matter if
+  // current_function_level > 0
+  std::stack<bool> parsed_function_name;
 
   // TRUE means we are parsing a class method in function or classdef file.
   bool parsing_class_method;
--- a/src/lex.ll
+++ b/src/lex.ll
@@ -617,7 +617,8 @@
     lexer_flags.looking_for_object_index = false;
     lexer_flags.at_beginning_of_statement = false;
 
-    if (lexer_flags.defining_func && ! lexer_flags.parsed_function_name)
+    if (lexer_flags.defining_func
+        && ! lexer_flags.parsed_function_name.top ())
       lexer_flags.looking_at_return_list = true;
     else
       lexer_flags.looking_at_matrix_or_assign_lhs = true;
@@ -1470,7 +1471,7 @@
               && (inside_any_object_index ()
                   || (lexer_flags.defining_func
                       && ! (lexer_flags.looking_at_return_list
-                            || lexer_flags.parsed_function_name))))
+                            || lexer_flags.parsed_function_name.top ()))))
             return 0;
 
           yylval.tok_val = new token (token::simple_end, l, c);
@@ -1581,7 +1582,7 @@
           promptflag--;
 
           lexer_flags.defining_func++;
-          lexer_flags.parsed_function_name = false;
+          lexer_flags.parsed_function_name.push (false);
 
           if (! (reading_fcn_file || reading_script_file
                  || reading_classdef_file))
@@ -3333,7 +3334,11 @@
 
   // Not initially defining a function.
   defining_func = 0;
-  parsed_function_name = false;
+
+  // Not parsing an object index.
+  while (! parsed_function_name.empty ())
+    parsed_function_name.pop ();
+
   parsing_class_method = false;
   
   // Not initially defining a class with classdef.
--- a/src/oct-parse.yy
+++ b/src/oct-parse.yy
@@ -1377,7 +1377,7 @@
                   {
                     std::string id_name = $1->name ();
 
-                    lexer_flags.parsed_function_name = true;
+                    lexer_flags.parsed_function_name.top () = true;
                     lexer_flags.maybe_classdef_get_set_method = false;
             
                     $$ = $1;
@@ -2998,7 +2998,7 @@
   current_function_depth--;
 
   lexer_flags.defining_func--;
-  lexer_flags.parsed_function_name = false;
+  lexer_flags.parsed_function_name.pop ();
   lexer_flags.looking_at_return_list = false;
   lexer_flags.looking_at_parameter_list = false;
 }