Branch: Tag:

2008-05-16

2008-05-16 13:28:08 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added this_function.
Identifiers now can keep track of where they were defined.

Rev: src/program.c:1.696

2:   || 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"
103:   #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[] = {
1415: Inside #if 0
   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);
1747:    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. */
2713:    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);    }    }   
2977: Inside #if defined(PIKE_DEBUG)
   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);
3041: Inside #if defined(PIKE_DEBUG)
   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"
4582:    int n;    int e;    +  struct compilation *c = THIS_COMPILATION;    struct program_state *state = Pike_compiler;    struct identifier dummy, *id;    struct reference ref;
4621:    } 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;
4732:   {    int n;    +  struct compilation *c = THIS_COMPILATION;    struct identifier dummy;    struct reference ref;   
4746:       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;
4999:    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);
5157:       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) {
5639:       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;   
5701:       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;
9257:    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");