pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: program.c,v 1.695 2008/05/14 14:10:38 grubba Exp $ + || $Id: program.c,v 1.696 2008/05/16 13:28:08 grubba Exp $   */      #include "global.h"   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"   #include "pike_types.h"   #include "stralloc.h"   #include "las.h"   #include "lex.h"
pike.git/src/program.c:96:   /* A value of zero disables this cache */   #define FIND_FUNCTION_HASHSIZE 15013      /* Programs with less methods will not use the cache for method lookups.. */   #define FIND_FUNCTION_HASH_TRESHOLD 9         #define DECLARE   #include "compilation.h"    - struct pike_string *this_program_string, *this_string; + struct pike_string *this_program_string; + static struct pike_string *this_string, *this_function_string;   static struct pike_string *UNDEFINED_string;      const char *const lfun_names[] = {    "__INIT",    "create",    "destroy",    "`+",    "`-",    "`&",    "`|",
pike.git/src/program.c:1408: Inside #if 0
  #if 0   /* This check is not possible to do since the identifier is added    * before checking for duplicates in add_constant. */   static void debug_add_to_identifiers (struct identifier id)   {    if (d_flag) {    int i;    for (i = 0; i < Pike_compiler->new_program->num_identifiers; i++)    if (Pike_compiler->new_program->identifiers[i].name == id.name) {    dump_program_tables (Pike_compiler->new_program, 0); -  Pike_fatal ("Adding identifier twice, old at %d.\n", i); +  Pike_fatal ("Adding identifier twice, old at %s:%d #%d.\n", +  Pike_compiler->new_program->identifiers[i].filename? +  Pike_compiler->new_program->identifiers[i].filename:"-", +  Pike_compiler->new_program->identifiers[i].linenumber, +  i);    }    }    add_to_identifiers (id);   }   #else   #define debug_add_to_identifiers(ARG) add_to_identifiers(ARG)   #endif      void add_relocated_int_to_program(INT32 i)   {
pike.git/src/program.c:1740:       /* Handle this_program */    if (ident == this_program_string) {    node *n = mkefuncallnode("object_program",    mkthisnode(state->new_program, inherit_num));    /* We know this expression is constant. */    n->node_info &= ~OPT_NOT_CONST;    n->tree_info &= ~OPT_NOT_CONST;    return n;    } +  +  /* Handle this_function */ +  if (ident == this_function_string) { +  int i; +  if ((i = Pike_compiler->compiler_frame->current_function_number) >= 0) { +  struct identifier *id; +  id = ID_FROM_INT(Pike_compiler->new_program, i); +  if (id->identifier_flags & IDENTIFIER_SCOPED) { +  return mktrampolinenode(i, Pike_compiler->compiler_frame->previous); +  } else { +  return mkidentifiernode(i);    } -  +  } else { +  /* FIXME: Fall back to __INIT? */ +  } +  } +  }       if (colon_colon_ref) {    /* These are only recognized when prefixed with the :: operator. */       if (inherit_num < 0) inherit_num = 0;    if(ident == lfun_strings[LFUN_ARROW] ||    ident == lfun_strings[LFUN_INDEX]) {    return mknode(F_MAGIC_INDEX, mknewintnode(inherit_num),    mknewintnode(state_depth));    } else if(ident == lfun_strings[LFUN_ASSIGN_ARROW] ||
pike.git/src/program.c:2706:    free_string(p->strings[e]);       if(p->identifiers)    {    for(e=0; e<p->num_identifiers; e++)    {    if(p->identifiers[e].name)    free_string(p->identifiers[e].name);    if(p->identifiers[e].type)    free_type(p->identifiers[e].type); +  if(p->identifiers[e].filename) +  free_string(p->identifiers[e].filename);    }    }       if(p->constants)    {    for(e=0;e<p->num_constants;e++)    {    free_svalue(& p->constants[e].sval);   #if 0    if(p->constants[e].name) free_string(p->constants[e].name);
pike.git/src/program.c:2970: Inside #if defined(PIKE_DEBUG)
   indent, "", p->flags);       fprintf(stderr,    "%*sReference table:\n"    "%*s ####: Flags Inherit Identifier\n",    indent, "", indent, "");    for (d=0; d < p->num_identifier_references; d++) {    struct reference *ref = p->identifier_references + d;    struct identifier *id = ID_FROM_PTR(p, ref);    -  fprintf(stderr, "%*s %4d: %5x %7d %10d %s\n", +  fprintf(stderr, +  "%*s %4d: %5x %7d %10d %s\n" +  "%*s %s:%d\n",    indent, "",    d, ref->id_flags, ref->inherit_offset,    ref->identifier_offset, -  ID_FROM_PTR(p,ref)->name->size_shift ? "(wide)" : -  ID_FROM_PTR(p,ref)->name->str); +  id->name->size_shift ? "(wide)" : id->name->str, +  indent, "", +  id->filename?id->filename:"-", id->linenumber);    if (IDENTIFIER_IS_ALIAS(id->identifier_flags)) {    fprintf (stderr, "%*s Alias for %d:%d\n",    indent, "", id->func.ext_ref.depth, id->func.ext_ref.id);    } else if (IDENTIFIER_IS_CONSTANT(id->identifier_flags)) {    fprintf (stderr, "%*s Constant #%ld\n",    indent, "", (long)id->func.offset);    } else if (IDENTIFIER_IS_VARIABLE(id->identifier_flags)) {    fprintf (stderr, "%*s Offset: 0x%08lx\n",    indent, "", (long)id->func.offset);    } else if (IDENTIFIER_IS_PIKE_FUNCTION(id->identifier_flags)) {
pike.git/src/program.c:3034: Inside #if defined(PIKE_DEBUG)
   inh->parent ? inh->parent->program_id : -1,    inh->identifier_ref_offset);    }    fprintf(stderr, "\n"    "%*sIdentifier table:\n"    "%*s ####: Flags Offset Type Name\n",    indent, "", indent, "");    for (d=0; d < p->num_identifiers; d++) {    struct identifier *id = p->identifiers + d;    -  fprintf(stderr, "%*s %4d: %5x %6"PRINTPTRDIFFT"d %4d \"%s\"\n", +  fprintf(stderr, +  "%*s %4d: %5x %6"PRINTPTRDIFFT"d %4d \"%s\"\n", +  "%*s %s:%d\n",    indent, "",    d, id->identifier_flags, id->func.offset, -  id->run_time_type, id->name->str); +  id->run_time_type, id->name->str, +  indent, "", +  id->filename?id->filename:"-", id->linenumber);    }       fprintf(stderr, "\n"    "%*sVariable table:\n"    "%*s ####: Index\n",    indent, "", indent, "");    for (d = 0; d < p->num_variable_index; d++) {    fprintf(stderr, "%*s %4d: %5d\n",    indent, "",    d, p->variable_index[d]);
pike.git/src/program.c:4575:    *    * Note that both type and name may be NULL. If they are NULL    * they will be defaulted to the values from the aliased identifier.    */   int low_define_alias(struct pike_string *name, struct pike_type *type,    int flags, int depth, int refno)   {    int n;    int e;    +  struct compilation *c = THIS_COMPILATION;    struct program_state *state = Pike_compiler;    struct identifier dummy, *id;    struct reference ref;      #ifdef PIKE_DEBUG    if(Pike_compiler->new_program->flags & (PROGRAM_FIXED | PROGRAM_OPTIMIZED))    Pike_fatal("Attempting to add variable to fixed program\n");       if(Pike_compiler->compiler_pass==2)    Pike_fatal("Internal error: Not allowed to add more identifiers during second compiler pass.\n"
pike.git/src/program.c:4614:    if (name) {    copy_shared_string(dummy.name, name);    } else {    copy_shared_string(dummy.name, id->name);    }    if (type) {    copy_pike_type(dummy.type, type);    } else {    copy_pike_type(dummy.type, id->type);    } +  copy_shared_string(dummy.filename, c->lex.current_file); +  dummy.linenumber = c->lex.current_line;    dummy.identifier_flags = id->identifier_flags | IDENTIFIER_ALIAS;    dummy.run_time_type = id->run_time_type; /* Not actually used. */    dummy.func.ext_ref.depth = depth;    dummy.func.ext_ref.id = refno;    dummy.opt_flags = 0;   #ifdef PROFILING    dummy.self_time=0;    dummy.num_calls=0;    dummy.total_time=0;   #endif
pike.git/src/program.c:4725:      /* argument must be a shared string */   int low_define_variable(struct pike_string *name,    struct pike_type *type,    INT32 flags,    size_t offset,    INT32 run_time_type)   {    int n;    +  struct compilation *c = THIS_COMPILATION;    struct identifier dummy;    struct reference ref;      #ifdef PIKE_DEBUG    if(Pike_compiler->new_program->flags & (PROGRAM_FIXED | PROGRAM_OPTIMIZED))    Pike_fatal("Attempting to add variable to fixed program\n");       if(Pike_compiler->compiler_pass==2)    Pike_fatal("Internal error: Not allowed to add more identifiers during second compiler pass.\n"    "Added identifier: \"%s\"\n", name->str);   #endif       copy_shared_string(dummy.name, name);    copy_pike_type(dummy.type, type); -  +  copy_shared_string(dummy.filename, c->lex.current_file); +  dummy.linenumber = c->lex.current_line;    dummy.identifier_flags = IDENTIFIER_VARIABLE;    dummy.run_time_type=run_time_type;    dummy.func.offset=offset - Pike_compiler->new_program->inherits[0].storage_offset;    dummy.opt_flags = 0;   #ifdef PROFILING    dummy.self_time=0;    dummy.num_calls=0;    dummy.total_time=0;   #endif   
pike.git/src/program.c:4992:    free_string(name_s);    free_type(type_s);    return ret;   }      PMOD_EXPORT int add_constant(struct pike_string *name,    struct svalue *c,    INT32 flags)   {    int n; +  struct compilation *cc = THIS_COMPILATION;    struct identifier dummy;    struct reference ref;    struct svalue zero;      #ifdef PROGRAM_BUILD_DEBUG -  struct compilation *cc = THIS_COMPILATION; +     {    if (c) {    struct pike_type *t = get_type_of_svalue(c);    struct pike_string *d = describe_type (t);    fprintf (stderr, "%.*sdefining constant (pass=%d): %s ",    cc->compilation_depth, "",    Pike_compiler->compiler_pass, d->str);    free_type(t);    free_string (d);    push_string (name);
pike.git/src/program.c:5150: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(Pike_compiler->new_program->flags & (PROGRAM_FIXED | PROGRAM_OPTIMIZED))    Pike_fatal("Attempting to add constant to fixed program\n");       if(Pike_compiler->compiler_pass==2)    Pike_fatal("Internal error: Not allowed to add more identifiers during second compiler pass.\n");   #endif       copy_shared_string(dummy.name, name);    dummy.identifier_flags = IDENTIFIER_CONSTANT; +  copy_shared_string(dummy.filename, cc->lex.current_file); +  dummy.linenumber = cc->lex.current_line;      #if 1    if (c) {   #endif    dummy.type = get_type_of_svalue(c);    dummy.run_time_type=c->type;    dummy.func.offset=store_constant(c, 0, 0);    dummy.opt_flags=OPT_SIDE_EFFECT | OPT_EXTERNAL_DEPEND;    if(c->type == PIKE_T_PROGRAM && (c->u.program->flags & PROGRAM_CONSTANT))    dummy.opt_flags=0;
pike.git/src/program.c:5632:    }       /* Otherwise we alter the existing definition */   #ifdef PROGRAM_BUILD_DEBUG    fprintf(stderr, "%.*saltering the existing definition\n",    c->compilation_depth, "");   #endif       copy_shared_string(fun.name, name);    copy_pike_type(fun.type, type); +  copy_shared_string(fun.filename, c->lex.current_file); +  fun.linenumber = c->lex.current_line;       fun.run_time_type = run_time_type;       fun.identifier_flags=function_flags;       if(func)    fun.func = *func;    else    fun.func.offset = -1;   
pike.git/src/program.c:5694: Inside #if defined(PIKE_DEBUG)
     #ifdef PIKE_DEBUG    if(Pike_compiler->compiler_pass==2)    Pike_fatal("Internal error: Not allowed to add more identifiers during second compiler pass.\n");   #endif       /* Define a new function */       copy_shared_string(fun.name, name);    copy_pike_type(fun.type, type); +  copy_shared_string(fun.filename, c->lex.current_file); +  fun.linenumber = c->lex.current_line;       fun.identifier_flags=function_flags;    fun.run_time_type = run_time_type;       if(func)    fun.func = *func;    else    fun.func.offset = -1;       fun.opt_flags = opt_flags;
pike.git/src/program.c:9250:   }      void init_program(void)   {    size_t i;    struct svalue key;    struct svalue val;    struct svalue id;    init_program_blocks();    +  MAKE_CONST_STRING(this_function_string,"this_function");    MAKE_CONST_STRING(this_program_string,"this_program");    MAKE_CONST_STRING(this_string,"this");    MAKE_CONST_STRING(UNDEFINED_string,"UNDEFINED");       lfun_ids = allocate_mapping(NUM_LFUNS);    lfun_types = allocate_mapping(NUM_LFUNS);    for (i=0; i < NELEM(lfun_names); i++) {    lfun_strings[i] = make_shared_string(lfun_names[i]);       id.type = T_INT;