|
|
1.1 root 1: /*
2: * n0/cc0key.c
3: * C compiler.
4: * Symbol table initialization.
5: */
6:
7: #ifdef vax
8: #include "INC$LIB:cc0.h"
9: #else
10: #include "cc0.h"
11: #endif
12:
13: /*
14: * Initialized tokens.
15: * Each of these gets linked in place into the hash table.
16: * This is a truly sleazy hack; each cxfoo string ends up at the right
17: * place to be the t_id member of the TOK.
18: */
19: static TOK txfile= {NULL,NULL}; static char cxfile[]= "__FILE__";
20: static TOK txuline= {NULL,NULL}; static char cxuline[]= "__LINE__";
21: static TOK txdate= {NULL,NULL}; static char cxdate[]= "__DATE__";
22: static TOK txtime= {NULL,NULL}; static char cxtime[]= "__TIME__";
23: #if 0
24: /*
25: * ANSI C says __STDC__ should be defined as 0 for a non-ANSI compiler,
26: * but too many sources use #ifdef __STDC__ when they should use #if __STDC__.
27: * This is therefore conditionalized out here and in n0/expand.c.
28: */
29: static TOK txstdc= {NULL,NULL}; static char cxstdc[]= "__STDC__";
30: #endif
31: static TOK txbasefile= {NULL,NULL}; static char cxbasefile[]="__BASE_FILE__";
32: static TOK txudefined= {NULL,NULL}; static char cxudefined[]="defined";
33: static TOK txdefine= {NULL,NULL}; static char cxdefine[]= "#define";
34: static TOK txinclude= {NULL,NULL}; static char cxinclude[]="#include";
35: static TOK txundef= {NULL,NULL}; static char cxundef[]= "#undef";
36: static TOK txline= {NULL,NULL}; static char cxline[]= "#line";
37: static TOK txassert= {NULL,NULL}; static char cxassert[]= "#assert";
38: static TOK txerror= {NULL,NULL}; static char cxerror[]= "#error";
39: static TOK txpragma= {NULL,NULL}; static char cxpragma[]= "#pragma";
40: static TOK txif= {NULL,NULL}; static char cxif[]= "#if";
41: static TOK txifdef= {NULL,NULL}; static char cxifdef[]= "#ifdef";
42: static TOK txifndef= {NULL,NULL}; static char cxifndef[]= "#ifndef";
43: static TOK txelse= {NULL,NULL}; static char cxelse[]= "#else";
44: static TOK txelif= {NULL,NULL}; static char cxelif[]= "#elif";
45: static TOK txendif= {NULL,NULL}; static char cxendif[]= "#endif";
46: static TOK txident= {NULL,NULL}; static char cxident[]= "#ident";
47: static TOK tint= {NULL,NULL}; static char cint[]= "int";
48: static TOK tchar= {NULL,NULL}; static char cchar[]= "char";
49: static TOK tfloat= {NULL,NULL}; static char cfloat[]= "float";
50: static TOK tdouble= {NULL,NULL}; static char cdouble[]= "double";
51: static TOK tunsigned= {NULL,NULL}; static char cunsigned[]="unsigned";
52: static TOK tsigned= {NULL,NULL}; static char csigned[]= "signed";
53: static TOK tregister= {NULL,NULL}; static char cregister[]="register";
54: static TOK tlong= {NULL,NULL}; static char clong[]= "long";
55: static TOK tstruct= {NULL,NULL}; static char cstruct[]= "struct";
56: static TOK tunion= {NULL,NULL}; static char cunion[]= "union";
57: static TOK tenum= {NULL,NULL}; static char cenum[]= "enum";
58: static TOK tauto= {NULL,NULL}; static char cauto[]= "auto";
59: static TOK tvoid= {NULL,NULL}; static char cvoid[]= "void";
60: static TOK tstatic= {NULL,NULL}; static char cstatic[]= "static";
61: static TOK textern= {NULL,NULL}; static char cextern[]= "extern";
62: static TOK tgoto= {NULL,NULL}; static char cgoto[]= "goto";
63: static TOK treturn= {NULL,NULL}; static char creturn[]= "return";
64: static TOK tif= {NULL,NULL}; static char cif[]= "if";
65: static TOK twhile= {NULL,NULL}; static char cwhile[]= "while";
66: static TOK tfor= {NULL,NULL}; static char cfor[]= "for";
67: static TOK tdo= {NULL,NULL}; static char cdo[]= "do";
68: static TOK telse= {NULL,NULL}; static char celse[]= "else";
69: static TOK tswitch= {NULL,NULL}; static char cswitch[]= "switch";
70: static TOK tcase= {NULL,NULL}; static char ccase[]= "case";
71: static TOK tdefault= {NULL,NULL}; static char cdefault[]= "default";
72: static TOK tbreak= {NULL,NULL}; static char cbreak[]= "break";
73: static TOK tcontinue= {NULL,NULL}; static char ccontinue[]="continue";
74: static TOK ttypedef= {NULL,NULL}; static char ctypedef[]= "typedef";
75: static TOK tsizeof= {NULL,NULL}; static char csizeof[]= "sizeof";
76: static TOK tshort= {NULL,NULL}; static char cshort[]= "short";
77: static TOK tconst= {NULL,NULL}; static char cconst[]= "const";
78: static TOK tvolatile= {NULL,NULL}; static char cvolatile[]="volatile";
79: #ifdef READONLY
80: static TOK treadonly= {NULL,NULL}; static char creadonly[]="readonly";
81: #endif
82: #ifdef ALIEN
83: static TOK talien= {NULL,NULL}; static char calien[]= "alien";
84: #endif
85:
86: /*
87: * Initialized symbols.
88: * Each of these gets linked in place into the symbol table,
89: * and the token each symbol specifies is entered into the token hash.
90: * This must be correspond to the symbol order in ktok[] below.
91: */
92: static KEYSYM ktab[] = {
93: NULL, SL_CPP, XUFILE,
94: NULL, SL_CPP, XULINE,
95: NULL, SL_CPP, XUDATE,
96: NULL, SL_CPP, XUTIME,
97: #if 0
98: NULL, SL_CPP, XUSTDC,
99: #endif
100: NULL, SL_CPP, XUBASE,
101: NULL, SL_CPP, XDEFINED,
102: NULL, SL_CPP, XDEFINE,
103: NULL, SL_CPP, XINCLUDE,
104: NULL, SL_CPP, XUNDEF,
105: NULL, SL_CPP, XLINE,
106: NULL, SL_CPP, XASSERT,
107: NULL, SL_CPP, XERROR,
108: NULL, SL_CPP, XPRAGMA,
109: NULL, SL_CPP, XIF,
110: NULL, SL_CPP, XIFDEF,
111: NULL, SL_CPP, XIFNDEF,
112: NULL, SL_CPP, XELSE,
113: NULL, SL_CPP, XELIF,
114: NULL, SL_CPP, XENDIF,
115: NULL, SL_CPP, XIDENT,
116: NULL, SL_KEY, INT,
117: NULL, SL_KEY, CHAR,
118: NULL, SL_KEY, FLOAT,
119: NULL, SL_KEY, DOUBLE,
120: NULL, SL_KEY, UNSIGNED,
121: NULL, SL_KEY, SIGNED,
122: NULL, SL_KEY, REGISTER,
123: NULL, SL_KEY, LONG,
124: NULL, SL_KEY, STRUCT,
125: NULL, SL_KEY, UNION,
126: NULL, SL_KEY, ENUM,
127: NULL, SL_KEY, AUTO,
128: NULL, SL_KEY, VOID,
129: NULL, SL_KEY, STATIC,
130: NULL, SL_KEY, EXTERN,
131: NULL, SL_KEY, GOTO,
132: NULL, SL_KEY, RETURN,
133: NULL, SL_KEY, IF,
134: NULL, SL_KEY, WHILE,
135: NULL, SL_KEY, FOR,
136: NULL, SL_KEY, DO,
137: NULL, SL_KEY, ELSE,
138: NULL, SL_KEY, SWITCH,
139: NULL, SL_KEY, CASE,
140: NULL, SL_KEY, DEFAULT,
141: NULL, SL_KEY, BREAK,
142: NULL, SL_KEY, CONTINUE,
143: NULL, SL_KEY, TYPEDEF,
144: NULL, SL_KEY, SIZEOF,
145: NULL, SL_KEY, SHORT,
146: NULL, SL_KEY, CONST,
147: NULL, SL_KEY, VOLATILE,
148: #ifdef READONLY
149: NULL, SL_KEY, READONLY,
150: #endif
151: #ifdef ALIEN
152: NULL, SL_KEY, ALIEN
153: #endif
154: };
155: #define NKEYS sizeof(ktab)/sizeof(KEYSYM)
156:
157: /*
158: * Keyword token pointers, used to initialize symbol table.
159: * This must be correspond to the symbol order in ktab[] above.
160: */
161: static TOK *ktok[] = {
162: &txfile,
163: &txuline,
164: &txdate,
165: &txtime,
166: #if 0
167: &txstdc,
168: #endif
169: &txbasefile,
170: &txudefined,
171: &txdefine,
172: &txinclude,
173: &txundef,
174: &txline,
175: &txassert,
176: &txerror,
177: &txpragma,
178: &txif,
179: &txifdef,
180: &txifndef,
181: &txelse,
182: &txelif,
183: &txendif,
184: &txident,
185: &tint,
186: &tchar,
187: &tfloat,
188: &tdouble,
189: &tunsigned,
190: &tsigned,
191: &tregister,
192: &tlong,
193: &tstruct,
194: &tunion,
195: &tenum,
196: &tauto,
197: &tvoid,
198: &tstatic,
199: &textern,
200: &tgoto,
201: &treturn,
202: &tif,
203: &twhile,
204: &tfor,
205: &tdo,
206: &telse,
207: &tswitch,
208: &tcase,
209: &tdefault,
210: &tbreak,
211: &tcontinue,
212: &ttypedef,
213: &tsizeof,
214: &tshort,
215: &tconst,
216: &tvolatile,
217: #ifdef READONLY
218: &treadonly,
219: #endif
220: #ifdef ALIEN
221: &talien
222: #endif
223: };
224:
225: /*
226: * Enter reserved words into the hash table.
227: */
228: kinit()
229: {
230: register char *p;
231: register int c;
232: register TOK **tpp, *tp;
233: register KEYSYM *kp;
234:
235: for (kp = ktab, tpp = ktok; kp < &ktab[NKEYS]; ++kp) {
236: tp = *tpp++;
237: #ifdef VALIEN
238: if (kp->s_value==ALIEN && notvariant(VALIEN))
239: continue;
240: #endif
241: #ifdef VREADONLY
242: if (kp->s_value==READONLY && notvariant(VREADONLY))
243: continue;
244: #endif
245: p = tp->t_id;
246: idhash = 0;
247: while (c = *p++)
248: idhash += c;
249: idhash %= NHASH;
250: tp->t_tp = hash0[idhash];
251: hash0[idhash] = tp;
252: tp->t_sym = kp;
253: }
254: }
255:
256: /* end of n0/cc0key.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.