1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #define INS 327680 /* input buffer */
24 #define OBS 8092 /* output 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 */
38 typedef unsigned char uchar
;
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
,
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. */
80 unsigned int identifier
; /* used from macro processor to identify where a macro becomes valid again. */
83 typedef struct tokenrow
85 Token
*tp
; /* current one to scan */
86 Token
*bp
; /* base (allocated value) */
87 Token
*lp
; /* last+1 token used */
88 size_t max
; /* number allocated */
93 char *filename
; /* name of file of the source */
94 int line
; /* current line number */
95 int lineinc
; /* adjustment for \\n lines */
96 uchar
*inb
; /* input buffer */
97 uchar
*inp
; /* input pointer */
98 uchar
*inl
; /* end of input */
99 int fd
; /* input source */
100 int ifdepth
; /* conditional nesting in include */
103 struct source
*next
; /* stack for #include */
111 Tokenrow
*vp
; /* value as macro */
112 Tokenrow
*ap
; /* list of argument names, if any */
113 char val
; /* value as preprocessor name */
114 char flag
; /* is defined, is pp name */
115 uchar
*loc
; /* location of definition */
118 typedef struct includelist
125 typedef struct wraplist
130 #define new(t) (t *)domalloc(sizeof(t))
131 #define quicklook(a,b) (namebit[(a)&077] & (1U<<((b)&037)))
132 #define quickset(a,b) namebit[(a)&077] |= (1U<<((b)&037))
133 extern unsigned long namebit
[077 + 1];
137 INFO
, WARNING
, ERROR
, FATAL
141 typedef struct macroValidator
144 unsigned int nTokenWhereMacroBecomesValid
;
145 struct macroValidator
*
150 MacroValidator
* pFirst
;
151 unsigned int nextFreeIdentifier
;
152 } MacroValidatorList
;
160 /* Adds MacroValidator to the list.
166 Token
* in_pTokenWhereMacroBecomesValid
);
168 /* Checks if one of the validators within the list points to
169 the token in_pTokenToCheck. If so, the macro is set valid and
170 the validator is removed.
175 Token
const * inout_pTokenToCheck
);
177 void tokenrow_zeroTokenIdentifiers(Tokenrow
* trp
);
179 void expandlex(void);
181 void setup(int, char **);
182 int gettokens(Tokenrow
*, int);
183 int comparetokens(Tokenrow
*, Tokenrow
*);
184 Source
*setsource(char *, int, int, char const *, int);
185 void unsetsource(void);
186 void puttokens(Tokenrow
*);
187 void process(Tokenrow
*);
188 void *domalloc(size_t);
190 void error(enum errtype
, char *,...);
192 int fillbuf(Source
*);
193 int trigraph(Source
*);
194 int foldline(Source
*);
195 Nlist
*lookup(Token
*, int);
196 void control(Tokenrow
*);
197 void dodefine(Tokenrow
*);
198 void doadefine(Tokenrow
*, int);
199 void doinclude(Tokenrow
*, int, int);
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
const *);
207 Token
*growtokenrow(Tokenrow
*);
208 Tokenrow
*normtokenrow(Tokenrow
*);
209 void adjustrow(Tokenrow
*, int);
210 void movetokenrow(Tokenrow
*, Tokenrow
const *);
211 void insertrow(Tokenrow
*, int, Tokenrow
const *);
212 void peektokens(Tokenrow
*, char *);
213 void doconcat(Tokenrow
*);
214 Tokenrow
*stringify(Tokenrow
*);
215 int lookuparg(Nlist
*, Token
const *);
216 long eval(Tokenrow
*, int);
218 void genimport(char const *, int, char const *, int);
220 void setempty(Tokenrow
*);
221 void makespace(Tokenrow
*, Token
const *);
222 char *outnum(char *, int);
224 uchar
*newstring(uchar
const *, size_t, size_t);
226 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
229 extern Token nltoken
;
230 extern Source
*cursource
;
231 extern char *curtime
;
234 extern int ifsatisfied
[NIF
];
244 extern int Cplusplus
;
246 extern Nlist
*kwdefined
;
247 extern Includelist includelist
[NINCLUDE
];
248 extern Wraplist wraplist
[NINCLUDE
];
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */