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.204 2000/09/09 19:39:44 hubbe Exp $"); + RCSID("$Id: las.c,v 1.205 2000/09/11 22:10:38 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)   {    if(!d_flag) return;    if(!n) return;    if(n->token==USHRT_MAX)    fatal("Free node in tree.\n");       check_node_hash(n);       switch(n->token)
pike.git/src/las.c:132: Inside #if defined(PIKE_DEBUG) and #if defined(PIKE_DEBUG)
   fatal("Type of external node is not matching it's identifier.\n");    }   #endif    }    }    }    }       if(d_flag<2) return;    +  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    if(CAR(n)->parent != n)    fatal("Parent is wrong.\n");   #endif /* !SHARED_NODES */       check_tree(CAR(n),depth);
pike.git/src/las.c:163: Inside #if defined(PIKE_DEBUG) and #if undefined(SHARED_NODES)
  #ifndef SHARED_NODES    if(CDR(n)->parent != n)    fatal("Parent is wrong.\n");   #endif /* !SHARED_NODES */       check_tree(CDR(n),depth);    }   }   #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)    {    case F_COMMA_EXPR:    case F_VAL_LVAL:    case F_ARG_LIST:
pike.git/src/las.c:228:    n->type == void_type_string)    return 0;    return 1;       default:    if(n->type == void_type_string) return 0;    return 1;    }   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   struct pike_string *find_return_type(node *n)   {    struct pike_string *a,*b;       check_tree(n,0);       if(!n) return 0;       if (n->token == F_RETURN) {    if (CAR(n)) {
pike.git/src/las.c:363: Inside #if defined(SHARED_NODES)
   orig->node_info |= OPT_DEFROSTED;    /* Make sure we don't find ourselves */    sub_node(orig);       n = node_hash.table[hash % node_hash.size];       while (n) {    if ((n->hash == hash) &&    !MEMCMP(&(n->token), &(orig->token),    sizeof(node) - OFFSETOF(node_s, token))) { +  if (orig->type && (orig->type != n->type)) { +  if (n->type) { +  /* Use the new type if it's stricter. */ +  if (pike_types_le(orig->type, n->type)) { +  free_string(n->type); +  copy_shared_string(n->type, orig->type); +  } +  } else { +  /* This probably doesn't happen, but... */ +  copy_shared_string(n->type, orig->type); +  } +  }    free_node(dmalloc_touch(node *, orig));    n->refs++;    return check_node_hash(dmalloc_touch(node *, n));    }    n = n->next;    }    orig->node_info &= ~OPT_DEFROSTED;    add_node(dmalloc_touch(node *, orig));    check_tree(orig,0);    return check_node_hash(orig);
pike.git/src/las.c:471:   #endif    free_all_node_s_blocks();    cumulative_parse_error=0;      #ifdef SHARED_NODES    MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size);   #endif /* SHARED_NODES */    }   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   void debug_free_node(node *n)   {    if(!n) return;   #ifdef PIKE_DEBUG    if(l_flag>9)    print_tree(n);      #ifdef SHARED_NODES    {    size_t hash;
pike.git/src/las.c:1409:    }    }    }    UNSETJMP(tmp);    ret=mkconstantsvaluenode(Pike_sp-1);    pop_stack();    return ret;   }       + /* FIXME: Ought to use parent pointer to avoid recursion. */   int node_is_eq(node *a,node *b)   {    check_tree(a,0);    check_tree(b,0);       if(a == b) return 1;    if(!a || !b) return 0;    if(a->token != b->token) return 0;       switch(a->token)
pike.git/src/las.c:1539:    return mkconstantsvaluenode(s);   }         /* these routines operates on parsetrees and are mostly used by the    * optimizer    */      #if 1 /* DEAD_CODE - I need this /Hubbe */    + /* FIXME: Ought to use parent pointer to avoid recursion. +  * In the SHARED_NODES case there's no need of course. +  */   node *copy_node(node *n)   {    node *b;    debug_malloc_touch(n);    debug_malloc_touch(n->type);    debug_malloc_touch(n->u.node.a);    debug_malloc_touch(n->u.node.b);    check_tree(n,0);    if(!n) return n;    switch(n->token)
pike.git/src/las.c:1707:    CAR(*a)->token != F_POP_VALUE &&    CAR(*a)->token != F_ARG_LIST &&    CAR(*a)->token != F_COMMA_EXPR)    return &_CAR(*a);    if((n=last_cmd(&_CAR(*a))))    return n;    }    return 0;   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static node **low_get_arg(node **a,int *nr)   {    node **n;    if (!a[0]) return NULL;    if(a[0]->token != F_ARG_LIST)    {    if(!(*nr)--)    return a;    else    return NULL;
pike.git/src/las.c:1747:    CAR(n)->token == F_CONSTANT &&    CAR(n)->u.sval.type == T_FUNCTION &&    CAR(n)->u.sval.subtype == FUNCTION_BUILTIN &&    CAR(n)->u.sval.u.efun->function == f)    return &_CDR(n);    }    return 0;   }       + /* FIXME: Ought to use parent pointer to avoid recursion. */   static void low_print_tree(node *foo,int needlval)   {    if(!foo) return;    if(l_flag>9)    {    fprintf(stderr, "/*%x*/",foo->tree_info);    }    switch(l_flag > 99 ? -1 : foo->token)    {    case USHRT_MAX:
pike.git/src/las.c:2131:    }   #endif /* PIKE_DEBUG */    new = (struct scope_info *)xalloc(sizeof(struct scope_info));    MEMSET(new, VAR_UNUSED, sizeof(struct scope_info));    new->next = *a;    new->scope_id = scope_id;    *a = new;    return new->vars + num;   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   /* Find the variables that are used in the tree n. */   static int find_used_variables(node *n,    struct used_vars *p,    int noblock,    int overwrite)   {    struct used_vars *a;    char *q;       if(!n) return 0;
pike.git/src/las.c:2257:    find_used_variables(CDR(n),p,noblock,0);    break;       default:    if(car_is_node(n)) find_used_variables(CAR(n),p,noblock,0);    if(cdr_is_node(n)) find_used_variables(CDR(n),p,noblock,0);    }    return 0;   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   /* no subtility needed */   static void find_written_vars(node *n,    struct used_vars *p,    int lvalue)   {    if(!n) return;       switch(n->token)    {    case F_LOCAL:
pike.git/src/las.c:2528: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr,"The answer is (durumroll) : no\n");    return 0;    }    }    return depend_p3(a,b);   }   #else   #define depend_p depend_p3   #endif    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static int cntargs(node *n)   {    if(!n) return 0;    switch(n->token)    {    case F_CAST:    case F_SOFT_CAST:    case F_APPLY:    return n->type != void_type_string;   
pike.git/src/las.c:2558:    case F_ARG_LIST:    return cntargs(CAR(n))+cntargs(CDR(n));       /* this might not be true, but it doesn't matter very much */    default: return 1;    }   }      static int function_type_max=0;    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static void low_build_function_type(node *n)   {    if(!n) return;    if(function_type_max++ > 999)    {    reset_type_stack();       push_type(T_MIXED);    push_type(T_VOID);    push_type(T_OR); /* return type is void or mixed */
pike.git/src/las.c:3165:    }    }    if (old_type) {    free_string(old_type);    }   #ifdef PIKE_DEBUG    check_type_string(n->type);   #endif /* PIKE_DEBUG */   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static void zapp_try_optimize(node *n)   {    if(!n) return;    n->node_info &=~ OPT_TRY_OPTIMIZE;    n->tree_info &=~ OPT_TRY_OPTIMIZE;    if(car_is_node(n)) zapp_try_optimize(CAR(n));    if(cdr_is_node(n)) zapp_try_optimize(CDR(n));   }      #if defined(SHARED_NODES) && !defined(IN_TPIKE) -  + /* FIXME: Ought to use parent pointer to avoid recursion. */   static void find_usage(node *n, unsigned char *usage,    unsigned char *switch_u,    const unsigned char *cont_u,    const unsigned char *break_u,    const unsigned char *catch_u)   {    if (!n)    return;       switch(n->token) {
pike.git/src/las.c:4272:    }    n = mksoftcastnode(nn->type, n);    free_node(nn);    }    }    return dmalloc_touch(node *, n);   }      INT32 last_function_opt_info;    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static int stupid_args(node *n, int expected,int vargs)   {    if(!n) return expected;    switch(n->token)    {    case F_PUSH_ARRAY:    if(!vargs) return -1;       if(stupid_args(CAR(n), expected,vargs) == expected+1)    return 65535;
pike.git/src/las.c:4295:    expected=stupid_args(CAR(n), expected,vargs);    if(expected==-1) return -1;    return stupid_args(CDR(n), expected,vargs);    case F_LOCAL:    return (!n->u.integer.b && n->u.integer.a==expected) ? expected + 1 : -1;    default:    return -1;    }   }    + /* FIXME: Ought to use parent pointer to avoid recursion. */   static int is_null_branch(node *n)   {    if(!n) return 1;    if((n->token==F_CAST && n->type==void_type_string) ||    n->token == F_POP_VALUE)    return is_null_branch(CAR(n));    if(n->token==F_ARG_LIST)    return is_null_branch(CAR(n)) && is_null_branch(CDR(n));    return 0;   }