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

source code of libcpp/internal.h