xref: /csrg-svn/usr.bin/pascal/src/lookup.c (revision 15016)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 #ifndef lint
4 static	char sccsid[] = "@(#)lookup.c 1.4 09/19/83";
5 #endif
6 
7 #include "whoami.h"
8 #include "0.h"
9 
10 struct nl *disptab[077+1];
11 
12 /*
13  * Lookup is called to
14  * find a symbol in the
15  * block structure symbol
16  * table and returns a pointer to
17  * its namelist entry.
18  */
19 struct nl *
20 lookup(s)
21 	register char *s;
22 {
23 	register struct nl *p;
24 	register struct udinfo;
25 
26 	if (s == NIL) {
27 		nocascade();
28 		return (NLNIL);
29 	}
30 	p = lookup1(s);
31 	if (p == NLNIL) {
32 		derror("%s is undefined", s);
33 		return (NLNIL);
34 	}
35 	if (p->class == FVAR) {
36 		p = p->chain;
37 		bn--;
38 	}
39 	return (p);
40 }
41 
42 #ifndef PI0
43 int	flagwas;
44 #endif
45 /*
46  * Lookup1 is an internal lookup.
47  * It is not an error to call lookup1
48  * if the symbol is not defined.  Also
49  * lookup1 will return FVARs while
50  * lookup never will, thus asgnop
51  * calls it when it thinks you are
52  * assigning to the function variable.
53  */
54 
55 struct nl *
56 lookup1(s)
57 	register char *s;
58 {
59 	register struct nl *p;
60 #ifndef PI0
61 	register struct nl *q;
62 #endif
63 	register int i;
64 
65 	if (s == NIL)
66 		return (NLNIL);
67 	bn = cbn;
68 #ifndef PI0
69 	/*
70 	 * We first check the field names
71 	 * of the currently active with
72 	 * statements (expensive since they
73 	 * are not hashed).
74 	 */
75 	for (p = withlist; p != NLNIL; p = p->nl_next) {
76 		q = p->type;
77 		if (q == NLNIL)
78 			continue;
79 		if (reclook(q, s) != NIL)
80 			/*
81 			 * Return the WITHPTR, lvalue understands.
82 			 */
83 			return (p);
84 	}
85 #endif
86 	/*
87 	 * Symbol table is a 64 way hash
88 	 * on the low bits of the character
89 	 * pointer value. (Simple, but effective)
90 	 */
91 	i = (int) s & 077;
92 	for (p = disptab[i]; p != NLNIL; p = p->nl_next)
93 		if (p->symbol == s && p->class != FIELD && p->class != BADUSE) {
94 			bn = (p->nl_block & 037);
95 #ifndef PI0
96 			flagwas = p->nl_flags;
97 			p->nl_flags |= NUSED;
98 #endif
99 			return (p);
100 		}
101 	return (NLNIL);
102 }
103 
104 #ifndef PI01
105 nlfund(sp)
106 	char *sp;
107 {
108 	register struct nl *p;
109 	register int i;
110 
111 	i = (int) sp & 077;
112 	for (p = disptab[i]; p != NLNIL; p = p->nl_next)
113 	if (p->symbol == sp && (p->nl_block & 037) == 0)
114 		return (nloff(p));
115 	return (0);
116 }
117 #endif
118