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.205 2000/09/11 22:10:38 grubba Exp $"); + RCSID("$Id: las.c,v 1.206 2000/09/12 14:02: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:87:    case F_IDENTIFIER:    case F_TRAMPOLINE:    case F_CONSTANT:    case F_LOCAL:    return 1;    }    return 0;   }      #ifdef PIKE_DEBUG - /* FIXME: Ought to use parent pointer to avoid recursion. */ +    void check_tree(node *n, int depth)   { -  +  node *orig_n = n; +  node *parent; +     if(!d_flag) return; -  if(!n) return; +  +  if (!n) return; +  +  parent = n->parent; +  n->parent = NULL; +  +  while(n) {    if(n->token==USHRT_MAX)    fatal("Free node in tree.\n");       check_node_hash(n);       switch(n->token)    {    case F_EXTERNAL:    if(n->type)    {
pike.git/src/las.c:131: Inside #if defined(PIKE_DEBUG) and #if defined(PIKE_DEBUG)
   printf("\n");       fatal("Type of external node is not matching it's identifier.\n");    }   #endif    }    }    }    }    -  if(d_flag<2) return; +  if(d_flag<2) break;       if (!(depth & 63)) {    /* 512 bytes/stack frame should be enough... */    check_c_stack(32768);       if(!(depth & 1023))    {    node *q;    for(q=n->parent;q;q=q->parent)    if(q->parent==n)    fatal("Cyclic node structure found.\n");    }    } -  depth++; +        if(car_is_node(n))    { - #ifndef SHARED_NODES +  /* Check CAR */ + #ifdef SHARED_NODES +  CAR(n)->parent = n; + #else /* !SHARED_NODES */    if(CAR(n)->parent != n)    fatal("Parent is wrong.\n"); - #endif /* !SHARED_NODES */ + #endif /* SHARED_NODES */    -  check_tree(CAR(n),depth); +  depth++; +  n = CAR(n); +  continue;    }       if(cdr_is_node(n))    { - #ifndef SHARED_NODES +  /* Check CDR */ + #ifdef SHARED_NODES +  CDR(n)->parent = n; + #else /* !SHARED_NODES */    if(CDR(n)->parent != n)    fatal("Parent is wrong.\n");   #endif /* !SHARED_NODES */    -  check_tree(CDR(n),depth); +  depth++; +  n = CDR(n); +  continue;    } -  +  +  while(n->parent && +  (!cdr_is_node(n->parent) || (CDR(n->parent) == n))) { +  /* Backtrack */ +  n = n->parent; +  depth--;    } -  +  +  if (n->parent && cdr_is_node(n->parent)) { +  /* Jump to the sibling */ + #ifdef SHARED_NODES +  CDR(n->parent)->parent = n->parent; + #else /* !SHARED_NODES */ +  if(CDR(n->parent)->parent != n->parent) +  fatal("Parent is wrong.\n"); + #endif /* !SHARED_NODES */ +  n = CDR(n->parent); +  continue; +  } +  break; +  } +  +  if (n != orig_n) { +  fprintf(stderr, "check_tree() lost track.\n"); +  d_flag = 0; +  fprintf(stderr, "n:"); +  print_tree(n); +  fprintf(stderr, "orig_n:"); +  print_tree(orig_n); +  fatal("check_tree() lost track.\n"); +  } +  n->parent = parent; + }   #endif      /* FIXME: Ought to use parent pointer to avoid recursion. */   INT32 count_args(node *n)   {    int a,b;    check_tree(n,0);    if(!n) return 0;    switch(n->token)    {
pike.git/src/las.c:213:    case F_RETURN:    case F_CONTINUE:    case F_FOREACH:    return 0;       case '?':    {    int tmp1,tmp2;    tmp1=count_args(CADR(n));    tmp2=count_args(CDDR(n)); -  if(tmp1==-1 || tmp2==-2) return -1; +  if(tmp1==-1 || tmp2==-1) return -1;    if(tmp1 < tmp2) return tmp1;    return tmp2;    }       case F_PUSH_ARRAY:    return -1;       case F_APPLY:    if(CAR(n)->token == F_CONSTANT &&    CAR(n)->u.sval.type == T_FUNCTION &&