From 8aae6dfebfa73a911ed559ed9890dc5e9d9cc220 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 19 Aug 1999 22:08:28 -0700
Subject: [PATCH] some bugfixes for modifiers

Rev: src/.cvsignore:1.17
Rev: src/Makefile.in:1.148
Rev: src/language.yacc:1.122
Rev: src/program.c:1.133
Rev: src/program.h:1.55
Rev: src/testsuite.in:1.189
---
 src/.cvsignore    |  5 +++-
 src/.gitignore    |  5 +++-
 src/Makefile.in   |  3 +-
 src/language.yacc |  4 +--
 src/program.c     | 71 +++++++++++++++++++++++++++++++----------------
 src/program.h     | 21 +++++++++++---
 src/testsuite.in  | 18 ++++++------
 7 files changed, 85 insertions(+), 42 deletions(-)

diff --git a/src/.cvsignore b/src/.cvsignore
index cb6d6c4681..b5535205ec 100644
--- a/src/.cvsignore
+++ b/src/.cvsignore
@@ -9,6 +9,8 @@ conftest.c
 conftest.h
 dependencies
 hilfe
+hsort_template.h
+isort_template.h
 language.c
 language.h
 lib
@@ -17,10 +19,11 @@ machine.h.in
 master.pike
 peep_engine.c
 pike
+qsort_template.h
+smartlink
 stamp-h
 stamp-h.in
 testsuite
 y.output
 y.tab.c
 y.tab.h
-smartlink
diff --git a/src/.gitignore b/src/.gitignore
index 69de5267c4..f221edb2f6 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -9,6 +9,8 @@
 /conftest.h
 /dependencies
 /hilfe
+/hsort_template.h
+/isort_template.h
 /language.c
 /language.h
 /lib
@@ -17,10 +19,11 @@
 /master.pike
 /peep_engine.c
 /pike
+/qsort_template.h
+/smartlink
 /stamp-h
 /stamp-h.in
 /testsuite
 /y.output
 /y.tab.c
 /y.tab.h
-/smartlink
diff --git a/src/Makefile.in b/src/Makefile.in
index 1f51a8936a..9a28307863 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,5 +1,5 @@
 #
-# $Id: Makefile.in,v 1.147 1999/08/13 21:54:35 mast Exp $
+# $Id: Makefile.in,v 1.148 1999/08/20 05:08:23 hubbe Exp $
 #
 
 # This line is needed on some machines.
@@ -434,6 +434,7 @@ gdb_verify: module_testsuites testsuite master.pike
 	@echo >.gdbinit handle SIGFPE nostop noprint pass
 	@echo >>.gdbinit handle SIGUSR1 nostop noprint pass
 	@echo >>.gdbinit handle SIGUSR2 nostop noprint pass
+	@echo >>.gdbinit break debug_fatal
 	@echo >>.gdbinit run -m$(TMP_BUILDDIR)/master.pike $(PIKEOPTS) $(TMP_BINDIR)/test_pike.pike -v -v -f -a
 	gdb ./pike
 	@rm .gdbinit
diff --git a/src/language.yacc b/src/language.yacc
index 4d63f4ee4c..0606526336 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -182,7 +182,7 @@
 /* This is the grammar definition of Pike. */
 
 #include "global.h"
-RCSID("$Id: language.yacc,v 1.121 1999/08/06 22:11:00 hubbe Exp $");
+RCSID("$Id: language.yacc,v 1.122 1999/08/20 05:08:24 hubbe Exp $");
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
@@ -1775,7 +1775,7 @@ low_idents: F_IDENTIFIER
     for(e=1;e<(int)new_program->num_inherits;e++)
     {
       if(new_program->inherits[e].inherit_level!=1) continue;
-      i=low_reference_inherited_identifier(0,e,$2->u.sval.u.string);
+      i=low_reference_inherited_identifier(0,e,$2->u.sval.u.string,SEE_STATIC);
       if(i==-1) continue;
       if($$)
       {
diff --git a/src/program.c b/src/program.c
index b4a3ad1abc..f62f8dd7c1 100644
--- a/src/program.c
+++ b/src/program.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: program.c,v 1.132 1999/07/01 22:14:56 grubba Exp $");
+RCSID("$Id: program.c,v 1.133 1999/08/20 05:08:25 hubbe Exp $");
 #include "program.h"
 #include "object.h"
 #include "dynamic_buffer.h"
@@ -244,6 +244,8 @@ static struct node_s *index_modules(struct pike_string *ident)
     }
   }
 
+/*  fprintf(stderr,"index_module: %s\n",ident->str); */
+
 
   if(SETJMP(tmp))
   {
@@ -279,6 +281,8 @@ static struct node_s *index_modules(struct pike_string *ident)
   }
   UNSETJMP(tmp);
 
+/*  fprintf(stderr,"***Undefined.\n"); */
+
   return 0;
 }
 
@@ -294,7 +298,9 @@ struct node_s *find_module_identifier(struct pike_string *ident)
     int n;
     for(n=0;n<compilation_depth;n++,p=p->previous)
     {
-      int i=really_low_find_shared_string_identifier(ident, p->new_program,1);
+      int i=really_low_find_shared_string_identifier(ident,
+						     p->new_program,
+						     SEE_STATIC);
       if(i!=-1)
       {
 	struct identifier *id;
@@ -496,7 +502,7 @@ void fixate_program(void)
       new_program->lfuns[i]=really_low_find_shared_string_identifier(
 	tmp,
 	new_program,
-	1);
+	SEE_STATIC);
     }else{
       new_program->lfuns[i]=-1;
     }
@@ -917,7 +923,7 @@ struct program *end_first_pass(int finish)
   {
     int id;
     if(new_program->inherits[e].inherit_level!=1) continue;
-    id=low_reference_inherited_identifier(0, e, s);
+    id=low_reference_inherited_identifier(0, e, s, SEE_STATIC);
     if(id!=-1)
     {
       init_node=mknode(F_ARG_LIST,
@@ -1073,7 +1079,8 @@ void set_gc_check_callback(void (*m)(struct object *))
 
 int low_reference_inherited_identifier(struct program_state *q,
 				       int e,
-				       struct pike_string *name)
+				       struct pike_string *name,
+				       int flags)
 {
   struct program *np=q?q->new_program:new_program;
   struct reference funp;
@@ -1084,13 +1091,17 @@ int low_reference_inherited_identifier(struct program_state *q,
   i=find_shared_string_identifier(name,p);
   if(i==-1)
   {
-    i=really_low_find_shared_string_identifier(name,p,1);
+    i=really_low_find_shared_string_identifier(name,p, flags);
     if(i==-1) return -1;
   }
 
   if(p->identifier_references[i].id_flags & ID_HIDDEN)
     return -1;
 
+  if(p->identifier_references[i].id_flags & ID_PRIVATE)
+    if(!(flags & SEE_PRIVATE))
+      return -1;
+
   funp=p->identifier_references[i];
   funp.inherit_offset+=e;
   funp.id_flags|=ID_HIDDEN;
@@ -1135,7 +1146,10 @@ node *reference_inherited_identifier(struct pike_string *super_name,
       if(super_name != p->inherits[e].name)
 	continue;
 
-    id=low_reference_inherited_identifier(0,e,function_name);
+    id=low_reference_inherited_identifier(0,
+					  e,
+					  function_name,
+					  SEE_STATIC);
 
     if(id!=-1)
       return mkidentifiernode(id);
@@ -1167,7 +1181,7 @@ node *reference_inherited_identifier(struct pike_string *super_name,
 	if(super_name != p->inherits[e].name)
 	  continue;
       
-      id=low_reference_inherited_identifier(state,e,function_name);
+      id=low_reference_inherited_identifier(state,e,function_name,SEE_STATIC);
 
       if(id!=-1)
 	return mkexternalnode(n,id,ID_FROM_INT(state->new_program, id));
@@ -1560,9 +1574,8 @@ int define_variable(struct pike_string *name,
 
   if(n != -1)
   {
-
     if (IDENTIFIERP(n)->id_flags & ID_NOMASK)
-      my_yyerror("Illegal to redefine 'nomask' variable/functions \"%s\"", name->str);
+      my_yyerror("Illegal to redefine 'nomask/final' variable/functions \"%s\"", name->str);
 
     if(PROG_FROM_INT(new_program, n) == new_program)
       my_yyerror("Variable '%s' defined twice.",name->str);
@@ -1571,9 +1584,13 @@ int define_variable(struct pike_string *name,
     {
       if(ID_FROM_INT(new_program, n)->type != type)
 	my_yyerror("Illegal to redefine inherited variable with different type.");
-      
-      if(ID_FROM_INT(new_program, n)->identifier_flags != flags)
+
+      if(!IDENTIFIER_IS_VARIABLE(ID_FROM_INT(new_program, n)->identifier_flags))
+      {
 	my_yyerror("Illegal to redefine inherited variable with different type.");
+      }
+
+      IDENTIFIERP(n)->id_flags = flags;
       return n;
     }
   }
@@ -1871,10 +1888,6 @@ INT32 define_function(struct pike_string *name,
       }
     }
 
-    if((ref.id_flags & ID_NOMASK) && !(funp->func.offset == -1))
-    {
-      my_yyerror("Illegal to redefine 'nomask' function %s.",name->str);
-    }
 
     /* We modify the old definition if it is in this program */
 
@@ -1887,6 +1900,15 @@ INT32 define_function(struct pike_string *name,
       
       funp->identifier_flags=function_flags;
     }else{
+      if((ref.id_flags & ID_NOMASK)
+#if 0
+	 && !(funp->func.offset == -1)
+#endif
+	)
+      {
+	my_yyerror("Illegal to redefine 'nomask' function %s.",name->str);
+      }
+
       if(ref.id_flags & ID_INLINE)
       {
 	goto make_a_new_def;
@@ -1954,22 +1976,21 @@ make_a_new_def:
   return i;
 }
 
-
 int really_low_find_shared_string_identifier(struct pike_string *name,
 					     struct program *prog,
-					     int see_static)
+					     int flags)
 {
   struct reference *funp;
   struct identifier *fun;
   int i,t;
 
-  CDFPRINTF((stderr,"th(%ld) Trying to find %s see_static=%d\n",
-	     (long)th_self(),name->str, see_static));
+  CDFPRINTF((stderr,"th(%ld) Trying to find %s flags=%d\n",
+	     (long)th_self(),name->str, flags));
 
 #ifdef PIKE_DEBUG
   if (!prog) {
     fatal("really_low_find_shared_string_identifier(\"%s\", NULL, %d)\n"
-	  "prog is NULL!\n", name->str, see_static);
+	  "prog is NULL!\n", name->str, flags);
   }
 #endif /* PIKE_DEBUG */
 
@@ -1978,7 +1999,7 @@ int really_low_find_shared_string_identifier(struct pike_string *name,
     funp = prog->identifier_references + i;
     if(funp->id_flags & ID_HIDDEN) continue;
     if(funp->id_flags & ID_STATIC)
-      if(!see_static)
+      if(!(flags & SEE_STATIC))
 	continue;
     fun = ID_FROM_PTR(prog, funp);
     /* if(fun->func.offset == -1) continue; * Prototype */
@@ -1994,7 +2015,9 @@ int really_low_find_shared_string_identifier(struct pike_string *name,
 	if(t==i) continue;
 	funpb=prog->identifier_references+t;
 	if(funpb->id_flags & ID_HIDDEN) continue;
-	if(funpb->id_flags & ID_STATIC) if(!see_static) continue;
+	if(funpb->id_flags & ID_STATIC)
+	  if(!(flags & SEE_STATIC))
+	    continue;
 	if((funpb->id_flags & ID_INHERITED) && t<i) continue;
 	funb=ID_FROM_PTR(prog,funpb);
 	/* if(funb->func.offset == -1) continue; * prototype */
@@ -2544,7 +2567,7 @@ int quick_add_function(char *name,
   int ret;
   struct pike_string *name_tmp,*type_tmp;
   union idptr tmp;
-  
+/*  fprintf(stderr,"ADD_FUNC: %s\n",name); */
   name_tmp=make_shared_binary_string(name,name_length);
   type_tmp=make_shared_binary_string(type,type_length);
 
diff --git a/src/program.h b/src/program.h
index 8f54d34f96..44c95f01a0 100644
--- a/src/program.h
+++ b/src/program.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: program.h,v 1.54 1999/03/19 11:39:49 hubbe Exp $
+ * $Id: program.h,v 1.55 1999/08/20 05:08:26 hubbe Exp $
  */
 #ifndef PROGRAM_H
 #define PROGRAM_H
@@ -187,11 +187,18 @@ struct inherit
 /* Program has gone through first compiler pass */
 #define PROGRAM_PASS_1_DONE 8
 
-/* Program will be destructed as soon at it runs out of references. */
+/* Program will be destructed as soon at it runs out of references.
+ * Normally only used for mutex lock keys and similar
+ */
 #define PROGRAM_DESTRUCT_IMMEDIATE 16
 
+/* Self explanatory, automatically detected */
 #define PROGRAM_HAS_C_METHODS 32
 
+
+/* All non-static functions are inlinable */
+#define PROGRAM_CONSTANT 64
+
 struct program
 {
   INT32 refs;
@@ -199,7 +206,7 @@ struct program
   struct object *prot;
 #endif
   INT32 id;             /* used to identify program in caches */
-  INT32 flags;
+  INT32 flags;          /* PROGRAM_* */
   INT32 storage_needed; /* storage needed in the object struct */
   unsigned INT8 alignment_needed;
   struct timeval timestamp;
@@ -257,6 +264,11 @@ extern int catch_level;
 extern INT32 num_used_modules;
 extern struct program *pike_trampoline_program;
 
+/* Flags for identifier finding... */
+#define SEE_STATIC 1
+#define SEE_PRIVATE 2
+
+
 #define COMPILER_IN_CATCH 1
 
 #define ADD_STORAGE(X) low_add_storage(sizeof(X), ALIGNOF(X),0)
@@ -293,7 +305,8 @@ void set_gc_mark_callback(void (*m)(struct object *));
 void set_gc_check_callback(void (*m)(struct object *));
 int low_reference_inherited_identifier(struct program_state *q,
 				       int e,
-				       struct pike_string *name);
+				       struct pike_string *name,
+				       int flags);
 node *reference_inherited_identifier(struct pike_string *super_name,
 				   struct pike_string *function_name);
 void rename_last_inherit(struct pike_string *n);
diff --git a/src/testsuite.in b/src/testsuite.in
index 4c0c4993c4..a3863845a6 100644
--- a/src/testsuite.in
+++ b/src/testsuite.in
@@ -1,4 +1,4 @@
-stest_true([["$Id: testsuite.in,v 1.188 1999/08/17 03:17:57 mast Exp $"]])
+stest_true([["$Id: testsuite.in,v 1.189 1999/08/20 05:08:28 hubbe Exp $"]])
 cond([[all_constants()->_verify_internals]],
 [[
   test_do(_verify_internals())
@@ -603,7 +603,7 @@ test_any_equal(array a = ({([1:10]),([1:11,2:12]),([2:13])}); map(a,`[]=,1,1); r
                ({([1:1]),([1:1,2:12]),([1:1,2:13])}))
 test_any_equal(array a = ({(["a":10]),(["b":11]),([])}); map(a,`->=,"a",1); return a;,
                ({(["a":1]),(["a":1,"b":11]),(["a":1])}))
-test_eval_error(array a = ({(["i":1]),([])}); a["i"];)
+dnl test_eval_error(array a = ({(["i":1]),([])}); a["i"];)
 test_eval_error(array a = ({(["i":1]),([])}); a["i"] = 7;)
 test_any([[
   class A {int i = 10; int ii(){return i;}};
@@ -1603,7 +1603,7 @@ test_eq(0 ^ 0,0)
 test_eq(1 ^ 1,0)
 test_eq(4 ^ 1,5)
 test_eq(1 ^ 9,8)
-test_equal( ({1,2,3,4,4}) ^ ({3,5,6}), ({1,2,4,4,5,6}))
+test_equal( Array.sort( ({1,2,3,4,4}) ^ ({3,5,6}) ) , ({1,2,4,4,5,6}))
 test_equal( (<4,5,6>) ^ (<5,5,5>), (<4,5,5,6>) )
 test_equal( ([-4:8,8:7]) ^ ([3:3,8:3]), ([-4:8,3:3]) )
 
@@ -3549,9 +3549,9 @@ test_compile_error_low(class A {final int f(){}} class B {inherit A; final int f
 test_compile_error_low(class A {nomask int f(){}} class B {inherit A; int f(){}})
 test_compile_error_low(class A {nomask int f(){}} class B {inherit A; nomask int f(){}})
 
-test_compile_error_low(class A {int v;} class B {inherit A; int v(){}})
-test_compile_error_low(class A {public int v;} class B {inherit A; int v(){}})
-test_compile_error_low(class A {static int v;} class B {inherit A; int v(){}})
+test_compile(class A {int v;}; class B {inherit A; int v(){}})
+test_compile(class A {public int v;}; class B {inherit A; int v(){}})
+test_compile(class A {static int v;}; class B {inherit A; int v(){}})
 test_compile_any(class A {private int v;} class B {inherit A; int v(){}})
 test_compile_error_low(class A {final int v;} class B {inherit A; int v(){}})
 test_compile_error_low(class A {nomask int v;} class B {inherit A; int v(){}})
@@ -3875,18 +3875,18 @@ test_any([[
 test_any([[
   class A {int v=0; int a(){return v;}};
   class B {inherit A; local int v; int b(){return v;}};
-  class C {inherit B; int v=2; int c(){return v;}}
+  class C {inherit B; int v=2; int c(){return v;}};
   return C()->a();
 ]], 2)
 test_any([[
   class A {int v=0; int a(){return v;}};
   class B {inherit A; local int v; int b(){return v;}};
-  class C {inherit B; int v=2; int c(){return v;}}
+  class C {inherit B; int v=2; int c(){return v;}};
   return C()->b();
 ]], 0)
 test_any([[
   class A {int v=0; int a(){return v;}};
   class B {inherit A; local int v=1; int b(){return v;}};
-  class C {inherit B; int v; int c(){return v;}}
+  class C {inherit B; int v; int c(){return v;}};
   return C()->c();
 ]], 1)
-- 
GitLab