changeset 16177:a7669b4d27f6

eliminate global global_command variable * toplev.h, toplev.cc (global_command): Delete. * parse.h, oct-parse.in.yy (octave_parser::stmt_list): New member variable. (octave_parser::octave_parser): Initialize it to zero. (octave_parser:~octave_parser): Delete it. (octave_parser::reset): Delete it and set it to zero. * toplev.cc (main_loop): Use curr_parser->stmt_list instead of global_command. * input.cc (get_debug_input): Likewise. * oct-parse.in.yy (eval_string, parse_fcn_file): Likewise. (ABORT_PARSE): Don't set global_command to zero. (input): Set curr_parser->stmt_list instead of global_command.
author John W. Eaton <jwe@octave.org>
date Sat, 02 Mar 2013 19:31:26 -0500
parents 74ba79f79fcc
children 3a93af21d206
files libinterp/interpfcn/input.cc libinterp/interpfcn/toplev.cc libinterp/interpfcn/toplev.h libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h
diffstat 5 files changed, 28 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/input.cc
+++ b/libinterp/interpfcn/input.cc
@@ -682,11 +682,6 @@
 
       curr_parser->reset ();
 
-      // Save current value of global_command.
-      middle_frame.protect_var (global_command);
-
-      global_command = 0;
-
       // Do this with an unwind-protect cleanup function so that the
       // forced variables will be unmarked in the event of an interrupt.
       symbol_table::scope_id scope = symbol_table::top_scope ();
@@ -694,17 +689,9 @@
 
       int retval = curr_parser->run ();
 
-      if (retval == 0 && global_command)
+      if (retval == 0 && curr_parser->stmt_list)
         {
-          unwind_protect inner_frame;
-
-          // Use an unwind-protect cleanup function so that the
-          // global_command list will be deleted in the event of an
-          // interrupt.
-
-          inner_frame.add_fcn (cleanup_statement_list, &global_command);
-
-          global_command->accept (*current_evaluator);
+          curr_parser->stmt_list->accept (*current_evaluator);
 
           if (octave_completion_matches_called)
             octave_completion_matches_called = false;
--- a/libinterp/interpfcn/toplev.cc
+++ b/libinterp/interpfcn/toplev.cc
@@ -99,9 +99,6 @@
 // TRUE means we've processed all the init code and we are good to go.
 bool octave_initialized = false;
 
-// Current command to execute.
-tree_statement_list *global_command = 0;
-
 octave_call_stack *octave_call_stack::instance = 0;
 
 void
@@ -588,23 +585,13 @@
           symbol_table::scope_id scope = symbol_table::top_scope ();
           inner_frame.add_fcn (symbol_table::unmark_forced_variables, scope);
 
-          inner_frame.protect_var (global_command);
-
-          global_command = 0;
-
           retval = curr_parser->run ();
 
           if (retval == 0)
             {
-              if (global_command)
+              if (curr_parser->stmt_list)
                 {
-                  // Use an unwind-protect cleanup function so that the
-                  // global_command list will be deleted in the event of
-                  // an interrupt.
-
-                  frame.add_fcn (cleanup_statement_list, &global_command);
-
-                  global_command->accept (*current_evaluator);
+                  curr_parser->stmt_list->accept (*current_evaluator);
 
                   octave_quit ();
 
--- a/libinterp/interpfcn/toplev.h
+++ b/libinterp/interpfcn/toplev.h
@@ -67,9 +67,6 @@
 extern OCTINTERP_API bool
 octave_remove_atexit_function (const std::string& fname);
 
-// Current command to execute.
-extern OCTINTERP_API tree_statement_list *global_command;
-
 // TRUE means we are ready to interpret commands, but not everything
 // is ready for interactive use.
 extern OCTINTERP_API bool octave_interpreter_ready;
--- a/libinterp/parse-tree/oct-parse.in.yy
+++ b/libinterp/parse-tree/oct-parse.in.yy
@@ -132,7 +132,6 @@
 #define ABORT_PARSE \
   do \
     { \
-      global_command = 0; \
       yyerrok; \
       if (! parser_symtab_context.empty ()) \
         parser_symtab_context.pop (); \
@@ -326,7 +325,7 @@
 
 input           : input1
                   {
-                    global_command = $1;
+                    curr_parser->stmt_list = $1;
                     promptflag = 1;
                     YYACCEPT;
                   }
@@ -1486,7 +1485,9 @@
   yypstate_delete (static_cast<yypstate *> (parser_state));
 #endif
 
-delete curr_lexer;
+  delete stmt_list;
+
+  delete curr_lexer;
 }
 void octave_parser::init (void)
 {
@@ -1497,6 +1498,16 @@
   CURR_LEXER = curr_lexer;
 }
 
+void
+octave_parser::reset (void)
+{
+  delete stmt_list;
+
+  stmt_list = 0;
+
+  curr_lexer->reset ();
+}
+
 int
 octave_parser::run (void)
 {
@@ -3467,18 +3478,8 @@
 
           curr_parser->curr_lexer->parsing_class_method = ! dispatch_type.empty ();
 
-          frame.protect_var (global_command);
-
-          global_command = 0;
-
           int status = curr_parser->run ();
 
-          // Use an unwind-protect cleanup function so that the
-          // global_command list will be deleted in the event of an
-          // interrupt.
-
-          frame.add_fcn (cleanup_statement_list, &global_command);
-
           fcn_ptr = curr_parser->primary_fcn_ptr;
 
           if (status != 0)
@@ -4212,10 +4213,6 @@
     {
       curr_parser->reset ();
 
-      frame.protect_var (global_command);
-
-      global_command = 0;
-
       // Do this with an unwind-protect cleanup function so that the
       // forced variables will be unmarked in the event of an
       // interrupt.
@@ -4224,28 +4221,17 @@
 
       parse_status = curr_parser->run ();
 
-      tree_statement_list *command_list = global_command;
-
       // Unmark forced variables.
-      // Restore previous value of global_command.
-      frame.run (2);
+      frame.run (1);
 
       if (parse_status == 0)
         {
-          if (command_list)
+          if (curr_parser->stmt_list)
             {
-              unwind_protect inner_frame;
-
-              // Use an unwind-protect cleanup function so that the
-              // global_command list will be deleted in the event of an
-              // interrupt.
-
-              inner_frame.add_fcn (cleanup_statement_list, &command_list);
-
               tree_statement *stmt = 0;
 
-              if (command_list->length () == 1
-                  && (stmt = command_list->front ())
+              if (curr_parser->stmt_list->length () == 1
+                  && (stmt = curr_parser->stmt_list->front ())
                   && stmt->is_expression ())
                 {
                   tree_expression *expr = stmt->expression ();
@@ -4274,7 +4260,7 @@
                     retval = octave_value_list ();
                 }
               else if (nargout == 0)
-                command_list->accept (*current_evaluator);
+                curr_parser->stmt_list->accept (*current_evaluator);
               else
                 error ("eval: invalid use of statement list");
 
--- a/libinterp/parse-tree/parse.h
+++ b/libinterp/parse-tree/parse.h
@@ -144,6 +144,7 @@
       parsing_subfunctions (false), max_fcn_depth (0),
       curr_fcn_depth (0), primary_fcn_scope (-1),
       curr_class_name (), function_scopes (), primary_fcn_ptr (0),
+      stmt_list (0),
       curr_lexer (new octave_lexer ()), parser_state (0)
   {
     init ();
@@ -153,10 +154,7 @@
 
   void init (void);
 
-  void reset (void)
-  {
-    curr_lexer->reset ();
-  }
+  void reset (void);
 
   int run (void);
 
@@ -382,6 +380,9 @@
   // Pointer to the primary user function or user script function.
   octave_function *primary_fcn_ptr;
 
+  // Result of parsing input.
+  tree_statement_list *stmt_list;
+
   // State of the lexer.
   octave_lexer *curr_lexer;