changeset 7876:8447a5024650

clear subfunctions when clearing parent function
author John W. Eaton <jwe@octave.org>
date Fri, 06 Jun 2008 15:04:12 -0400
parents bff8dbc1be11
children 59031cfe331b
files src/ChangeLog src/ov-base.h src/ov-usr-fcn.h src/ov.h src/symtab.h
diffstat 5 files changed, 47 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Jun 06 11:35:10 2008 -0400
+++ b/src/ChangeLog	Fri Jun 06 15:04:12 2008 -0400
@@ -1,5 +1,18 @@
 2008-06-06  John W. Eaton  <jwe@octave.org>
 
+	* ov.h (octave_value::erase_subfunctions):
+	New function.
+	* ov-base.h (octave_base_value::erase_subfunctions):
+	New virtual function.
+	* ov-usr-fcn.h (octave_user_function::erase_subfunctions):
+	New function.
+	* symtab.h (symbol_table::fcn_info::::erase_subfunction,
+	symbol_table::fcn_info::fcn_info_rep::erase_subfunction,
+	symbol_table::erase_subfunctions_in_scope):
+	New functions.
+	(symbol_table::fcn_info::fcn_info_rep::clear_user_function):
+	Erase subfunctions here.
+
 	* variables.cc (Fmlock): Doc fix.
 
 2008-06-05  John W. Eaton  <jwe@octave.org>
--- a/src/ov-base.h	Fri Jun 06 11:35:10 2008 -0400
+++ b/src/ov-base.h	Fri Jun 06 15:04:12 2008 -0400
@@ -310,6 +310,8 @@
 
   virtual bool is_mex_function (void) const { return false; }
 
+  virtual void erase_subfunctions (void) { }
+
   virtual short int short_value (bool = false, bool = false) const;
 
   virtual unsigned short int ushort_value (bool = false, bool = false) const;
--- a/src/ov-usr-fcn.h	Fri Jun 06 11:35:10 2008 -0400
+++ b/src/ov-usr-fcn.h	Fri Jun 06 15:04:12 2008 -0400
@@ -225,6 +225,11 @@
 
   bool is_user_function (void) const { return true; }
 
+  void erase_subfunctions (void)
+    {
+      symbol_table::erase_subfunctions_in_scope (local_scope);
+    }
+
   bool takes_varargs (void) const;
 
   bool takes_var_return (void) const;
--- a/src/ov.h	Fri Jun 06 11:35:10 2008 -0400
+++ b/src/ov.h	Fri Jun 06 15:04:12 2008 -0400
@@ -613,6 +613,8 @@
   bool is_mex_function (void) const
     { return rep->is_mex_function (); }
 
+  void erase_subfunctions (void) { rep->erase_subfunctions (); }
+
   // Values.
 
   octave_value eval (void) { return *this; }
--- a/src/symtab.h	Fri Jun 06 11:35:10 2008 -0400
+++ b/src/symtab.h	Fri Jun 06 15:04:12 2008 -0400
@@ -568,6 +568,14 @@
 	  : std::pair<std::string, octave_value> (name, p->second);
       }	     
 
+      void erase_subfunction (scope_id scope)
+      {
+	scope_val_iterator p = subfunctions.find (scope);
+
+	if (p != subfunctions.end ())
+	  subfunctions.erase (p);
+      }
+
       void install_cmdline_function (const octave_value& f)
       {
 	cmdline_function = f;
@@ -620,7 +628,11 @@
       void clear_user_function (void)
       {
 	if (! function_on_path.islocked ())
-	  function_on_path = octave_value ();
+	  {
+	    function_on_path.erase_subfunctions ();
+
+	    function_on_path = octave_value ();
+	  }
       }
 
       void clear_mex_function (void)
@@ -779,6 +791,11 @@
       return rep->subfunction_defined_in_scope (scope);
     }	     
 
+    void erase_subfunction (scope_id scope)
+    {
+      rep->erase_subfunction (scope);
+    }
+
     void install_cmdline_function (const octave_value& f)
     {
       rep->install_cmdline_function (f);
@@ -959,6 +976,13 @@
       }
   }
 
+  static void erase_subfunctions_in_scope (scope_id scope)
+  {
+    for (fcn_table_iterator q = fcn_table.begin ();
+	 q != fcn_table.end (); q++)
+      q->second.erase_subfunction (scope);
+  }
+
   static scope_id dup_scope (scope_id scope)
   {
     scope_id retval = -1;