--- ray/src/common/caldefn.c 1992/11/21 21:42:42 2.5 +++ ray/src/common/caldefn.c 1997/02/12 17:38:03 2.11 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1997 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -42,10 +42,12 @@ extern char *ecalloc(), *emalloc(), *savestr(), *strc static double dvalue(); -long eclock = -1; /* value storage timer */ +unsigned long eclock = 0; /* value storage timer */ -static char context[MAXWORD+1]; /* current context path */ +#define MAXCNTX 1023 /* maximum context length */ +static char context[MAXCNTX+1]; /* current context path */ + static VARDEF *hashtbl[NHASH]; /* definition list */ static int htndx; /* index for */ static VARDEF *htpos; /* ...dfirst() and */ @@ -55,7 +57,7 @@ static EPNODE *outchan; #endif #ifdef FUNCTION -EPNODE *curfunc; +EPNODE *curfunc = NULL; #define dname(ep) ((ep)->v.kid->type == SYM ? \ (ep)->v.kid->v.name : \ (ep)->v.kid->v.kid->v.name) @@ -189,15 +191,16 @@ register char *ctx; if (ctx == NULL) return(context); /* just asking */ + while (*ctx == CNTXMARK) + ctx++; /* skip past marks */ if (!*ctx) { - context[0] = '\0'; /* clear context */ + context[0] = '\0'; /* empty means clear context */ return(context); } - cpp = context; /* else copy it (carefully!) */ - if (*ctx != CNTXMARK) - *cpp++ = CNTXMARK; /* make sure there's a mark */ - do { - if (cpp >= context+MAXWORD) + cpp = context; /* start context with mark */ + *cpp++ = CNTXMARK; + do { /* carefully copy new context */ + if (cpp >= context+MAXCNTX) break; /* just copy what we can */ if (isid(*ctx)) *cpp++ = *ctx++; @@ -205,12 +208,51 @@ register char *ctx; *cpp++ = '_'; ctx++; } } while (*ctx); + while (cpp[-1] == CNTXMARK) /* cannot end in context mark */ + cpp--; *cpp = '\0'; return(context); } char * +pushcontext(ctx) /* push on another context */ +char *ctx; +{ + extern char *strncpy(), *strcpy(); + char oldcontext[MAXCNTX+1]; + register int n; + + strcpy(oldcontext, context); /* save old context */ + setcontext(ctx); /* set new context */ + n = strlen(context); /* tack on old */ + if (n+strlen(oldcontext) > MAXCNTX) { + strncpy(context+n, oldcontext, MAXCNTX-n); + context[MAXCNTX] = '\0'; + } else + strcpy(context+n, oldcontext); + return(context); +} + + +char * +popcontext() /* pop off top context */ +{ + register char *cp1, *cp2; + + if (!context[0]) /* nothing left to pop */ + return(context); + cp2 = context; /* find mark */ + while (*++cp2 && *cp2 != CNTXMARK) + ; + cp1 = context; /* copy tail to front */ + while (*cp1++ = *cp2++) + ; + return(context); +} + + +char * qualname(nam, lvl) /* get qualified name */ register char *nam; int lvl; @@ -259,6 +301,8 @@ toolong: incontext(qn) /* is qualified name in current context? */ register char *qn; { + if (!context[0]) /* global context accepts all */ + return(1); while (*qn && *qn != CNTXMARK) /* find context mark */ qn++; return(!strcmp(qn, context)); @@ -287,7 +331,7 @@ int lvl; /* if context is global, clear all */ for (i = 0; i < NHASH; i++) for (vp = hashtbl[i]; vp != NULL; vp = vp->next) - if (!context[0] || incontext(vp->name)) + if (incontext(vp->name)) if (lvl >= 2) dremove(vp->name); else @@ -516,7 +560,7 @@ getstatement() /* get next statement */ qname = qualname(dname(ep), 0); #ifdef REDEFW if ((vdef = varlookup(qname)) != NULL) - if (vdef->def != NULL) { + if (vdef->def != NULL && epcmp(ep, vdef->def)) { wputs(qname); if (vdef->def->type == ':') wputs(": redefined constant expression\n"); @@ -578,8 +622,7 @@ getdefn() /* A -> SYM = E1 */ syntax("')' expected"); scan(); curfunc = ep1; - } else - curfunc = NULL; + } #endif if (nextc != '=' && nextc != ':') @@ -598,13 +641,17 @@ getdefn() /* A -> SYM = E1 */ ep1->sibling->type != NUM) { ep1 = newnode(); ep1->type = TICK; - ep1->v.tick = -1; + ep1->v.tick = 0; addekid(ep2, ep1); ep1 = newnode(); ep1->type = NUM; addekid(ep2, ep1); } +#ifdef FUNCTION + curfunc = NULL; +#endif + return(ep2); } @@ -659,8 +706,8 @@ EPNODE *d; if (ep1->type == NUM) return(ep1->v.num); /* return if number */ ep2 = ep1->sibling; /* check time */ - if (ep2->v.tick < 0 || ep2->v.tick < eclock) { - ep2->v.tick = d->type == ':' ? 1L<<30 : eclock; + if (ep2->v.tick == 0 || ep2->v.tick < eclock) { + ep2->v.tick = d->type == ':' ? ~0L : eclock; ep2 = ep2->sibling; ep2->v.num = evalue(ep1); /* needs new value */ } else