changeset 348:528943cab4e6

[project @ 1994-02-09 22:21:13 by jwe]
author jwe
date Wed, 09 Feb 1994 22:21:13 +0000
parents 8954f149acff
children 15d748dd2aab
files src/t-builtins.cc
diffstat 1 files changed, 109 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/t-builtins.cc	Tue Feb 08 06:38:52 1994 +0000
+++ b/src/t-builtins.cc	Wed Feb 09 22:21:13 1994 +0000
@@ -633,57 +633,139 @@
 static int
 load_variable (char *nm, int force, istream& is)
 {
-  symbol_record *gsr = global_sym_tab->lookup (nm, 0, 0);
+// Is there already a symbol by this name?  If so, what is it?
+
   symbol_record *lsr = curr_sym_tab->lookup (nm, 0, 0);
 
-  if (! force
-      && ((gsr != (symbol_record *) NULL && gsr->is_variable ())
-	  || lsr != (symbol_record *) NULL))
+  int is_undefined = 1;
+  int is_variable = 0;
+  int is_function = 0;
+  int is_global = 0;
+
+  if (lsr != (symbol_record *) NULL)
     {
-      warning ("load: variable name `%s' exists.", nm);
-      warning ("Use `load -force' to overwrite");
-      return -1;
+      is_undefined = ! lsr->is_defined ();
+      is_variable = lsr->is_variable ();
+      is_function = lsr->is_function ();
+      is_global = lsr->is_linked_to_global ();
     }
 
-// We found it.  Read data for this entry, and if that succeeds,
-// insert it into symbol table.
+// Try to read data for this name.
 
   tree_constant tc;
   int global = tc.load (is);
-  if (tc.const_type () != tree_constant_rep::unknown_constant)
+
+  if (tc.const_type () == tree_constant_rep::unknown_constant)
     {
-      symbol_record *sr;
-      if (global)
+      error ("load: unable to load variable `%s'", nm);
+      return 0;
+    }
+
+  symbol_record *sr = (symbol_record *) NULL;
+
+  if (global)
+    {
+      if (is_global || is_undefined)
 	{
-	  if (lsr != (symbol_record *) NULL)
+	  if (force || is_undefined)
+	    {
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      link_to_global_variable (lsr);
+	      sr = lsr;
+	    }
+	  else
+	    {
+	      warning ("load: global variable name `%s' exists.", nm);
+	      warning ("use `load -force' to overwrite");
+	    }
+	}
+      else if (is_function)
+	{
+	  if (force)
 	    {
-	      warning ("load: replacing local symbol `%s' with", nm);
-	      warning ("global value from file");
-	      curr_sym_tab->clear (nm);
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      link_to_global_variable (lsr);
+	      sr = lsr;
+	    }
+	  else
+	    {
+	      warning ("load: `%s' is currently a function in this scope", nm);
+	      warning ("`load -force' will load variable and hide function");
 	    }
-	  sr = global_sym_tab->lookup (nm, 1, 0);
+	}
+      else if (is_variable)
+	{
+	  if (force)
+	    {
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      link_to_global_variable (lsr);
+	      sr = lsr;
+	    }
+	  else
+	    {
+	      warning ("load: local variable name `%s' exists.", nm);
+	      warning ("use `load -force' to overwrite");
+	    }
 	}
       else
+	panic_impossible ();
+    }
+  else
+    {
+      if (is_global)
 	{
-	  if (gsr != (symbol_record *) NULL)
+	  if (force || is_undefined)
 	    {
-	      warning ("loading `%s' as a global variable", nm);
-	      sr = gsr;
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      link_to_global_variable (lsr);
+	      sr = lsr;
+	    }
+	  else
+	    {
+	      warning ("load: global variable name `%s' exists.", nm);
+	      warning ("use `load -force' to overwrite");
+	    }
+	}
+      else if (is_function)
+	{
+	  if (force)
+	    {
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      link_to_global_variable (lsr);
+	      sr = lsr;
 	    }
 	  else
-	    sr = curr_sym_tab->lookup (nm, 1, 0);
+	    {
+	      warning ("load: `%s' is currently a function in this scope", nm);
+	      warning ("`load -force' will load variable and hide function");
+	    }
 	}
-
-      if (sr != (symbol_record *) NULL)
+      else if (is_variable || is_undefined)
 	{
-	  tree_constant *tmp_tc = new tree_constant (tc);
-	  sr->define (tmp_tc);
-	  return 1;
+	  if (force || is_undefined)
+	    {
+	      lsr = curr_sym_tab->lookup (nm, 1, 0);
+	      sr = lsr;
+	    }
+	  else
+	    {
+	      warning ("load: local variable name `%s' exists.", nm);
+	      warning ("use `load -force' to overwrite");
+	    }
 	}
       else
-	error ("load: unable to load variable `%s'", nm);
+	panic_impossible ();
     }
 
+  if (sr != (symbol_record *) NULL)
+    {
+      tree_constant *tmp_tc = new tree_constant (tc);
+      sr->define (tmp_tc);
+      return 1;
+    }
+  else
+    error ("load: unable to load variable `%s'", nm);
+
   return 0;
 }