--- ray/src/common/caldefn.c 1992/09/21 12:01:44 2.4 +++ ray/src/common/caldefn.c 1995/02/17 18:34:42 2.8 @@ -34,15 +34,15 @@ static char SCCSid[] = "$SunId$ LBL"; #define NHASH 521 /* hash size (a prime!) */ #endif +#define hash(s) (shash(s)%NHASH) + #define newnode() (EPNODE *)ecalloc(1, sizeof(EPNODE)) extern char *ecalloc(), *emalloc(), *savestr(), *strcpy(); -static int hash(); - static double dvalue(); -long eclock = -1; /* value storage timer */ +unsigned long eclock = 0; /* value storage timer */ static char context[MAXWORD+1]; /* current context path */ @@ -189,14 +189,15 @@ 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 { + cpp = context; /* start context with mark */ + *cpp++ = CNTXMARK; + do { /* carefully copy new context */ if (cpp >= context+MAXWORD) break; /* just copy what we can */ if (isid(*ctx)) @@ -205,12 +206,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[MAXWORD+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) > MAXWORD) { + strncpy(context+n, oldcontext, MAXWORD-n); + context[MAXWORD] = '\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; @@ -516,7 +556,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"); @@ -598,7 +638,7 @@ 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; @@ -659,25 +699,12 @@ 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 ep2 = ep2->sibling; /* else reuse old value */ return(ep2->v.num); -} - - -static int -hash(s) /* hash a string */ -register char *s; -{ - register int rval = 0; - - while (*s) - rval += *s++; - - return(rval % NHASH); }