changeset 9009:da58ec8f62e8

tag bug don't define forced variables
author John W. Eaton <jwe@octave.org>
date Mon, 23 Mar 2009 19:29:01 -0400
parents 7a7cf569528d
children f914834836e7
files src/ChangeLog src/octave.cc src/parse.y src/symtab.h
diffstat 4 files changed, 51 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Mar 23 18:21:25 2009 -0400
+++ b/src/ChangeLog	Mon Mar 23 19:29:01 2009 -0400
@@ -1,3 +1,22 @@
+2009-03-23  John W. Eaton  <jwe@octave.org>
+
+	* symtab.h
+	(symbol_table::symbol_record::symobl_recoord_rep::is_variable):
+	Also return true if symbol is tagged as a variable.
+	(symbol_table::symbol_record::symobl_recoord_rep::force_variable):
+	Don't set variable value.
+	(symbol_table::symbol_record::symobl_recoord_rep::clear_forced,
+	symbol_table::symbol_record::clear_forced): Delete.
+	(symbol_table::unmark_forced_variables): Rename from
+	symbol_table::clear_forced_variables.
+	(symbol_table::do_unmark_forced_variables): Rename from
+	symbol_table::do_clear_forced_variables.
+	* parse.y (make_script, finish_function): Call
+	symbol_table::unmark_forced_variables instead of
+	symbol_table::clear_forced_variables.
+	* octave.cc (unmark_forced_vars): New function.
+	(execute_eval_option_code): Add it to the unwind-protect stack.
+
 2009-03-22  Jaroslav Hajek  <highegg@gmail.com>
 
 	* pt-eval.cc (tree_evaluator::visit_simple_for_command):
--- a/src/octave.cc	Mon Mar 23 18:21:25 2009 -0400
+++ b/src/octave.cc	Mon Mar 23 19:29:01 2009 -0400
@@ -367,6 +367,18 @@
   unwind_protect::run_frame ("execute_startup_files");
 }
 
+static void
+unmark_forced_vars (void *arg)
+{
+  // Unmark any symbols that may have been tagged as local variables
+  // while parsing (for example, by force_local_variable in lex.l).
+
+  symbol_table::scope_id *pscope = static_cast <symbol_table::scope_id *> (arg);
+
+  if (pscope)
+    symbol_table::unmark_forced_variables (*pscope);
+}
+
 static int
 execute_eval_option_code (const std::string& code)
 {
@@ -386,6 +398,11 @@
 
   unwind_protect_bool (interactive);
 
+  // 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 ();
+  unwind_protect::add (unmark_forced_vars, &scope);
+
   interactive = false;
 
   int parse_status = 0;
--- a/src/parse.y	Mon Mar 23 18:21:25 2009 -0400
+++ b/src/parse.y	Mon Mar 23 19:29:01 2009 -0400
@@ -2528,7 +2528,10 @@
 
   curr_fcn_ptr = script;
 
-  symbol_table::clear_forced_variables ();
+  // Unmark any symbols that may have been tagged as local variables
+  // while parsing (for example, by force_local_variable in lex.l).
+
+  symbol_table::unmark_forced_variables ();
 }
 
 // Begin defining a function.
@@ -2708,10 +2711,11 @@
 	  retval = new tree_function_def (fcn);
 	}
 
-      // Clear any local variables that may have been added while
-      // parsing (for example, by force_local_variable in lex.l). 
-
-      symbol_table::clear_forced_variables (fcn->scope ());
+      // Unmark any symbols that may have been tagged as local
+      // variables while parsing (for example, by force_local_variable
+      // in lex.l).
+
+      symbol_table::unmark_forced_variables (fcn->scope ());
     }
 
   return retval;
--- a/src/symtab.h	Mon Mar 23 18:21:25 2009 -0400
+++ b/src/symtab.h	Mon Mar 23 19:29:01 2009 -0400
@@ -204,10 +204,7 @@
 	octave_value& val = varref (context);
 
 	if (! val.is_defined ())
-	  {
-	    val = Matrix ();
-	    mark_forced ();
-	  }
+	  mark_forced ();
       }
 
       octave_value& varref (context_id context)
@@ -293,15 +290,6 @@
 	  }
       }
 
-      void clear_forced (void)
-      {
-	if (is_forced ())
-	  {
-	    varref (xcurrent_context) = octave_value ();
-	    unmark_forced ();
-	  }
-      }
-
       bool is_defined (context_id context) const
       {
 	return varval (context).is_defined ();
@@ -309,7 +297,7 @@
 
       bool is_variable (context_id context) const
       {
-	return (storage_class != local || is_defined (context));
+	return (storage_class != local || is_defined (context) || is_forced ());
       }
 
       bool is_local (void) const { return storage_class & local; }
@@ -457,8 +445,6 @@
 
     void clear (void) { rep->clear (); }
 
-    void clear_forced (void) { rep->clear_forced (); }
-    
     bool is_defined (context_id context = xcurrent_context) const
     {
       return rep->is_defined (context);
@@ -1353,12 +1339,12 @@
       inst->do_clear_variables ();
   }
 
-  static void clear_forced_variables (scope_id scope = xcurrent_scope)
+  static void unmark_forced_variables (scope_id scope = xcurrent_scope)
   {
     symbol_table *inst = get_instance (scope);
 
     if (inst)
-      inst->do_clear_forced_variables ();
+      inst->do_unmark_forced_variables ();
   }
 
   // For unwind_protect.
@@ -2133,10 +2119,10 @@
       p->second.clear ();
   }
 
-  void do_clear_forced_variables (void)
+  void do_unmark_forced_variables (void)
   {
     for (table_iterator p = table.begin (); p != table.end (); p++)
-      p->second.clear_forced ();
+      p->second.unmark_forced ();
   }
 
   void do_clear_global (const std::string& name)