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