Branch libreoffice-5-0-4
[LibreOffice.git] / soltools / cpp / cpp.h
blob5e57118fbd895c6939aa2a7d0b69ed40e5a71b06
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 extern void setup_kwtab(void);
62 #define ISDEFINED 0x01 /* has #defined value */
63 #define ISKW 0x02 /* is PP keyword */
64 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
65 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
66 #define ISARCHITECTURE 0x10 /* architecture */
67 #define ISACTIVE 0x80 /* is macro currently expanded */
69 #define EOB 0xFE /* sentinel for end of input buffer */
70 #define EOFC 0xFD /* sentinel for end of input file */
71 #define XPWS 1 /* token flag: white space to assure token sep. */
72 #define XTWS 2
74 typedef struct token
76 unsigned char type;
77 unsigned char flag;
78 size_t wslen;
79 size_t len;
80 uchar *t;
81 unsigned int identifier; /* used from macro processor to identify where a macro becomes valid again. */
82 } Token;
84 typedef struct tokenrow
86 Token *tp; /* current one to scan */
87 Token *bp; /* base (allocated value) */
88 Token *lp; /* last+1 token used */
89 size_t max; /* number allocated */
90 } Tokenrow;
92 typedef struct source
94 char *filename; /* name of file of the source */
95 int line; /* current line number */
96 int lineinc; /* adjustment for \\n lines */
97 uchar *inb; /* input buffer */
98 uchar *inp; /* input pointer */
99 uchar *inl; /* end of input */
100 int fd; /* input source */
101 int ifdepth; /* conditional nesting in include */
102 int pathdepth;
103 int wrap;
104 struct source *next; /* stack for #include */
105 } Source;
107 typedef struct nlist
109 struct nlist *next;
110 uchar *name;
111 size_t len;
112 Tokenrow *vp; /* value as macro */
113 Tokenrow *ap; /* list of argument names, if any */
114 char val; /* value as preprocessor name */
115 char flag; /* is defined, is pp name */
116 uchar *loc; /* location of definition */
117 } Nlist;
119 typedef struct includelist
121 char deleted;
122 char always;
123 char *file;
124 } Includelist;
126 typedef struct wraplist
128 char *file;
129 } Wraplist;
131 #define new(t) (t *)domalloc(sizeof(t))
132 #define quicklook(a,b) (namebit[(a)&077] & (1U<<((b)&037)))
133 #define quickset(a,b) namebit[(a)&077] |= (1U<<((b)&037))
134 extern unsigned long namebit[077 + 1];
136 enum errtype
138 INFO, WARNING, ERROR, FATAL
142 typedef struct macroValidator
144 Nlist * pMacro;
145 unsigned int nTokenWhereMacroBecomesValid;
146 struct macroValidator *
147 pNext;
148 } MacroValidator;
149 typedef struct mvl
151 MacroValidator * pFirst;
152 unsigned int nextFreeIdentifier;
153 } MacroValidatorList;
155 void mvl_init(
156 MacroValidatorList *
157 out_pValidators);
158 void mvl_destruct(
159 MacroValidatorList *
160 out_pValidators);
161 /* Adds MacroValidator to the list.
163 void mvl_add(
164 MacroValidatorList *
165 inout_pValidators,
166 Nlist * in_pMacro,
167 Token * in_pTokenWhereMacroBecomesValid);
169 /* Checks if one of the validators within the list points to
170 the token in_pTokenToCheck. If so, the macro is set valid and
171 the validator is removed.
173 void mvl_check(
174 MacroValidatorList *
175 inout_pValidators,
176 Token * inout_pTokenToCheck);
178 void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
180 void expandlex(void);
181 void fixlex(void);
182 void setup(int, char **);
183 int gettokens(Tokenrow *, int);
184 int comparetokens(Tokenrow *, Tokenrow *);
185 Source *setsource(char *, int, int, char *, int);
186 void unsetsource(void);
187 void puttokens(Tokenrow *);
188 void process(Tokenrow *);
189 void *domalloc(size_t);
190 void dofree(void *);
191 void error(enum errtype, char *,...);
192 void flushout(void);
193 int fillbuf(Source *);
194 int trigraph(Source *);
195 int foldline(Source *);
196 Nlist *lookup(Token *, int);
197 void control(Tokenrow *);
198 void dodefine(Tokenrow *);
199 void doadefine(Tokenrow *, int);
200 void doinclude(Tokenrow *, int, int);
201 void doif(Tokenrow *, enum kwtype);
202 void expand(Tokenrow *, Nlist *, MacroValidatorList *);
203 void builtin(Tokenrow *, int);
204 int gatherargs(Tokenrow *, Tokenrow **, int *);
205 void substargs(Nlist *, Tokenrow *, Tokenrow **);
206 void expandrow(Tokenrow *, char *);
207 void maketokenrow(int, Tokenrow *);
208 Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
209 Token *growtokenrow(Tokenrow *);
210 Tokenrow *normtokenrow(Tokenrow *);
211 void adjustrow(Tokenrow *, int);
212 void movetokenrow(Tokenrow *, Tokenrow *);
213 void insertrow(Tokenrow *, int, Tokenrow *);
214 void peektokens(Tokenrow *, char *);
215 void doconcat(Tokenrow *);
216 Tokenrow *stringify(Tokenrow *);
217 int lookuparg(Nlist *, Token *);
218 long eval(Tokenrow *, int);
219 void genline(void);
220 void genimport(char *, int, char *, int);
221 void genwrap(int);
222 void setempty(Tokenrow *);
223 void makespace(Tokenrow *, Token *);
224 char *outnum(char *, int);
225 int digit(int);
226 uchar *newstring(uchar *, size_t, size_t);
228 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
230 extern char *outptr;
231 extern Token nltoken;
232 extern Source *cursource;
233 extern char *curtime;
234 extern int incdepth;
235 extern int ifdepth;
236 extern int ifsatisfied[NIF];
237 extern int Mflag;
238 extern int Iflag;
239 extern int Pflag;
240 extern int Aflag;
241 extern int Lflag;
242 extern int Xflag;
243 extern int Vflag;
244 extern int Cflag;
245 extern int Dflag;
246 extern int Cplusplus;
247 extern int skipping;
248 extern Nlist *kwdefined;
249 extern Includelist includelist[NINCLUDE];
250 extern Wraplist wraplist[NINCLUDE];
251 extern char wd[];
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */