1 /* $Id: cpp.h,v 1.4 2006-06-20 05:07:28 hr Exp $ */
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 */
18 typedef unsigned char uchar
;
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
,
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
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 */
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. */
59 unsigned int identifier
; /* used from macro processor to identify where a macro becomes valid again. */
62 typedef struct tokenrow
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 */
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 */
82 struct source
*next
; /* stack for #include */
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 */
97 typedef struct includelist
104 typedef struct wraplist
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];
116 INFO
, WARNING
, ERROR
, FATAL
120 typedef struct macroValidator
123 unsigned int nTokenWhereMacroBecomesValid
;
124 struct macroValidator
*
129 MacroValidator
* pFirst
;
130 unsigned int nextFreeIdentifier
;
131 } MacroValidatorList
;
139 /* Adds MacroValidator to the list.
145 Token
* in_pTokenWhereMacroBecomesValid
);
146 /* Updates all token pointers within the list, when the tokens have
148 pTokenWhereMacroBecomesValid += in_nNrofTokens;
154 int in_nSpace); // in pointer units.
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.
163 Token
* inout_pTokenToCheck
);
165 void tokenrow_zeroTokenIdentifiers(Tokenrow
* trp
);
167 void expandlex(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
*);
178 void error(enum errtype
, char *,...);
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);
207 void genimport(char *, int, char *, int);
209 void setempty(Tokenrow
*);
210 void makespace(Tokenrow
*, Token
*);
211 char *outnum(char *, int);
213 uchar
*newstring(uchar
*, int, int);
215 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
218 extern Token nltoken
;
219 extern Source
*cursource
;
220 extern char *curtime
;
223 extern int ifsatisfied
[NIF
];
233 extern int Cplusplus
;
235 extern Nlist
*kwdefined
;
236 extern Includelist includelist
[NINCLUDE
];
237 extern Wraplist wraplist
[NINCLUDE
];