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 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 */
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
, IDENT
,
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. */
79 unsigned int identifier
; /* used from macro processor to identify where a macro becomes valid again. */
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 */
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 */
102 struct source
*next
; /* stack for #include */
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 */
117 typedef struct includelist
124 typedef struct 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];
136 INFO
, WARNING
, ERROR
, FATAL
140 typedef struct macroValidator
143 unsigned int nTokenWhereMacroBecomesValid
;
144 struct macroValidator
*
149 MacroValidator
* pFirst
;
150 unsigned int nextFreeIdentifier
;
151 } MacroValidatorList
;
159 /* Adds MacroValidator to the list.
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.
174 Token
* inout_pTokenToCheck
);
176 void tokenrow_zeroTokenIdentifiers(Tokenrow
* trp
);
178 void expandlex(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);
189 void error(enum errtype
, char *,...);
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);
218 void genimport(char *, int, char *, int);
220 void setempty(Tokenrow
*);
221 void makespace(Tokenrow
*, Token
*);
222 char *outnum(char *, int);
224 uchar
*newstring(uchar
*, 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: */