From fae37d3ff14ad51190bf1d8a912830fed8df94d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Sun, 30 Aug 1998 00:15:18 +0200
Subject: [PATCH] Improved some error messages. index_node() now takes 3
 arguments.

Rev: src/language.yacc:1.102
Rev: src/las.c:1.66
Rev: src/las.h:1.16
---
 src/language.yacc | 17 +++++++++++++----
 src/las.c         | 36 ++++++++++++++++++++++++++++--------
 src/las.h         |  4 ++--
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/src/language.yacc b/src/language.yacc
index 05bf04b611..55ac4caf9b 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -179,7 +179,7 @@
 /* This is the grammar definition of Pike. */
 
 #include "global.h"
-RCSID("$Id: language.yacc,v 1.101 1998/08/29 21:33:05 grubba Exp $");
+RCSID("$Id: language.yacc,v 1.102 1998/08/29 22:15:15 grubba Exp $");
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
@@ -1614,7 +1614,8 @@ expr4: string
 idents: low_idents
   | idents '.' F_IDENTIFIER
   {
-    $$=index_node($1, $3->u.sval.u.string);
+    $$=index_node($1, last_identifier?last_identifier->str:NULL,
+		  $3->u.sval.u.string);
     free_node($1);
     if(last_identifier) free_string(last_identifier);
     copy_shared_string(last_identifier, $3->u.sval.u.string);
@@ -1628,7 +1629,7 @@ idents: low_idents
     SAFE_APPLY_MASTER("handle_import",2);
     tmp=mkconstantsvaluenode(sp-1);
     pop_stack();
-    $$=index_node(tmp, $2->u.sval.u.string);
+    $$=index_node(tmp, ".", $2->u.sval.u.string);
     free_node(tmp);
     if(last_identifier) free_string(last_identifier);
     copy_shared_string(last_identifier, $2->u.sval.u.string);
@@ -1673,9 +1674,11 @@ low_idents: F_IDENTIFIER
 #ifdef __CHECKER__
     tmp.subtype=0;
 #endif /* __CHECKER__ */
+    if(last_identifier) free_string(last_identifier);
+    copy_shared_string(last_identifier, $3->u.sval.u.string);
     tmp.u.mapping=get_builtin_constants();
     tmp2=mkconstantsvaluenode(&tmp);
-    $$=index_node(tmp2, $3->u.sval.u.string);
+    $$=index_node(tmp2, "predef", $3->u.sval.u.string);
     free_node(tmp2);
     free_node($3);
   }
@@ -1685,6 +1688,9 @@ low_idents: F_IDENTIFIER
   }
   | F_IDENTIFIER F_COLON_COLON F_IDENTIFIER
   {
+    if(last_identifier) free_string(last_identifier);
+    copy_shared_string(last_identifier, $3->u.sval.u.string);
+
     $$=reference_inherited_identifier($1->u.sval.u.string,
 				     $3->u.sval.u.string);
     if (!$$)
@@ -1704,6 +1710,9 @@ low_idents: F_IDENTIFIER
   {
     int e,i;
 
+    if(last_identifier) free_string(last_identifier);
+    copy_shared_string(last_identifier, $2->u.sval.u.string);
+
     $$=0;
     for(e=1;e<(int)new_program->num_inherits;e++)
     {
diff --git a/src/las.c b/src/las.c
index 88457d5795..a0c778bc4b 100644
--- a/src/las.c
+++ b/src/las.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: las.c,v 1.65 1998/08/05 22:48:01 hubbe Exp $");
+RCSID("$Id: las.c,v 1.66 1998/08/29 22:15:17 grubba Exp $");
 
 #include "language.h"
 #include "interpret.h"
@@ -680,7 +680,7 @@ void resolv_program(node *n)
 
 
 
-node *index_node(node *n, struct pike_string * id)
+node *index_node(node *n, char *node_name, struct pike_string *id)
 {
   node *ret;
   JMP_BUF tmp;
@@ -695,23 +695,38 @@ node *index_node(node *n, struct pike_string * id)
     APPLY_MASTER("handle_error", 1);
     pop_stack();
     UNSET_ONERROR(tmp);
-    
-    yyerror("Couldn't index module.");
+
+    if (node_name) {
+      my_yyerror("Couldn't index module '%s'.", node_name);
+    } else {
+      yyerror("Couldn't index module.");
+    }
     push_int(0);
   }else{
     resolv_constant(n);
     switch(sp[-1].type)
     {
     case T_INT:
-      if(!num_parse_error)
-	yyerror("Failed to index module (module doesn't exist?)");
+      if(!num_parse_error) {
+	if (node_name) {
+	  my_yyerror("Failed to index module '%s' (module doesn't exist?)",
+		     node_name);
+	} else {
+	  yyerror("Failed to index module (module doesn't exist?)");
+	}
+      }
       break;
 
     case T_PROGRAM:
     case T_FLOAT:
     case T_STRING:
     case T_ARRAY:
-      yyerror("Failed to index module (Not a module?)");
+      if (node_name) {
+	my_yyerror("Failed to index module '%s' (Not a module?)",
+		   node_name);
+      } else {
+	yyerror("Failed to index module (Not a module?)");
+      }
       pop_stack();
       push_int(0);
       break;
@@ -733,7 +748,12 @@ node *index_node(node *n, struct pike_string * id)
 	   !sp[-1].u.integer &&
 	   sp[-1].subtype==NUMBER_UNDEFINED)
 	{
-	  my_yyerror("Index '%s' not present in module.",id->str);
+	  if (node_name) {
+	    my_yyerror("Index '%s' not present in module '%s'.",
+		       id->str, node_name);
+	  } else {
+	    my_yyerror("Index '%s' not present in module.", id->str);
+	  }
 	}
 	END_CYCLIC();
       }
diff --git a/src/las.h b/src/las.h
index 7a308693cb..8b63e0dc04 100644
--- a/src/las.h
+++ b/src/las.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: las.h,v 1.15 1998/06/06 03:27:26 hubbe Exp $
+ * $Id: las.h,v 1.16 1998/08/29 22:15:18 grubba Exp $
  */
 #ifndef LAS_H
 #define LAS_H
@@ -86,7 +86,7 @@ node *mkexternalnode(int level,
 node *mkcastnode(struct pike_string *type,node *n);
 void resolv_constant(node *n);
 void resolv_program(node *n);
-node *index_node(node *n, struct pike_string * id);
+node *index_node(node *n, char *node_name, struct pike_string * id);
 int node_is_eq(node *a,node *b);
 node *mkconstantsvaluenode(struct svalue *s);
 node *mkliteralsvaluenode(struct svalue *s);
-- 
GitLab