pike.git / src / las.c

version» Context lines:

pike.git/src/las.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   /**/   #include "global.h" - RCSID("$Id: las.c,v 1.103 1999/11/12 01:32:04 grubba Exp $"); + RCSID("$Id: las.c,v 1.104 1999/11/12 18:19:42 grubba Exp $");      #include "language.h"   #include "interpret.h"   #include "las.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "lex.h"   #include "pike_types.h"
pike.git/src/las.c:255: Inside #if defined(SHARED_NODES)
  }      static node *freeze_node(node *orig)   {    unsigned INT32 hash = hash_node(orig);    node *n = node_hash.table[hash % node_hash.size];       /* free_node() wants a correct hash */    orig->hash = hash;    - #ifdef PIKE_DEBUG -  if (orig->refs != 1) { -  print_tree(orig); -  fatal("Node to be frozen is already shared!\n"); -  } - #endif /* PIKE_DEBUG */ -  +     if (orig->node_info & OPT_NOT_SHARED) {    /* No need to have this node in the hash-table. */    /* add_node(orig); */ -  return dmalloc_touch(node *, orig); +  return check_node_hash(dmalloc_touch(node *, orig));    }       while (n) {    if ((n->hash == hash) &&    !MEMCMP(&(n->token), &(orig->token),    sizeof(node) - OFFSETOF(node_s, token))) {   #ifdef PIKE_DEBUG    if (n == orig) {    fatal("Node to be frozen was already cold!\n");    }   #endif /* PIKE_DEBUG */    free_node(dmalloc_touch(node *, orig));    n->refs++; -  return dmalloc_touch(node *, n); +  return check_node_hash(dmalloc_touch(node *, n));    }    n = n->next;    }    add_node(dmalloc_touch(node *, orig)); -  return orig; +  return check_node_hash(orig);   }      #else /* !SHARED_NODES */      #define freeze_node(X) (X)      #endif /* SHARED_NODES */      void free_all_nodes(void)   {
pike.git/src/las.c:426:    if(n->current_file) free_string(n->current_file);   #endif    really_free_node_s(n);   }         node *debug_check_node_hash(node *n)   {   #if defined(PIKE_DEBUG) && defined(SHARED_NODES)    if (n && (n->hash != hash_node(n))) { +  fprintf(stderr,"Bad node hash at %p, (%s:%d) (token=%d).\n", +  n, n->current_file->str, n->line_number, +  n->token); +  debug_malloc_dump_references(n); +  print_tree(n);    fatal("Bad node hash!\n");    }   #endif /* PIKE_DEBUG && SHARED_NODES */    return n;   }      /* here starts routines to make nodes */   static node *debug_mkemptynode(void)   {    node *res=alloc_node_s();
pike.git/src/las.c:740: Inside #if defined(SHARED_NODES)
  #ifdef SHARED_NODES    res->u.id.prog = new_program;   #endif /* SHARED_NODES */       res = freeze_node(res);       check_tree(res,0);    return res;   }    + node *debug_mktrampolinenode(int i) + { +  node *res = mkemptynode(); +  res->token = F_TRAMPOLINE; +  copy_shared_string(res->type, ID_FROM_INT(new_program, i)->type); +  +  /* FIXME */ +  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(new_program, i)->identifier_flags)) +  { +  res->node_info = OPT_EXTERNAL_DEPEND; +  }else{ +  res->node_info = OPT_NOT_CONST; +  } +  res->tree_info=res->node_info; +  + #ifdef __CHECKER__ +  _CDR(res) = 0; + #endif +  res->u.id.number = i; + #ifdef SHARED_NODES +  res->u.id.prog = new_program; + #endif /* SHARED_NODES */ +  +  res = freeze_node(res); +  +  check_tree(res,0); +  return res; + } +    node *debug_mkexternalnode(int level,    int i,    struct identifier *id)   {    node *res = mkemptynode();    res->token = F_EXTERNAL;       copy_shared_string(res->type, id->type);       /* FIXME */
pike.git/src/las.c:796:       _CAR(res) = n;   #ifdef SHARED_NODES    _CDR(res) = (node *)type;   #else /* !SHARED_NODES */   #ifdef __CHECKER__    _CDR(res) = 0;   #endif   #endif /* SHARED_NODES */    -  n->parent=res; +  n->parent = res;       return freeze_node(res);   }      void resolv_constant(node *n)   {    struct identifier *i;    struct program *p;    INT32 numid;   
pike.git/src/las.c:2086:    if(car_is_node(n)) zapp_try_optimize(CAR(n));    if(cdr_is_node(n)) zapp_try_optimize(CDR(n));   }      static void optimize(node *n)   {    node *tmp1, *tmp2, *tmp3;    INT32 save_line = lex.current_line;    do    { -  if(car_is_node(n) && !(CAR(n)->node_info & OPT_OPTIMIZED)) +  if(car_is_node(n) && +  ((CAR(n)->node_info & (OPT_OPTIMIZED|OPT_DEFROSTED)) != OPT_OPTIMIZED))    { -  n=CAR(n); +  CAR(n)->parent = n; +  n = CAR(n);    continue;    } -  if(cdr_is_node(n) && !(CDR(n)->node_info & OPT_OPTIMIZED)) +  if(cdr_is_node(n) && +  ((CDR(n)->node_info & (OPT_OPTIMIZED|OPT_DEFROSTED)) != OPT_OPTIMIZED))    { -  n=CDR(n); +  CDR(n)->parent = n; +  n = CDR(n);    continue;    } -  +  + #if defined(SHARED_NODES) +  if ((n->node_info & OPT_DEFROSTED) && (n->parent)) { + #ifndef IN_TPIKE +  /* Add ref since both freeze_node() and use_tmp1 will free it. */ +  ADD_NODE_REF(n); +  /* We don't want freeze_node() to find this node in the hash-table. */ +  sub_node(n); +  tmp1 = freeze_node(n); +  if (tmp1 != n) { +  /* n was a duplicate node. Use the original. */ +  goto use_tmp1; +  } +  /* Remove the extra ref from n */ +  free_node(n); + #endif /* !IN_TPIKE */ +  /* The node is now frozen again. */ +  n->node_info &= ~OPT_DEFROSTED; +  if (n->node_info & OPT_OPTIMIZED) { +  /* No need to check this node any more. */ +  n = n->parent; +  continue; +  } +  } + #endif /* SHARED_NODES && !IN_TPIKE */ +     lex.current_line = n->line_number;          n->tree_info = n->node_info;    if(car_is_node(n)) n->tree_info |= CAR(n)->tree_info;    if(cdr_is_node(n)) n->tree_info |= CDR(n)->tree_info;       if(!n->parent) break;       if(n->tree_info & (OPT_NOT_CONST|
pike.git/src/las.c:2124:    OPT_ASSIGNMENT)) &&    (CAR(n)->tree_info & OPT_TRY_OPTIMIZE) &&    CAR(n)->token != ':')    {   #ifdef SHARED_NODES    sub_node(n);   #endif /* SHARED_NODES */    _CAR(n) = eval(CAR(n));   #ifdef SHARED_NODES    n->hash = hash_node(n); +  n->node_info |= OPT_DEFROSTED;    add_node(n);   #endif /* SHARED_NODES */    if(CAR(n)) CAR(n)->parent = n;    zapp_try_optimize(CAR(n)); /* avoid infinite loops */    continue;    }    if(cdr_is_node(n) &&    !(CDR(n)->tree_info & (OPT_NOT_CONST|    OPT_SIDE_EFFECT|    OPT_EXTERNAL_DEPEND|    OPT_ASSIGNMENT)) &&    (CDR(n)->tree_info & OPT_TRY_OPTIMIZE) &&    CDR(n)->token != ':')    {   #ifdef SHARED_NODES    sub_node(n);   #endif /* SHARED_NODES */    _CDR(n) = eval(CDR(n));   #ifdef SHARED_NODES    n->hash = hash_node(n); -  +  n->node_info |= OPT_DEFROSTED;    add_node(n);   #endif /* SHARED_NODES */    if(CDR(n)) CDR(n)->parent = n;    zapp_try_optimize(CDR(n)); /* avoid infinite loops */    continue;    }    }    fix_type_field(n);    debug_malloc_touch(n->type);   
pike.git/src/las.c:2167: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr,"Optimizing (tree info=%x):",n->tree_info);    print_tree(n);    }   #endif      #ifndef IN_TPIKE    switch(n->token)    {   #include "treeopt.h"    use_car: -  tmp1=CAR(n); +  tmp1 = CAR(n);    ADD_NODE_REF(CAR(n));    goto use_tmp1;       use_cdr: -  tmp1=CDR(n); +  tmp1 = CDR(n);    ADD_NODE_REF(CDR(n));    goto use_tmp1;       zap_node:    tmp1 = 0;    goto use_tmp1;       use_tmp1: -  + #ifdef PIKE_DEBUG +  if (l_flag > 4) { +  fprintf(stderr, "Optimized: "); +  print_tree(n); +  fprintf(stderr, "Result: "); +  print_tree(tmp1); +  } + #endif /* PIKE_DEBUG */ +    #ifdef SHARED_NODES    sub_node(n->parent);   #endif /* SHARED_NODES */       if(CAR(n->parent) == n)    _CAR(n->parent) = tmp1;    else    _CDR(n->parent) = tmp1;      #ifdef SHARED_NODES    n->parent->hash = hash_node(n->parent);    add_node(n->parent); -  +  n->parent->node_info |= OPT_DEFROSTED;   #endif /* SHARED_NODES */       if(tmp1)    tmp1->parent = n->parent;    else    tmp1 = n->parent;       free_node(n);    n = tmp1;      #ifdef PIKE_DEBUG    if(l_flag > 3)    { -  fprintf(stderr,"Result: "); +  fprintf(stderr,"Result: ");    print_tree(n);    }   #endif    continue;       }   #endif /* !IN_TPIKE */    n->node_info |= OPT_OPTIMIZED;    n=n->parent;    }while(n);