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.108 1999/11/17 02:50:34 grubba Exp $"); + RCSID("$Id: las.c,v 1.109 1999/11/17 03:20:26 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:39:   static void optimize(node *n);   static node *localopt(node *n);      node *init_node = 0;   int num_parse_error;   int cumulative_parse_error=0;   extern char *get_type_name(int);      #define MAX_GLOBAL 2048    - int car_is_node(const node *n) + int car_is_node(node *n)   {    switch(n->token)    {    case F_EXTERNAL:    case F_IDENTIFIER:    case F_TRAMPOLINE:    case F_CONSTANT:    case F_LOCAL:    return 0;       default:    return !!_CAR(n);    }   }    - int cdr_is_node(const node *n) + int cdr_is_node(node *n)   {    switch(n->token)    {    case F_EXTERNAL:    case F_IDENTIFIER:    case F_TRAMPOLINE:    case F_CONSTANT:    case F_LOCAL:    case F_CAST:    return 0;
pike.git/src/las.c:2170: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   const unsigned char *cont_u,    const unsigned char *break_u)   {    if (!n)    return;       switch(n->token) {    case F_ASSIGN:    if ((CDR(n)->token == F_LOCAL) && (!CDR(n)->u.integer.b)) {    usage[CDR(n)->u.integer.a] = 0; +  } else if (CDR(n)->token == F_ARRAY_LVALUE) { +  find_usage(CDR(n), usage, switch_u, cont_u, break_u);    }    find_usage(CAR(n), usage, switch_u, cont_u, break_u);    return;    -  +  case F_LVALUE_LIST: +  find_usage(CDR(n), usage, switch_u, cont_u, break_u); +  if (CAR(n)) { +  if ((CAR(n)->token == F_LOCAL) && (!CAR(n)->u.integer.b)) { +  usage[CAR(n)->u.integer.a] = 0; +  } +  } +  return; +  +  case F_ARRAY_LVALUE: +  find_usage(CAR(n), usage, switch_u, cont_u, break_u); +  return; +     case F_CONTINUE:    MEMCPY(usage, cont_u, MAX_LOCAL);    return;       case F_BREAK:    MEMCPY(usage, break_u, MAX_LOCAL);    return;       case F_DEFAULT:    case F_CASE:
pike.git/src/las.c:2278: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
      find_usage(CAR(n), usage, switch_u, break_usage, continue_usage);    return;    }       case F_FOR:    {    unsigned char break_usage[MAX_LOCAL];    unsigned char continue_usage[MAX_LOCAL];    node *car1, cadr, cddr; +  int i;       MEMCPY(break_usage, usage, MAX_LOCAL);       /* for(;a;b) c; is handled like:    *    * if (a) { do { c; b; } while(a); }    */    find_usage(CAR(n), usage, switch_u, cont_u, break_u);    find_usage(CDDR(n), usage, switch_u, cont_u, break_usage);       MEMCPY(continue_usage, usage, MAX_LOCAL);       find_usage(CADR(n), usage, switch_u, continue_usage, break_usage);    -  +  for (i = 0; i < MAX_LOCAL; i++) { +  usage[i] |= break_usage[i]; +  } +     find_usage(CAR(n), usage, switch_u, cont_u, break_u);    return;    }       case F_FOREACH:    {    unsigned char break_usage[MAX_LOCAL];    unsigned char continue_usage[MAX_LOCAL];       MEMCPY(break_usage, usage, MAX_LOCAL);
pike.git/src/las.c:2353: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
      switch(n->token) {    case F_ASSIGN:    if ((CDR(n)->token == F_LOCAL) && (!CDR(n)->u.integer.b)) {    /* Assignment of local variable */    if (!(usage[CDR(n)->u.integer.a] & 1)) {    /* Value isn't used. */    return low_localopt(CAR(n), usage, switch_u, cont_u, break_u);    }    usage[CDR(n)->u.integer.a] = 0; +  cdr = CDR(n); +  ADD_NODE_REF(cdr); +  } else if (CDR(n)->token == F_ARRAY_LVALUE) { +  cdr = low_localopt(CDR(n), usage, switch_u, cont_u, break_u); +  } else { +  cdr = CDR(n); +  ADD_NODE_REF(cdr);    } -  ADD_NODE_REF(CDR(n)); +     return mknode(F_ASSIGN, low_localopt(CAR(n), usage, switch_u, cont_u, -  break_u), CDR(n)); +  break_u), cdr);    -  +  case F_LVALUE_LIST: +  cdr = low_localopt(CDR(n), usage, switch_u, cont_u, break_u); +  if (CAR(n)) { +  if ((CAR(n)->token == F_LOCAL) && (!CAR(n)->u.integer.b)) { +  /* Array assignment of local variable. */ +  if (!(usage[CDR(n)->u.integer.a] & 1)) { +  /* Variable isn't used. */ +  /* FIXME: Warn? */ +  } +  usage[CAR(n)->u.integer.a] = 0; +  } +  ADD_NODE_REF(CAR(n)); +  } +  return mknode(F_LVALUE_LIST, CAR(n), cdr); +  +  case F_ARRAY_LVALUE: +  return mknode(F_ARRAY_LVALUE, low_localopt(CAR(n), usage, switch_u, cont_u, +  break_u), 0); +  +  +     case F_CAST:    return mkcastnode(n->type, low_localopt(CAR(n), usage, switch_u, cont_u,    break_u));       case F_CONTINUE:    MEMCPY(usage, cont_u, MAX_LOCAL);    ADD_NODE_REF(n);    return n;       case F_BREAK:
pike.git/src/las.c:2474: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   car = low_localopt(CAR(n), usage, switch_u, continue_usage, break_usage);       return mknode(F_DO, car, cdr);    }       case F_FOR:    {    unsigned char break_usage[MAX_LOCAL];    unsigned char continue_usage[MAX_LOCAL];    node *car1, *cadr, *cddr; +  int i;       MEMCPY(break_usage, usage, MAX_LOCAL);       /* Find the usage from the body. */    find_usage(n, usage, switch_u, cont_u, break_usage);       /* for(;a;b) c; is handled like:    *    * if (a) { do { c; b; } while(a); }    */    car = low_localopt(CAR(n), usage, switch_u, cont_u, break_u);    cddr = low_localopt(CDDR(n), usage, switch_u, cont_u, break_usage);       MEMCPY(continue_usage, usage, MAX_LOCAL);       cadr = low_localopt(CADR(n), usage, switch_u, continue_usage,    break_usage);    cdr = mknode(':', cadr, cddr);    -  +  for (i = 0; i < MAX_LOCAL; i++) { +  usage[i] |= break_usage[i]; +  } +     /* We need to update the usage set */    find_usage(car, usage, switch_u, cont_u, break_u);       return mknode(F_FOR, car, cdr);    }       case F_FOREACH:    {    unsigned char break_usage[MAX_LOCAL];    unsigned char continue_usage[MAX_LOCAL];