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.692 2008/05/11 14:55:54 mast Exp $ + || $Id: program.c,v 1.693 2008/05/13 17:11:18 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:3301:    dump_program_tables(p, 0);    Pike_fatal("Circular alias for reference %d!\n", e);    }    } else 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;    if (i->run_time_type == PIKE_T_GET_SET) {    struct reference *ref = PTR_FROM_INT(p, e);    if (!ref->inherit_offset) { -  INT32 *gs_info = (INT32 *)(p->program + i->func.offset); -  if ((gs_info + 2) > (INT32 *)(p->program + p->num_program)) { -  dump_program_tables(p, 0); -  Pike_fatal("Getter/setter variable outside program!\n"); -  } -  if (gs_info[0] >= p->num_identifier_references) { +  if (i->func.gs_info.getter >= p->num_identifier_references) {    Pike_fatal("Getter outside references.\n");    } -  if (gs_info[1] >= p->num_identifier_references) { +  if (i->func.gs_info.setter >= p->num_identifier_references) {    Pike_fatal("Setter outside references.\n");    }    }    continue;    }    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);   
pike.git/src/program.c:5391:    unsigned function_flags,    union idptr *func,    unsigned opt_flags)   {    struct compilation *c = THIS_COMPILATION;    struct identifier *funp,fun;    struct reference ref;    struct svalue *lfun_type;    int run_time_type = T_FUNCTION;    INT32 i; -  INT32 getter_setter_offset = -1; +  INT16 *getter_setter = NULL;       CHECK_COMPILER();      #ifdef PROGRAM_BUILD_DEBUG    {    struct pike_string *d = describe_type (type);    fprintf (stderr, "%.*sdefining function (pass=%d): %s ",    c->compilation_depth, "", Pike_compiler->compiler_pass, d->str);    free_string (d);    push_string (name);
pike.git/src/program.c:5443:    (index_shared_string(name, 1) == '-') &&    (index_shared_string(name, 2) == '>')) ||    ((name->len > 1) &&    (index_shared_string(name, 0) == '`') &&    ((index_shared_string(name, 1) >= 256) ||    isidchar(index_shared_string(name, 1))))) {    /* Getter setter. */    struct pike_string *symbol = NULL;    struct pike_type *symbol_type = NULL;    struct pike_type *gs_type = NULL; +  int is_setter = 0;    int delta = 1; /* new-style */    if (index_shared_string(name, 1) == '-') {    /* Getter setter (old-style). */    delta = 3;    }    if (index_shared_string(name, name->len-1) != '=') {    /* fprintf(stderr, "Got getter: %s\n", name->str); */    gs_type = lfun_getter_type_string; -  getter_setter_offset = 0; +     symbol = string_slice(name, delta, name->len-delta);    symbol_type = get_argument_type(type, -1);    } else if (name->len > delta+1) {    /* fprintf(stderr, "Got setter: %s\n", name->str); */    gs_type = lfun_setter_type_string; -  getter_setter_offset = -  ((PIKE_OPCODE_T *)(((INT32 *)0) + 1)) - ((PIKE_OPCODE_T *)0); +  is_setter = 1;    symbol = string_slice(name, delta, name->len-(delta+1));    symbol_type = get_argument_type(type, 0);    }       if (symbol) {    /* We got a getter or a setter. */    struct reference *ref;    if (!pike_types_le(type, gs_type)) {    if (!match_types(type, gs_type)) {    my_yyerror("Type mismatch for callback function %S:", name);
pike.git/src/program.c:5483:    }    }    i = isidentifier(symbol);    if ((i >= 0) &&    !((ref = PTR_FROM_INT(Pike_compiler->new_program, i))->    id_flags & ID_INHERITED)) {    /* Not an inherited symbol. */    struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, i);    if (!IDENTIFIER_IS_VARIABLE(id->identifier_flags)) {    my_yyerror("Illegal to redefine function %S with variable.", symbol); -  getter_setter_offset = -1; +     } else if (id->run_time_type != PIKE_T_GET_SET) {    my_yyerror("Illegal to redefine a current variable with a getter/setter: %S.", symbol); -  getter_setter_offset = -1; +     } else {    if ((ref->id_flags | ID_USED) != (flags | ID_USED)) {    if (Pike_compiler->compiler_pass == 1) {    yywarning("Modifier mismatch for variable %S.", symbol);    }    ref->id_flags &= flags | ID_USED;    } -  getter_setter_offset += id->func.offset; +  getter_setter = &id->func.gs_info.getter + is_setter;    }    /* FIXME: Update id->type here. */    } else { -  INT32 offset = Pike_compiler->new_program->num_program; -  getter_setter_offset += offset; -  /* Get/set information. -  * reference number to getter. -  * reference number to setter. -  * NOTE: Only place-holders for now. -  * The proper entry gets set when we have added the function. -  */ -  ins_pointer(-1); -  ins_pointer(-1); -  low_define_variable(symbol, symbol_type, flags, -  offset, PIKE_T_GET_SET); +  struct identifier *id; +  i = low_define_variable(symbol, symbol_type, flags, +  ~0, PIKE_T_GET_SET); +  id = ID_FROM_INT(Pike_compiler->new_program, i); +  +  /* Paranoia. */ +  id->func.gs_info.getter = -1; +  id->func.gs_info.setter = -1; +  +  getter_setter = &id->func.gs_info.getter + is_setter;    }    /* NOTE: The function needs to have the same PRIVATE/INLINE    * behaviour as the variable for overloading to behave    * as expected.    *    * FIXME: Force PRIVATE?    */    flags |= ID_STATIC;    free_type(symbol_type);    free_string(symbol);
pike.git/src/program.c:5563:    function_flags |= IDENTIFIER_HAS_BODY;       if(!(ref.id_flags & ID_INHERITED)) /* not inherited */    {       if( !( IDENTIFIER_IS_FUNCTION(funp->identifier_flags) &&    ( (!func || func->offset == -1) || (funp->func.offset == -1))))    {    my_yyerror("Identifier %S defined twice.", name);    -  if (getter_setter_offset >= 0) { -  upd_pointer(getter_setter_offset, i); +  if (getter_setter) { +  *getter_setter = i;    }    return i;    }       /* Note: The type from pass 1 may be incompatible with the one from    * pass 2. Only do this in pass 2, and only if the previous    * type isn't from pass 1.    */    if ((Pike_compiler->compiler_pass == 2) &&    (funp->run_time_type == T_FUNCTION)) {
pike.git/src/program.c:5671: Inside #if defined(PIKE_DEBUG)
   ref.inherit_offset, ref.identifier_offset,    ref.id_flags,    oref->inherit_offset,    oref->identifier_offset,    oref->id_flags,    overridden);    Pike_fatal("New function overloading algorithm failed!\n");    }   #endif    -  if (getter_setter_offset >= 0) { -  INT32 old_i = (INT32)read_pointer(getter_setter_offset); +  if (getter_setter) { +  INT32 old_i = *getter_setter;    if ((old_i >= 0) && (old_i != overridden)) {    my_yyerror("Multiple definitions for %S.", name);    } -  upd_pointer(getter_setter_offset, overridden); +  *getter_setter = overridden;    }    return overridden;    }    /* NOTE: At this point we already have the identifier in the    * new program, and just need to add the reference.    */    } else {    make_a_new_def:      #ifdef PIKE_DEBUG
pike.git/src/program.c:5736:    /* Add the reference. */       i=Pike_compiler->new_program->num_identifier_references;    add_to_identifier_references(ref);      #ifdef PROGRAM_BUILD_DEBUG    fprintf(stderr, "%.*sadded new definition #%d\n",    c->compilation_depth, "", i);   #endif    -  if (getter_setter_offset >= 0) { -  INT32 old_i = (INT32)read_pointer(getter_setter_offset); +  if (getter_setter) { +  INT32 old_i = *getter_setter;    if (old_i >= 0) {    my_yyerror("Multiple definitions for %S.", name);    } -  upd_pointer(getter_setter_offset, i); +  *getter_setter = i;    }       return i;   }      #if 0      int add_ext_ref(struct program_state *state, struct program *target, int i)   {    struct reference ref, *r;