1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* $Id: cpp.h,v 1.4 2006-06-20 05:07:28 hr Exp $ */
4 #define INS 32768 /* input buffer */
5 #define OBS 8092 /* outbut buffer */
6 #define NARG 32 /* Max number arguments to a macro */
7 #define NINCLUDE 48 /* Max number of include directories (-I) */
8 #define NIF 64 /* depth of nesting of #if */
9 #define NINC 32 /* depth of nesting of #include */
19 typedef unsigned char uchar
;
23 END
, UNCLASS
, NAME
, NUMBER
, STRING
, CCON
, NL
, WS
, DSHARP
,
24 EQ
, NEQ
, LEQ
, GEQ
, LSH
, RSH
, LAND
, LOR
, PPLUS
, MMINUS
,
25 ARROW
, SBRA
, SKET
, LP
, RP
, DOT
, AND
, STAR
, PLUS
, MINUS
,
26 TILDE
, NOT
, SLASH
, PCT
, LT
, GT
, CIRC
, OR
, QUEST
,
27 COLON
, ASGN
, COMMA
, SHARP
, SEMIC
, CBRA
, CKET
,
28 ASPLUS
, ASMINUS
, ASSTAR
, ASSLASH
, ASPCT
, ASCIRC
, ASLSH
,
29 ASRSH
, ASOR
, ASAND
, ELLIPS
,
30 DSHARP1
, NAME1
, NAME2
, DEFINED
, UMINUS
, ARCHITECTURE
, IDENT
,
36 KIF
, KIFDEF
, KIFNDEF
, KELIF
, KELSE
, KENDIF
, KINCLUDE
, KINCLUDENEXT
,
37 KIMPORT
, KDEFINE
, KUNDEF
, KLINE
, KERROR
, KPRAGMA
, KIDENT
, KDEFINED
,
38 KMACHINE
, KLINENO
, KFILE
, KDATE
, KTIME
, KSTDC
, KEVAL
41 #define ISDEFINED 0x01 /* has #defined value */
42 #define ISKW 0x02 /* is PP keyword */
43 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
44 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
45 #define ISARCHITECTURE 0x10 /* architecture */
46 #define ISACTIVE 0x80 /* is macro currently expanded */
48 #define EOB 0xFE /* sentinel for end of input buffer */
49 #define EOFC 0xFD /* sentinel for end of input file */
50 #define XPWS 1 /* token flag: white space to assure token sep. */
60 unsigned int identifier
; /* used from macro processor to identify where a macro becomes valid again. */
63 typedef struct tokenrow
65 Token
*tp
; /* current one to scan */
66 Token
*bp
; /* base (allocated value) */
67 Token
*lp
; /* last+1 token used */
68 size_t max
; /* number allocated */
73 char *filename
; /* name of file of the source */
74 int line
; /* current line number */
75 int lineinc
; /* adjustment for \\n lines */
76 uchar
*inb
; /* input buffer */
77 uchar
*inp
; /* input pointer */
78 uchar
*inl
; /* end of input */
79 int fd
; /* input source */
80 int ifdepth
; /* conditional nesting in include */
83 struct source
*next
; /* stack for #include */
91 Tokenrow
*vp
; /* value as macro */
92 Tokenrow
*ap
; /* list of argument names, if any */
93 char val
; /* value as preprocessor name */
94 char flag
; /* is defined, is pp name */
95 uchar
*loc
; /* location of definition */
98 typedef struct includelist
105 typedef struct wraplist
110 #define new(t) (t *)domalloc(sizeof(t))
111 #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
112 #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
113 extern unsigned long namebit
[077 + 1];
117 INFO
, WARNING
, ERROR
, FATAL
121 typedef struct macroValidator
124 unsigned int nTokenWhereMacroBecomesValid
;
125 struct macroValidator
*
130 MacroValidator
* pFirst
;
131 unsigned int nextFreeIdentifier
;
132 } MacroValidatorList
;
140 /* Adds MacroValidator to the list.
146 Token
* in_pTokenWhereMacroBecomesValid
);
148 /* Checks if one of the validators within the list points to
149 the token in_pTokenToCheck. If so, the macro is set valid and
150 the validator is removed.
155 Token
* inout_pTokenToCheck
);
157 void tokenrow_zeroTokenIdentifiers(Tokenrow
* trp
);
159 void expandlex(void);
161 void setup(int, char **);
162 int gettokens(Tokenrow
*, int);
163 int comparetokens(Tokenrow
*, Tokenrow
*);
164 Source
*setsource(char *, int, int, char *, int);
165 void unsetsource(void);
166 void puttokens(Tokenrow
*);
167 void process(Tokenrow
*);
168 void *domalloc(size_t);
170 void error(enum errtype
, char *,...);
172 int fillbuf(Source
*);
173 int trigraph(Source
*);
174 int foldline(Source
*);
175 Nlist
*lookup(Token
*, int);
176 void control(Tokenrow
*);
177 void dodefine(Tokenrow
*);
178 void doadefine(Tokenrow
*, int);
179 void doinclude(Tokenrow
*, int, int);
180 void doif(Tokenrow
*, enum kwtype
);
181 void expand(Tokenrow
*, Nlist
*, MacroValidatorList
*);
182 void builtin(Tokenrow
*, int);
183 int gatherargs(Tokenrow
*, Tokenrow
**, int *);
184 void substargs(Nlist
*, Tokenrow
*, Tokenrow
**);
185 void expandrow(Tokenrow
*, char *);
186 void maketokenrow(int, Tokenrow
*);
187 Tokenrow
*copytokenrow(Tokenrow
*, Tokenrow
*);
188 Token
*growtokenrow(Tokenrow
*);
189 Tokenrow
*normtokenrow(Tokenrow
*);
190 void adjustrow(Tokenrow
*, int);
191 void movetokenrow(Tokenrow
*, Tokenrow
*);
192 void insertrow(Tokenrow
*, int, Tokenrow
*);
193 void peektokens(Tokenrow
*, char *);
194 void doconcat(Tokenrow
*);
195 Tokenrow
*stringify(Tokenrow
*);
196 int lookuparg(Nlist
*, Token
*);
197 long eval(Tokenrow
*, int);
199 void genimport(char *, int, char *, int);
201 void setempty(Tokenrow
*);
202 void makespace(Tokenrow
*, Token
*);
203 char *outnum(char *, int);
205 uchar
*newstring(uchar
*, size_t, size_t);
207 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
210 extern Token nltoken
;
211 extern Source
*cursource
;
212 extern char *curtime
;
215 extern int ifsatisfied
[NIF
];
225 extern int Cplusplus
;
227 extern Nlist
*kwdefined
;
228 extern Includelist includelist
[NINCLUDE
];
229 extern Wraplist wraplist
[NINCLUDE
];
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */