update credits
[LibreOffice.git] / soltools / cpp / cpp.h
blob29a77ee22808801fa7aa1d61f3a482ac3b62eeed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdlib.h>
21 #include <string.h>
23 #define INS 32768 /* input buffer */
24 #define OBS 8092 /* outbut buffer */
25 #define NARG 32 /* Max number arguments to a macro */
26 #define NINCLUDE 48 /* Max number of include directories (-I) */
27 #define NIF 64 /* depth of nesting of #if */
28 #define NINC 32 /* depth of nesting of #include */
30 #ifndef EOF
31 #define EOF (-1)
32 #endif
34 #ifndef NULL
35 #define NULL 0
36 #endif
38 typedef unsigned char uchar;
40 enum toktype
42 END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
43 EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
44 ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
45 TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
46 COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
47 ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
48 ASRSH, ASOR, ASAND, ELLIPS,
49 DSHARP1, NAME1, NAME2, DEFINED, UMINUS, ARCHITECTURE, IDENT,
50 COMMENT
53 enum kwtype
55 KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KINCLUDENEXT,
56 KIMPORT, KDEFINE, KUNDEF, KLINE, KERROR, KPRAGMA, KIDENT, KDEFINED,
57 KMACHINE, KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL
60 #define ISDEFINED 0x01 /* has #defined value */
61 #define ISKW 0x02 /* is PP keyword */
62 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
63 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
64 #define ISARCHITECTURE 0x10 /* architecture */
65 #define ISACTIVE 0x80 /* is macro currently expanded */
67 #define EOB 0xFE /* sentinel for end of input buffer */
68 #define EOFC 0xFD /* sentinel for end of input file */
69 #define XPWS 1 /* token flag: white space to assure token sep. */
70 #define XTWS 2
72 typedef struct token
74 unsigned char type;
75 unsigned char flag;
76 size_t wslen;
77 size_t len;
78 uchar *t;
79 unsigned int identifier; /* used from macro processor to identify where a macro becomes valid again. */
80 } Token;
82 typedef struct tokenrow
84 Token *tp; /* current one to scan */
85 Token *bp; /* base (allocated value) */
86 Token *lp; /* last+1 token used */
87 size_t max; /* number allocated */
88 } Tokenrow;
90 typedef struct source
92 char *filename; /* name of file of the source */
93 int line; /* current line number */
94 int lineinc; /* adjustment for \\n lines */
95 uchar *inb; /* input buffer */
96 uchar *inp; /* input pointer */
97 uchar *inl; /* end of input */
98 int fd; /* input source */
99 int ifdepth; /* conditional nesting in include */
100 int pathdepth;
101 int wrap;
102 struct source *next; /* stack for #include */
103 } Source;
105 typedef struct nlist
107 struct nlist *next;
108 uchar *name;
109 size_t len;
110 Tokenrow *vp; /* value as macro */
111 Tokenrow *ap; /* list of argument names, if any */
112 char val; /* value as preprocessor name */
113 char flag; /* is defined, is pp name */
114 uchar *loc; /* location of definition */
115 } Nlist;
117 typedef struct includelist
119 char deleted;
120 char always;
121 char *file;
122 } Includelist;
124 typedef struct wraplist
126 char *file;
127 } Wraplist;
129 #define new(t) (t *)domalloc(sizeof(t))
130 #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
131 #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
132 extern unsigned long namebit[077 + 1];
134 enum errtype
136 INFO, WARNING, ERROR, FATAL
140 typedef struct macroValidator
142 Nlist * pMacro;
143 unsigned int nTokenWhereMacroBecomesValid;
144 struct macroValidator *
145 pNext;
146 } MacroValidator;
147 typedef struct mvl
149 MacroValidator * pFirst;
150 unsigned int nextFreeIdentifier;
151 } MacroValidatorList;
153 void mvl_init(
154 MacroValidatorList *
155 out_pValidators);
156 void mvl_destruct(
157 MacroValidatorList *
158 out_pValidators);
159 /* Adds MacroValidator to the list.
161 void mvl_add(
162 MacroValidatorList *
163 inout_pValidators,
164 Nlist * in_pMacro,
165 Token * in_pTokenWhereMacroBecomesValid);
167 /* Checks if one of the validators within the list points to
168 the token in_pTokenToCheck. If so, the macro is set valid and
169 the validator is removed.
171 void mvl_check(
172 MacroValidatorList *
173 inout_pValidators,
174 Token * inout_pTokenToCheck);
176 void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
178 void expandlex(void);
179 void fixlex(void);
180 void setup(int, char **);
181 int gettokens(Tokenrow *, int);
182 int comparetokens(Tokenrow *, Tokenrow *);
183 Source *setsource(char *, int, int, char *, int);
184 void unsetsource(void);
185 void puttokens(Tokenrow *);
186 void process(Tokenrow *);
187 void *domalloc(size_t);
188 void dofree(void *);
189 void error(enum errtype, char *,...);
190 void flushout(void);
191 int fillbuf(Source *);
192 int trigraph(Source *);
193 int foldline(Source *);
194 Nlist *lookup(Token *, int);
195 void control(Tokenrow *);
196 void dodefine(Tokenrow *);
197 void doadefine(Tokenrow *, int);
198 void doinclude(Tokenrow *, int, int);
199 void doif(Tokenrow *, enum kwtype);
200 void expand(Tokenrow *, Nlist *, MacroValidatorList *);
201 void builtin(Tokenrow *, int);
202 int gatherargs(Tokenrow *, Tokenrow **, int *);
203 void substargs(Nlist *, Tokenrow *, Tokenrow **);
204 void expandrow(Tokenrow *, char *);
205 void maketokenrow(int, Tokenrow *);
206 Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
207 Token *growtokenrow(Tokenrow *);
208 Tokenrow *normtokenrow(Tokenrow *);
209 void adjustrow(Tokenrow *, int);
210 void movetokenrow(Tokenrow *, Tokenrow *);
211 void insertrow(Tokenrow *, int, Tokenrow *);
212 void peektokens(Tokenrow *, char *);
213 void doconcat(Tokenrow *);
214 Tokenrow *stringify(Tokenrow *);
215 int lookuparg(Nlist *, Token *);
216 long eval(Tokenrow *, int);
217 void genline(void);
218 void genimport(char *, int, char *, int);
219 void genwrap(int);
220 void setempty(Tokenrow *);
221 void makespace(Tokenrow *, Token *);
222 char *outnum(char *, int);
223 int digit(int);
224 uchar *newstring(uchar *, size_t, size_t);
226 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
228 extern char *outptr;
229 extern Token nltoken;
230 extern Source *cursource;
231 extern char *curtime;
232 extern int incdepth;
233 extern int ifdepth;
234 extern int ifsatisfied[NIF];
235 extern int Mflag;
236 extern int Iflag;
237 extern int Pflag;
238 extern int Aflag;
239 extern int Lflag;
240 extern int Xflag;
241 extern int Vflag;
242 extern int Cflag;
243 extern int Dflag;
244 extern int Cplusplus;
245 extern int skipping;
246 extern Nlist *kwdefined;
247 extern Includelist includelist[NINCLUDE];
248 extern Wraplist wraplist[NINCLUDE];
249 extern char wd[];
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */