Branch: Tag:

1999-11-18

1999-11-18 02:46:04 by Martin Stjernholm <mast@lysator.liu.se>

Handle forward references to program constants.

Rev: src/language.yacc:1.134
Rev: src/las.c:1.111
Rev: src/program.c:1.173

5:   \*/   /**/   #include "global.h" - RCSID("$Id: program.c,v 1.172 1999/11/11 15:23:08 grubba Exp $"); + RCSID("$Id: program.c,v 1.173 1999/11/18 02:46:04 mast Exp $");   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"
40:         /* #define COMPILER_DEBUG */ + /* #define PROGRAM_BUILD_DEBUG */      #ifdef COMPILER_DEBUG   #define CDFPRINTF(X) fprintf X
632:       new_program=p;    + #ifdef PROGRAM_BUILD_DEBUG +  if (name) { +  fprintf (stderr, "%.*sstarting program %d (pass=%d): ", +  compilation_depth, " ", new_program->id, compiler_pass); +  push_string (name); +  print_svalue (stderr, --sp); +  putc ('\n', stderr); +  } +  else +  fprintf (stderr, "%.*sstarting program %d (pass=%d)\n", +  compilation_depth, " ", new_program->id, compiler_pass); + #endif +     if(new_program->program)    {   #define FOO(NUMTYPE,TYPE,NAME) \
1100:    }       } +  + #ifdef PROGRAM_BUILD_DEBUG +  fprintf (stderr, "%.*sfinishing program %d (pass=%d)\n", +  compilation_depth, " ", new_program->id, compiler_pass); + #endif +     toss_compilation_resources();      #ifdef SHARED_NODES
1720:   {    int ret;    struct pike_string *n,*t; +  + #ifdef PROGRAM_BUILD_DEBUG +  fprintf (stderr, "%.*sdefining variable (pass=%d): %s %s\n", +  compilation_depth, " ", compiler_pass, type, name); + #endif +     n=make_shared_string(name);    t=parse_type(type);    ret=low_define_variable(n,t,flags,offset,run_time_type);
1740:    fatal("define_variable on nonshared string.\n");   #endif    + #ifdef PROGRAM_BUILD_DEBUG +  { +  struct pike_string *d = describe_type (type); +  fprintf (stderr, "%.*sdefining variable (pass=%d): %s ", +  compilation_depth, " ", compiler_pass, d->str); +  free_string (d); +  push_string (name); +  print_svalue (stderr, --sp); +  putc ('\n', stderr); +  } + #endif +     if(type == void_type_string)    yyerror("Variables can't be of type void");   
1749:    {    if(n==-1)    yyerror("Pass2: Variable disappeared!"); -  else +  else { +  struct identifier *id; +  id=ID_FROM_INT(new_program,n); +  free_string(id->type); +  copy_shared_string(id->type, type);    return n;    } -  +  }      #ifdef PIKE_DEBUG    if(new_program->flags & (PROGRAM_FIXED | PROGRAM_OPTIMIZED))
1829:    return ret;   }    - /* FIXME: add_constant with c==0 means declaration */ +    int add_constant(struct pike_string *name,    struct svalue *c,    INT32 flags)
1838:    struct identifier dummy;    struct reference ref;    + #ifdef PROGRAM_BUILD_DEBUG +  { +  if (c) { +  struct pike_string *t = get_type_of_svalue (c); +  struct pike_string *d = describe_type (t); +  fprintf (stderr, "%.*sdefining constant (pass=%d): %s ", +  compilation_depth, " ", compiler_pass, d->str); +  free_string (t); +  free_string (d); +  } +  else +  fprintf (stderr, "%.*sdeclaring constant (pass=%d): ", +  compilation_depth, " ", compiler_pass); +  push_string (name); +  print_svalue (stderr, --sp); +  putc ('\n', stderr); +  } + #endif +    #ifdef PIKE_DEBUG    if(name!=debug_findstring(name))    fatal("define_constant on nonshared string.\n");
1852:    {    yyerror("Pass2: Constant disappeared!");    }else{ - #if 1 +     struct identifier *id;    id=ID_FROM_INT(new_program,n);    if(id->func.offset>=0)
1864: Inside #if 1
   free_string(id->type);    id->type=s;    } +  else { + #ifdef PIKE_DEBUG +  if (!c) fatal("Can't declare constant during second compiler pass\n");   #endif -  +  free_string(id->type); +  id->type = get_type_of_svalue(c); +  id->run_time_type = c->type; +  id->func.offset = store_constant(c, 0, 0); +  }    return n;    }    }
1878:   #endif       copy_shared_string(dummy.name, name); -  dummy.type = get_type_of_svalue(c); -  +     dummy.identifier_flags = IDENTIFIER_CONSTANT; -  dummy.run_time_type=c->type; +     -  +  if (c) { +  dummy.type = get_type_of_svalue(c); +  dummy.run_time_type=c->type;    dummy.func.offset=store_constant(c, 0, 0); -  +  } +  else { +  reference_shared_string(mixed_type_string); +  dummy.type = mixed_type_string; +  dummy.run_time_type=T_MIXED; +  dummy.func.offset=-1; +  }       ref.id_flags=flags;    ref.identifier_offset=new_program->num_identifiers;
2063:    struct reference ref;    INT32 i;    + #ifdef PROGRAM_BUILD_DEBUG +  { +  struct pike_string *d = describe_type (type); +  fprintf (stderr, "%.*sdefining function (pass=%d): %s ", +  compilation_depth, " ", compiler_pass, d->str); +  free_string (d); +  push_string (name); +  print_svalue (stderr, --sp); +  putc ('\n', stderr); +  } + #endif +    #ifdef PROFILING    fun.self_time=0;    fun.num_calls=0;
2105:    funp->func.offset = -1;       funp->identifier_flags=function_flags; +  +  free_string(funp->type); +  copy_shared_string(funp->type, type);    }else{       if((ref.id_flags & ID_NOMASK)