changeset 16199:810a71122c25

move more global variables to octave_lexical_feedback class * help.cc (raw_help_from_file): Don't protect and set reading_script_file. * octave.cc (likewise): * oct_parse.in.yy (parse_fcn_file): Don't protect reading_script_file. * input.cc (get_debug_input): Don't protect and set reading_fcn_file, reading_classdef_file, or reading_script_file. * lex.h, lex.ll, input.h, input.cc (reading_fcn_file, reading_classdef_file, reading_script_file): Declare as members of the lexical_feedback class. Change all uses. (lexical_feedback::lexical_feedback, lexical_feedback::reset): Initialize and set them.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Mar 2013 17:50:37 -0500
parents 2c5c538be353
children 743b895259e0
files libinterp/interpfcn/help.cc libinterp/interpfcn/input.cc libinterp/interpfcn/input.h libinterp/octave.cc libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy
diffstat 7 files changed, 57 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/help.cc	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/interpfcn/help.cc	Tue Mar 05 17:50:37 2013 -0500
@@ -902,11 +902,6 @@
 {
   bool retval = false;
 
-  // FIXME -- this is a bit of a kluge...
-  unwind_protect frame;
-  frame.protect_var (reading_script_file);
-  reading_script_file = true;
-
   h = get_help_from_file (nm, symbol_found, file);
 
   if (h.length () > 0)
--- a/libinterp/interpfcn/input.cc	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/interpfcn/input.cc	Tue Mar 05 17:50:37 2013 -0500
@@ -101,21 +101,12 @@
 // TRUE means that stdin is a terminal, not a pipe or redirected file.
 bool stdin_is_tty = false;
 
-// TRUE means we're parsing a function file.
-bool reading_fcn_file = false;
-
-// TRUE means we're parsing a classdef file.
-bool reading_classdef_file = false;
-
 // Simple name of function file we are reading.
 std::string curr_fcn_file_name;
 
 // Full name of file we are reading.
 std::string curr_fcn_file_full_name;
 
-// TRUE means we're parsing a script file.
-bool reading_script_file = false;
-
 // TRUE means this is an interactive shell.
 bool interactive = false;
 
@@ -151,7 +142,7 @@
 static void
 do_input_echo (const std::string& input_string)
 {
-  int do_echo = reading_script_file ?
+  int do_echo = CURR_LEXER->reading_script_file ?
     (Vecho_executing_commands & ECHO_SCRIPTS)
       : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive;
 
@@ -527,9 +518,9 @@
   VPS1 = prompt;
 
   if (! (interactive || forced_interactive)
-      || (reading_fcn_file
-          || reading_classdef_file
-          || reading_script_file
+      || (CURR_LEXER->reading_fcn_file
+          || CURR_LEXER->reading_classdef_file
+          || CURR_LEXER->reading_script_file
           || CURR_LEXER->input_from_eval_string ()
           || input_from_startup_file
           || input_from_command_line_file))
@@ -537,15 +528,6 @@
       frame.protect_var (forced_interactive);
       forced_interactive = true;
 
-      frame.protect_var (reading_fcn_file);
-      reading_fcn_file = false;
-
-      frame.protect_var (reading_classdef_file);
-      reading_classdef_file = false;
-
-      frame.protect_var (reading_script_file);
-      reading_script_file = false;
-
       frame.protect_var (input_from_startup_file);
       input_from_startup_file = false;
 
--- a/libinterp/interpfcn/input.h	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/interpfcn/input.h	Tue Mar 05 17:50:37 2013 -0500
@@ -44,21 +44,12 @@
 // TRUE means that stdin is a terminal, not a pipe or redirected file.
 extern bool stdin_is_tty;
 
-// TRUE means we're parsing a function file.
-extern bool reading_fcn_file;
-
 // Simple name of function file we are reading.
 extern std::string curr_fcn_file_name;
 
 // Full name of file we are reading.
 extern std::string curr_fcn_file_full_name;
 
-// TRUE means we're parsing a script file.
-extern bool reading_script_file;
-
-// TRUE means we're parsing a classdef file.
-extern bool reading_classdef_file;
-
 // Fix things up so that input can come from file 'name', printing a
 // warning if the file doesn't exist.
 
--- a/libinterp/octave.cc	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/octave.cc	Tue Mar 05 17:50:37 2013 -0500
@@ -488,7 +488,6 @@
   octave_initialized = true;
 
   frame.protect_var (interactive);
-  frame.protect_var (reading_script_file);
   frame.protect_var (input_from_command_line_file);
 
   frame.protect_var (curr_fcn_file_name);
@@ -498,7 +497,6 @@
   frame.protect_var (octave_program_name);
 
   interactive = false;
-  reading_script_file = true;
   input_from_command_line_file = true;
 
   curr_fcn_file_name = fname;
--- a/libinterp/parse-tree/lex.h	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/parse-tree/lex.h	Tue Mar 05 17:50:37 2013 -0500
@@ -170,7 +170,8 @@
       looking_for_object_index (false), 
       looking_at_indirect_ref (false), parsing_class_method (false),
       maybe_classdef_get_set_method (false), parsing_classdef (false),
-      quote_is_transpose (false),
+      quote_is_transpose (false), reading_fcn_file (false),
+      reading_script_file (false), reading_classdef_file (false),
       input_line_number (1), current_input_column (1),
       bracketflag (0), braceflag (0),
       looping (0), defining_func (0), looking_at_function_handle (0),
@@ -243,6 +244,15 @@
   // return transpose or start a string?
   bool quote_is_transpose;
 
+  // TRUE means we're parsing a function file.
+  bool reading_fcn_file;
+
+  // TRUE means we're parsing a script file.
+  bool reading_script_file;
+
+  // TRUE means we're parsing a classdef file.
+  bool reading_classdef_file;
+
   // the current input line number.
   int input_line_number;
 
--- a/libinterp/parse-tree/lex.ll	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/parse-tree/lex.ll	Tue Mar 05 17:50:37 2013 -0500
@@ -1324,6 +1324,9 @@
   maybe_classdef_get_set_method = false;
   parsing_classdef = false;
   quote_is_transpose = false;
+  reading_fcn_file = false;
+  reading_script_file = false;
+  reading_classdef_file = false;
   input_line_number = 1;
   current_input_column = 1;
   bracketflag = 0;
--- a/libinterp/parse-tree/oct-parse.in.yy	Tue Mar 05 17:43:00 2013 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Tue Mar 05 17:50:37 2013 -0500
@@ -1013,11 +1013,11 @@
 
                     curr_parser.function_scopes.push_back (symbol_table::current_scope ());
 
-                    if (! reading_script_file && curr_parser.curr_fcn_depth == 1
+                    if (! curr_lexer->reading_script_file && curr_parser.curr_fcn_depth == 1
                         && ! curr_parser.parsing_subfunctions)
                       curr_parser.primary_fcn_scope = symbol_table::current_scope ();
 
-                    if (reading_script_file && curr_parser.curr_fcn_depth > 1)
+                    if (curr_lexer->reading_script_file && curr_parser.curr_fcn_depth > 1)
                       curr_parser.bison_error ("nested functions not implemented in this context");
                   }
                 ;
@@ -1154,7 +1154,7 @@
                   {
                     $$ = $3;
 
-                    if (reading_classdef_file || curr_lexer->parsing_classdef)
+                    if (curr_lexer->reading_classdef_file || curr_lexer->parsing_classdef)
                       curr_lexer->maybe_classdef_get_set_method = true;
                   }
                 ;
@@ -1222,7 +1222,7 @@
                 | END_OF_INPUT
                   {
 // A lot of tests are based on the assumption that this is OK
-//                  if (reading_script_file)
+//                  if (curr_lexer->reading_script_file)
 //                    {
 //                      curr_parser.bison_error ("function body open at end of script");
 //                      YYABORT;
@@ -1236,14 +1236,14 @@
                         YYABORT;
                       }
 
-                    if (! (reading_fcn_file || reading_script_file
+                    if (! (curr_lexer->reading_fcn_file || curr_lexer->reading_script_file
                            || (curr_lexer)->input_from_eval_string ()))
                       {
                         curr_parser.bison_error ("function body open at end of input");
                         YYABORT;
                       }
 
-                    if (reading_classdef_file)
+                    if (curr_lexer->reading_classdef_file)
                       {
                         curr_parser.bison_error ("classdef body open at end of input");
                         YYABORT;
@@ -2654,7 +2654,7 @@
   // the file does not match the name of the function stated in the
   // file.  Matlab doesn't provide a diagnostic (it ignores the stated
   // name).
-  if (! autoloading && reading_fcn_file
+  if (! autoloading && curr_lexer->reading_fcn_file
       && curr_fcn_depth == 1 && ! parsing_subfunctions)
   {
     // FIXME -- should curr_fcn_file_name already be
@@ -2679,7 +2679,7 @@
       }
   }
 
-  if (reading_fcn_file || reading_classdef_file || autoloading)
+  if (curr_lexer->reading_fcn_file || curr_lexer->reading_classdef_file || autoloading)
     {
       octave_time now;
 
@@ -2719,7 +2719,7 @@
                          "time stamp for '%s' is in the future", nm.c_str ());
     }
   else if (! (input_from_tmp_history_file || input_from_startup_file)
-           && reading_script_file
+           && curr_lexer->reading_script_file
            && curr_fcn_file_name == id_name)
     {
       warning ("function '%s' defined within script file '%s'",
@@ -2738,7 +2738,7 @@
       help_buf.pop ();
     }
 
-  if (reading_fcn_file && curr_fcn_depth == 1
+  if (curr_lexer->reading_fcn_file && curr_fcn_depth == 1
       && ! parsing_subfunctions)
     primary_fcn_ptr = fcn;
 
@@ -2791,7 +2791,7 @@
       if (curr_fcn_depth == 1 && fcn)
         symbol_table::update_nest (fcn->scope ());
 
-      if (! reading_fcn_file && curr_fcn_depth == 1)
+      if (! curr_lexer->reading_fcn_file && curr_fcn_depth == 1)
         {
           // We are either reading a script file or defining a function
           // at the command line, so this definition creates a
@@ -2824,7 +2824,7 @@
 
   parser_symtab_context.pop ();
 
-  if (reading_fcn_file && curr_fcn_depth == 1
+  if (curr_lexer->reading_fcn_file && curr_fcn_depth == 1
       && ! parsing_subfunctions)
     parsing_subfunctions = true;
 
@@ -2945,7 +2945,7 @@
         retval = new tree_persistent_command (lst, l, c);
       else
         {
-          if (reading_script_file)
+          if (curr_lexer->reading_script_file)
             warning ("ignoring persistent declaration near line %d of file '%s'",
                      l, curr_fcn_file_full_name.c_str ());
           else
@@ -3098,7 +3098,7 @@
 
   std::ostringstream output_buf;
 
-  if (reading_fcn_file || reading_script_file || reading_classdef_file)
+  if (curr_lexer->reading_fcn_file || curr_lexer->reading_script_file || curr_lexer->reading_classdef_file)
     output_buf << "parse error near line " << curr_lexer->input_line_number
                << " of file " << curr_fcn_file_full_name;
   else
@@ -3375,10 +3375,8 @@
 
   frame.add_fcn (command_editor::set_input_stream, in_stream);
 
-  frame.protect_var (reading_fcn_file);
   frame.protect_var (line_editing);
 
-  reading_fcn_file = true;
   line_editing = false;
 
   frame.add_fcn (command_history::ignore_entries,
@@ -3402,6 +3400,8 @@
 
       octave_parser curr_parser (ffile);
 
+      curr_parser.curr_lexer->reading_fcn_file = true;
+
       curr_parser.curr_class_name = dispatch_type;
       curr_parser.autoloading = autoload;
       curr_parser.fcn_file_from_relative_lookup = relative_lookup;
@@ -3419,44 +3419,36 @@
         {
           std::string file_type;
 
-          frame.protect_var (reading_fcn_file);
-          frame.protect_var (reading_script_file);
-          frame.protect_var (reading_classdef_file);
           frame.protect_var (Vecho_executing_commands);
 
+          Vecho_executing_commands = ECHO_OFF;
+
           if (! force_script && looking_at_function_keyword (ffile))
             {
               file_type = "function";
-
-              Vecho_executing_commands = ECHO_OFF;
-
-              reading_classdef_file = false;
-              reading_fcn_file = true;
-              reading_script_file = false;
-            }
-          else if (! force_script && looking_at_classdef_keyword (ffile))
-            {
-              file_type = "classdef";
-
-              Vecho_executing_commands = ECHO_OFF;
-
-              reading_classdef_file = true;
-              reading_fcn_file = false;
-              // FIXME -- Should classdef files be handled as
-              // scripts or separately?  Currently, without setting up
-              // for reading script files, parsing classdef files
-              // fails.
-              reading_script_file = true;
             }
           else
             {
-              file_type = "script";
-
-              Vecho_executing_commands = ECHO_OFF;
-
-              reading_classdef_file = false;
-              reading_fcn_file = false;
-              reading_script_file = true;
+              curr_parser.curr_lexer->reading_fcn_file = false;
+
+              if (! force_script && looking_at_classdef_keyword (ffile))
+                {
+                  file_type = "classdef";
+
+                  curr_parser.curr_lexer->reading_classdef_file = true;
+
+                  // FIXME -- Should classdef files be handled as
+                  // scripts or separately?  Currently, without
+                  // setting up for reading script files, parsing
+                  // classdef files fails.
+                  curr_parser.curr_lexer->reading_script_file = true;
+                }
+              else
+                {
+                  file_type = "script";
+
+                  curr_parser.curr_lexer->reading_script_file = true;
+                }
             }
 
           // Do this with an unwind-protect cleanup function so that
@@ -3468,7 +3460,7 @@
           if (! help_txt.empty ())
             help_buf.push (help_txt);
 
-          if (reading_script_file)
+          if (curr_parser.curr_lexer->reading_script_file)
             curr_parser.curr_lexer->prep_for_script_file ();
           else
             curr_parser.curr_lexer->prep_for_function_file ();
@@ -4192,14 +4184,8 @@
   octave_parser curr_parser (eval_str);
 
   frame.protect_var (line_editing);
-  frame.protect_var (reading_fcn_file);
-  frame.protect_var (reading_script_file);
-  frame.protect_var (reading_classdef_file);
 
   line_editing = false;
-  reading_fcn_file = false;
-  reading_script_file = false;
-  reading_classdef_file = false;
 
   do
     {