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.511 2003/08/02 01:10:17 mast Exp $ + || $Id: program.c,v 1.512 2003/08/03 01:01:37 mast Exp $   */      #include "global.h" - RCSID("$Id: program.c,v 1.511 2003/08/02 01:10:17 mast Exp $"); + RCSID("$Id: program.c,v 1.512 2003/08/03 01:01:37 mast Exp $");   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"   #include "pike_types.h"   #include "stralloc.h"   #include "las.h"   #include "language.h"   #include "lex.h"   #include "pike_macros.h"   #include "fsort.h"
pike.git/src/program.c:1305:    }    END_CYCLIC();    if(ret) return ret;    }       return 0;   }      /*! @decl constant this    *! -  *! Builtin constant that evaluates to the current object. +  *! Builtin read only variable that evaluates to the current object.    *!    *! @seealso    *! @[this_program], @[this_object()]    */      /*! @decl constant this_program    *!    *! Builtin constant that evaluates to the current program.    *!    *! @seealso
pike.git/src/program.c:1338: Inside #if 0
  {   #if 0    fprintf (stderr, "magic_identifier (state, %d, %d, %s, %d)\n",    state_depth, inherit_num, ident->str, colon_colon_ref);   #endif       if (!inherit_num) {    /* These are only recognized when looking in the current program    * and not an inherited one. */    -  /* Handle this */ -  if (ident == this_string) -  return mkefuncallnode ("this_object", mknewintnode (state_depth)); +  /* Handle this by referring to the magic this identifier at index 0. */ +  if (ident == this_string) { +  if (state_depth > 0) +  return mkexternalnode (state->new_program, IDREF_MAGIC_THIS); +  else +  return mkidentifiernode (IDREF_MAGIC_THIS); +  }       /* Handle this_program */ -  if (ident == this_program_string) -  return mkefuncallnode ("object_program", -  mkefuncallnode ("this_object", -  mknewintnode (state_depth))); +  if (ident == this_program_string) { +  node *n = mkefuncallnode ("object_program", +  state_depth > 0 ? +  mkexternalnode (state->new_program, IDREF_MAGIC_THIS) : +  mkidentifiernode (IDREF_MAGIC_THIS)); +  /* We know this expression is constant. */ +  n->node_info &= ~OPT_NOT_CONST; +  n->tree_info &= ~OPT_NOT_CONST; +  return n;    } -  +  }       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:2525: Inside #if defined(PIKE_DEBUG)
      if(p->inherits[e].storage_offset < 0)    Pike_fatal("Inherit->storage_offset is wrong.\n");       if(p->inherits[e].prog &&    p->inherits[e].storage_offset + STORAGE_NEEDED(p->inherits[e].prog) >    p->storage_needed)    Pike_fatal("Not enough room allocated by inherit!\n");       if (p->inherits[e].inherit_level == 1 && -  p->inherits[e].identifier_level != p->inherits[e].identifier_ref_offset) { +  p->inherits[e].identifier_level != (INT32) p->inherits[e].identifier_ref_offset) {    dump_program_tables (p, 0);    Pike_fatal ("Unexpected difference between identifier_level "    "and identifier_ref_offset in inherit %d.\n", e);    }       if(e)    {    if(p->inherits[e-1].storage_offset >    p->inherits[e].storage_offset)    Pike_fatal("Overlapping inherits! (1)\n");
pike.git/src/program.c:2553: Inside #if defined(PIKE_DEBUG)
   }    }          if(p->flags & PROGRAM_FINISHED)    for(e=0;e<p->num_identifiers;e++)    {    check_string(p->identifiers[e].name);    check_type_string(p->identifiers[e].type);    +  switch (p->identifiers[e].identifier_flags & IDENTIFIER_TYPE_MASK) { +  case IDENTIFIER_VARIABLE: +  case IDENTIFIER_PIKE_FUNCTION: +  case IDENTIFIER_C_FUNCTION: +  case IDENTIFIER_CONSTANT: +  break; +  +  default: +  Pike_fatal("Invalid identifier type.\n"); +  } +     if(p->identifiers[e].identifier_flags & ~IDENTIFIER_MASK)    Pike_fatal("Unknown flags in identifier flag field.\n");       if(p->identifiers[e].run_time_type!=T_MIXED)    check_type(p->identifiers[e].run_time_type);       if(IDENTIFIER_IS_VARIABLE(p->identifiers[e].identifier_flags))    {    if( (p->identifiers[e].func.offset /* + OFFSETOF(object,storage)*/ ) &    (alignof_variable(p->identifiers[e].run_time_type)-1))
pike.git/src/program.c:2594: Inside #if defined(PIKE_DEBUG)
      if(p->identifier_references[e].identifier_offset >    p->inherits[p->identifier_references[e].inherit_offset].prog->num_identifiers)    Pike_fatal("Identifier offset %d is wrong! %d > %d\n",    e,    p->identifier_references[e].identifier_offset,    p->inherits[p->identifier_references[e].inherit_offset].prog->num_identifiers);       i=ID_FROM_INT(p, e);    -  if( !(i->identifier_flags & (IDENTIFIER_FUNCTION | IDENTIFIER_CONSTANT))) +  if(IDENTIFIER_IS_VARIABLE(i->identifier_flags))    {    size_t q, size;    /* Variable */    ptrdiff_t offset = INHERIT_FROM_INT(p, e)->storage_offset+i->func.offset;    size=sizeof_variable(i->run_time_type);       if((offset+size > (size_t)p->storage_needed) || offset<0)    Pike_fatal("Variable outside storage! (%s)\n",i->name->str);       for(q=0;q<size;q++)
pike.git/src/program.c:3221:   }      void rename_last_inherit(struct pike_string *n)   {    if(Pike_compiler->new_program->inherits[Pike_compiler->new_program->num_inherits].name)    free_string(Pike_compiler->new_program->inherits[Pike_compiler->new_program->num_inherits].name);    copy_shared_string(Pike_compiler->new_program->inherits[Pike_compiler->new_program->num_inherits].name,    n);   }    + #if 0   static int locate_parent_state(struct program_state **state,    struct inherit **i,    int *parent_identifier,    int depth)   {    int result=1;    if(depth<=0) return depth;    while(depth-->0)    {    if( (*i)->parent_offset != INHERIT_PARENT)
pike.git/src/program.c:3288: Inside #if 0
   for(e=0;e<=parent_offset;e++) state=state->previous;    oi=INHERIT_FROM_INT(state->new_program, parent_identifier);    parent_offset+=i->parent_offset;   #endif       return locate_parent_state(&state,    &i,    &parent_identifier,    depth);   } + #endif      /*    * make this program inherit another program    */   void low_inherit(struct program *p,    struct object *parent,    int parent_identifier,    int parent_offset,    INT32 flags,    struct pike_string *name)
pike.git/src/program.c:3587:    if (!state) {    yyerror("Failed to resolv external constant.\n");    return;    }    p = state->new_program;    numid = n->u.integer.b;    }       continue_inherit:    -  i=ID_FROM_INT(p, numid); -  -  if(IDENTIFIER_IS_CONSTANT(i->identifier_flags)) +  if(numid != IDREF_MAGIC_THIS && +  (i=ID_FROM_INT(p, numid), IDENTIFIER_IS_CONSTANT(i->identifier_flags)))    {    struct svalue *s=&PROG_FROM_INT(p, numid)->    constants[i->func.offset].sval;    if(s->type != T_PROGRAM)    {    do_inherit(s,flags,name);    return;    }else{    low_inherit(s->u.program,    0,
pike.git/src/program.c:3708: Inside #if defined(PIKE_DEBUG)
   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);    if (flags & ID_ALIAS) { -  dummy.identifier_flags = IDENTIFIER_ALIAS; +  dummy.identifier_flags = IDENTIFIER_VARIABLE | IDENTIFIER_ALIAS;    } else { -  dummy.identifier_flags = 0; +  dummy.identifier_flags = IDENTIFIER_VARIABLE;    }    dummy.run_time_type=run_time_type;    dummy.func.offset=offset - Pike_compiler->new_program->inherits[0].storage_offset;   #ifdef PROFILING    dummy.self_time=0;    dummy.num_calls=0;    dummy.total_time=0;   #endif       ref.id_flags=flags;
pike.git/src/program.c:4018:    do {    if(/* c && */    c->type == T_FUNCTION &&    c->subtype != FUNCTION_BUILTIN &&    c->u.object->prog)    {    struct identifier *id=ID_FROM_INT(c->u.object->prog, c->subtype);    if(c->u.object->prog == Pike_compiler->new_program &&    !c->u.object->prog->identifier_references[c->subtype].inherit_offset)    { -  if(id->identifier_flags & IDENTIFIER_FUNCTION) +  if(IDENTIFIER_IS_FUNCTION(id->identifier_flags))    {    return define_function(name,    id->type,    flags,    id->identifier_flags | IDENTIFIER_ALIAS,    & id->func,    id->opt_flags);       } -  else if((id->identifier_flags & IDENTIFIER_CONSTANT) && +  else if(IDENTIFIER_IS_CONSTANT(id->identifier_flags) &&    id->func.offset != -1)    {    c=& Pike_compiler->new_program->constants[id->func.offset].sval;    }    }    else    { -  if((id->identifier_flags & IDENTIFIER_CONSTANT) && +  if(IDENTIFIER_IS_CONSTANT(id->identifier_flags) &&    id->func.offset != -1 &&    INHERIT_FROM_INT(c->u.object->prog, c->subtype)->prog->    constants[id->func.offset].sval.type == T_PROGRAM)    {    /* In this one case we allow fake objects to enter the    * mainstream...    */    break;    }    }
pike.git/src/program.c:7464:    }       if((Pike_fp->fun & 0xffff) == 0xffff)    Pike_error("Cannot access parent storage!\n");       loc.parent_identifier=Pike_fp->fun;    loc.inherit=INHERIT_FROM_INT(p, Pike_fp->fun);       find_external_context(&loc, depth);    +  if (!loc.o->prog) +  Pike_error ("Cannot access storage of destructed parent object.\n"); +     return loc.o->storage + loc.inherit->storage_offset;   }      PMOD_EXPORT void change_compiler_compatibility(int major, int minor)   {    STACK_LEVEL_START(0);       if(major == PIKE_MAJOR_VERSION && minor == PIKE_MINOR_VERSION)    {    push_int(0); /* optimization */