|
|
1.1 root 1: /*
2: * This header file contains the definitions used by
3: * all parts of the C compiler parser (cc0)
4: * and the C compiler preprocessor (cpp).
5: * It includes the definitions of the reserved words,
6: * the built-in types, and so forth.
7: */
8: #define CC0_H CC0_H
9:
10: #include <stdio.h>
11: #include <setjmp.h>
12: #ifdef vax
13: #include "INC$LIB:mch.h"
14: #include "INC$LIB:host.h"
15: #include "INC$LIB:ops.h"
16: #include "INC$LIB:var.h"
17: #include "INC$LIB:varmch.h"
18: #include "INC$LIB:cc0mch.h"
19: #include "INC$LIB:stream.h"
20: #include "INC$LIB:cppmch.h"
21: #else
22: #include "mch.h"
23: #include "host.h"
24: #include "ops.h"
25: #include "var.h"
26: #include "varmch.h"
27: #include "cc0mch.h"
28: #include "stream.h"
29: #include "cppmch.h"
30: #endif
31:
32: /*
33: * These defines adjust the sizes of the tables in the parser.
34: * They can be changed to just about anything,
35: */
36: #define NHASH 67 /* Hash buckets */
37: #define NDIRS 32 /* Number of include directories */
38: #define NLEV 32 /* Nesting level of cpp constructs */
39: #define NDLEV 128 /* DSTACK size */
40: #define NDBUF 1024 /* Size of the define buffer */
41: #define ARG0 0200 /* Base of formals in define bodies */
42: #define SET0 (ARG0+NARGS) /* Base of hide set indices in text */
43: /* High parity characters are accepted in strings, but otherwise forbidden */
44: /* because they conflict with this scheme for packing macro formals and hide */
45: /* sets into the least space and overhead I can manage */
46:
47: /*
48: * cpp keywords and macro classes.
49: * these hide at a distinct level
50: * in the symbol table.
51: */
52: #define XUSER 0 /* User macro */
53: #define XUSERA 1 /* User macro with arguments */
54: #define XUFILE 2 /* Macro __FILE__ */
55: #define XULINE 3 /* Macro __LINE__ */
56: #define XUDATE 4 /* Macro __DATE__ */
57: #define XUTIME 5 /* Macro __TIME__ */
58: #define XUSTDC 6 /* Macro __STDC__ */
59: #define XDEFINED 8 /* User macro defined() */
60: #define XDEFINE 9 /* #define */
61: #define XINCLUDE 10 /* #include */
62: #define XUNDEF 11 /* #undef */
63: #define XLINE 12 /* #line */
64: #define XASSERT 13 /* #assert */
65: #define XERROR 14 /* #error */
66: #define XPRAGMA 15 /* #pragma */
67: #define XIF 20 /* #if is the first conditional */
68: #define XIFDEF 21 /* #ifdef */
69: #define XIFNDEF 22 /* #ifndef */
70: #define XELSE 23 /* #else */
71: #define XELIF 24 /* #elif */
72: #define XENDIF 25 /* #endif */
73:
74: /*
75: * Tokens.
76: * Character classes.
77: * Other things that are C compiler parser specific.
78: * By convention, these begin at 100 decimal.
79: */
80: #define DOT 100 /* . */
81: #define ARROW 101 /* -> */
82: #define SEMI 102 /* ; */
83: #define SHARP 103 /* # */
84: #define JUNK 104 /* Junk character */
85: #define SKIP 105 /* Whitespace */
86: #define LBRACE 106 /* { */
87: #define RBRACE 107 /* } */
88: #define LBRACK 108 /* [ */
89: #define RBRACK 109 /* ] */
90: #define LPAREN 110 /* ( */
91: #define RPAREN 111 /* ) */
92: #define ID 112 /* All identifiers */
93: #define CON 113 /* Constants */
94: #define QUOTE 114 /* ' */
95: #define STRING 115 /* " */
96: #define HIGH0 116 /* High parity junk, 0200..0237 */
97: #define HIGH1 117 /* High parity junk, 0240..0277 */
98: #define HIGH2 118 /* High parity junk, 0300..0337 */
99: #define HIGH3 119 /* High parity junk, 0340..0377 */
100: #define BACKDIV 120 /* Back slash */
101:
102: /*
103: * Types.
104: * Classes.
105: * Do not change these unless you update the tables in "gcandt.c".
106: */
107: #define INT 150 /* int */
108: #define CHAR 151 /* char */
109: #define FLOAT 152 /* float */
110: #define DOUBLE 153 /* double */
111: #define VOID 154 /* void */
112: #define STRUCT 155 /* struct */
113: #define UNION 156 /* union */
114: #define ENUM 157 /* enum */
115: #define LONG 158 /* long */
116: #define SHORT 159 /* short */
117: #define UNSIGNED 160 /* unsigned */
118: #define EXTERN 161 /* extern */
119: #define STATIC 162 /* static */
120: #define REGISTER 163 /* register */
121: #define TYPEDEF 164 /* typedef */
122: #define AUTO 165 /* auto */
123: #define CONST 166 /* const */
124: #define VOLATILE 167 /* volatile */
125: #define SIGNED 168 /* signed */
126:
127: /*
128: * Other C reserved words.
129: * These are in no particular order at all.
130: */
131: #define DEFAULT 180 /* default */
132: #define DO 181 /* do */
133: #define ELSE 182 /* else */
134: #define GOTO 183 /* goto */
135: #define IF 184 /* if */
136: #define RETURN 185 /* return */
137: #define SWITCH 186 /* switch */
138: #define CONTINUE 187 /* continue */
139: #define FOR 188 /* for */
140: #define WHILE 189 /* while */
141: #define BREAK 190 /* break */
142: #define CASE 191 /* case */
143:
144: /* MWC proprietary keywords */
145: #define READONLY 200 /* readonly */
146: #define ALIEN 201 /* Other language interface */
147:
148: /*
149: * Types.
150: */
151: #define T_NONE 0 /* No type (yet) */
152: #define T_CHAR 1 /* Char */
153: #define T_UCHAR 2 /* Unsigned char */
154: #define T_SHORT 3 /* Short */
155: #define T_USHORT 4 /* Unsigned short */
156: #define T_INT 5 /* Int */
157: #define T_UINT 6 /* Unsigned int */
158: #define T_PTR 7 /* Pointer */
159: #define T_LONG 8 /* Long */
160: #define T_ULONG 9 /* Unsigned long */
161: #define T_FLOAT 10 /* Float */
162: #define T_DOUBLE 11 /* Double */
163: #define T_VOID 12 /* Void */
164: #define T_STRUCT 13 /* Struct */
165: #define T_FSTRUCT 14 /* Forward struct reference */
166: #define T_UNION 15 /* Union */
167: #define T_FUNION 16 /* Forward union reference */
168: #define T_ENUM 17 /* Enumeration */
169: #define T_FENUM 18 /* Forward enumeration reference */
170: #define T_LDOUBLE 19 /* Long double, should follow double NB */
171:
172: /*
173: * Storage classes.
174: */
175: #define C_NONE 0 /* No class */
176: #define C_AUTO 1 /* Auto */
177: #define C_SIN 2 /* Static internal */
178: #define C_SEX 3 /* Static external */
179: #define C_GDEF 4 /* Global def. */
180: #define C_GREF 5 /* Global ref. */
181: #define C_ARG 6 /* Argument */
182: #define C_CXT 7 /* Contextual */
183: #define C_LAB 8 /* Label */
184: #define C_FREF 9 /* Forward ref. label */
185: #define C_KEY 10 /* Keyword */
186: #define C_TYPE 11 /* Typedef name */
187: #define C_REG 12 /* Register */
188: #define C_STAG 13 /* Structure tag */
189: #define C_UTAG 14 /* Union tag */
190: #define C_ETAG 15 /* Enumeration tag */
191: #define C_MOS 16 /* Member of structure */
192: #define C_MOU 17 /* Member of union */
193: #define C_MOE 18 /* Member of enumeration */
194: #define C_PAUTO 19 /* Parametric auto */
195: #define C_PREG 20 /* Parametric register */
196:
197: /*
198: * Dimensions.
199: * A list of these begins at the "s_dp" of a symbol
200: * and at the "e_dp" of an expression tree node.
201: */
202: typedef struct dim {
203: struct dim *d_dp; /* Link */
204: short d_type; /* Type */
205: sizeof_t d_bound; /* Array bound */
206: } DIM;
207:
208: #define D_PTR 0 /* Pointer */
209: #define D_FUNC 1 /* Function returning */
210: #define D_ARRAY 2 /* Array */
211: #define D_MOSAR 3 /* MOS array */
212: #define D_CONST 4 /* const modifier */
213: #define D_VOLATILE 5 /* volatile modifier */
214:
215: /*
216: * An INFO structure keeps track of structure elements,
217: * union elements and enumeration constants.
218: * It is pointed to by the INFO links of symbols and expressions.
219: * The reference count only considers symbol usages.
220: */
221: typedef struct {
222: short i_refc; /* Reference count */
223: short i_nsp; /* Number of symbols */
224: union {
225: sizeof_t i_data0;
226: int i_data1;
227: } i_data;
228: struct sym *i_sp[]; /* The symbols */
229: } INFO;
230:
231: #define i_size i_data.i_data0 /* Structure or union size */
232: #define i_type i_data.i_data1 /* Base type of an enumeration */
233:
234: /*
235: * Symbol.
236: * Symbols are kept in a hash table.
237: * Each bucket has the keywords on the front.
238: */
239:
240: typedef struct symbol SYM;
241: typedef struct token TOK;
242: struct symbol {
243: SYM *s_sp; /* Link */
244: int s_slevel; /* Symbol table level */
245: int s_value; /* Value */
246: int s_dline; /* Decl. line number */
247: char s_level; /* Block level */
248: char s_flag; /* Flag */
249: char s_width; /* Field width */
250: char s_offset; /* Bit offset */
251: char s_seg; /* Segment */
252: char s_class; /* Class */
253: char s_type; /* Type */
254: DIM *s_dp; /* Dimensions */
255: INFO *s_ip; /* Info */
256: char *s_id; /* Name string */
257: };
258:
259: /* Keyword symbols occupy less space */
260: typedef struct {
261: SYM *s_sp;
262: int s_slevel;
263: int s_value;
264: } KEYSYM;
265:
266: /* Preprocessor symbols take a little more space */
267: typedef struct {
268: SYM *s_sp;
269: int s_slevel;
270: int s_value;
271: int s_narg;
272: #if ANSI_STUPID
273: TOK *s_targs;
274: #endif
275: char s_body[];
276: } CPPSYM;
277:
278: /* C symbol s_flag values */
279: #define S_RONLY 01 /* Readonly */
280: #define S_ALIEN 02 /* Other language */
281: #define S_USED 04 /* Used */
282: #define S_TAG 010 /* Tag present */
283: #define S_INIT 020 /* Initialized */
284: #define S_SYMB 040 /* Written to debug table */
285:
286: /* Disjunct symbol table levels */
287: #define SL_CPP -2 /* Cpp tokens */
288: #define SL_KEY -1 /* C keywords and ops */
289: #define SL_VAR 0 /* Normal symbols */
290: #define SL_LAB 1 /* Labels */
291: #define SL_TAG 2 /* Tags */
292: #define SL_MOS 3 /* Members of structures, and up */
293:
294: /* Lexical scope levels */
295: #define LL_EXT 0 /* Externals */
296: #define LL_ARG 1 /* Parameters */
297: #define LL_AUTO 2 /* Automatics, and up */
298:
299: /*
300: * All tokens are hashed.
301: * Each unique token is the head
302: * of a list of symbol buckets.
303: */
304: struct token {
305: TOK *t_tp;
306: SYM *t_sym;
307: char t_id[];
308: };
309:
310: /*
311: * Macro expansion stack.
312: */
313: typedef struct {
314: char ds_type; /* Type of stack item */
315: char ds_char; /* Ungotten char or temp */
316: char *ds_ptr; /* Pointer to string */
317: } DSTACK;
318:
319: #define DS_FILE 0 /* Dstack is at source file level */
320: #define DS_UNGET 1 /* Dstack is ungotten character */
321: #define DS_FUNGET 2 /* Dstack is ungotten file character */
322: #define DS_STRNG 3 /* Dstack is normal string to read */
323: #define DS_PARAM 4 /* Dstack is parameter to be expanded */
324: #define DS_SHARP 5 /* Dstack is parameter to stringize */
325: #define DS_SHARP2 6 /* Dstack is parameter to glue */
326: #define DS_DPUTP 7 /* Dstack is pushed dputp pointer */
327: #define DS_NAME 8 /* Dstack is pushed name of macro */
328: #define DS_IEOF 9 /* Dstack is internal end of file */
329: #define DS_UFILE 10 /* Dstack is __FILE__ to expand */
330:
331: /*
332: * Macro hide set structure.
333: */
334: typedef struct hideset HIDESET;
335: typedef struct hidemem HIDEMEM;
336: struct hideset {
337: HIDESET *h_next_set;
338: HIDEMEM *h_this_set;
339: };
340: struct hidemem {
341: HIDEMEM *h_next_mem;
342: TOK *h_this_mem;
343: };
344:
345: /*
346: * Conditional stack.
347: * One of these is allocated when a #if* line
348: * is encountered to store the state of the
349: * conditional block until the matching #endif
350: * is found.
351: */
352: typedef struct {
353: int c_op; /* Last operator seen in block */
354: int c_state; /* Has any block been true */
355: } CSTACK;
356:
357: /*
358: * Include pushdown stack entry.
359: * One of these is allocated when a #include line
360: * is encountered to hold the file name, the line number
361: * and the FILE pointer of the old source file.
362: */
363: typedef struct {
364: FILE *i_fp; /* Saved FILE pointer */
365: int i_line; /* Saved line */
366: TOK *i_file; /* Saved file name */
367: CSTACK *i_cstackp; /* Saved conditional stack state */
368: } ISTACK;
369:
370: /*
371: * These structures keep track of the labels and constants for switches.
372: * It is used by code in the statement reader "stat.c".
373: */
374: typedef struct {
375: int sc_lab; /* Label number */
376: ival_t sc_val; /* Value */
377: } SCASE;
378:
379: typedef struct {
380: int sb_ncase; /* # of cases */
381: int sb_dlab; /* Default label */
382: SCASE sb_case[]; /* Adjustable array */
383: } SBLOCK;
384:
385: /*
386: * Tree nodes.
387: * All tree nodes are the same size.
388: * A node of any type may be changed into a node of any other type.
389: * The madness with the defines and the dots is just niceness
390: * in the wake of wishing to compile under both Bell and UCB structure rules.
391: */
392: typedef struct tree TREE;
393: struct tree
394: {
395: short t_op; /* Opcode */
396: short t_type; /* Internal type (T_) */
397: DIM *t_dp; /* DIM list */
398: INFO *t_ip; /* INFO if aggregate */
399: union {
400: struct {
401: TREE *t_xlp;
402: union {
403: TREE *t_xrp;
404: struct {
405: char t_xfw;
406: char t_xfb;
407: } t_1;
408: } t_2;
409: } t_3;
410: ival_t t_xival;
411: lval_t t_xlval;
412: dval_t t_xdval;
413: sizeof_t t_xzval;
414: struct {
415: sizeof_t t_xoffs;
416: int t_xseg;
417: union {
418: int t_xlab;
419: SYM *t_xsp;
420: } t_4;
421: } t_5;
422: short t_xreg;
423: } t_6;
424: };
425:
426: #define t_lp t_6.t_3.t_xlp /* Left link */
427: #define t_rp t_6.t_3.t_2.t_xrp /* Right link */
428: #define t_width t_6.t_3.t_2.t_1.t_xfw /* Field width, bits */
429: #define t_base t_6.t_3.t_2.t_1.t_xfb /* Field base bit */
430: #define t_ival t_6.t_xival /* ICON value */
431: #define t_lval t_6.t_xlval /* LCON value */
432: #define t_dval t_6.t_xdval /* DCON value */
433: #define t_zval t_6.t_xzval /* ZCON value */
434: #define t_reg t_6.t_xreg /* Register code */
435: #define t_offs t_6.t_5.t_xoffs /* Label offset */
436: #define t_seg t_6.t_5.t_xseg /* Segment */
437: #define t_label t_6.t_5.t_4.t_xlab /* Label # */
438: #define t_sp t_6.t_5.t_4.t_xsp /* Global symbol link */
439:
440: /*
441: * Opdope flag bits.
442: */
443: #define PRIO 037 /* Priority */
444: #define NSTL 040 /* No structures on left */
445: #define RAS 0100 /* Right associative */
446: #define RLVL 0200 /* Require lvalue on left */
447: #define NFLT 0400 /* No floats */
448: #define NPTR 01000 /* No pointers on right */
449: #define NPTL 02000 /* No pointers on left */
450: #define RTOR 04000 /* Require truth value on right */
451: #define RTOL 010000 /* Require truth value on left */
452: #define ASGN 020000 /* Assignment op */
453: #define NSTR 040000 /* No structures on right */
454:
455: /*
456: * Conversion dope bits.
457: */
458: #define GOAL 077 /* Goal type */
459: #define CVRA 0100 /* Convert right on assignment */
460: #define CVR 0200 /* Convert right */
461: #define CVL 0400 /* Convert left */
462: #define GTL 01000 /* Goal type from left */
463: #define GTR 02000 /* Goal type from right */
464: #define UREL 04000 /* Unsigned relation check needed */
465: #define CARA 010000 /* Cast right on assignment */
466:
467: /*
468: * cpp variables.
469: */
470: extern char dbuf[NDBUF], *dputp, *dpshp;
471: extern DSTACK dstack[], *dstackp, *dlistp;
472: extern ISTACK istack[], *istackp;
473: extern CSTACK cstack[], *cstackp;
474: extern HIDESET *hidefree, *hidesets;
475: extern int cstate;
476: extern int lastchar;
477: extern int instring;
478: extern int notskip;
479: extern int ndirs;
480: extern char *incdirs[];
481: extern char deftrue[];
482: extern char deffalse[];
483: extern long curtime;
484:
485: /*
486: * Functions and variables.
487: */
488: extern int mysizes[];
489: extern SYM *cfsym;
490: extern int cflab;
491: extern char id[];
492: extern unsigned idhash;
493: extern unsigned idhide;
494: extern int idsize;
495: extern TOK *idp;
496: extern TOK *hash0[];
497: extern int llex;
498: extern int lsym;
499: extern int s;
500: extern ival_t ival;
501: extern lval_t lval;
502: extern dval_t dval;
503: extern short tval;
504: extern int line;
505: extern char file[];
506: extern TOK *tfile;
507: extern unsigned char ct[];
508: extern TOK *newtoken();
509: extern SYM *newsym();
510: extern CPPSYM *newcpp();
511: extern DIM *dupldim();
512: extern DIM *tackdim();
513: extern INFO *newinfo();
514: extern char *new();
515: extern int nerr;
516: extern char *passname;
517: extern int nargs;
518: extern SYM *args[];
519: extern TREE *expr();
520: extern int incpp;
521: extern int ininit;
522: extern int incase;
523: extern char *talloc();
524: extern TREE *transform();
525: extern short opdope[];
526: extern short cvdope[];
527: extern TREE *pexpr();
528: extern DIM *tdalloc();
529: extern TREE *build();
530: extern TREE *charray();
531: extern TREE *chfun();
532: extern TREE *bicon();
533: extern TREE *bzcon();
534: extern TREE *bid();
535: extern TREE *bcvt();
536: extern TREE *bconvert();
537: extern TREE *term();
538: extern TREE *tree();
539: extern TREE *bstring();
540: extern char mytypes[];
541: extern TREE *fold0();
542: extern SYM *deflookup();
543: extern SYM *reflookup();
544: extern SYM *moslookup();
545: extern SYM *fakedef();
546: extern SYM *taglookup();
547: extern SYM *fixlevel();
548: extern SYM *declare();
549: extern long fieldalign();
550: extern sizeof_t ssize();
551: extern sizeof_t tsize();
552: extern sizeof_t sdsize();
553: extern sizeof_t tidsize();
554: extern sizeof_t psize();
555: extern sizeof_t getbound();
556: extern sizeof_t szcheck(); /* mch - object size check */
557: extern TREE *cast(); /* cast declarator reader */
558: extern int oldseg;
559: extern int mnamef;
560: extern int labgen;
561: extern int cblab;
562: extern int cclab;
563: extern SBLOCK *sbp;
564: extern FILE *ifp;
565: extern FILE *ofp; /* Output file */
566:
567: #if OVERLAID
568: extern jmp_buf death; /* Fatal errors */
569: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.