From 993ba7514c4159951846b5170c62936bf4e49b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Tue, 15 Feb 2000 14:06:23 -0800 Subject: [PATCH] fixed a bug when external identifiers being resolved in first compilation pass Rev: src/language.yacc:1.163 Rev: src/las.c:1.166 Rev: src/pike_types.c:1.122 Rev: src/program.c:1.204 Rev: src/program.h:1.79 Rev: src/testsuite.in:1.278 --- src/language.yacc | 38 +++++++++++++++++++------------------- src/las.c | 8 ++------ src/pike_types.c | 13 +++++++++++-- src/program.c | 38 ++++++++++++++++++++++++++------------ src/program.h | 8 +++++--- src/testsuite.in | 36 +++++++++++++++++++++++++++++++++++- 6 files changed, 98 insertions(+), 43 deletions(-) diff --git a/src/language.yacc b/src/language.yacc index 26f380181d..270a914c6a 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -188,7 +188,7 @@ /* This is the grammar definition of Pike. */ #include "global.h" -RCSID("$Id: language.yacc,v 1.162 2000/02/02 21:45:59 hubbe Exp $"); +RCSID("$Id: language.yacc,v 1.163 2000/02/15 22:06:17 hubbe Exp $"); #ifdef HAVE_MEMORY_H #include <memory.h> #endif @@ -1732,7 +1732,9 @@ class: modifiers F_CLASS optional_identifier if ($1 & ID_EXTERN) { yywarning("Extern declared class definition."); } - low_start_new_program(0, $3->u.sval.u.string); + low_start_new_program(0, $3->u.sval.u.string, + $1, + &$<number>$); if(lex.current_file) { store_linenumber(lex.current_line, lex.current_file); @@ -1747,7 +1749,9 @@ class: modifiers F_CLASS optional_identifier i=isidentifier($3->u.sval.u.string); if(i<0) { - low_start_new_program(new_program,0); + low_start_new_program(new_program,0, + $1, + &$<number>$); yyerror("Pass 2: program not defined!"); }else{ id=ID_FROM_INT(new_program, i); @@ -1757,14 +1761,21 @@ class: modifiers F_CLASS optional_identifier s=&PROG_FROM_INT(new_program,i)->constants[id->func.offset].sval; if(s->type==T_PROGRAM) { - low_start_new_program(s->u.program, $3->u.sval.u.string); + low_start_new_program(s->u.program, + $3->u.sval.u.string, + $1, + &$<number>$); }else{ yyerror("Pass 2: constant redefined!"); - low_start_new_program(new_program, 0); + low_start_new_program(new_program, 0, + $1, + &$<number>$); } }else{ yyerror("Pass 2: class constant no longer constant!"); - low_start_new_program(new_program, 0); + low_start_new_program(new_program, 0, + $1, + &$<number>$); } } compiler_pass=tmp; @@ -1773,7 +1784,6 @@ class: modifiers F_CLASS optional_identifier } failsafe_program { - int id; struct program *p; if(compiler_pass == 1) p=end_first_pass(0); @@ -1783,22 +1793,12 @@ class: modifiers F_CLASS optional_identifier /* fprintf(stderr, "LANGUAGE.YACC: CLASS end\n"); */ if(!p) { - struct svalue s; yyerror("Class definition failed."); - s.type = T_INT; - s.subtype = 0; - s.u.integer = 0; - id = add_constant($3->u.sval.u.string, &s, $1 & ~ID_EXTERN); - } - else { - struct svalue s; - s.type = T_PROGRAM; - s.u.program = p; - id = add_constant($3->u.sval.u.string, &s, $1 & ~ID_EXTERN); + }else{ free_program(p); } - $$=mkidentifiernode(id); + $$=mkidentifiernode($<number>4); free_node($3); check_tree($$,0); diff --git a/src/las.c b/src/las.c index 92eb9264c1..9c46c2a845 100644 --- a/src/las.c +++ b/src/las.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: las.c,v 1.165 2000/02/15 03:28:32 hubbe Exp $"); +RCSID("$Id: las.c,v 1.166 2000/02/15 22:06:18 hubbe Exp $"); #include "language.h" #include "interpret.h" @@ -1327,11 +1327,7 @@ node *debug_mkconstantsvaluenode(struct svalue *s) if(s->type == T_OBJECT || (s->type==T_FUNCTION && s->subtype!=FUNCTION_BUILTIN)) { - /* Is it in a fake object? */ - if( s->u.object->next == s->u.object) - { - res->node_info|=OPT_EXTERNAL_DEPEND; - } + res->node_info|=OPT_EXTERNAL_DEPEND; } res->type = get_type_of_svalue(s); return freeze_node(res); diff --git a/src/pike_types.c b/src/pike_types.c index 8f013dd708..da751c07b5 100644 --- a/src/pike_types.c +++ b/src/pike_types.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: pike_types.c,v 1.121 2000/02/03 19:09:13 grubba Exp $"); +RCSID("$Id: pike_types.c,v 1.122 2000/02/15 22:06:19 hubbe Exp $"); #include <ctype.h> #include "svalue.h" #include "pike_types.h" @@ -3288,7 +3288,16 @@ struct pike_string *get_type_of_svalue(struct svalue *s) { char *a; struct pike_string *tmp; - int id=FIND_LFUN(s->u.program,LFUN_CREATE); + int id; + + if(!s->u.program->identifiers) + { + a=function_type_string->str; + if((tmp=zzap_function_return(a, s->u.program->id))) + return tmp; + } + + id=FIND_LFUN(s->u.program,LFUN_CREATE); if(id>=0) { a=ID_FROM_INT(s->u.program, id)->type->str; diff --git a/src/program.c b/src/program.c index 4272d8a8e0..177f74e7c1 100644 --- a/src/program.c +++ b/src/program.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: program.c,v 1.203 2000/02/13 05:09:04 hubbe Exp $"); +RCSID("$Id: program.c,v 1.204 2000/02/15 22:06:21 hubbe Exp $"); #include "program.h" #include "object.h" #include "dynamic_buffer.h" @@ -613,9 +613,12 @@ struct program *low_allocate_program(void) * Start building a new program */ void low_start_new_program(struct program *p, - struct pike_string *name) + struct pike_string *name, + int flags, + int *idp) { int e,id=0; + struct svalue tmp; #if 0 #ifdef SHARED_NODES @@ -640,21 +643,32 @@ void low_start_new_program(struct program *p, CDFPRINTF((stderr, "th(%ld) low_start_new_program() pass=%d: compilation_depth:%d\n", (long)th_self(),compilation_depth,compiler_pass)); + tmp.type=T_PROGRAM; if(!p) { p=low_allocate_program(); + if(name) + { + tmp.u.program=p; + id=add_constant(name, &tmp, flags & ~ID_EXTERN); + } e=1; }else{ + tmp.u.program=p; add_ref(p); + if(name) + { + struct identifier *i; + id=isidentifier(name); + if (id < 0) + fatal("Program constant disappeared in second pass.\n"); + i=ID_FROM_INT(new_program, id); + free_string(i->type); + i->type=get_type_of_svalue(&tmp); + } e=2; } - - if(name) - { - id=isidentifier(name); - if (e == 2 && id < 0) - fatal("Program constant disappeared in second pass.\n"); - } + if(idp) *idp=id; init_type_stack(); @@ -780,7 +794,7 @@ void debug_start_new_program(PROGRAM_LINE_ARGS) "th(%ld) start_new_program(): threads_disabled:%d, compilation_depth:%d\n", (long)th_self(),threads_disabled, compilation_depth)); - low_start_new_program(0,0); + low_start_new_program(0,0,0,0); #ifdef PIKE_DEBUG { struct pike_string *s=make_shared_string(file); @@ -3005,7 +3019,7 @@ struct program *compile(struct pike_string *prog, struct object *handler) lex.pragmas = 0; } - low_start_new_program(0,0); + low_start_new_program(0,0,0,0); initialize_buf(&used_modules); { @@ -3045,7 +3059,7 @@ struct program *compile(struct pike_string *prog, struct object *handler) if(p) { - low_start_new_program(p,0); + low_start_new_program(p,0,0,0); free_program(p); p=0; compiler_pass=2; diff --git a/src/program.h b/src/program.h index d722b85297..476b6f5417 100644 --- a/src/program.h +++ b/src/program.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: program.h,v 1.78 2000/01/02 23:41:06 mast Exp $ + * $Id: program.h,v 1.79 2000/02/15 22:06:22 hubbe Exp $ */ #ifndef PROGRAM_H #define PROGRAM_H @@ -323,7 +323,9 @@ int program_function_index_compare(const void *a,const void *b); void fixate_program(void); struct program *low_allocate_program(void); void low_start_new_program(struct program *p, - struct pike_string *name); + struct pike_string *name, + int flags, + int *idp); void debug_start_new_program(PROGRAM_LINE_ARGS); void really_free_program(struct program *p); void dump_program_desc(struct program *p); @@ -378,7 +380,7 @@ int simple_add_variable(char *name, int add_constant(struct pike_string *name, struct svalue *c, INT32 flags); -int simple_add_constant(char *name, +int simple_add_constant(char *name, struct svalue *c, INT32 flags); int add_integer_constant(char *name, diff --git a/src/testsuite.in b/src/testsuite.in index 9fef2a23df..551b62047c 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,5 +1,5 @@ dnl -*- Pike -*- -test_true([["$Id: testsuite.in,v 1.277 2000/02/13 05:09:05 hubbe Exp $"]]); +test_true([["$Id: testsuite.in,v 1.278 2000/02/15 22:06:23 hubbe Exp $"]]); cond([[all_constants()->_verify_internals]], [[ @@ -4818,3 +4818,37 @@ test_any(class A {int f(){return 1;}}; class B {inherit A; final int f(){return test_any(class A {int f(){return 1;}}; class B {inherit A; nomask int f(){return 2;}}; return B()->f(), 2) test_any(class A {int f(){return 1;}}; class B {inherit A; local int f(){return 2;}}; return B()->f(), 2) test_any(class A {int f(){return 1;}}; class B {inherit A; inline int f(){return 2;}}; return B()->f(), 2) + +test_any([[ +class Fnord +{ + array gnzpp() { } + constant fNord = 4711; + + class Bzonk + { + int xxxxx=17; + int yyyyy=17; + int zzzzz=17; + + } + + class Zboink + { + int pphfiztzz=1; + inherit Bzonk; + constant floingngg=fNord; + array Zpfoooinginoooo() {} + + int t() + { + return fNord + fNord; + } + int z() + { + return floingngg + floingngg; + } + } +}; +return Fnord()->Zboink()->t() + Fnord()->Zboink()->z(); +]],4711 * 4) -- GitLab