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.195 2000/08/27 17:27:46 grubba Exp $"); + RCSID("$Id: las.c,v 1.196 2000/08/27 19:10:24 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:1891:      void print_tree(node *n)   {    check_tree(n,0);    low_print_tree(n,0);    fprintf(stderr, "\n");    fflush(stdout);   }       - /* The following routines needs much better commenting */ - /* They also need to support lexical scoping and external variables. + /* The following routines need much better commenting. */ + /* They also needed to support lexical scoping and external variables.    * /grubba 2000-08-27    */      #if MAX_LOCAL > MAX_GLOBAL   #define MAX_VAR MAX_LOCAL   #else /* MAX_LOCAL <= MAX_GLOBAL */   #define MAX_VAR MAX_GLOBAL   #endif /* MAX_LOCAL > MAX_GLOBAL */    -  + /* FIXME: Should perhaps use BLOCK_ALLOC for struct scope_info? */   struct scope_info   {    struct scope_info *next;    int scope_id;    char vars[MAX_VAR];   };      struct used_vars   {    int err;    int ext_flags; -  struct scope_info *locals; -  struct scope_info *externals; +  /* Note that the locals and externals linked lists are sorted on scope_id. */ +  struct scope_info *locals; /* Lexical scopes. scope_id == depth */ +  struct scope_info *externals; /* External scopes. scope_id == program_id */   };      #define VAR_BLOCKED 0   #define VAR_UNUSED 1   #define VAR_USED 3    - /* FIXME: Shouldn't these two be named "or_vars"? */ + /* FIXME: Shouldn't the following two functions be named "*_or_vars"? */ +  + /* Perform a merge into a. +  * Note that b is freed. +  */   static void low_and_vars(struct scope_info **a, struct scope_info *b)   {    while (*a && b) {    if ((*a)->scope_id < b->scope_id) {    a = &((*a)->next);    } else if ((*a)->scope_id > b->scope_id) {    struct scope_info *tmp = *a;    *a = b;    b = b->next;    (*a)->next = tmp;
pike.git/src/las.c:1959:   static void do_and_vars(struct used_vars *a,struct used_vars *b)   {    low_and_vars(&(a->locals), b->locals);    low_and_vars(&(a->externals), b->externals);       a->err |= b->err;    a->ext_flags |= b->ext_flags;    free(b);   }    + /* Makes a copy of a. +  * Note: Can throw errors on out of memory. +  */   static struct used_vars *copy_vars(struct used_vars *a)   {    struct used_vars *ret;    struct scope_info *src;    struct scope_info **dst;    ret=(struct used_vars *)xalloc(sizeof(struct used_vars));    src = a->locals;    dst = &(ret->locals);    *dst = NULL;    while (src) {
pike.git/src/las.c:2017:    MEMCPY(*dst, src, sizeof(struct scope_info));    dst = &((*dst)->next);    *dst = NULL;    }       ret->err = a->err;    ret->ext_flags = a->ext_flags;    return ret;   }    + /* Find the insertion point for the variable a:scope_id:num. +  * Allocates a new scope if needed. +  * Can throw errors on out of memory. +  */   char *find_q(struct scope_info **a, int num, int scope_id)   {    struct scope_info *new;      #ifdef PIKE_DEBUG    if (l_flag > 3) {    fprintf(stderr, "find_q %d:%d\n", scope_id, num);    }   #endif /* PIKE_DEBUG */    while (*a && ((*a)->scope_id < scope_id)) {
pike.git/src/las.c:2050:    }   #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;   }    + /* 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;    switch(n->token)