diff src/symtab.cc @ 3308:7ae1928ca623

[project @ 1999-10-21 08:57:11 by jwe]
author jwe
date Thu, 21 Oct 1999 08:57:14 +0000
parents 4964d5391acc
children 2efa28a91e7a
line wrap: on
line diff
--- a/src/symtab.cc	Thu Oct 21 03:09:53 1999 +0000
+++ b/src/symtab.cc	Thu Oct 21 08:57:14 1999 +0000
@@ -37,6 +37,7 @@
 #include "glob-match.h"
 #include "str-vec.h"
 
+#include "defun.h"
 #include "error.h"
 #include "oct-lvalue.h"
 #include "ov.h"
@@ -45,6 +46,11 @@
 #include "utils.h"
 #include "variables.h"
 
+// Should variables be allowed to hide functions of the same name?  A
+// positive value means yes.  A negative value means yes, but print a
+// warning message.  Zero means it should be considered an error.
+static int Vvariables_can_hide_functions;
+
 octave_allocator
 symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def));
 
@@ -74,7 +80,17 @@
   if (! (is_variable () && read_only_error ("redefine")))
     {
       if (is_function () || is_constant ())
-	push_def (new symbol_def ());
+	{
+	  if (Vvariables_can_hide_functions)
+	    {
+	      push_def (new symbol_def ());
+
+	      if (Vvariables_can_hide_functions < 0)
+		warning ("variable `%s' hides function", nm.c_str ());
+	    }
+	  else
+	    error ("variable `%s' hides function", nm.c_str ());
+	}
 
       if (definition->type () == symbol_record::BUILTIN_VARIABLE)
 	sym_type = symbol_record::BUILTIN_VARIABLE;
@@ -243,6 +259,19 @@
 octave_lvalue
 symbol_record::variable_reference (void)
 {
+  if (Vvariables_can_hide_functions <= 0
+      && (is_function ()
+	  || (! is_defined () && is_valid_function (nm))))
+    {
+      if (Vvariables_can_hide_functions < 0)
+	warning ("variable `%s' hides function", nm.c_str ());
+      else
+	{
+	  error ("variable `%s' hides function", nm.c_str ());
+	  return octave_lvalue ();
+	}
+    }
+
   if (is_function () || is_constant ())
     clear ();
 
@@ -778,6 +807,24 @@
   return h & (table_size - 1);
 }
 
+
+static int
+variables_can_hide_functions (void)
+{
+  Vvariables_can_hide_functions
+    = check_preference ("variables_can_hide_functions");
+
+  return 0;
+}
+
+void
+symbols_of_symtab (void)
+{
+  DEFVAR (variables_can_hide_functions, 1.0, variables_can_hide_functions,
+    "Should variables be allowed to hide functions of the same name?");
+}
+
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***