Update ooo320-m1
[ooovba.git] / soltools / cpp / cpp.h
blob5742b699cc8a76e5d8189acfb7735e3f2f46522d
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 */
10 #ifndef EOF
11 #define EOF (-1)
12 #endif
14 #ifndef NULL
15 #define NULL 0
16 #endif
18 #ifndef __alpha
19 typedef unsigned char uchar;
21 #endif
23 enum toktype
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,
33 COMMENT
36 enum kwtype
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. */
53 #define XTWS 2
55 typedef struct token
57 unsigned char type;
58 unsigned char flag;
59 unsigned int wslen;
60 unsigned int len;
61 uchar *t;
62 unsigned int identifier; /* used from macro processor to identify where a macro becomes valid again. */
63 } Token;
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 */
71 } Tokenrow;
73 typedef struct source
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 */
83 int pathdepth;
84 int wrap;
85 struct source *next; /* stack for #include */
86 } Source;
88 typedef struct nlist
90 struct nlist *next;
91 uchar *name;
92 int len;
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 */
98 } Nlist;
100 typedef struct includelist
102 char deleted;
103 char always;
104 char *file;
105 } Includelist;
107 typedef struct wraplist
109 char *file;
110 } 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];
117 enum errtype
119 INFO, WARNING, ERROR, FATAL
123 typedef struct macroValidator
125 Nlist * pMacro;
126 unsigned int nTokenWhereMacroBecomesValid;
127 struct macroValidator *
128 pNext;
129 } MacroValidator;
130 typedef struct mvl
132 MacroValidator * pFirst;
133 unsigned int nextFreeIdentifier;
134 } MacroValidatorList;
136 void mvl_init(
137 MacroValidatorList *
138 out_pValidators);
139 void mvl_destruct(
140 MacroValidatorList *
141 out_pValidators);
142 /* Adds MacroValidator to the list.
144 void mvl_add(
145 MacroValidatorList *
146 inout_pValidators,
147 Nlist * in_pMacro,
148 Token * in_pTokenWhereMacroBecomesValid);
149 /* Updates all token pointers within the list, when the tokens have
150 moved, by
151 pTokenWhereMacroBecomesValid += in_nNrofTokens;
154 void mvl_move(
155 MacroValidatorList *
156 inout_pValidators,
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.
163 void mvl_check(
164 MacroValidatorList *
165 inout_pValidators,
166 Token * inout_pTokenToCheck);
168 void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
170 void expandlex(void);
171 void fixlex(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 *);
179 void *domalloc(int);
180 void dofree(void *);
181 void error(enum errtype, char *,...);
182 void flushout(void);
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);
209 void genline(void);
210 void genimport(char *, int, char *, int);
211 void genwrap(int);
212 void setempty(Tokenrow *);
213 void makespace(Tokenrow *, Token *);
214 char *outnum(char *, int);
215 int digit(int);
216 uchar *newstring(uchar *, int, int);
218 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
220 extern char *outptr;
221 extern Token nltoken;
222 extern Source *cursource;
223 extern char *curtime;
224 extern int incdepth;
225 extern int ifdepth;
226 extern int ifsatisfied[NIF];
227 extern int Mflag;
228 extern int Iflag;
229 extern int Pflag;
230 extern int Aflag;
231 extern int Lflag;
232 extern int Xflag;
233 extern int Vflag;
234 extern int Cflag;
235 extern int Dflag;
236 extern int Cplusplus;
237 extern int skipping;
238 extern Nlist *kwdefined;
239 extern Includelist includelist[NINCLUDE];
240 extern Wraplist wraplist[NINCLUDE];
241 extern char wd[];