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 */
19 typedef unsigned char uchar
;
25 END
, UNCLASS
, NAME
, NUMBER
, STRING
, CCON
, NL
, WS
, DSHARP
,
26 EQ
, NEQ
, LEQ
, GEQ
, LSH
, RSH
, LAND
, LOR
, PPLUS
, MMINUS
,
27 ARROW
, SBRA
, SKET
, LP
, RP
, DOT
, AND
, STAR
, PLUS
, MINUS
,
28 TILDE
, NOT
, SLASH
, PCT
, LT
, GT
, CIRC
, OR
, QUEST
,
29 COLON
, ASGN
, COMMA
, SHARP
, SEMIC
, CBRA
, CKET
,
30 ASPLUS
, ASMINUS
, ASSTAR
, ASSLASH
, ASPCT
, ASCIRC
, ASLSH
,
31 ASRSH
, ASOR
, ASAND
, ELLIPS
,
32 DSHARP1
, NAME1
, NAME2
, DEFINED
, UMINUS
, ARCHITECTURE
, IDENT
,
38 KIF
, KIFDEF
, KIFNDEF
, KELIF
, KELSE
, KENDIF
, KINCLUDE
, KINCLUDENEXT
,
39 KIMPORT
, KDEFINE
, KUNDEF
, KLINE
, KERROR
, KPRAGMA
, KIDENT
, KDEFINED
,
40 KMACHINE
, KLINENO
, KFILE
, KDATE
, KTIME
, KSTDC
, KEVAL
43 #define ISDEFINED 0x01 /* has #defined value */
44 #define ISKW 0x02 /* is PP keyword */
45 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
46 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
47 #define ISARCHITECTURE 0x10 /* architecture */
48 #define ISACTIVE 0x80 /* is macro currently expanded */
50 #define EOB 0xFE /* sentinel for end of input buffer */
51 #define EOFC 0xFD /* sentinel for end of input file */
52 #define XPWS 1 /* token flag: white space to assure token sep. */
62 unsigned int identifier
; /* used from macro processor to identify where a macro becomes valid again. */
65 typedef struct tokenrow
67 Token
*tp
; /* current one to scan */
68 Token
*bp
; /* base (allocated value) */
69 Token
*lp
; /* last+1 token used */
70 int max
; /* number allocated */
75 char *filename
; /* name of file of the source */
76 int line
; /* current line number */
77 int lineinc
; /* adjustment for \\n lines */
78 uchar
*inb
; /* input buffer */
79 uchar
*inp
; /* input pointer */
80 uchar
*inl
; /* end of input */
81 int fd
; /* input source */
82 int ifdepth
; /* conditional nesting in include */
85 struct source
*next
; /* stack for #include */
93 Tokenrow
*vp
; /* value as macro */
94 Tokenrow
*ap
; /* list of argument names, if any */
95 char val
; /* value as preprocessor name */
96 char flag
; /* is defined, is pp name */
97 uchar
*loc
; /* location of definition */
100 typedef struct includelist
107 typedef struct wraplist
112 #define new(t) (t *)domalloc(sizeof(t))
113 #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
114 #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
115 extern unsigned long namebit
[077 + 1];
119 INFO
, WARNING
, ERROR
, FATAL
123 typedef struct macroValidator
126 unsigned int nTokenWhereMacroBecomesValid
;
127 struct macroValidator
*
132 MacroValidator
* pFirst
;
133 unsigned int nextFreeIdentifier
;
134 } MacroValidatorList
;
142 /* Adds MacroValidator to the list.
148 Token
* in_pTokenWhereMacroBecomesValid
);
149 /* Updates all token pointers within the list, when the tokens have
151 pTokenWhereMacroBecomesValid += in_nNrofTokens;
157 int in_nSpace); // in pointer units.
159 /* Checks if one of the validators within the list points to
160 the token in_pTokenToCheck. If so, the macro is set valid and
161 the validator is removed.
166 Token
* inout_pTokenToCheck
);
168 void tokenrow_zeroTokenIdentifiers(Tokenrow
* trp
);
170 void expandlex(void);
172 void setup(int, char **);
173 int gettokens(Tokenrow
*, int);
174 int comparetokens(Tokenrow
*, Tokenrow
*);
175 Source
*setsource(char *, int, int, char *, int);
176 void unsetsource(void);
177 void puttokens(Tokenrow
*);
178 void process(Tokenrow
*);
181 void error(enum errtype
, char *,...);
183 int fillbuf(Source
*);
184 int trigraph(Source
*);
185 int foldline(Source
*);
186 Nlist
*lookup(Token
*, int);
187 void control(Tokenrow
*);
188 void dodefine(Tokenrow
*);
189 void doadefine(Tokenrow
*, int);
190 void doinclude(Tokenrow
*, int, int);
191 void doif(Tokenrow
*, enum kwtype
);
192 void expand(Tokenrow
*, Nlist
*, MacroValidatorList
*);
193 void builtin(Tokenrow
*, int);
194 int gatherargs(Tokenrow
*, Tokenrow
**, int *);
195 void substargs(Nlist
*, Tokenrow
*, Tokenrow
**);
196 void expandrow(Tokenrow
*, char *);
197 void maketokenrow(int, Tokenrow
*);
198 Tokenrow
*copytokenrow(Tokenrow
*, Tokenrow
*);
199 Token
*growtokenrow(Tokenrow
*);
200 Tokenrow
*normtokenrow(Tokenrow
*);
201 void adjustrow(Tokenrow
*, int);
202 void movetokenrow(Tokenrow
*, Tokenrow
*);
203 void insertrow(Tokenrow
*, int, Tokenrow
*);
204 void peektokens(Tokenrow
*, char *);
205 void doconcat(Tokenrow
*);
206 Tokenrow
*stringify(Tokenrow
*);
207 int lookuparg(Nlist
*, Token
*);
208 long eval(Tokenrow
*, int);
210 void genimport(char *, int, char *, int);
212 void setempty(Tokenrow
*);
213 void makespace(Tokenrow
*, Token
*);
214 char *outnum(char *, int);
216 uchar
*newstring(uchar
*, int, int);
218 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
221 extern Token nltoken
;
222 extern Source
*cursource
;
223 extern char *curtime
;
226 extern int ifsatisfied
[NIF
];
236 extern int Cplusplus
;
238 extern Nlist
*kwdefined
;
239 extern Includelist includelist
[NINCLUDE
];
240 extern Wraplist wraplist
[NINCLUDE
];