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.770 2009/09/09 15:58:21 grubba Exp $ + || $Id: program.c,v 1.771 2009/09/12 13:31:37 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:1945:    }    }    }    }    /* fprintf(stderr, "not found\n"); */    return 0;   }      /* Here starts routines which are used to build new programs */    + /* +  * A typical program goes through the following steps: +  * +  * allocate_program ==> PROGRAM_VIRGIN +  * +  * start_program ==> !PROGRAM_VIRGIN +  * +  * end_first_pass ==> PROGRAM_PASS_1_DONE +  * +  * fixate_program ==> PROGRAM_FIXED +  * +  * optimize_program ==> PROGRAM_OPTIMIZED +  * +  * end_first_pass(1) ==> PROGRAM_FINISHED +  */ +    /* Re-allocate all the memory in the program in one chunk. because:    * 1) The individual blocks are much bigger than they need to be    * 2) cuts down on malloc overhead (maybe)    * 3) localizes memory access (decreases paging)    */   void optimize_program(struct program *p)   {    size_t size=0;    char *data;   
pike.git/src/program.c:2475:    int *idp)   {    struct compilation *c = THIS_COMPILATION;    int id=0;    struct svalue tmp;       CHECK_COMPILER();      #ifdef WITH_FACETS    if(Pike_compiler->compiler_pass == 1 && p) { -  p->facet_class = 0; +     p->facet_index = -1;    p->facet_group = NULL;    }   #endif       /* We don't want to change thread, but we don't want to    * wait for the other threads to complete either.    */    low_init_threads_disable();   
pike.git/src/program.c:3686:    * Finish this program, returning the newly built program    */   PMOD_EXPORT struct program *debug_end_program(void)   {    Pike_compiler->compiler_pass = 2;    return end_first_pass(1);   }         /* -  * Allocate needed for this program in the object structure. +  * Allocate space needed for this program in the object structure.    * An offset to the data is returned.    */   PMOD_EXPORT size_t low_add_storage(size_t size, size_t alignment,    ptrdiff_t modulo_orig)   {    ptrdiff_t offset;    ptrdiff_t modulo;       if(!size) return Pike_compiler->new_program->storage_needed;   
pike.git/src/program.c:4041:   }      int find_inherit(struct program *p, struct pike_string *name)   {    int e;      #if 0    fprintf(stderr, "find_inherit(0x%08lx, \"%s\")...\n",    (unsigned long)p, name->str);   #endif /* 0 */ +  /* FIXME: This loop could be optimized by advancing by the number +  * of inherits in the inherit. But in that case the loop +  * would have to go the other way. +  */    for(e = p->num_inherits-1; e>0; e--) {   #if 0    fprintf(stderr, " %04d: %04d %s\n",    e, p->inherits[e].inherit_level,    p->inherits[e].name?p->inherits[e].name->str:"NULL");   #endif /* 0 */    if (p->inherits[e].inherit_level > 1) continue;    if (name == p->inherits[e].name) return e;    }    return 0;   }    -  + /* Reference the symbol super_name::function_name */   node *reference_inherited_identifier(struct pike_string *super_name,    struct pike_string *function_name)   {    int n,e,id;    struct compilation *c = THIS_COMPILATION;    struct program_state *state=Pike_compiler->previous;       struct program *p;         #ifdef PIKE_DEBUG    if(function_name!=debug_findstring(function_name))    Pike_fatal("reference_inherited_function on nonshared string.\n");   #endif       p=Pike_compiler->new_program;    -  +  /* FIXME: This loop could be optimized by advancing by the number +  * of inherits in the inherit. But in that case the loop +  * would have to go the other way. +  */    for(e=p->num_inherits-1;e>0;e--)    {    if(p->inherits[e].inherit_level!=1) continue;    if(!p->inherits[e].name) continue;       if(super_name)    if(super_name != p->inherits[e].name)    continue;       id=low_reference_inherited_identifier(0,
pike.git/src/program.c:4115:    {    return mknode(F_MAGIC_VALUES,mknewintnode(e),mknewintnode(0));    }    }          for(n=0;n<c->compilation_depth;n++,state=state->previous)    {    struct program *p=state->new_program;    +  /* FIXME: This loop could be optimized by advancing by the number +  * of inherits in the inherit. But in that case the loop +  * would have to go the other way. +  */    for(e=p->num_inherits-1;e>0;e--)    {    if(p->inherits[e].inherit_level!=1) continue;    if(!p->inherits[e].name) continue;       if(super_name)    if(super_name != p->inherits[e].name)    continue;       id=low_reference_inherited_identifier(state,e,function_name,SEE_PROTECTED);
pike.git/src/program.c:4160:    {    return mknode(F_MAGIC_VALUES,    mknewintnode(e),mknewintnode(n+1));    }    }    }       return 0;   }    + /* FIXME: This function probably doesn't do what it is intended to do +  * if the last inherit had inherits of its own. Consider removal. +  */   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,
pike.git/src/program.c:4245:   }   #endif      #ifdef WITH_FACETS   void check_for_facet_inherit(struct program *p)   {    /* If the inherit statement comes before the facet keyword in the    * class declaration the class will be temporarily marked as a    * product-class, but this will be taken care of when the facet    * keyword is found. */ -  if (p && Pike_compiler->new_program->facet_group && +  if (!p) return; +  if (Pike_compiler->new_program->facet_group &&    p->facet_group != Pike_compiler->new_program->facet_group)    yyerror("A class can not belong to two facet-groups."); -  if (p && p->facet_class == PROGRAM_IS_FACET_CLASS) { -  if (Pike_compiler->new_program->facet_class == PROGRAM_IS_FACET_CLASS) { +  if (p->flags & PROGRAM_IS_FACET) { +  if (Pike_compiler->new_program->flags & PROGRAM_IS_FACET) {    if(Pike_compiler->new_program->facet_index != p->facet_index)    yyerror("Facet class can't inherit from class in different facet.");    }    /* Otherwise this is a product class */    else {    if( !Pike_compiler->new_program->facet_group ) { -  Pike_compiler->new_program->facet_class = PROGRAM_IS_PRODUCT_CLASS; +  Pike_compiler->new_program->flags |= PROGRAM_IS_PRODUCT;    add_ref(p->facet_group);    Pike_compiler->new_program->facet_group = p->facet_group;    }    push_int(Pike_compiler->new_program->id);    push_int(p->facet_index);    push_int(p->id);    safe_apply(p->facet_group, "add_product_class", 3);    pop_stack();    }    }    /* The inherited class is not a facet class */ -  else if (p && p->facet_class == PROGRAM_IS_PRODUCT_CLASS) { -  if (Pike_compiler->new_program->facet_class == PROGRAM_IS_FACET_CLASS) { +  else if (p->flags & PROGRAM_IS_PRODUCT) { +  if (Pike_compiler->new_program->flags & PROGRAM_IS_FACET) {    yyerror("Facet class can't inherit from product class.");    } -  else if(Pike_compiler->new_program->facet_class==PROGRAM_IS_PRODUCT_CLASS){ -  yyerror("Product class can't inherit from other prodcut class."); +  else if(Pike_compiler->new_program->flags & PROGRAM_IS_PRODUCT){ +  yyerror("Product class can't inherit from other product class.");    }    /* A class that inherits from a product class is also a product class */ -  else if(Pike_compiler->new_program->facet_class!=PROGRAM_IS_FACET_CLASS) { -  Pike_compiler->new_program->facet_class = PROGRAM_IS_PRODUCT_CLASS; +  else { +  Pike_compiler->new_program->flags |= PROGRAM_IS_PRODUCT;    add_ref(p->facet_group);    Pike_compiler->new_program->facet_group = p->facet_group;    }    }   }   #endif         /*    * make this program inherit another program
pike.git/src/program.c:4703:   /*    * Return the index of the identifier found, otherwise -1.    */   int isidentifier(struct pike_string *s)   {    return really_low_find_shared_string_identifier(s,    Pike_compiler->new_program,    SEE_PROTECTED|SEE_PRIVATE);   }    + /* +  * Definition of identifiers. +  * +  * Pike has three plus one classes of identifiers: +  * +  * IDENTIFIER_VARIABLE - A value stored in object->storage +  * IDENTIFIER_CONSTANT - A value stored in program->constants +  * IDENTIFIER_FUNCTION - Either a C function or a Pike function +  * and +  * IDENTIFIER_ALIAS - An alias for a different identifier. +  * +  */ +  +    /* Define an alias for a (possibly extern) identifier.    *    * 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;
pike.git/src/program.c:4914:    add_to_variable_index(ref.identifier_offset);       debug_add_to_identifiers(dummy);       n=Pike_compiler->new_program->num_identifier_references;    add_to_identifier_references(ref);       return n;   }    + /* type is a textual type */   PMOD_EXPORT int map_variable(const char *name,    const char *type,    INT32 flags,    size_t offset,    INT32 run_time_type)   {    int ret;    struct pike_string *n;    struct pike_type *t;   
pike.git/src/program.c:4939:   #endif       n=make_shared_string(name);    t=parse_type(type);    ret=low_define_variable(n,t,flags|ID_USED,offset,run_time_type);    free_string(n);    free_type(t);    return ret;   }    + /* type is a serialized tokenized type. */   PMOD_EXPORT int quick_map_variable(const char *name,    int name_length,    size_t offset,    const char *type,    int type_length,    INT32 run_time_type,    INT32 flags)   {    int ret;    struct pike_string *n;