]>
Commit | Line | Data |
---|---|---|
88ae23e7 | 1 | /* Part of CPP library. |
6441eb6d | 2 | Copyright (C) 1997-2025 Free Software Foundation, Inc. |
4283012f JL |
3 | |
4 | This program is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the | |
748086b7 | 6 | Free Software Foundation; either version 3, or (at your option) any |
4283012f JL |
7 | later version. |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
748086b7 JJ |
15 | along with this program; see the file COPYING3. If not see |
16 | <http://www.gnu.org/licenses/>. */ | |
4283012f | 17 | |
88ae23e7 | 18 | /* This header defines all the internal data structures and functions |
4f4e53dd PB |
19 | that need to be visible across files. It should not be used outside |
20 | cpplib. */ | |
88ae23e7 | 21 | |
4f4e53dd PB |
22 | #ifndef LIBCPP_INTERNAL_H |
23 | #define LIBCPP_INTERNAL_H | |
bb52fa7f | 24 | |
4f4e53dd | 25 | #include "symtab.h" |
abcd1775 | 26 | #include "cpplib.h" |
78d132d7 | 27 | #include "rich-location.h" |
2a967f3d | 28 | |
968e08d6 | 29 | #if HAVE_ICONV |
e6cc3a24 ZW |
30 | #include <iconv.h> |
31 | #else | |
32 | #define HAVE_ICONV 0 | |
33 | typedef int iconv_t; /* dummy */ | |
34 | #endif | |
35 | ||
4851089f ILT |
36 | #ifdef __cplusplus |
37 | extern "C" { | |
38 | #endif | |
39 | ||
2a967f3d | 40 | struct directive; /* Deliberately incomplete. */ |
af0d16cd | 41 | struct pending_option; |
87ed109f | 42 | struct op; |
a8016863 | 43 | struct _cpp_strbuf; |
6b88314c ZW |
44 | |
45 | typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t, | |
a8016863 | 46 | struct _cpp_strbuf *); |
6b88314c ZW |
47 | struct cset_converter |
48 | { | |
49 | convert_f func; | |
50 | iconv_t cd; | |
b6baa67d | 51 | int width; |
eccec868 JM |
52 | const char* from; |
53 | const char* to; | |
6b88314c | 54 | }; |
8121d2c3 | 55 | |
4268e8bb NB |
56 | #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t)) |
57 | ||
93c80368 NB |
58 | /* Test if a sign is valid within a preprocessing number. */ |
59 | #define VALID_SIGN(c, prevc) \ | |
60 | (((c) == '+' || (c) == '-') && \ | |
61 | ((prevc) == 'e' || (prevc) == 'E' \ | |
bdb05a7b NB |
62 | || (((prevc) == 'p' || (prevc) == 'P') \ |
63 | && CPP_OPTION (pfile, extended_numbers)))) | |
93c80368 | 64 | |
7057e645 ESR |
65 | #define DIGIT_SEP(c) ((c) == '\'' && CPP_OPTION (pfile, digit_separators)) |
66 | ||
8121d2c3 NB |
67 | #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) |
68 | #define CPP_BUFFER(PFILE) ((PFILE)->buffer) | |
26aea073 | 69 | #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base) |
8121d2c3 NB |
70 | #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur) |
71 | ||
12f9df4e | 72 | #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ |
99b1c316 | 73 | const class line_maps *line_table = PFILE->line_table; \ |
0e50b624 | 74 | const struct line_map_ordinary *map = \ |
46427374 | 75 | LINEMAPS_LAST_ORDINARY_MAP (line_table); \ |
1bb64668 | 76 | linenum_type line = SOURCE_LINE (map, line_table->highest_line); \ |
500bee0a | 77 | linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ |
12f9df4e PB |
78 | } while (0) |
79 | ||
c70f6ed3 NB |
80 | /* Host alignment handling. */ |
81 | struct dummy | |
82 | { | |
83 | char c; | |
84 | union | |
85 | { | |
86 | double d; | |
87 | int *p; | |
c93eb81c | 88 | location_t l; |
c70f6ed3 NB |
89 | } u; |
90 | }; | |
91 | ||
92 | #define DEFAULT_ALIGNMENT offsetof (struct dummy, u) | |
93 | #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1)) | |
94 | #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT) | |
95 | ||
3f6677f4 NS |
96 | #define _cpp_mark_macro_used(NODE) \ |
97 | (cpp_user_macro_p (NODE) ? (NODE)->value.macro->used = 1 : 0) | |
a69cbaac | 98 | |
644eddaa | 99 | /* A generic memory buffer, and operations on it. */ |
b8af0ca5 NB |
100 | typedef struct _cpp_buff _cpp_buff; |
101 | struct _cpp_buff | |
102 | { | |
103 | struct _cpp_buff *next; | |
ece54d54 | 104 | unsigned char *base, *cur, *limit; |
b8af0ca5 NB |
105 | }; |
106 | ||
6cf87ca4 ZW |
107 | extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t); |
108 | extern void _cpp_release_buff (cpp_reader *, _cpp_buff *); | |
109 | extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t); | |
110 | extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t); | |
111 | extern void _cpp_free_buff (_cpp_buff *); | |
112 | extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t); | |
113 | extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t); | |
644eddaa | 114 | |
8c3b2693 | 115 | #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur) |
ece54d54 NB |
116 | #define BUFF_FRONT(BUFF) ((BUFF)->cur) |
117 | #define BUFF_LIMIT(BUFF) ((BUFF)->limit) | |
b8af0ca5 | 118 | |
ba133c96 | 119 | /* #include types. */ |
a0be978a NS |
120 | enum include_type |
121 | { | |
122 | /* Directive-based including mechanisms. */ | |
123 | IT_INCLUDE, /* #include */ | |
124 | IT_INCLUDE_NEXT, /* #include_next */ | |
125 | IT_IMPORT, /* #import */ | |
eba6d2aa | 126 | IT_EMBED, /* #embed */ |
a0be978a NS |
127 | |
128 | /* Non-directive including mechanisms. */ | |
129 | IT_CMDLINE, /* -include */ | |
130 | IT_DEFAULT, /* forced header */ | |
6bf2ff0d | 131 | IT_MAIN, /* main, start on line 1 */ |
d1c566d7 NS |
132 | IT_PRE_MAIN, /* main, but there will be a preamble before line |
133 | 1 */ | |
b0d11f1e NS |
134 | |
135 | IT_DIRECTIVE_HWM = IT_IMPORT + 1, /* Directives below this. */ | |
68710ac7 | 136 | IT_HEADER_HWM = IT_DEFAULT + 1 /* Header files below this. */ |
a0be978a | 137 | }; |
ba133c96 | 138 | |
4ed5bcfb | 139 | union utoken |
8121d2c3 | 140 | { |
4ed5bcfb NB |
141 | const cpp_token *token; |
142 | const cpp_token **ptoken; | |
8121d2c3 NB |
143 | }; |
144 | ||
5d8ebbd8 | 145 | /* A "run" of tokens; part of a chain of runs. */ |
5fddcffc NB |
146 | typedef struct tokenrun tokenrun; |
147 | struct tokenrun | |
148 | { | |
bdcbe496 | 149 | tokenrun *next, *prev; |
5fddcffc NB |
150 | cpp_token *base, *limit; |
151 | }; | |
152 | ||
82eda77e | 153 | /* Accessor macros for struct cpp_context. */ |
79ba5e3b NB |
154 | #define FIRST(c) ((c)->u.iso.first) |
155 | #define LAST(c) ((c)->u.iso.last) | |
156 | #define CUR(c) ((c)->u.trad.cur) | |
157 | #define RLIMIT(c) ((c)->u.trad.rlimit) | |
82eda77e | 158 | |
92582b75 TT |
159 | /* This describes some additional data that is added to the macro |
160 | token context of type cpp_context, when -ftrack-macro-expansion is | |
161 | on. */ | |
162 | typedef struct | |
163 | { | |
164 | /* The node of the macro we are referring to. */ | |
165 | cpp_hashnode *macro_node; | |
166 | /* This buffer contains an array of virtual locations. The virtual | |
167 | location at index 0 is the virtual location of the token at index | |
168 | 0 in the current instance of cpp_context; similarly for all the | |
169 | other virtual locations. */ | |
620e594b | 170 | location_t *virt_locs; |
92582b75 TT |
171 | /* This is a pointer to the current virtual location. This is used |
172 | to iterate over the virtual locations while we iterate over the | |
173 | tokens they belong to. */ | |
620e594b | 174 | location_t *cur_virt_loc; |
92582b75 TT |
175 | } macro_context; |
176 | ||
177 | /* The kind of tokens carried by a cpp_context. */ | |
178 | enum context_tokens_kind { | |
179 | /* This is the value of cpp_context::tokens_kind if u.iso.first | |
180 | contains an instance of cpp_token **. */ | |
181 | TOKENS_KIND_INDIRECT, | |
182 | /* This is the value of cpp_context::tokens_kind if u.iso.first | |
183 | contains an instance of cpp_token *. */ | |
184 | TOKENS_KIND_DIRECT, | |
185 | /* This is the value of cpp_context::tokens_kind when the token | |
186 | context contains tokens resulting from macro expansion. In that | |
187 | case struct cpp_context::macro points to an instance of struct | |
188 | macro_context. This is used only when the | |
189 | -ftrack-macro-expansion flag is on. */ | |
190 | TOKENS_KIND_EXTENDED | |
191 | }; | |
192 | ||
8121d2c3 NB |
193 | typedef struct cpp_context cpp_context; |
194 | struct cpp_context | |
195 | { | |
196 | /* Doubly-linked list. */ | |
197 | cpp_context *next, *prev; | |
198 | ||
82eda77e NB |
199 | union |
200 | { | |
201 | /* For ISO macro expansion. Contexts other than the base context | |
202 | are contiguous tokens. e.g. macro expansions, expanded | |
203 | argument tokens. */ | |
204 | struct | |
205 | { | |
206 | union utoken first; | |
207 | union utoken last; | |
208 | } iso; | |
209 | ||
210 | /* For traditional macro expansion. */ | |
211 | struct | |
212 | { | |
c812785a RS |
213 | const unsigned char *cur; |
214 | const unsigned char *rlimit; | |
82eda77e NB |
215 | } trad; |
216 | } u; | |
8121d2c3 | 217 | |
1e013d2e | 218 | /* If non-NULL, a buffer used for storage related to this context. |
c9e7a609 | 219 | When the context is popped, the buffer is released. */ |
1e013d2e NB |
220 | _cpp_buff *buff; |
221 | ||
92582b75 TT |
222 | /* If tokens_kind is TOKEN_KIND_EXTENDED, then (as we thus are in a |
223 | macro context) this is a pointer to an instance of macro_context. | |
224 | Otherwise if tokens_kind is *not* TOKEN_KIND_EXTENDED, then, if | |
225 | we are in a macro context, this is a pointer to an instance of | |
226 | cpp_hashnode, representing the name of the macro this context is | |
227 | for. If we are not in a macro context, then this is just NULL. | |
228 | Note that when tokens_kind is TOKEN_KIND_EXTENDED, the memory | |
229 | used by the instance of macro_context pointed to by this member | |
230 | is de-allocated upon de-allocation of the instance of struct | |
231 | cpp_context. */ | |
232 | union | |
233 | { | |
234 | macro_context *mc; | |
235 | cpp_hashnode *macro; | |
236 | } c; | |
4ed5bcfb | 237 | |
92582b75 TT |
238 | /* This determines the type of tokens held by this context. */ |
239 | enum context_tokens_kind tokens_kind; | |
8121d2c3 NB |
240 | }; |
241 | ||
242 | struct lexer_state | |
243 | { | |
056f95ec NS |
244 | /* 1 if we're handling a directive. 2 if it's an include-like |
245 | directive. */ | |
8121d2c3 NB |
246 | unsigned char in_directive; |
247 | ||
a8d0ddaf ZW |
248 | /* Nonzero if in a directive that will handle padding tokens itself. |
249 | #include needs this to avoid problems with computed include and | |
250 | spacing between tokens. */ | |
251 | unsigned char directive_wants_padding; | |
252 | ||
cef0d199 NB |
253 | /* True if we are skipping a failed conditional group. */ |
254 | unsigned char skipping; | |
255 | ||
8121d2c3 NB |
256 | /* Nonzero if in a directive that takes angle-bracketed headers. */ |
257 | unsigned char angled_headers; | |
258 | ||
d97371e0 NB |
259 | /* Nonzero if in a #if or #elif directive. */ |
260 | unsigned char in_expression; | |
261 | ||
8121d2c3 NB |
262 | /* Nonzero to save comments. Turned off if discard_comments, and in |
263 | all directives apart from #define. */ | |
264 | unsigned char save_comments; | |
265 | ||
fb771b9d | 266 | /* Nonzero if lexing __VA_ARGS__ and __VA_OPT__ are valid. */ |
8121d2c3 NB |
267 | unsigned char va_args_ok; |
268 | ||
269 | /* Nonzero if lexing poisoned identifiers is valid. */ | |
270 | unsigned char poisoned_ok; | |
271 | ||
272 | /* Nonzero to prevent macro expansion. */ | |
df383483 | 273 | unsigned char prevent_expansion; |
8121d2c3 NB |
274 | |
275 | /* Nonzero when parsing arguments to a function-like macro. */ | |
276 | unsigned char parsing_args; | |
87ed109f | 277 | |
c6e83800 ZW |
278 | /* Nonzero if prevent_expansion is true only because output is |
279 | being discarded. */ | |
280 | unsigned char discarding_output; | |
281 | ||
87ed109f NB |
282 | /* Nonzero to skip evaluating part of an expression. */ |
283 | unsigned int skip_eval; | |
bc4071dd | 284 | |
7cf3f604 | 285 | /* Nonzero when tokenizing a deferred pragma. */ |
bc4071dd RH |
286 | unsigned char in_deferred_pragma; |
287 | ||
c9c3d5f2 NS |
288 | /* Count to token that is a header-name. */ |
289 | unsigned char directive_file_token; | |
290 | ||
bc4071dd RH |
291 | /* Nonzero if the deferred pragma being handled allows macro expansion. */ |
292 | unsigned char pragma_allow_expansion; | |
a6e0d593 JJ |
293 | |
294 | /* Nonzero if _Pragma should not be interpreted. */ | |
295 | unsigned char ignore__Pragma; | |
8121d2c3 NB |
296 | }; |
297 | ||
298 | /* Special nodes - identifiers with predefined significance. */ | |
299 | struct spec_nodes | |
300 | { | |
8121d2c3 | 301 | cpp_hashnode *n_defined; /* defined operator */ |
037313ae ZW |
302 | cpp_hashnode *n_true; /* C++ keyword true */ |
303 | cpp_hashnode *n_false; /* C++ keyword false */ | |
8121d2c3 | 304 | cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ |
fb771b9d | 305 | cpp_hashnode *n__VA_OPT__; /* C++ vararg macros */ |
c9c3d5f2 NS |
306 | |
307 | enum {M_EXPORT, M_MODULE, M_IMPORT, M__IMPORT, M_HWM}; | |
45ab93d9 | 308 | |
c9c3d5f2 NS |
309 | /* C++20 modules, only set when module_directives is in effect. |
310 | incoming variants [0], outgoing ones [1] */ | |
311 | cpp_hashnode *n_modules[M_HWM][2]; | |
8121d2c3 NB |
312 | }; |
313 | ||
26aea073 NB |
314 | typedef struct _cpp_line_note _cpp_line_note; |
315 | struct _cpp_line_note | |
316 | { | |
317 | /* Location in the clean line the note refers to. */ | |
c812785a | 318 | const unsigned char *pos; |
26aea073 | 319 | |
41c32c98 NB |
320 | /* Type of note. The 9 'from' trigraph characters represent those |
321 | trigraphs, '\\' an escaped newline, ' ' an escaped newline with | |
d4499a23 JJ |
322 | intervening space, 'W' trailing whitespace, 'L', 'S' and 'T' for |
323 | leading whitespace issues, 0 represents a note that | |
ac615e10 | 324 | has already been handled, and anything else is invalid. */ |
41c32c98 | 325 | unsigned int type; |
26aea073 NB |
326 | }; |
327 | ||
a8260ebe AM |
328 | /* Tail padding required by search_line_fast alternatives. */ |
329 | #ifdef HAVE_SSSE3 | |
330 | #define CPP_BUFFER_PADDING 64 | |
331 | #else | |
332 | #define CPP_BUFFER_PADDING 16 | |
333 | #endif | |
334 | ||
5d8ebbd8 | 335 | /* Represents the contents of a file cpplib has read in. */ |
27e2564a NB |
336 | struct cpp_buffer |
337 | { | |
c812785a RS |
338 | const unsigned char *cur; /* Current location. */ |
339 | const unsigned char *line_base; /* Start of current physical line. */ | |
340 | const unsigned char *next_line; /* Start of to-be-cleaned logical line. */ | |
cf551fba | 341 | |
c812785a RS |
342 | const unsigned char *buf; /* Entire character buffer. */ |
343 | const unsigned char *rlimit; /* Writable byte at end of file. */ | |
28937f11 JJ |
344 | const unsigned char *to_free; /* Pointer that should be freed when |
345 | popping the buffer. */ | |
26aea073 | 346 | |
c812785a RS |
347 | _cpp_line_note *notes; /* Array of notes. */ |
348 | unsigned int cur_note; /* Next note to process. */ | |
349 | unsigned int notes_used; /* Number of notes. */ | |
350 | unsigned int notes_cap; /* Size of allocated array. */ | |
27e2564a | 351 | |
27e2564a NB |
352 | struct cpp_buffer *prev; |
353 | ||
8f9b4009 NB |
354 | /* Pointer into the file table; non-NULL if this is a file buffer. |
355 | Used for include_next and to record control macros. */ | |
356 | struct _cpp_file *file; | |
27e2564a | 357 | |
be8ac3e2 GZ |
358 | /* Saved value of __TIMESTAMP__ macro - date and time of last modification |
359 | of the assotiated file. */ | |
360 | const unsigned char *timestamp; | |
361 | ||
27e2564a NB |
362 | /* Value of if_stack at start of this file. |
363 | Used to prohibit unmatched #endif (etc) in an include file. */ | |
364 | struct if_stack *if_stack; | |
365 | ||
26aea073 | 366 | /* True if we need to get the next clean line. */ |
a0be978a | 367 | bool need_line : 1; |
27e2564a NB |
368 | |
369 | /* True if we have already warned about C++ comments in this file. | |
370 | The warning happens only for C89 extended mode with -pedantic on, | |
371 | or for -Wtraditional, and only once per file (otherwise it would | |
372 | be far too noisy). */ | |
a0be978a | 373 | bool warned_cplusplus_comments : 1; |
27e2564a NB |
374 | |
375 | /* True if we don't process trigraphs and escaped newlines. True | |
376 | for preprocessed input, command line directives, and _Pragma | |
377 | buffers. */ | |
a0be978a | 378 | bool from_stage3 : 1; |
27e2564a | 379 | |
22234f56 PB |
380 | /* At EOF, a buffer is automatically popped. If RETURN_AT_EOF is |
381 | true, a CPP_EOF token is then returned. Otherwise, the next | |
382 | token from the enclosing buffer is returned. */ | |
a0be978a | 383 | bool return_at_eof : 1; |
ba133c96 | 384 | |
12f9df4e | 385 | /* One for a system header, two for a C system header file that therefore |
9ac97460 | 386 | needs to be extern "C" protected in C++, and zero otherwise. */ |
12f9df4e PB |
387 | unsigned char sysp; |
388 | ||
591e15a1 NB |
389 | /* The directory of the this buffer's file. Its NAME member is not |
390 | allocated, so we don't need to worry about freeing it. */ | |
8f9b4009 | 391 | struct cpp_dir dir; |
004cb263 | 392 | |
cf551fba EC |
393 | /* Descriptor for converting from the input character set to the |
394 | source character set. */ | |
395 | struct cset_converter input_cset_desc; | |
27e2564a NB |
396 | }; |
397 | ||
17e7cb85 KT |
398 | /* The list of saved macros by push_macro pragma. */ |
399 | struct def_pragma_macro { | |
400 | /* Chain element to previous saved macro. */ | |
401 | struct def_pragma_macro *next; | |
402 | /* Name of the macro. */ | |
403 | char *name; | |
404 | /* The stored macro content. */ | |
d6874138 KT |
405 | unsigned char *definition; |
406 | ||
407 | /* Definition line number. */ | |
620e594b | 408 | location_t line; |
d6874138 KT |
409 | /* If macro defined in system header. */ |
410 | unsigned int syshdr : 1; | |
411 | /* Nonzero if it has been expanded or had its existence tested. */ | |
412 | unsigned int used : 1; | |
413 | ||
414 | /* Mark if we save an undefined macro. */ | |
415 | unsigned int is_undef : 1; | |
aa23e73b JJ |
416 | /* Nonzero if it was a builtin macro. */ |
417 | unsigned int is_builtin : 1; | |
17e7cb85 KT |
418 | }; |
419 | ||
8121d2c3 NB |
420 | /* A cpp_reader encapsulates the "state" of a pre-processor run. |
421 | Applying cpp_get_token repeatedly yields a stream of pre-processor | |
422 | tokens. Usually, there is only one cpp_reader object active. */ | |
8121d2c3 NB |
423 | struct cpp_reader |
424 | { | |
425 | /* Top of buffer stack. */ | |
426 | cpp_buffer *buffer; | |
427 | ||
d97371e0 NB |
428 | /* Overlaid buffer (can be different after processing #include). */ |
429 | cpp_buffer *overlaid_buffer; | |
430 | ||
8121d2c3 NB |
431 | /* Lexer state. */ |
432 | struct lexer_state state; | |
433 | ||
67821e3a | 434 | /* Source line tracking. */ |
99b1c316 | 435 | class line_maps *line_table; |
1444f2ed | 436 | |
50410426 | 437 | /* The line of the '#' of the current directive. */ |
620e594b | 438 | location_t directive_line; |
8121d2c3 | 439 | |
b8af0ca5 | 440 | /* Memory buffers. */ |
8c3b2693 | 441 | _cpp_buff *a_buff; /* Aligned permanent storage. */ |
ece54d54 NB |
442 | _cpp_buff *u_buff; /* Unaligned permanent storage. */ |
443 | _cpp_buff *free_buffs; /* Free buffer chain. */ | |
b8af0ca5 | 444 | |
8121d2c3 NB |
445 | /* Context stack. */ |
446 | struct cpp_context base_context; | |
447 | struct cpp_context *context; | |
448 | ||
449 | /* If in_directive, the directive if known. */ | |
450 | const struct directive *directive; | |
451 | ||
21b11495 ZW |
452 | /* Token generated while handling a directive, if any. */ |
453 | cpp_token directive_result; | |
454 | ||
5ffeb913 TT |
455 | /* When expanding a macro at top-level, this is the location of the |
456 | macro invocation. */ | |
620e594b | 457 | location_t invocation_location; |
5ffeb913 | 458 | |
f8abc9ba DS |
459 | /* This is the node representing the macro being expanded at |
460 | top-level. The value of this data member is valid iff | |
a0be978a | 461 | cpp_in_macro_expansion_p() returns TRUE. */ |
f8abc9ba DS |
462 | cpp_hashnode *top_most_macro_node; |
463 | ||
828a7f76 DS |
464 | /* Nonzero if we are about to expand a macro. Note that if we are |
465 | really expanding a macro, the function macro_of_context returns | |
466 | the macro being expanded and this flag is set to false. Client | |
a0be978a | 467 | code should use the function cpp_in_macro_expansion_p to know if we |
828a7f76 DS |
468 | are either about to expand a macro, or are actually expanding |
469 | one. */ | |
470 | bool about_to_expand_macro_p; | |
5ffeb913 | 471 | |
1ae24f7e JJ |
472 | /* True if the preprocessor should diagnose CPP_DOT or CPP_COLON |
473 | tokens as the first ones coming from macro expansion. */ | |
474 | bool diagnose_dot_colon_from_macro_p; | |
475 | ||
5793b276 | 476 | /* Search paths for include files. */ |
8f9b4009 NB |
477 | struct cpp_dir *quote_include; /* "" */ |
478 | struct cpp_dir *bracket_include; /* <> */ | |
479 | struct cpp_dir no_search_path; /* No path. */ | |
eba6d2aa | 480 | struct cpp_dir *embed_include; /* #embed <> */ |
8f9b4009 | 481 | |
49634b3a NB |
482 | /* Chain of all hashed _cpp_file instances. */ |
483 | struct _cpp_file *all_files; | |
8f9b4009 | 484 | |
4dc299fb PB |
485 | struct _cpp_file *main_file; |
486 | ||
8f9b4009 | 487 | /* File and directory hash table. */ |
bf42e45b | 488 | struct htab *file_hash; |
a23ee064 | 489 | struct htab *dir_hash; |
97f6bd40 | 490 | struct file_hash_entry_pool *file_hash_entries; |
8f9b4009 | 491 | |
0b4cafec ILT |
492 | /* Negative path lookup hash table. */ |
493 | struct htab *nonexistent_file_hash; | |
494 | struct obstack nonexistent_file_ob; | |
495 | ||
8f9b4009 NB |
496 | /* Nonzero means don't look for #include "foo" the source-file |
497 | directory. */ | |
498 | bool quote_ignores_source_dir; | |
499 | ||
83a00410 | 500 | /* Nonzero if any file has contained #pragma once or #import has |
49634b3a NB |
501 | been used. */ |
502 | bool seen_once_only; | |
5793b276 | 503 | |
5943a2fa | 504 | /* Multiple include optimization and -Wheader-guard warning. */ |
8121d2c3 NB |
505 | const cpp_hashnode *mi_cmacro; |
506 | const cpp_hashnode *mi_ind_cmacro; | |
5943a2fa JJ |
507 | const cpp_hashnode *mi_def_cmacro; |
508 | location_t mi_loc, mi_def_loc; | |
6d18adbc | 509 | bool mi_valid; |
8121d2c3 | 510 | |
5fddcffc NB |
511 | /* Lexing. */ |
512 | cpp_token *cur_token; | |
513 | tokenrun base_run, *cur_run; | |
bdcbe496 | 514 | unsigned int lookaheads; |
5fddcffc | 515 | |
da7d8304 | 516 | /* Nonzero prevents the lexer from re-using the token runs. */ |
5fddcffc NB |
517 | unsigned int keep_tokens; |
518 | ||
8121d2c3 NB |
519 | /* Buffer to hold macro definition string. */ |
520 | unsigned char *macro_buffer; | |
521 | unsigned int macro_buffer_len; | |
522 | ||
6b88314c ZW |
523 | /* Descriptor for converting from the source character set to the |
524 | execution character set. */ | |
525 | struct cset_converter narrow_cset_desc; | |
e6cc3a24 | 526 | |
2c6e3f55 JJ |
527 | /* Descriptor for converting from the source character set to the |
528 | UTF-8 execution character set. */ | |
529 | struct cset_converter utf8_cset_desc; | |
530 | ||
b6baa67d KVH |
531 | /* Descriptor for converting from the source character set to the |
532 | UTF-16 execution character set. */ | |
533 | struct cset_converter char16_cset_desc; | |
534 | ||
535 | /* Descriptor for converting from the source character set to the | |
536 | UTF-32 execution character set. */ | |
537 | struct cset_converter char32_cset_desc; | |
538 | ||
6b88314c ZW |
539 | /* Descriptor for converting from the source character set to the |
540 | wide execution character set. */ | |
541 | struct cset_converter wide_cset_desc; | |
e6cc3a24 | 542 | |
278c4662 | 543 | /* Date and time text. Calculated together if either is requested. */ |
c812785a RS |
544 | const unsigned char *date; |
545 | const unsigned char *time; | |
8121d2c3 | 546 | |
4b5f564a NS |
547 | /* Time stamp, set idempotently lazily. */ |
548 | time_t time_stamp; | |
549 | int time_stamp_kind; /* Or errno. */ | |
174f6622 | 550 | |
5abe05b4 | 551 | /* A token forcing paste avoidance, and one demarking macro arguments. */ |
4ed5bcfb | 552 | cpp_token avoid_paste; |
5abe05b4 | 553 | cpp_token endarg; |
4ed5bcfb | 554 | |
e53b6e56 | 555 | /* Opaque handle to the dependencies of mkdeps.cc. */ |
99b1c316 | 556 | class mkdeps *deps; |
8121d2c3 NB |
557 | |
558 | /* Obstack holding all macro hash nodes. This never shrinks. | |
e53b6e56 | 559 | See identifiers.cc */ |
2a967f3d | 560 | struct obstack hash_ob; |
8121d2c3 NB |
561 | |
562 | /* Obstack holding buffer and conditional structures. This is a | |
e53b6e56 | 563 | real stack. See directives.cc. */ |
2a967f3d | 564 | struct obstack buffer_ob; |
8121d2c3 NB |
565 | |
566 | /* Pragma table - dynamic, because a library user can add to the | |
567 | list of recognized pragmas. */ | |
568 | struct pragma_entry *pragmas; | |
569 | ||
48c4721e | 570 | /* Call backs to cpplib client. */ |
8121d2c3 NB |
571 | struct cpp_callbacks cb; |
572 | ||
df383483 | 573 | /* Identifier hash table. */ |
2a967f3d NB |
574 | struct ht *hash_table; |
575 | ||
cb05acdc LH |
576 | /* Identifier ancillary data hash table. */ |
577 | struct ht *extra_hash_table; | |
578 | ||
87ed109f NB |
579 | /* Expression parser stack. */ |
580 | struct op *op_stack, *op_limit; | |
581 | ||
8121d2c3 NB |
582 | /* User visible options. */ |
583 | struct cpp_options opts; | |
584 | ||
585 | /* Special nodes - identifiers with predefined significance to the | |
586 | preprocessor. */ | |
587 | struct spec_nodes spec_nodes; | |
588 | ||
2a967f3d | 589 | /* Whether cpplib owns the hashtable. */ |
cb05acdc | 590 | bool our_hashtable, our_extra_hashtable; |
004cb263 | 591 | |
1a76916c NB |
592 | /* Traditional preprocessing output buffer (a logical line). */ |
593 | struct | |
594 | { | |
c812785a RS |
595 | unsigned char *base; |
596 | unsigned char *limit; | |
597 | unsigned char *cur; | |
620e594b | 598 | location_t first_line; |
1a76916c NB |
599 | } out; |
600 | ||
e53b6e56 | 601 | /* Used for buffer overlays by traditional.cc. */ |
c812785a | 602 | const unsigned char *saved_cur, *saved_rlimit, *saved_line_base; |
12f9df4e | 603 | |
17211ab5 GK |
604 | /* A saved list of the defined macros, for dependency checking |
605 | of precompiled headers. */ | |
606 | struct cpp_savedstate *savedstate; | |
a702045a OW |
607 | |
608 | /* Next value of __COUNTER__ macro. */ | |
609 | unsigned int counter; | |
631d0d36 MG |
610 | |
611 | /* Table of comments, when state.save_comments is true. */ | |
612 | cpp_comment_table comments; | |
17e7cb85 KT |
613 | |
614 | /* List of saved macros by push_macro. */ | |
615 | struct def_pragma_macro *pushed_macros; | |
e3dfef44 | 616 | |
f3f6029d | 617 | /* If non-zero, the lexer will use this location for the next token |
e3dfef44 | 618 | instead of getting a location from the linemap. */ |
620e594b | 619 | location_t forced_token_location; |
9844497a NS |
620 | |
621 | /* Location identifying the main source file -- intended to be line | |
622 | zero of said file. */ | |
623 | location_t main_loc; | |
51c50026 | 624 | |
65c5bbe1 LH |
625 | /* If non-zero, override diagnostic locations (other than DK_NOTE |
626 | diagnostics) to this one. */ | |
627 | location_t diagnostic_override_loc; | |
628 | ||
51c50026 MP |
629 | /* Returns true iff we should warn about UTF-8 bidirectional control |
630 | characters. */ | |
631 | bool warn_bidi_p () const | |
632 | { | |
ae36f839 MP |
633 | return (CPP_OPTION (this, cpp_warn_bidirectional) |
634 | & (bidirectional_unpaired|bidirectional_any)); | |
51c50026 | 635 | } |
8121d2c3 NB |
636 | }; |
637 | ||
eba6d2aa JJ |
638 | /* Lists of tokens for #embed/__has_embed prefix/suffix/if_empty |
639 | parameters. */ | |
640 | struct cpp_embed_params_tokens | |
641 | { | |
642 | cpp_token *cur_token; | |
643 | tokenrun base_run, *cur_run; | |
644 | size_t count; | |
645 | }; | |
646 | ||
647 | /* #embed and __has_embed parameters. */ | |
648 | struct cpp_embed_params | |
649 | { | |
650 | location_t loc; | |
651 | bool has_embed; | |
44058b84 | 652 | cpp_num_part limit, offset; |
ce0aecc7 | 653 | cpp_embed_params_tokens prefix, suffix, if_empty, base64; |
eba6d2aa JJ |
654 | }; |
655 | ||
f6bbde28 | 656 | /* Character classes. Based on the more primitive macros in safe-ctype.h. |
88ae23e7 | 657 | If the definition of `numchar' looks odd to you, please look up the |
91fcd158 NB |
658 | definition of a pp-number in the C standard [section 6.4.8 of C99]. |
659 | ||
660 | In the unlikely event that characters other than \r and \n enter | |
e53b6e56 | 661 | the set is_vspace, the macro handle_newline() in lex.cc must be |
91fcd158 | 662 | updated. */ |
ae79697b | 663 | #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) |
88ae23e7 | 664 | |
f6bbde28 ZW |
665 | #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x)) |
666 | #define is_numchar(x) ISIDNUM(x) | |
667 | #define is_idstart(x) (ISIDST(x) || _dollar_ok(x)) | |
668 | #define is_numstart(x) ISDIGIT(x) | |
669 | #define is_hspace(x) ISBLANK(x) | |
670 | #define is_vspace(x) IS_VSPACE(x) | |
671 | #define is_nvspace(x) IS_NVSPACE(x) | |
672 | #define is_space(x) IS_SPACE_OR_NUL(x) | |
88ae23e7 | 673 | |
18f5df94 JJ |
674 | #define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF) |
675 | ||
f6bbde28 | 676 | /* This table is constant if it can be initialized at compile time, |
88ae23e7 ZW |
677 | which is the case if cpp was compiled with GCC >=2.7, or another |
678 | compiler that supports C99. */ | |
61d0346d | 679 | #if HAVE_DESIGNATED_INITIALIZERS |
61d0346d | 680 | extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; |
e4c0595e JJ |
681 | #elif __cpp_constexpr >= 201304L |
682 | extern const struct _cpp_trigraph_map_s { | |
683 | unsigned char map[UCHAR_MAX + 1]; | |
684 | constexpr _cpp_trigraph_map_s (); | |
685 | } _cpp_trigraph_map_d; | |
686 | #define _cpp_trigraph_map _cpp_trigraph_map_d.map | |
88ae23e7 | 687 | #else |
61d0346d | 688 | extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; |
88ae23e7 ZW |
689 | #endif |
690 | ||
c5d725c0 NS |
691 | #if !defined (HAVE_UCHAR) && !defined (IN_GCC) |
692 | typedef unsigned char uchar; | |
693 | #endif | |
694 | ||
695 | #define UC (const uchar *) /* Intended use: UC"string" */ | |
696 | ||
bf425849 | 697 | /* Accessors. */ |
88ae23e7 | 698 | |
bf425849 NS |
699 | inline int |
700 | _cpp_in_system_header (cpp_reader *pfile) | |
12f9df4e PB |
701 | { |
702 | return pfile->buffer ? pfile->buffer->sysp : 0; | |
703 | } | |
e3339d0f JM |
704 | #define CPP_PEDANTIC(PF) CPP_OPTION (PF, cpp_pedantic) |
705 | #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, cpp_warn_traditional) | |
88ae23e7 | 706 | |
bf425849 NS |
707 | /* Return true if we're in the main file (unless it's considered to be |
708 | an include file in its own right. */ | |
709 | inline int | |
710 | _cpp_in_main_source_file (cpp_reader *pfile) | |
705e2d28 | 711 | { |
9844497a NS |
712 | return (!CPP_OPTION (pfile, main_search) |
713 | && pfile->buffer->file == pfile->main_file); | |
705e2d28 TT |
714 | } |
715 | ||
ad1a3914 | 716 | /* True if NODE is a macro for the purposes of ifdef, defined etc. */ |
5943a2fa JJ |
717 | inline bool |
718 | _cpp_defined_macro_p (const cpp_hashnode *node) | |
ad1a3914 NS |
719 | { |
720 | /* Do not treat conditional macros as being defined. This is due to | |
721 | the powerpc port using conditional macros for 'vector', 'bool', | |
722 | and 'pixel' to act as conditional keywords. This messes up tests | |
723 | like #ifndef bool. */ | |
724 | return cpp_macro_p (node) && !(node->flags & NODE_CONDITIONAL); | |
725 | } | |
726 | ||
e53b6e56 | 727 | /* In macro.cc */ |
13f93cf5 NS |
728 | extern bool _cpp_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node, |
729 | location_t); | |
730 | inline bool _cpp_maybe_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node, | |
e9a2e208 | 731 | location_t loc) |
3f6677f4 NS |
732 | { |
733 | if (!(node->flags & NODE_USED)) | |
13f93cf5 NS |
734 | return _cpp_notify_macro_use (pfile, node, loc); |
735 | return true; | |
3f6677f4 | 736 | } |
10f04917 | 737 | extern cpp_macro *_cpp_new_macro (cpp_reader *, cpp_macro_kind, void *); |
6cf87ca4 | 738 | extern void _cpp_free_definition (cpp_hashnode *); |
4f3be7cb | 739 | extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *, location_t); |
6cf87ca4 ZW |
740 | extern void _cpp_pop_context (cpp_reader *); |
741 | extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *, | |
c812785a | 742 | const unsigned char *, size_t); |
729a01f7 | 743 | extern bool _cpp_save_parameter (cpp_reader *, unsigned, cpp_hashnode *, |
be5ffc59 | 744 | cpp_hashnode *); |
729a01f7 | 745 | extern void _cpp_unsave_parameters (cpp_reader *, unsigned); |
6cf87ca4 ZW |
746 | extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *, |
747 | unsigned int); | |
c812785a | 748 | extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *, |
64824205 | 749 | cpp_hashnode *, |
620e594b | 750 | location_t = 0); |
eba6d2aa | 751 | extern const cpp_token *_cpp_get_token_no_padding (cpp_reader *); |
bc4071dd RH |
752 | extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *); |
753 | extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *, | |
754 | const cpp_token *, unsigned int); | |
5950c3c9 | 755 | extern void _cpp_backup_tokens_direct (cpp_reader *, unsigned int); |
bc4071dd | 756 | |
e53b6e56 | 757 | /* In identifiers.cc */ |
cb05acdc LH |
758 | extern void |
759 | _cpp_init_hashtable (cpp_reader *, cpp_hash_table *, cpp_hash_table *); | |
6cf87ca4 | 760 | extern void _cpp_destroy_hashtable (cpp_reader *); |
bb52fa7f | 761 | |
e53b6e56 | 762 | /* In files.cc */ |
4623a6f2 | 763 | enum _cpp_find_file_kind |
eba6d2aa JJ |
764 | { _cpp_FFK_NORMAL, _cpp_FFK_FAKE, _cpp_FFK_PRE_INCLUDE, _cpp_FFK_HAS_INCLUDE, |
765 | _cpp_FFK_EMBED, _cpp_FFK_HAS_EMBED }; | |
6568f34b | 766 | extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *, |
4623a6f2 | 767 | int angle, _cpp_find_file_kind, location_t); |
4dc299fb | 768 | extern bool _cpp_find_failed (_cpp_file *); |
49634b3a | 769 | extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *); |
dbfbd3aa JM |
770 | extern cpp_dir *search_path_head (cpp_reader *, const char *, int, |
771 | include_type, bool = false); | |
1f9db692 NS |
772 | extern const char *_cpp_find_header_unit (cpp_reader *, const char *file, |
773 | bool angle_p, location_t); | |
eba6d2aa JJ |
774 | extern int _cpp_stack_embed (cpp_reader *, const char *, bool, |
775 | cpp_embed_params *); | |
6cf87ca4 | 776 | extern void _cpp_fake_include (cpp_reader *, const char *); |
b0d11f1e | 777 | extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, include_type, location_t); |
8f9b4009 | 778 | extern bool _cpp_stack_include (cpp_reader *, const char *, int, |
620e594b | 779 | enum include_type, location_t); |
6cf87ca4 ZW |
780 | extern int _cpp_compare_file_date (cpp_reader *, const char *, int); |
781 | extern void _cpp_report_missing_guards (cpp_reader *); | |
8f9b4009 NB |
782 | extern void _cpp_init_files (cpp_reader *); |
783 | extern void _cpp_cleanup_files (cpp_reader *); | |
28937f11 JJ |
784 | extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *, |
785 | const unsigned char *); | |
73e61092 GK |
786 | extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f); |
787 | extern bool _cpp_read_file_entries (cpp_reader *, FILE *); | |
b492b686 | 788 | extern const char *_cpp_get_file_name (_cpp_file *); |
be8ac3e2 | 789 | extern struct stat *_cpp_get_file_stat (_cpp_file *); |
7b8b96a3 | 790 | extern struct cpp_dir *_cpp_get_file_dir (_cpp_file *); |
a15f7cb8 ESR |
791 | extern bool _cpp_has_header (cpp_reader *, const char *, int, |
792 | enum include_type); | |
88ae23e7 | 793 | |
e53b6e56 | 794 | /* In expr.cc */ |
eba6d2aa JJ |
795 | extern cpp_num_part _cpp_parse_expr (cpp_reader *, const char *, |
796 | const cpp_token *); | |
6cf87ca4 | 797 | extern struct op *_cpp_expand_op_stack (cpp_reader *); |
88ae23e7 | 798 | |
e53b6e56 | 799 | /* In lex.cc */ |
6cf87ca4 ZW |
800 | extern void _cpp_process_line_notes (cpp_reader *, int); |
801 | extern void _cpp_clean_line (cpp_reader *); | |
802 | extern bool _cpp_get_fresh_line (cpp_reader *); | |
803 | extern bool _cpp_skip_block_comment (cpp_reader *); | |
804 | extern cpp_token *_cpp_temp_token (cpp_reader *); | |
805 | extern const cpp_token *_cpp_lex_token (cpp_reader *); | |
806 | extern cpp_token *_cpp_lex_direct (cpp_reader *); | |
be5ffc59 | 807 | extern unsigned char *_cpp_spell_ident_ucns (unsigned char *, cpp_hashnode *); |
6cf87ca4 ZW |
808 | extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); |
809 | extern void _cpp_init_tokenrun (tokenrun *, unsigned int); | |
ad2305ad | 810 | extern int _cpp_remaining_tokens_num_in_context (cpp_context *); |
b0c084b7 | 811 | extern void _cpp_init_lexer (void); |
10f04917 NS |
812 | static inline void *_cpp_reserve_room (cpp_reader *pfile, size_t have, |
813 | size_t extra) | |
814 | { | |
815 | if (BUFF_ROOM (pfile->a_buff) < (have + extra)) | |
816 | _cpp_extend_buff (pfile, &pfile->a_buff, extra); | |
817 | return BUFF_FRONT (pfile->a_buff); | |
818 | } | |
819 | extern void *_cpp_commit_buff (cpp_reader *pfile, size_t size); | |
45b966db | 820 | |
e53b6e56 | 821 | /* In init.cc. */ |
6cf87ca4 | 822 | extern void _cpp_maybe_push_include_file (cpp_reader *); |
cfc93532 | 823 | extern const char *cpp_named_operator2name (enum cpp_ttype type); |
aa23e73b JJ |
824 | extern void _cpp_restore_special_builtin (cpp_reader *pfile, |
825 | struct def_pragma_macro *); | |
d7bc7a98 | 826 | |
e53b6e56 | 827 | /* In directives.cc */ |
6cf87ca4 | 828 | extern int _cpp_test_assertion (cpp_reader *, unsigned int *); |
a0be978a | 829 | extern int _cpp_handle_directive (cpp_reader *, bool); |
6cf87ca4 ZW |
830 | extern void _cpp_define_builtin (cpp_reader *, const char *); |
831 | extern char ** _cpp_save_pragma_names (cpp_reader *); | |
832 | extern void _cpp_restore_pragma_names (cpp_reader *, char **); | |
620e594b | 833 | extern int _cpp_do__Pragma (cpp_reader *, location_t); |
6cf87ca4 ZW |
834 | extern void _cpp_init_directives (cpp_reader *); |
835 | extern void _cpp_init_internal_pragmas (cpp_reader *); | |
ce0aecc7 | 836 | extern void _cpp_free_embed_params_tokens (cpp_embed_params_tokens *); |
eba6d2aa | 837 | extern bool _cpp_parse_embed_params (cpp_reader *, struct cpp_embed_params *); |
6cf87ca4 | 838 | extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *, |
1bb64668 | 839 | linenum_type, unsigned int); |
6cf87ca4 | 840 | extern void _cpp_pop_buffer (cpp_reader *); |
a15f7cb8 | 841 | extern char *_cpp_bracket_include (cpp_reader *); |
12cf91fe | 842 | |
e53b6e56 | 843 | /* In errors.cc */ |
bd5e882c DM |
844 | extern location_t cpp_diagnostic_get_current_location (cpp_reader *); |
845 | ||
e53b6e56 | 846 | /* In traditional.cc. */ |
fb136e35 | 847 | extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *, bool); |
6cf87ca4 | 848 | extern bool _cpp_read_logical_line_trad (cpp_reader *); |
c812785a RS |
849 | extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *, |
850 | size_t); | |
6cf87ca4 | 851 | extern void _cpp_remove_overlay (cpp_reader *); |
10f04917 | 852 | extern cpp_macro *_cpp_create_trad_definition (cpp_reader *); |
6cf87ca4 ZW |
853 | extern bool _cpp_expansions_different_trad (const cpp_macro *, |
854 | const cpp_macro *); | |
c812785a RS |
855 | extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *, |
856 | unsigned char *); | |
6cf87ca4 | 857 | extern size_t _cpp_replacement_text_len (const cpp_macro *); |
004cb263 | 858 | |
e53b6e56 | 859 | /* In charset.cc. */ |
50668cf6 GK |
860 | |
861 | /* The normalization state at this point in the sequence. | |
862 | It starts initialized to all zeros, and at the end | |
863 | 'level' is the normalization level of the sequence. */ | |
864 | ||
45ab93d9 | 865 | struct normalize_state |
50668cf6 | 866 | { |
d3f4ff8b | 867 | /* The previous starter character. */ |
50668cf6 | 868 | cppchar_t previous; |
d3f4ff8b JM |
869 | /* The combining class of the previous character (whether or not a |
870 | starter). */ | |
50668cf6 GK |
871 | unsigned char prev_class; |
872 | /* The lowest normalization level so far. */ | |
873 | enum cpp_normalize_level level; | |
874 | }; | |
875 | #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC } | |
876 | #define NORMALIZE_STATE_RESULT(st) ((st)->level) | |
877 | ||
d3f4ff8b | 878 | /* We saw a character C that matches ISIDNUM(), update a |
50668cf6 | 879 | normalize_state appropriately. */ |
d3f4ff8b JM |
880 | #define NORMALIZE_STATE_UPDATE_IDNUM(st, c) \ |
881 | ((st)->previous = (c), (st)->prev_class = 0) | |
50668cf6 | 882 | |
fbb22910 PC |
883 | extern bool _cpp_valid_ucn (cpp_reader *, const unsigned char **, |
884 | const unsigned char *, int, | |
885 | struct normalize_state *state, | |
88fa5555 DM |
886 | cppchar_t *, |
887 | source_range *char_range, | |
888 | cpp_string_location_reader *loc_reader); | |
7d112d66 LH |
889 | |
890 | extern bool _cpp_valid_utf8 (cpp_reader *pfile, | |
891 | const uchar **pstr, | |
892 | const uchar *limit, | |
893 | int identifier_pos, | |
894 | struct normalize_state *nst, | |
895 | cppchar_t *cp); | |
896 | ||
6b88314c | 897 | extern void _cpp_destroy_iconv (cpp_reader *); |
c812785a RS |
898 | extern unsigned char *_cpp_convert_input (cpp_reader *, const char *, |
899 | unsigned char *, size_t, size_t, | |
688e7a53 | 900 | const unsigned char **, off_t *); |
16dd5cfe | 901 | extern const char *_cpp_default_encoding (void); |
47e20491 GK |
902 | extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile, |
903 | const unsigned char *id, | |
904 | size_t len); | |
1613e52b | 905 | |
c31a6508 | 906 | /* Utility routines and macros. */ |
c812785a | 907 | #define DSC(str) (const unsigned char *)str, sizeof str - 1 |
c31a6508 | 908 | |
8121d2c3 NB |
909 | /* These are inline functions instead of macros so we can get type |
910 | checking. */ | |
c812785a RS |
911 | static inline int ustrcmp (const unsigned char *, const unsigned char *); |
912 | static inline int ustrncmp (const unsigned char *, const unsigned char *, | |
913 | size_t); | |
914 | static inline size_t ustrlen (const unsigned char *); | |
0c1dace3 PC |
915 | static inline const unsigned char *uxstrdup (const unsigned char *); |
916 | static inline const unsigned char *ustrchr (const unsigned char *, int); | |
c812785a | 917 | static inline int ufputs (const unsigned char *, FILE *); |
8121d2c3 | 918 | |
be0f1e54 PB |
919 | /* Use a const char for the second parameter since it is usually a literal. */ |
920 | static inline int ustrcspn (const unsigned char *, const char *); | |
921 | ||
8121d2c3 | 922 | static inline int |
c812785a | 923 | ustrcmp (const unsigned char *s1, const unsigned char *s2) |
8121d2c3 NB |
924 | { |
925 | return strcmp ((const char *)s1, (const char *)s2); | |
926 | } | |
927 | ||
928 | static inline int | |
c812785a | 929 | ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n) |
8121d2c3 NB |
930 | { |
931 | return strncmp ((const char *)s1, (const char *)s2, n); | |
932 | } | |
933 | ||
be0f1e54 PB |
934 | static inline int |
935 | ustrcspn (const unsigned char *s1, const char *s2) | |
936 | { | |
937 | return strcspn ((const char *)s1, s2); | |
938 | } | |
939 | ||
8121d2c3 | 940 | static inline size_t |
c812785a | 941 | ustrlen (const unsigned char *s1) |
8121d2c3 NB |
942 | { |
943 | return strlen ((const char *)s1); | |
944 | } | |
945 | ||
0c1dace3 | 946 | static inline const unsigned char * |
c812785a | 947 | uxstrdup (const unsigned char *s1) |
8121d2c3 | 948 | { |
0c1dace3 | 949 | return (const unsigned char *) xstrdup ((const char *)s1); |
8121d2c3 NB |
950 | } |
951 | ||
0c1dace3 | 952 | static inline const unsigned char * |
c812785a | 953 | ustrchr (const unsigned char *s1, int c) |
8121d2c3 | 954 | { |
0c1dace3 | 955 | return (const unsigned char *) strchr ((const char *)s1, c); |
8121d2c3 NB |
956 | } |
957 | ||
958 | static inline int | |
c812785a | 959 | ufputs (const unsigned char *s, FILE *f) |
8121d2c3 NB |
960 | { |
961 | return fputs ((const char *)s, f); | |
962 | } | |
963 | ||
e53b6e56 | 964 | /* In line-map.cc. */ |
46427374 TT |
965 | |
966 | /* Create and return a virtual location for a token that is part of a | |
967 | macro expansion-list at a macro expansion point. See the comment | |
968 | inside struct line_map_macro to see what an expansion-list exactly | |
969 | is. | |
970 | ||
971 | A call to this function must come after a call to | |
972 | linemap_enter_macro. | |
973 | ||
974 | MAP is the map into which the source location is created. TOKEN_NO | |
975 | is the index of the token in the macro replacement-list, starting | |
976 | at number 0. | |
977 | ||
978 | ORIG_LOC is the location of the token outside of this macro | |
979 | expansion. If the token comes originally from the macro | |
980 | definition, it is the locus in the macro definition; otherwise it | |
981 | is a location in the context of the caller of this macro expansion | |
982 | (which is a virtual location or a source location if the caller is | |
983 | itself a macro expansion or not). | |
984 | ||
985 | MACRO_DEFINITION_LOC is the location in the macro definition, | |
986 | either of the token itself or of a macro parameter that it | |
987 | replaces. */ | |
620e594b DM |
988 | location_t linemap_add_macro_token (const line_map_macro *, |
989 | unsigned int, | |
990 | location_t, | |
991 | location_t); | |
46427374 TT |
992 | |
993 | /* Return the source line number corresponding to source location | |
994 | LOCATION. SET is the line map set LOCATION comes from. If | |
995 | LOCATION is the location of token that is part of the | |
996 | expansion-list of a macro expansion return the line number of the | |
997 | macro expansion point. */ | |
25af7c1a | 998 | int linemap_get_expansion_line (const line_maps *, |
620e594b | 999 | location_t); |
46427374 TT |
1000 | |
1001 | /* Return the path of the file corresponding to source code location | |
1002 | LOCATION. | |
1003 | ||
1004 | If LOCATION is the location of a token that is part of the | |
1005 | replacement-list of a macro expansion return the file path of the | |
1006 | macro expansion point. | |
1007 | ||
1008 | SET is the line map set LOCATION comes from. */ | |
25af7c1a | 1009 | const char* linemap_get_expansion_filename (const line_maps *, |
620e594b | 1010 | location_t); |
46427374 | 1011 | |
bd5e882c DM |
1012 | /* A subclass of rich_location for emitting a diagnostic |
1013 | at the current location of the reader, but flagging | |
1014 | it with set_escape_on_output (true). */ | |
1015 | class encoding_rich_location : public rich_location | |
1016 | { | |
1017 | public: | |
1018 | encoding_rich_location (cpp_reader *pfile) | |
1019 | : rich_location (pfile->line_table, | |
1020 | cpp_diagnostic_get_current_location (pfile)) | |
1021 | { | |
1022 | set_escape_on_output (true); | |
1023 | } | |
1024 | ||
1025 | encoding_rich_location (cpp_reader *pfile, location_t loc) | |
1026 | : rich_location (pfile->line_table, loc) | |
1027 | { | |
1028 | set_escape_on_output (true); | |
1029 | } | |
1030 | }; | |
1031 | ||
4851089f ILT |
1032 | #ifdef __cplusplus |
1033 | } | |
1034 | #endif | |
1035 | ||
4f4e53dd | 1036 | #endif /* ! LIBCPP_INTERNAL_H */ |