xref: /aoo41x/main/soltools/cpp/cpp.h (revision cdf0e10c)
1 /* $Id: cpp.h,v 1.4 2006-06-20 05:07:28 hr Exp $ */
2 
3 #define	INS			32768	/* input buffer								*/
4 #define	OBS			8092    /* outbut buffer							*/
5 #define	NARG		32      /* Max number arguments to a macro			*/
6 #define	NINCLUDE	48      /* Max number of include directories (-I)	*/
7 #define	NIF			64		/* depth of nesting of #if					*/
8 #define	NINC		32		/* depth of nesting of #include				*/
9 
10 #ifndef EOF
11 #define	EOF	(-1)
12 #endif
13 
14 #ifndef NULL
15 #define NULL	0
16 #endif
17 
18 typedef unsigned char uchar;
19 
20 enum toktype
21 {
22     END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
23     EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
24     ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
25     TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
26     COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
27     ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
28     ASRSH, ASOR, ASAND, ELLIPS,
29     DSHARP1, NAME1, NAME2, DEFINED, UMINUS, ARCHITECTURE, IDENT,
30 	COMMENT
31 };
32 
33 enum kwtype
34 {
35     KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KINCLUDENEXT,
36     KIMPORT, KDEFINE, KUNDEF, KLINE, KERROR, KPRAGMA, KIDENT, KDEFINED,
37 	KMACHINE, KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL
38 };
39 
40 #define	ISDEFINED		0x01            /* has #defined value */
41 #define	ISKW			0x02            /* is PP keyword */
42 #define	ISUNCHANGE		0x04            /* can't be #defined in PP */
43 #define	ISMAC			0x08            /* builtin macro, e.g. __LINE__ */
44 #define	ISARCHITECTURE	0x10            /* architecture */
45 #define ISACTIVE        0x80            /* is macro currently expanded */
46 
47 #define	EOB		0xFE                    /* sentinel for end of input buffer */
48 #define	EOFC	0xFD                    /* sentinel for end of input file */
49 #define	XPWS	1                       /* token flag: white space to assure token sep. */
50 #define XTWS	2
51 
52 typedef struct token
53 {
54     unsigned char type;
55     unsigned char flag;
56     unsigned int wslen;
57     unsigned int len;
58 	uchar *t;
59 	unsigned int identifier;			/* used from macro processor to identify where a macro becomes valid again. */
60 }   Token;
61 
62 typedef struct tokenrow
63 {
64 	Token *tp;                          /* current one to scan */
65 	Token *bp;                          /* base (allocated value) */
66 	Token *lp;                          /* last+1 token used */
67 	int max;                            /* number allocated */
68 }   Tokenrow;
69 
70 typedef struct source
71 {
72 	char *filename;                     /* name of file of the source */
73 	int line;                           /* current line number */
74 	int lineinc;                        /* adjustment for \\n lines */
75 	uchar *inb;                         /* input buffer */
76 	uchar *inp;                         /* input pointer */
77 	uchar *inl;                         /* end of input */
78 	int fd;                             /* input source */
79 	int ifdepth;                        /* conditional nesting in include */
80 	int pathdepth;
81 	int wrap;
82 	struct source *next;                /* stack for #include */
83 }   Source;
84 
85 typedef struct nlist
86 {
87 	struct nlist *next;
88 	uchar *name;
89 	int len;
90 	Tokenrow *vp;                       /* value as macro */
91 	Tokenrow *ap;                       /* list of argument names, if any */
92 	char val;                           /* value as preprocessor name */
93 	char flag;                          /* is defined, is pp name */
94 	uchar *loc;							/* location of definition */
95 }   Nlist;
96 
97 typedef struct includelist
98 {
99 	char deleted;
100 	char always;
101 	char *file;
102 }   Includelist;
103 
104 typedef struct wraplist
105 {
106 	char *file;
107 }   Wraplist;
108 
109 #define	new(t)	(t *)domalloc(sizeof(t))
110 #define	quicklook(a,b)	(namebit[(a)&077] & (1<<((b)&037)))
111 #define	quickset(a,b)	namebit[(a)&077] |= (1<<((b)&037))
112 extern unsigned long namebit[077 + 1];
113 
114 enum errtype
115 {
116 	INFO, WARNING, ERROR, FATAL
117 };
118 
119 
120 typedef struct macroValidator
121 {
122 	Nlist *				pMacro;
123 	unsigned int		nTokenWhereMacroBecomesValid;
124 	struct macroValidator *
125 						pNext;
126 } MacroValidator;
127 typedef struct mvl
128 {
129 	MacroValidator * pFirst;
130     unsigned int	 nextFreeIdentifier;
131 } MacroValidatorList;
132 
133 void		mvl_init(
134 				MacroValidatorList *
135 								out_pValidators);
136 void		mvl_destruct(
137 				MacroValidatorList *
138 								out_pValidators);
139 /* 	Adds MacroValidator to the list.
140 */
141 void 		mvl_add(
142 				MacroValidatorList *
143 								inout_pValidators,
144 				Nlist *         in_pMacro,
145 				Token *			in_pTokenWhereMacroBecomesValid);
146 /* 	Updates all token pointers within the list, when the tokens have
147 	moved, by
148 		pTokenWhereMacroBecomesValid += in_nNrofTokens;
149 	.
150 
151 void		mvl_move(
152 				MacroValidatorList *
153 								inout_pValidators,
154 				int				in_nSpace);	// in pointer units.
155 */
156 /*	Checks if one of the validators within the list points to
157 	the token in_pTokenToCheck. If so, the macro is set valid and
158 	the validator is removed.
159 */
160 void		mvl_check(
161 				MacroValidatorList *
162 								inout_pValidators,
163 				Token *			inout_pTokenToCheck);
164 
165 void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
166 
167 void expandlex(void);
168 void fixlex(void);
169 void setup(int, char **);
170 int gettokens(Tokenrow *, int);
171 int comparetokens(Tokenrow *, Tokenrow *);
172 Source *setsource(char *, int, int, char *, int);
173 void unsetsource(void);
174 void puttokens(Tokenrow *);
175 void process(Tokenrow *);
176 void *domalloc(int);
177 void dofree(void *);
178 void error(enum errtype, char *,...);
179 void flushout(void);
180 int fillbuf(Source *);
181 int trigraph(Source *);
182 int foldline(Source *);
183 Nlist *lookup(Token *, int);
184 void control(Tokenrow *);
185 void dodefine(Tokenrow *);
186 void doadefine(Tokenrow *, int);
187 void doinclude(Tokenrow *, int, int);
188 void doif(Tokenrow *, enum kwtype);
189 void expand(Tokenrow *, Nlist *, MacroValidatorList *);
190 void builtin(Tokenrow *, int);
191 int gatherargs(Tokenrow *, Tokenrow **, int *);
192 void substargs(Nlist *, Tokenrow *, Tokenrow **);
193 void expandrow(Tokenrow *, char *);
194 void maketokenrow(int, Tokenrow *);
195 Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
196 Token *growtokenrow(Tokenrow *);
197 Tokenrow *normtokenrow(Tokenrow *);
198 void adjustrow(Tokenrow *, int);
199 void movetokenrow(Tokenrow *, Tokenrow *);
200 void insertrow(Tokenrow *, int, Tokenrow *);
201 void peektokens(Tokenrow *, char *);
202 void doconcat(Tokenrow *);
203 Tokenrow *stringify(Tokenrow *);
204 int lookuparg(Nlist *, Token *);
205 long eval(Tokenrow *, int);
206 void genline(void);
207 void genimport(char *, int, char *, int);
208 void genwrap(int);
209 void setempty(Tokenrow *);
210 void makespace(Tokenrow *, Token *);
211 char *outnum(char *, int);
212 int digit(int);
213 uchar *newstring(uchar *, int, int);
214 
215 #define	rowlen(tokrow)	((tokrow)->lp - (tokrow)->bp)
216 
217 extern char *outptr;
218 extern Token nltoken;
219 extern Source *cursource;
220 extern char *curtime;
221 extern int incdepth;
222 extern int ifdepth;
223 extern int ifsatisfied[NIF];
224 extern int Mflag;
225 extern int Iflag;
226 extern int Pflag;
227 extern int Aflag;
228 extern int Lflag;
229 extern int Xflag;
230 extern int Vflag;
231 extern int Cflag;
232 extern int Dflag;
233 extern int Cplusplus;
234 extern int skipping;
235 extern Nlist *kwdefined;
236 extern Includelist includelist[NINCLUDE];
237 extern Wraplist wraplist[NINCLUDE];
238 extern char wd[];
239 
240