1/* Definitions for CPP library.
2 Copyright (C) 1995-2026 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
4
5This program is free software; you can redistribute it and/or modify it
6under the terms of the GNU General Public License as published by the
7Free Software Foundation; either version 3, or (at your option) any
8later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; see the file COPYING3. If not see
17<http://www.gnu.org/licenses/>.
18
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
22#ifndef LIBCPP_CPPLIB_H
23#define LIBCPP_CPPLIB_H
24
25#include <sys/types.h>
26#include "symtab.h"
27#include "line-map.h"
28
29typedef struct cpp_reader cpp_reader;
30typedef struct cpp_buffer cpp_buffer;
31typedef struct cpp_options cpp_options;
32typedef struct cpp_token cpp_token;
33typedef struct cpp_string cpp_string;
34typedef struct cpp_hashnode cpp_hashnode;
35typedef struct cpp_macro cpp_macro;
36typedef struct cpp_callbacks cpp_callbacks;
37typedef struct cpp_dir cpp_dir;
38
39struct _cpp_file;
40
41class rich_location;
42
43/* The first three groups, apart from '=', can appear in preprocessor
44 expressions (+= and -= are used to indicate unary + and - resp.).
45 This allows a lookup table to be implemented in _cpp_parse_expr.
46
47 The first group, to CPP_LAST_EQ, can be immediately followed by an
48 '='. The lexer needs operators ending in '=', like ">>=", to be in
49 the same order as their counterparts without the '=', like ">>".
50
51 See the cpp_operator table optab in expr.cc if you change the order or
52 add or remove anything in the first group. */
53
54#define TTYPE_TABLE \
55 OP(EQ, "=") \
56 OP(NOT, "!") \
57 OP(GREATER, ">") /* compare */ \
58 OP(LESS, "<") \
59 OP(PLUS, "+") /* math */ \
60 OP(MINUS, "-") \
61 OP(MULT, "*") \
62 OP(DIV, "/") \
63 OP(MOD, "%") \
64 OP(AND, "&") /* bit ops */ \
65 OP(OR, "|") \
66 OP(XOR, "^") \
67 OP(RSHIFT, ">>") \
68 OP(LSHIFT, "<<") \
69 \
70 OP(COMPL, "~") \
71 OP(AND_AND, "&&") /* logical */ \
72 OP(OR_OR, "||") \
73 OP(QUERY, "?") \
74 OP(COLON, ":") \
75 OP(COMMA, ",") /* grouping */ \
76 OP(OPEN_PAREN, "(") \
77 OP(CLOSE_PAREN, ")") \
78 TK(EOF, NONE) \
79 OP(EQ_EQ, "==") /* compare */ \
80 OP(NOT_EQ, "!=") \
81 OP(GREATER_EQ, ">=") \
82 OP(LESS_EQ, "<=") \
83 OP(SPACESHIP, "<=>") \
84 \
85 /* These two are unary + / - in preprocessor expressions. */ \
86 OP(PLUS_EQ, "+=") /* math */ \
87 OP(MINUS_EQ, "-=") \
88 \
89 OP(MULT_EQ, "*=") \
90 OP(DIV_EQ, "/=") \
91 OP(MOD_EQ, "%=") \
92 OP(AND_EQ, "&=") /* bit ops */ \
93 OP(OR_EQ, "|=") \
94 OP(XOR_EQ, "^=") \
95 OP(RSHIFT_EQ, ">>=") \
96 OP(LSHIFT_EQ, "<<=") \
97 /* Digraphs together, beginning with CPP_FIRST_DIGRAPH. */ \
98 OP(HASH, "#") /* digraphs */ \
99 OP(PASTE, "##") \
100 OP(OPEN_SQUARE, "[") \
101 OP(CLOSE_SQUARE, "]") \
102 OP(OPEN_BRACE, "{") \
103 OP(CLOSE_BRACE, "}") \
104 OP(OPEN_SPLICE, "[:") \
105 OP(CLOSE_SPLICE, ":]") \
106 /* The remainder of the punctuation. Order is not significant. */ \
107 OP(SEMICOLON, ";") /* structure */ \
108 OP(ELLIPSIS, "...") \
109 OP(PLUS_PLUS, "++") /* increment */ \
110 OP(MINUS_MINUS, "--") \
111 OP(DEREF, "->") /* accessors */ \
112 OP(DOT, ".") \
113 OP(SCOPE, "::") \
114 OP(DEREF_STAR, "->*") \
115 OP(DOT_STAR, ".*") \
116 OP(REFLECT_OP, "^^") \
117 OP(ATSIGN, "@") /* used in Objective-C */ \
118 \
119 TK(NAME, IDENT) /* word */ \
120 TK(AT_NAME, IDENT) /* @word - Objective-C */ \
121 TK(NUMBER, LITERAL) /* 34_be+ta */ \
122 \
123 TK(CHAR, LITERAL) /* 'char' */ \
124 TK(WCHAR, LITERAL) /* L'char' */ \
125 TK(CHAR16, LITERAL) /* u'char' */ \
126 TK(CHAR32, LITERAL) /* U'char' */ \
127 TK(UTF8CHAR, LITERAL) /* u8'char' */ \
128 TK(OTHER, LITERAL) /* stray punctuation */ \
129 \
130 TK(STRING, LITERAL) /* "string" */ \
131 TK(WSTRING, LITERAL) /* L"string" */ \
132 TK(STRING16, LITERAL) /* u"string" */ \
133 TK(STRING32, LITERAL) /* U"string" */ \
134 TK(UTF8STRING, LITERAL) /* u8"string" */ \
135 TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \
136 TK(HEADER_NAME, LITERAL) /* <stdio.h> in #include */ \
137 TK(UNEVAL_STRING, LITERAL) /* unevaluated "string" - C++26 */ \
138 \
139 TK(CHAR_USERDEF, LITERAL) /* 'char'_suffix - C++11 */ \
140 TK(WCHAR_USERDEF, LITERAL) /* L'char'_suffix - C++11 */ \
141 TK(CHAR16_USERDEF, LITERAL) /* u'char'_suffix - C++11 */ \
142 TK(CHAR32_USERDEF, LITERAL) /* U'char'_suffix - C++11 */ \
143 TK(UTF8CHAR_USERDEF, LITERAL) /* u8'char'_suffix - C++11 */ \
144 TK(STRING_USERDEF, LITERAL) /* "string"_suffix - C++11 */ \
145 TK(WSTRING_USERDEF, LITERAL) /* L"string"_suffix - C++11 */ \
146 TK(STRING16_USERDEF, LITERAL) /* u"string"_suffix - C++11 */ \
147 TK(STRING32_USERDEF, LITERAL) /* U"string"_suffix - C++11 */ \
148 TK(UTF8STRING_USERDEF,LITERAL) /* u8"string"_suffix - C++11 */ \
149 \
150 TK(EMBED, LITERAL) /* #embed - C23 */ \
151 \
152 TK(COMMENT, LITERAL) /* Only if output comments. */ \
153 /* SPELL_LITERAL happens to DTRT. */ \
154 TK(MACRO_ARG, NONE) /* Macro argument. */ \
155 TK(PRAGMA, NONE) /* Only for deferred pragmas. */ \
156 TK(PRAGMA_EOL, NONE) /* End-of-line for deferred pragmas. */ \
157 TK(PADDING, NONE) /* Whitespace for -E. */
158
159#define OP(e, s) CPP_ ## e,
160#define TK(e, s) CPP_ ## e,
161enum cpp_ttype
162{
163 TTYPE_TABLE
164 N_TTYPES,
165
166 /* A token type for keywords, as opposed to ordinary identifiers. */
167 CPP_KEYWORD,
168
169 /* Positions in the table. */
170 CPP_LAST_EQ = CPP_LSHIFT,
171 CPP_FIRST_DIGRAPH = CPP_HASH,
172 CPP_LAST_PUNCTUATOR= CPP_ATSIGN,
173 CPP_LAST_CPP_OP = CPP_LESS_EQ
174};
175#undef OP
176#undef TK
177
178/* C language kind, used when calling cpp_create_reader. */
179enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC23,
180 CLK_GNUC2Y,
181 CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,
182 CLK_STDC23, CLK_STDC2Y,
183 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
184 CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
185 CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
186 CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
187
188/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
189struct GTY(()) cpp_string {
190 unsigned int len;
191
192 /* TEXT is always null terminated (terminator not included in len); but this
193 GTY markup arranges that PCH streaming works properly even if there is a
194 null byte in the middle of the string. */
195 const unsigned char * GTY((string_length ("1 + %h.len"))) text;
196};
197
198/* Flags for the cpp_token structure. */
199#define PREV_WHITE (1 << 0) /* If whitespace before this token. */
200#define DIGRAPH (1 << 1) /* If it was a digraph. */
201#define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */
202#define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */
203#define NAMED_OP (1 << 4) /* C++ named operators. */
204#define PREV_FALLTHROUGH (1 << 5) /* On a token preceeded by FALLTHROUGH
205 comment. */
206#define DECIMAL_INT (1 << 6) /* Decimal integer, set in c-lex.cc. */
207#define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend,
208 set in c-lex.cc. */
209#define COLON_SCOPE PURE_ZERO /* Adjacent colons in C < 23. */
210#define NO_DOT_COLON PURE_ZERO /* Set on CPP_NAME tokens whose expansion
211 shouldn't start with CPP_DOT or CPP_COLON
212 after optional CPP_PADDING. */
213#define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */
214#define SP_PREV_WHITE (1 << 9) /* If whitespace before a ##
215 operator, or before this token
216 after a # operator. */
217#define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */
218#define PRAGMA_OP (1 << 11) /* _Pragma token. */
219#define BOL (1 << 12) /* Token at beginning of line. */
220
221/* Specify which field, if any, of the cpp_token union is used. */
222
223enum cpp_token_fld_kind {
224 CPP_TOKEN_FLD_NODE,
225 CPP_TOKEN_FLD_SOURCE,
226 CPP_TOKEN_FLD_STR,
227 CPP_TOKEN_FLD_ARG_NO,
228 CPP_TOKEN_FLD_TOKEN_NO,
229 CPP_TOKEN_FLD_PRAGMA,
230 CPP_TOKEN_FLD_NONE
231};
232
233/* A macro argument in the cpp_token union. */
234struct GTY(()) cpp_macro_arg {
235 /* Argument number. */
236 unsigned int arg_no;
237 /* The original spelling of the macro argument token. */
238 cpp_hashnode *
239 GTY ((nested_ptr (union tree_node,
240 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
241 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
242 spelling;
243};
244
245/* An identifier in the cpp_token union. */
246struct GTY(()) cpp_identifier {
247 /* The canonical (UTF-8) spelling of the identifier. */
248 cpp_hashnode *
249 GTY ((nested_ptr (union tree_node,
250 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
251 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
252 node;
253 /* The original spelling of the identifier. */
254 cpp_hashnode *
255 GTY ((nested_ptr (union tree_node,
256 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
257 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
258 spelling;
259};
260
261/* A preprocessing token. This occupies 32 bytes on a 64-bit host. On a
262 32-bit host it occupies 20 or 24 bytes, depending whether a uint64_t
263 requires 4- or 8-byte alignment. */
264
265struct GTY(()) cpp_token {
266
267 /* Location of first char of token, together with range of full token. */
268 location_t src_loc;
269
270 ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */
271 unsigned short flags; /* flags - see above */
272
273 union cpp_token_u
274 {
275 /* An identifier. */
276 struct cpp_identifier GTY ((tag ("CPP_TOKEN_FLD_NODE"))) node;
277
278 /* Inherit padding from this token. */
279 cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source;
280
281 /* A string, or number. */
282 struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str;
283
284 /* Argument no. (and original spelling) for a CPP_MACRO_ARG. */
285 struct cpp_macro_arg GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) macro_arg;
286
287 /* Original token no. for a CPP_PASTE (from a sequence of
288 consecutive paste tokens in a macro expansion). */
289 unsigned int GTY ((tag ("CPP_TOKEN_FLD_TOKEN_NO"))) token_no;
290
291 /* Caller-supplied identifier for a CPP_PRAGMA. */
292 unsigned int GTY ((tag ("CPP_TOKEN_FLD_PRAGMA"))) pragma;
293 } GTY ((desc ("cpp_token_val_index (&%1)"))) val;
294};
295
296/* Say which field is in use. */
297extern enum cpp_token_fld_kind cpp_token_val_index (const cpp_token *tok);
298
299/* A type wide enough to hold any multibyte source character.
300 cpplib's character constant interpreter requires an unsigned type.
301 Also, a typedef for the signed equivalent.
302 The width of this type is capped at 32 bits; there do exist targets
303 where wchar_t is 64 bits, but only in a non-default mode, and there
304 would be no meaningful interpretation for a wchar_t value greater
305 than 2^32 anyway -- the widest wide-character encoding around is
306 ISO 10646, which stops at 2^31. */
307#if CHAR_BIT * SIZEOF_INT >= 32
308# define CPPCHAR_SIGNED_T int
309#elif CHAR_BIT * SIZEOF_LONG >= 32
310# define CPPCHAR_SIGNED_T long
311#else
312# error "Cannot find a least-32-bit signed integer type"
313#endif
314typedef unsigned CPPCHAR_SIGNED_T cppchar_t;
315typedef CPPCHAR_SIGNED_T cppchar_signed_t;
316
317/* Style of header dependencies to generate. */
318enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM };
319
320/* Structured format of module dependencies to generate. */
321enum cpp_fdeps_format { FDEPS_FMT_NONE = 0, FDEPS_FMT_P1689R5 };
322
323/* The possible normalization levels, from most restrictive to least. */
324enum cpp_normalize_level {
325 /* In NFKC. */
326 normalized_KC = 0,
327 /* In NFC. */
328 normalized_C,
329 /* In NFC, except for subsequences where being in NFC would make
330 the identifier invalid. */
331 normalized_identifier_C,
332 /* Not normalized at all. */
333 normalized_none
334};
335
336enum cpp_main_search
337{
338 CMS_none, /* A regular source file. */
339 CMS_header, /* Is a directly-specified header file (eg PCH or
340 header-unit). */
341 CMS_user, /* Search the user INCLUDE path. */
342 CMS_system, /* Search the system INCLUDE path. */
343};
344
345/* The possible bidirectional control characters checking levels. */
346enum cpp_bidirectional_level {
347 /* No checking. */
348 bidirectional_none = 0,
349 /* Only detect unpaired uses of bidirectional control characters. */
350 bidirectional_unpaired = 1,
351 /* Detect any use of bidirectional control characters. */
352 bidirectional_any = 2,
353 /* Also warn about UCNs. */
354 bidirectional_ucn = 4
355};
356
357/* This structure is nested inside struct cpp_reader, and
358 carries all the options visible to the command line. */
359struct cpp_options
360{
361 /* The language we're preprocessing. */
362 enum c_lang lang;
363
364 /* Nonzero means use extra default include directories for C++. */
365 unsigned char cplusplus;
366
367 /* Nonzero means handle cplusplus style comments. */
368 unsigned char cplusplus_comments;
369
370 /* Nonzero means define __OBJC__, treat @ as a special token, use
371 the OBJC[PLUS]_INCLUDE_PATH environment variable, and allow
372 "#import". */
373 unsigned char objc;
374
375 /* Nonzero means don't copy comments into the output file. */
376 unsigned char discard_comments;
377
378 /* Nonzero means don't copy comments into the output file during
379 macro expansion. */
380 unsigned char discard_comments_in_macro_exp;
381
382 /* Nonzero means process the ISO trigraph sequences. */
383 unsigned char trigraphs;
384
385 /* Nonzero means process the ISO digraph sequences. */
386 unsigned char digraphs;
387
388 /* Nonzero means to allow hexadecimal floats and LL suffixes. */
389 unsigned char extended_numbers;
390
391 /* Nonzero means process u/U prefix literals (UTF-16/32). */
392 unsigned char uliterals;
393
394 /* Nonzero means process u8 prefixed character literals (UTF-8). */
395 unsigned char utf8_char_literals;
396
397 /* Nonzero means process r/R raw strings. If this is set, uliterals
398 must be set as well. */
399 unsigned char rliterals;
400
401 /* Nonzero means print names of header files (-H). */
402 unsigned char print_include_names;
403
404 /* Nonzero means complain about deprecated features. */
405 unsigned char cpp_warn_deprecated;
406
407 /* Nonzero means warn if slash-star appears in a comment. */
408 unsigned char warn_comments;
409
410 /* Nonzero means to warn about __DATA__, __TIME__ and __TIMESTAMP__ usage. */
411 unsigned char warn_date_time;
412
413 /* Nonzero means warn if a user-supplied include directory does not
414 exist. */
415 unsigned char warn_missing_include_dirs;
416
417 /* Nonzero means warn if there are any trigraphs. */
418 unsigned char warn_trigraphs;
419
420 /* Nonzero means warn about multicharacter charconsts. */
421 unsigned char warn_multichar;
422
423 /* Nonzero means warn about various incompatibilities with
424 traditional C. */
425 unsigned char cpp_warn_traditional;
426
427 /* Nonzero means warn about long long numeric constants. */
428 unsigned char cpp_warn_long_long;
429
430 /* Nonzero means warn about text after an #endif (or #else). */
431 unsigned char warn_endif_labels;
432
433 /* Nonzero means warn about implicit sign changes owing to integer
434 promotions. */
435 unsigned char warn_num_sign_change;
436
437 /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode.
438 Presumably the usage is protected by the appropriate #ifdef. */
439 unsigned char warn_variadic_macros;
440
441 /* Non-zero means suppress diagnostics for NODE_WARN #define or #undef.
442 Used for cpp_define/cpp_undef. */
443 unsigned char suppress_builtin_macro_warnings;
444
445 /* Nonzero means warn about builtin macros that are redefined or
446 explicitly undefined. */
447 unsigned char warn_builtin_macro_redefined;
448
449 /* Different -Wimplicit-fallthrough= levels. */
450 unsigned char cpp_warn_implicit_fallthrough;
451
452 /* Nonzero means warn about a define of a different macro right after
453 #ifndef/#if !defined header guard directive. */
454 unsigned char warn_header_guard;
455
456 /* Nonzero means we should look for header.gcc files that remap file
457 names. */
458 unsigned char remap;
459
460 /* Zero means dollar signs are punctuation. */
461 unsigned char dollars_in_ident;
462
463 /* Nonzero means UCNs are accepted in identifiers. */
464 unsigned char extended_identifiers;
465
466 /* True if we should warn about dollars in identifiers or numbers
467 for this translation unit. */
468 unsigned char warn_dollars;
469
470 /* Nonzero means warn if undefined identifiers are evaluated in an #if. */
471 unsigned char warn_undef;
472
473 /* Nonzero means warn if "defined" is encountered in a place other than
474 an #if. */
475 unsigned char warn_expansion_to_defined;
476
477 /* Nonzero means warn of unused macros from the main file. */
478 unsigned char warn_unused_macros;
479
480 /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */
481 unsigned char c99;
482
483 /* Nonzero if we are conforming to a specific C or C++ standard. */
484 unsigned char std;
485
486 /* Nonzero means give all the error messages the ANSI standard requires. */
487 unsigned char cpp_pedantic;
488
489 /* Nonzero means we're looking at already preprocessed code, so don't
490 bother trying to do macro expansion and whatnot. */
491 unsigned char preprocessed;
492
493 /* Nonzero means we are going to emit debugging logs during
494 preprocessing. */
495 unsigned char debug;
496
497 /* Nonzero means we are tracking locations of tokens involved in
498 macro expansion. 1 Means we track the location in degraded mode
499 where we do not track locations of tokens resulting from the
500 expansion of arguments of function-like macro. 2 Means we do
501 track all macro expansions. This last option is the one that
502 consumes the highest amount of memory. */
503 unsigned char track_macro_expansion;
504
505 /* Nonzero means handle C++ alternate operator names. */
506 unsigned char operator_names;
507
508 /* Nonzero means warn about use of C++ alternate operator names. */
509 unsigned char warn_cxx_operator_names;
510
511 /* True for traditional preprocessing. */
512 unsigned char traditional;
513
514 /* Nonzero for C++ 2011 Standard user-defined literals. */
515 unsigned char user_literals;
516
517 /* Nonzero means warn when a string or character literal is followed by a
518 ud-suffix which does not beging with an underscore. */
519 unsigned char warn_literal_suffix;
520
521 /* Nonzero means interpret imaginary, fixed-point, or other gnu extension
522 literal number suffixes as user-defined literal number suffixes. */
523 unsigned char ext_numeric_literals;
524
525 /* Nonzero means extended identifiers allow the characters specified
526 in C11. */
527 unsigned char c11_identifiers;
528
529 /* Nonzero means extended identifiers allow the characters specified
530 by Unicode XID_Start and XID_Continue properties. */
531 unsigned char xid_identifiers;
532
533 /* Nonzero for C++ 2014 Standard binary constants. */
534 unsigned char binary_constants;
535
536 /* Nonzero for C2Y imaginary (floating) constants. */
537 unsigned char imaginary_constants;
538
539 /* Nonzero for C++ 2014 Standard digit separators. */
540 unsigned char digit_separators;
541
542 /* Nonzero for C23 decimal floating-point constants. */
543 unsigned char dfp_constants;
544
545 /* Nonzero for C++20 __VA_OPT__ feature. */
546 unsigned char va_opt;
547
548 /* Nonzero for the '::' token. */
549 unsigned char scope;
550
551 /* Nonzero for the '#elifdef' and '#elifndef' directives. */
552 unsigned char elifdef;
553
554 /* Nonzero for the '#warning' directive. */
555 unsigned char warning_directive;
556
557 /* Nonzero means tokenize C++20 module directives. */
558 unsigned char module_directives;
559
560 /* Nonzero for C++23 size_t literals. */
561 unsigned char size_t_literals;
562
563 /* Nonzero for C++23 delimited escape sequences. */
564 unsigned char delimited_escape_seqs;
565
566 /* Nonzero for C++23 named universal character escape sequences. */
567 unsigned char named_uc_escape_seqs;
568
569 /* Nonzero for C++ and C23 UCNs for characters below 0xa0. */
570 unsigned char low_ucns;
571
572 /* Nonzero for C2Y 0o prefixed octal integer constants. */
573 unsigned char octal_constants;
574
575 /* Nonzero for 'true' and 'false' in #if expressions. */
576 unsigned char true_false;
577
578 /* Nonzero for the '#embed' directive. */
579 unsigned char embed;
580
581 /* Holds the name of the target (execution) character set. */
582 const char *narrow_charset;
583
584 /* Holds the name of the target wide character set. */
585 const char *wide_charset;
586
587 /* Holds the name of the input character set. */
588 const char *input_charset;
589
590 /* The minimum permitted level of normalization before a warning
591 is generated. See enum cpp_normalize_level. */
592 int warn_normalize;
593
594 /* True to warn about precompiled header files we couldn't use. */
595 bool warn_invalid_pch;
596
597 /* True if dependencies should be restored from a precompiled header. */
598 bool restore_pch_deps;
599
600 /* True if warn about differences between C90 and C99. */
601 signed char cpp_warn_c90_c99_compat;
602
603 /* True if warn about differences between C11 and C23. */
604 signed char cpp_warn_c11_c23_compat;
605
606 /* True if warn about differences between C23 and C2Y. */
607 signed char cpp_warn_c23_c2y_compat;
608
609 /* True if warn about differences between C++98 and C++11. */
610 bool cpp_warn_cxx11_compat;
611
612 /* True if warn about differences between C++17 and C++20. */
613 bool cpp_warn_cxx20_compat;
614
615 /* Nonzero if bidirectional control characters checking is on. See enum
616 cpp_bidirectional_level. */
617 unsigned char cpp_warn_bidirectional;
618
619 /* True if libcpp should warn about invalid UTF-8 characters in comments.
620 2 if it should be a pedwarn. */
621 unsigned char cpp_warn_invalid_utf8;
622
623 /* True if libcpp should warn about invalid forms of delimited or named
624 escape sequences. */
625 bool cpp_warn_unicode;
626
627 /* True if -finput-charset= option has been used explicitly. */
628 bool cpp_input_charset_explicit;
629
630 /* True if -Wkeyword-macro. */
631 bool cpp_warn_keyword_macro;
632
633 /* -Wleading-whitespace= value. */
634 unsigned char cpp_warn_leading_whitespace;
635
636 /* -Wtrailing-whitespace= value. */
637 unsigned char cpp_warn_trailing_whitespace;
638
639 /* -ftabstop= value. */
640 unsigned int cpp_tabstop;
641
642 /* Dependency generation. */
643 struct
644 {
645 /* Style of header dependencies to generate. */
646 enum cpp_deps_style style;
647
648 /* Structured format of module dependencies to generate. */
649 enum cpp_fdeps_format fdeps_format;
650
651 /* Assume missing files are generated files. */
652 bool missing_files;
653
654 /* Generate phony targets for each dependency apart from the first
655 one. */
656 bool phony_targets;
657
658 /* Generate dependency info for modules. */
659 bool modules;
660
661 /* If true, no dependency is generated on the main file. */
662 bool ignore_main_file;
663
664 /* If true, intend to use the preprocessor output (e.g., for compilation)
665 in addition to the dependency info. */
666 bool need_preprocessor_output;
667 } deps;
668
669 /* Target-specific features set by the front end or client. */
670
671 /* Precision for target CPP arithmetic, target characters, target
672 ints and target wide characters, respectively. */
673 size_t precision, char_precision, int_precision, wchar_precision;
674
675 /* True means chars (wide chars, UTF-8 chars) are unsigned. */
676 bool unsigned_char, unsigned_wchar, unsigned_utf8char;
677
678 /* True if the most significant byte in a word has the lowest
679 address in memory. */
680 bool bytes_big_endian;
681
682 /* Nonzero means __STDC__ should have the value 0 in system headers. */
683 unsigned char stdc_0_in_system_headers;
684
685 /* True disables tokenization outside of preprocessing directives. */
686 bool directives_only;
687
688 /* True enables canonicalization of system header file paths. */
689 bool canonical_system_headers;
690
691 /* The maximum depth of the nested #include. */
692 unsigned int max_include_depth;
693
694 cpp_main_search main_search : 8;
695};
696
697#if GCC_VERSION >= 3005
698#define ATTRIBUTE_CPP_PPDIAG(m, n) \
699 __attribute__ ((__format__ (__gcc_diag__, m , n))) ATTRIBUTE_NONNULL(m)
700#else
701#define ATTRIBUTE_CPP_PPDIAG(m, n) ATTRIBUTE_NONNULL(m)
702#endif
703
704/* Diagnostic levels. To get a diagnostic without associating a
705 position in the translation unit with it, use cpp_error_with_line
706 with a line number of zero. */
707
708enum cpp_diagnostic_level {
709 /* Warning, an error with -Werror. */
710 CPP_DL_WARNING = 0,
711 /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */
712 CPP_DL_WARNING_SYSHDR,
713 /* Warning, an error with -pedantic-errors or -Werror. */
714 CPP_DL_PEDWARN,
715 /* An error. */
716 CPP_DL_ERROR,
717 /* An internal consistency check failed. Prints "internal error: ",
718 otherwise the same as CPP_DL_ERROR. */
719 CPP_DL_ICE,
720 /* An informative note following a warning. */
721 CPP_DL_NOTE,
722 /* A fatal error. */
723 CPP_DL_FATAL
724};
725
726/* Warning reason codes. Use a reason code of CPP_W_NONE for unclassified
727 warnings and diagnostics that are not warnings. */
728
729enum cpp_warning_reason {
730 CPP_W_NONE = 0,
731 CPP_W_DEPRECATED,
732 CPP_W_COMMENTS,
733 CPP_W_MISSING_INCLUDE_DIRS,
734 CPP_W_TRIGRAPHS,
735 CPP_W_MULTICHAR,
736 CPP_W_TRADITIONAL,
737 CPP_W_LONG_LONG,
738 CPP_W_ENDIF_LABELS,
739 CPP_W_NUM_SIGN_CHANGE,
740 CPP_W_VARIADIC_MACROS,
741 CPP_W_BUILTIN_MACRO_REDEFINED,
742 CPP_W_DOLLARS,
743 CPP_W_UNDEF,
744 CPP_W_UNUSED_MACROS,
745 CPP_W_CXX_OPERATOR_NAMES,
746 CPP_W_NORMALIZE,
747 CPP_W_INVALID_PCH,
748 CPP_W_WARNING_DIRECTIVE,
749 CPP_W_LITERAL_SUFFIX,
750 CPP_W_SIZE_T_LITERALS,
751 CPP_W_DATE_TIME,
752 CPP_W_PEDANTIC,
753 CPP_W_C90_C99_COMPAT,
754 CPP_W_C11_C23_COMPAT,
755 CPP_W_C23_C2Y_COMPAT,
756 CPP_W_CXX11_COMPAT,
757 CPP_W_CXX20_COMPAT,
758 CPP_W_CXX14_EXTENSIONS,
759 CPP_W_CXX17_EXTENSIONS,
760 CPP_W_CXX20_EXTENSIONS,
761 CPP_W_CXX23_EXTENSIONS,
762 CPP_W_CXX26_EXTENSIONS,
763 CPP_W_EXPANSION_TO_DEFINED,
764 CPP_W_BIDIRECTIONAL,
765 CPP_W_INVALID_UTF8,
766 CPP_W_UNICODE,
767 CPP_W_HEADER_GUARD,
768 CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER,
769 CPP_W_LEADING_WHITESPACE,
770 CPP_W_TRAILING_WHITESPACE,
771 CPP_W_KEYWORD_MACRO
772};
773
774/* Callback for header lookup for HEADER, which is the name of a
775 source file. It is used as a method of last resort to find headers
776 that are not otherwise found during the normal include processing.
777 The return value is the malloced name of a header to try and open,
778 if any, or NULL otherwise. This callback is called only if the
779 header is otherwise unfound. */
780typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **);
781
782/* Call backs to cpplib client. */
783struct cpp_callbacks
784{
785 /* Called when a new line of preprocessed output is started. */
786 void (*line_change) (cpp_reader *, const cpp_token *, int);
787
788 /* Called when switching to/from a new file.
789 The line_map is for the new file. It is NULL if there is no new file.
790 (In C this happens when done with <built-in>+<command line> and also
791 when done with a main file.) This can be used for resource cleanup. */
792 void (*file_change) (cpp_reader *, const line_map_ordinary *);
793
794 void (*dir_change) (cpp_reader *, const char *);
795 void (*include) (cpp_reader *, location_t, const unsigned char *,
796 const char *, int, const cpp_token **);
797 void (*define) (cpp_reader *, location_t, cpp_hashnode *);
798 void (*undef) (cpp_reader *, location_t, cpp_hashnode *);
799 void (*ident) (cpp_reader *, location_t, const cpp_string *);
800 void (*def_pragma) (cpp_reader *, location_t);
801 int (*valid_pch) (cpp_reader *, const char *, int);
802 void (*read_pch) (cpp_reader *, const char *, int, const char *);
803 missing_header_cb missing_header;
804
805 /* Context-sensitive macro support. Returns macro (if any) that should
806 be expanded. */
807 cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);
808
809 /* Called to emit a diagnostic. This callback receives the
810 translated message. */
811 bool (*diagnostic) (cpp_reader *,
812 enum cpp_diagnostic_level,
813 enum cpp_warning_reason,
814 rich_location *,
815 const char *, va_list *)
816 ATTRIBUTE_CPP_PPDIAG (5,0);
817
818 /* Callbacks for when a macro is expanded, or tested (whether
819 defined or not at the time) in #ifdef, #ifndef or "defined". */
820 void (*used_define) (cpp_reader *, location_t, cpp_hashnode *);
821 void (*used_undef) (cpp_reader *, location_t, cpp_hashnode *);
822 /* Called before #define and #undef or other macro definition
823 changes are processed. */
824 void (*before_define) (cpp_reader *);
825 /* Called whenever a macro is expanded or tested.
826 Second argument is the location of the start of the current expansion. */
827 void (*used) (cpp_reader *, location_t, cpp_hashnode *);
828
829 /* Callback to identify whether an attribute exists. */
830 int (*has_attribute) (cpp_reader *, bool);
831
832 /* Callback to determine whether a built-in function is recognized. */
833 int (*has_builtin) (cpp_reader *);
834
835 /* Callback to determine whether a feature is available. */
836 int (*has_feature) (cpp_reader *, bool);
837
838 /* Callback that can change a user lazy into normal macro. */
839 void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);
840
841 /* Callback to handle deferred cpp_macros. */
842 cpp_macro *(*user_deferred_macro) (cpp_reader *, location_t, cpp_hashnode *);
843
844 /* Callback to parse SOURCE_DATE_EPOCH from environment. */
845 time_t (*get_source_date_epoch) (cpp_reader *);
846
847 /* Callback for providing suggestions for misspelled directives. */
848 const char *(*get_suggestion) (cpp_reader *, const char *, const char *const *);
849
850 /* Callback for when a comment is encountered, giving the location
851 of the opening slash, a pointer to the content (which is not
852 necessarily 0-terminated), and the length of the content.
853 The content contains the opening slash-star (or slash-slash),
854 and for C-style comments contains the closing star-slash. For
855 C++-style comments it does not include the terminating newline. */
856 void (*comment) (cpp_reader *, location_t, const unsigned char *,
857 size_t);
858
859 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
860 expansions. */
861 const char *(*remap_filename) (const char*);
862
863 /* Maybe translate a #include into something else. Return a
864 cpp_buffer containing the translation if translating. */
865 char *(*translate_include) (cpp_reader *, line_maps *, location_t,
866 _cpp_file *file, bool angle_brackets,
867 const char **alternate);
868};
869
870#ifdef VMS
871#define INO_T_CPP ino_t ino[3]
872#elif defined (_AIX) && SIZEOF_INO_T == 4
873#define INO_T_CPP ino64_t ino
874#else
875#define INO_T_CPP ino_t ino
876#endif
877
878#if defined (_AIX) && SIZEOF_DEV_T == 4
879#define DEV_T_CPP dev64_t dev
880#else
881#define DEV_T_CPP dev_t dev
882#endif
883
884/* Chain of directories to look for include files in. */
885struct cpp_dir
886{
887 /* NULL-terminated singly-linked list. */
888 struct cpp_dir *next;
889
890 /* NAME of the directory, NUL-terminated. */
891 char *name;
892 unsigned int len;
893
894 /* One if a system header, two if a system header that has extern
895 "C" guards for C++. */
896 unsigned char sysp;
897
898 /* Is this a user-supplied directory? */
899 bool user_supplied_p;
900
901 /* The canonicalized NAME as determined by lrealpath. This field
902 is only used by hosts that lack reliable inode numbers. */
903 char *canonical_name;
904
905 /* Mapping of file names for this directory for MS-DOS and related
906 platforms. A NULL-terminated array of (from, to) pairs. */
907 const char **name_map;
908
909 /* Routine to construct pathname, given the search path name and the
910 HEADER we are trying to find, return a constructed pathname to
911 try and open. If this is NULL, the constructed pathname is as
912 constructed by append_file_to_dir. */
913 char *(*construct) (const char *header, cpp_dir *dir);
914
915 /* The C front end uses these to recognize duplicated
916 directories in the search path. */
917 INO_T_CPP;
918 DEV_T_CPP;
919};
920
921/* The kind of the cpp_macro. */
922enum cpp_macro_kind {
923 cmk_macro, /* An ISO macro (token expansion). */
924 cmk_assert, /* An assertion. */
925 cmk_traditional /* A traditional macro (text expansion). */
926};
927
928/* Each macro definition is recorded in a cpp_macro structure.
929 Variadic macros cannot occur with traditional cpp. */
930struct GTY(()) cpp_macro {
931 union cpp_parm_u
932 {
933 /* Parameters, if any. If parameter names use extended identifiers,
934 the original spelling of those identifiers, not the canonical
935 UTF-8 spelling, goes here. */
936 cpp_hashnode ** GTY ((tag ("false"),
937 nested_ptr (union tree_node,
938 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
939 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
940 length ("%1.paramc"))) params;
941
942 /* If this is an assertion, the next one in the chain. */
943 cpp_macro *GTY ((tag ("true"))) next;
944 } GTY ((desc ("%1.kind == cmk_assert"))) parm;
945
946 /* Definition line number. */
947 location_t line;
948
949 /* Number of tokens in body, or bytes for traditional macros. */
950 /* Do we really need 2^32-1 range here? */
951 unsigned int count;
952
953 /* Number of parameters. */
954 unsigned short paramc;
955
956 /* Non-zero if this is a user-lazy macro, value provided by user. */
957 unsigned char lazy;
958
959 /* The kind of this macro (ISO, trad or assert) */
960 unsigned kind : 2;
961
962 /* If a function-like macro. */
963 unsigned int fun_like : 1;
964
965 /* If a variadic macro. */
966 unsigned int variadic : 1;
967
968 /* If macro defined in system header. */
969 unsigned int syshdr : 1;
970
971 /* Nonzero if it has been expanded or had its existence tested. */
972 unsigned int used : 1;
973
974 /* Indicate whether the tokens include extra CPP_PASTE tokens at the
975 end to track invalid redefinitions with consecutive CPP_PASTE
976 tokens. */
977 unsigned int extra_tokens : 1;
978
979 /* Imported C++20 macro (from a header unit). */
980 unsigned int imported_p : 1;
981
982 /* 0 bits spare (32-bit). 32 on 64-bit target. */
983
984 union cpp_exp_u
985 {
986 /* Trailing array of replacement tokens (ISO), or assertion body value. */
987 cpp_token GTY ((tag ("false"), length ("%1.count"))) tokens[1];
988
989 /* Pointer to replacement text (traditional). See comment at top
990 of cpptrad.c for how traditional function-like macros are
991 encoded. */
992 const unsigned char *GTY ((tag ("true"))) text;
993 } GTY ((desc ("%1.kind == cmk_traditional"))) exp;
994};
995
996/* Poisoned identifiers are flagged NODE_POISONED. NODE_OPERATOR (C++
997 only) indicates an identifier that behaves like an operator such as
998 "xor". NODE_DIAGNOSTIC is for speed in lex_token: it indicates a
999 diagnostic may be required for this node. Currently this only
1000 applies to __VA_ARGS__, poisoned identifiers, and -Wc++-compat
1001 warnings about NODE_OPERATOR. */
1002
1003/* Hash node flags. */
1004#define NODE_OPERATOR (1 << 0) /* C++ named operator. */
1005#define NODE_POISONED (1 << 1) /* Poisoned identifier. */
1006#define NODE_DIAGNOSTIC (1 << 2) /* Possible diagnostic when lexed. */
1007#define NODE_WARN (1 << 3) /* Warn if redefined or undefined. */
1008#define NODE_DISABLED (1 << 4) /* A disabled macro. */
1009#define NODE_USED (1 << 5) /* Dumped with -dU. */
1010#define NODE_CONDITIONAL (1 << 6) /* Conditional macro */
1011#define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */
1012#define NODE_MODULE (1 << 8) /* C++-20 module-related name. */
1013
1014/* Different flavors of hash node. */
1015enum node_type
1016{
1017 NT_VOID = 0, /* Maybe an assert? */
1018 NT_MACRO_ARG, /* A macro arg. */
1019 NT_USER_MACRO, /* A user macro. */
1020 NT_BUILTIN_MACRO, /* A builtin macro. */
1021 NT_MACRO_MASK = NT_USER_MACRO /* Mask for either macro kind. */
1022};
1023
1024/* Different flavors of builtin macro. _Pragma is an operator, but we
1025 handle it with the builtin code for efficiency reasons. */
1026enum cpp_builtin_type
1027{
1028 BT_SPECLINE = 0, /* `__LINE__' */
1029 BT_DATE, /* `__DATE__' */
1030 BT_FILE, /* `__FILE__' */
1031 BT_FILE_NAME, /* `__FILE_NAME__' */
1032 BT_BASE_FILE, /* `__BASE_FILE__' */
1033 BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
1034 BT_TIME, /* `__TIME__' */
1035 BT_STDC, /* `__STDC__' */
1036 BT_PRAGMA, /* `_Pragma' operator */
1037 BT_TIMESTAMP, /* `__TIMESTAMP__' */
1038 BT_COUNTER, /* `__COUNTER__' */
1039 BT_HAS_ATTRIBUTE, /* `__has_attribute(x)' */
1040 BT_HAS_STD_ATTRIBUTE, /* `__has_c_attribute(x)' */
1041 BT_HAS_BUILTIN, /* `__has_builtin(x)' */
1042 BT_HAS_INCLUDE, /* `__has_include(x)' */
1043 BT_HAS_INCLUDE_NEXT, /* `__has_include_next(x)' */
1044 BT_HAS_EMBED, /* `__has_embed(x)' */
1045 BT_HAS_FEATURE, /* `__has_feature(x)' */
1046 BT_HAS_EXTENSION /* `__has_extension(x)' */
1047};
1048
1049#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
1050#define HT_NODE(NODE) (&(NODE)->ident)
1051#define NODE_LEN(NODE) HT_LEN (HT_NODE (NODE))
1052#define NODE_NAME(NODE) HT_STR (HT_NODE (NODE))
1053
1054/* The common part of an identifier node shared amongst all 3 C front
1055 ends. Also used to store CPP identifiers, which are a superset of
1056 identifiers in the grammatical sense. */
1057
1058union GTY(()) _cpp_hashnode_value {
1059 /* Assert (maybe NULL) */
1060 cpp_macro * GTY((tag ("NT_VOID"))) answers;
1061 /* Macro (maybe NULL) */
1062 cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
1063 /* Code for a builtin macro. */
1064 enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
1065 /* Macro argument index. */
1066 unsigned short GTY ((tag ("NT_MACRO_ARG"))) arg_index;
1067};
1068
1069struct GTY(()) cpp_hashnode {
1070 struct ht_identifier ident;
1071 unsigned int is_directive : 1;
1072 unsigned int directive_index : 7; /* If is_directive,
1073 then index into directive table.
1074 Otherwise, a NODE_OPERATOR. */
1075 unsigned int rid_code : 8; /* Rid code - for front ends. */
1076 unsigned int flags : 9; /* CPP flags. */
1077 ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */
1078
1079 /* 5 bits spare. */
1080
1081 /* The deferred cookie is applicable to NT_USER_MACRO or NT_VOID.
1082 The latter for when a macro had a prevailing undef.
1083 On a 64-bit system there would be 32-bits of padding to the value
1084 field. So placing the deferred index here is not costly. */
1085 unsigned deferred; /* Deferred cookie */
1086
1087 union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
1088};
1089
1090/* Extra information we may need to store per identifier, which is needed rarely
1091 enough that it's not worth adding directly into the main identifier hash. */
1092struct GTY(()) cpp_hashnode_extra
1093{
1094 struct ht_identifier ident;
1095 location_t poisoned_loc;
1096};
1097
1098/* A class for iterating through the source locations within a
1099 string token (before escapes are interpreted, and before
1100 concatenation). */
1101
1102class cpp_string_location_reader {
1103 public:
1104 cpp_string_location_reader (location_t src_loc,
1105 line_maps *line_table);
1106
1107 source_range get_next ();
1108
1109 private:
1110 location_t m_loc;
1111 int m_offset_per_column;
1112};
1113
1114/* A class for storing the source ranges of all of the characters within
1115 a string literal, after escapes are interpreted, and after
1116 concatenation.
1117
1118 This is not GTY-marked, as instances are intended to be temporary. */
1119
1120class cpp_substring_ranges
1121{
1122 public:
1123 cpp_substring_ranges ();
1124 ~cpp_substring_ranges ();
1125
1126 int get_num_ranges () const { return m_num_ranges; }
1127 source_range get_range (int idx) const
1128 {
1129 linemap_assert (idx < m_num_ranges);
1130 return m_ranges[idx];
1131 }
1132
1133 void add_range (source_range range);
1134 void add_n_ranges (int num, cpp_string_location_reader &loc_reader);
1135
1136 private:
1137 source_range *m_ranges;
1138 int m_num_ranges;
1139 int m_alloc_ranges;
1140};
1141
1142/* Call this first to get a handle to pass to other functions.
1143
1144 The first hash table argument is for associating a struct cpp_hashnode
1145 with each identifier. The second hash table argument is for associating
1146 a struct cpp_hashnode_extra with each identifier that needs one. For
1147 either, pass in a NULL pointer if you want cpplib to create and manage
1148 the hash table itself, or else pass a suitably initialized hash table to
1149 be managed external to libcpp, as is done by the C-family frontends. */
1150extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
1151 class line_maps *,
1152 struct ht * = nullptr);
1153
1154/* Reset the cpp_reader's line_map. This is only used after reading a
1155 PCH file. */
1156extern void cpp_set_line_map (cpp_reader *, class line_maps *);
1157
1158/* Call this to change the selected language standard (e.g. because of
1159 command line options). */
1160extern void cpp_set_lang (cpp_reader *, enum c_lang);
1161
1162/* Set the include paths. */
1163extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *,
1164 cpp_dir *, int);
1165
1166/* Call these to get pointers to the options, callback, and deps
1167 structures for a given reader. These pointers are good until you
1168 call cpp_finish on that reader. You can either edit the callbacks
1169 through the pointer returned from cpp_get_callbacks, or set them
1170 with cpp_set_callbacks. */
1171extern cpp_options *cpp_get_options (cpp_reader *) ATTRIBUTE_PURE;
1172extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) ATTRIBUTE_PURE;
1173extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
1174extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE;
1175
1176extern const char *cpp_probe_header_unit (cpp_reader *, const char *file,
1177 bool angle_p, location_t);
1178
1179/* Call these to get name data about the various compile-time
1180 charsets. */
1181extern const char *cpp_get_narrow_charset_name (cpp_reader *) ATTRIBUTE_PURE;
1182extern const char *cpp_get_wide_charset_name (cpp_reader *) ATTRIBUTE_PURE;
1183
1184extern location_t cpp_get_diagnostic_override_loc (const cpp_reader *);
1185
1186/* This function reads the file, but does not start preprocessing. It
1187 returns the name of the original file; this is the same as the
1188 input file, except for preprocessed input. This will generate at
1189 least one file change callback, and possibly a line change callback
1190 too. If there was an error opening the file, it returns NULL. */
1191extern const char *cpp_read_main_file (cpp_reader *, const char *,
1192 bool injecting = false);
1193extern location_t cpp_main_loc (const cpp_reader *);
1194
1195/* Adjust for the main file to be an include. */
1196extern void cpp_retrofit_as_include (cpp_reader *);
1197
1198/* Set up built-ins with special behavior. Use cpp_init_builtins()
1199 instead unless your know what you are doing. */
1200extern void cpp_init_special_builtins (cpp_reader *);
1201
1202/* Set up built-ins like __FILE__. */
1203extern void cpp_init_builtins (cpp_reader *, int);
1204
1205/* This is called after options have been parsed, and partially
1206 processed. */
1207extern void cpp_post_options (cpp_reader *);
1208
1209/* Set up translation to the target character set. */
1210extern void cpp_init_iconv (cpp_reader *);
1211
1212/* Call this to finish preprocessing. If you requested dependency
1213 generation, pass open stream(s) to write the information to,
1214 otherwise NULL. It is your responsibility to close the stream(s). */
1215extern void cpp_finish (cpp_reader *, FILE *deps_stream, FILE *fdeps_stream = NULL);
1216
1217/* Call this to release the handle at the end of preprocessing. Any
1218 use of the handle after this function returns is invalid. */
1219extern void cpp_destroy (cpp_reader *);
1220
1221extern unsigned int cpp_token_len (const cpp_token *);
1222extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *);
1223extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *,
1224 unsigned char *, bool);
1225extern void cpp_register_pragma (cpp_reader *, const char *, const char *,
1226 void (*) (cpp_reader *), bool);
1227extern void cpp_register_deferred_pragma (cpp_reader *, const char *,
1228 const char *, unsigned, bool, bool);
1229extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
1230 const cpp_token *);
1231extern const cpp_token *cpp_get_token (cpp_reader *);
1232extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
1233 location_t *);
1234inline bool cpp_user_macro_p (const cpp_hashnode *node)
1235{
1236 return node->type == NT_USER_MACRO;
1237}
1238inline bool cpp_builtin_macro_p (const cpp_hashnode *node)
1239{
1240 return node->type == NT_BUILTIN_MACRO;
1241}
1242inline bool cpp_macro_p (const cpp_hashnode *node)
1243{
1244 return node->type & NT_MACRO_MASK;
1245}
1246inline cpp_macro *cpp_set_deferred_macro (cpp_hashnode *node,
1247 cpp_macro *forced = NULL)
1248{
1249 cpp_macro *old = node->value.macro;
1250
1251 node->value.macro = forced;
1252 node->type = NT_USER_MACRO;
1253 node->flags &= ~NODE_USED;
1254
1255 return old;
1256}
1257cpp_macro *cpp_get_deferred_macro (cpp_reader *, cpp_hashnode *, location_t);
1258
1259/* Returns true if NODE is a function-like user macro. */
1260inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
1261{
1262 return cpp_user_macro_p (node) && node->value.macro->fun_like;
1263}
1264
1265/* Return true for nodes marked for -Wkeyword-macro diagnostics. */
1266inline bool cpp_keyword_p (cpp_hashnode *node)
1267{
1268 /* As keywords are marked identifiers which don't start with underscore
1269 or start with underscore followed by capital letter (except for
1270 _Pragma). */
1271 return ((node->flags & NODE_WARN)
1272 && (NODE_NAME (node)[0] != '_'
1273 || (NODE_NAME (node)[1] != '_' && NODE_NAME (node)[1] != 'P')));
1274}
1275
1276extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *);
1277extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *,
1278 const cpp_macro *);
1279inline location_t cpp_macro_definition_location (cpp_hashnode *node)
1280{
1281 const cpp_macro *macro = node->value.macro;
1282 return macro ? macro->line : 0;
1283}
1284/* Return an idempotent time stamp (possibly from SOURCE_DATE_EPOCH). */
1285enum class CPP_time_kind
1286{
1287 FIXED = -1, /* Fixed time via source epoch. */
1288 DYNAMIC = -2, /* Dynamic via time(2). */
1289 UNKNOWN = -3 /* Wibbly wobbly, timey wimey. */
1290};
1291extern CPP_time_kind cpp_get_date (cpp_reader *, time_t *);
1292
1293extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
1294extern const cpp_token *cpp_peek_token (cpp_reader *, int);
1295
1296/* Evaluate a CPP_*CHAR* token. */
1297extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *,
1298 unsigned int *, int *);
1299/* Evaluate a vector of CPP_*STRING* tokens. */
1300extern bool cpp_interpret_string (cpp_reader *,
1301 const cpp_string *, size_t,
1302 cpp_string *, enum cpp_ttype);
1303extern const char *cpp_interpret_string_ranges (cpp_reader *pfile,
1304 const cpp_string *from,
1305 cpp_string_location_reader *,
1306 size_t count,
1307 cpp_substring_ranges *out,
1308 enum cpp_ttype type);
1309extern bool cpp_interpret_string_notranslate (cpp_reader *,
1310 const cpp_string *, size_t,
1311 cpp_string *, enum cpp_ttype);
1312extern bool cpp_translate_string (cpp_reader *, const cpp_string *,
1313 cpp_string *, enum cpp_ttype, bool);
1314extern bool cpp_valid_identifier (cpp_reader *, const unsigned char *);
1315
1316/* Convert a host character constant to the execution character set. */
1317extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t);
1318
1319/* Used to register macros and assertions, perhaps from the command line.
1320 The text is the same as the command line argument. */
1321extern void cpp_define (cpp_reader *, const char *);
1322extern void cpp_define_unused (cpp_reader *, const char *);
1323extern void cpp_define_formatted (cpp_reader *pfile,
1324 const char *fmt, ...) ATTRIBUTE_PRINTF_2;
1325extern void cpp_define_formatted_unused (cpp_reader *pfile,
1326 const char *fmt,
1327 ...) ATTRIBUTE_PRINTF_2;
1328extern void cpp_assert (cpp_reader *, const char *);
1329extern void cpp_undef (cpp_reader *, const char *);
1330extern void cpp_unassert (cpp_reader *, const char *);
1331
1332/* Mark a node as a lazily defined macro. */
1333extern void cpp_define_lazily (cpp_reader *, cpp_hashnode *node, unsigned N);
1334
1335/* Undefine all macros and assertions. */
1336extern void cpp_undef_all (cpp_reader *);
1337
1338extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *,
1339 size_t, int);
1340extern int cpp_defined (cpp_reader *, const unsigned char *, int);
1341
1342/* A preprocessing number. Code assumes that any unused high bits of
1343 the double integer are set to zero. */
1344
1345/* This type has to be equal to unsigned HOST_WIDE_INT, see
1346 gcc/c-family/c-lex.cc. */
1347typedef uint64_t cpp_num_part;
1348typedef struct cpp_num cpp_num;
1349struct cpp_num
1350{
1351 cpp_num_part high;
1352 cpp_num_part low;
1353 bool unsignedp; /* True if value should be treated as unsigned. */
1354 bool overflow; /* True if the most recent calculation overflowed. */
1355};
1356
1357/* cpplib provides two interfaces for interpretation of preprocessing
1358 numbers.
1359
1360 cpp_classify_number categorizes numeric constants according to
1361 their field (integer, floating point, or invalid), radix (decimal,
1362 octal, hexadecimal), and type suffixes. */
1363
1364#define CPP_N_CATEGORY 0x000F
1365#define CPP_N_INVALID 0x0000
1366#define CPP_N_INTEGER 0x0001
1367#define CPP_N_FLOATING 0x0002
1368
1369#define CPP_N_WIDTH 0x00F0
1370#define CPP_N_SMALL 0x0010 /* int, float, short _Fract/Accum */
1371#define CPP_N_MEDIUM 0x0020 /* long, double, long _Fract/_Accum. */
1372#define CPP_N_LARGE 0x0040 /* long long, long double,
1373 long long _Fract/Accum. */
1374
1375#define CPP_N_WIDTH_MD 0xF0000 /* machine defined. */
1376#define CPP_N_MD_W 0x10000
1377#define CPP_N_MD_Q 0x20000
1378
1379#define CPP_N_RADIX 0x0F00
1380#define CPP_N_DECIMAL 0x0100
1381#define CPP_N_HEX 0x0200
1382#define CPP_N_OCTAL 0x0400
1383#define CPP_N_BINARY 0x0800
1384
1385#define CPP_N_UNSIGNED 0x1000 /* Properties. */
1386#define CPP_N_IMAGINARY 0x2000
1387#define CPP_N_DFLOAT 0x4000
1388#define CPP_N_DEFAULT 0x8000
1389
1390#define CPP_N_FRACT 0x100000 /* Fract types. */
1391#define CPP_N_ACCUM 0x200000 /* Accum types. */
1392#define CPP_N_FLOATN 0x400000 /* _FloatN types. */
1393#define CPP_N_FLOATNX 0x800000 /* _FloatNx types. */
1394
1395#define CPP_N_USERDEF 0x1000000 /* C++11 user-defined literal. */
1396
1397#define CPP_N_SIZE_T 0x2000000 /* C++23 size_t literal. */
1398#define CPP_N_BFLOAT16 0x4000000 /* std::bfloat16_t type. */
1399#define CPP_N_BITINT 0x8000000 /* C23 _BitInt literal. */
1400
1401#define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value
1402 of N, divided by 16. */
1403#define CPP_FLOATN_SHIFT 24
1404#define CPP_FLOATN_MAX 0xF0
1405
1406/* Classify a CPP_NUMBER token. The return value is a combination of
1407 the flags from the above sets. */
1408extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
1409 const char **, location_t);
1410
1411/* Return the classification flags for a float suffix. */
1412extern unsigned int cpp_interpret_float_suffix (cpp_reader *, const char *,
1413 size_t);
1414
1415/* Return the classification flags for an int suffix. */
1416extern unsigned int cpp_interpret_int_suffix (cpp_reader *, const char *,
1417 size_t);
1418
1419/* Evaluate a token classified as category CPP_N_INTEGER. */
1420extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
1421 unsigned int);
1422
1423/* Sign extend a number, with PRECISION significant bits and all
1424 others assumed clear, to fill out a cpp_num structure. */
1425cpp_num cpp_num_sign_extend (cpp_num, size_t);
1426
1427/* Output a diagnostic of some kind. */
1428extern bool cpp_error (cpp_reader *, enum cpp_diagnostic_level,
1429 const char *msgid, ...)
1430 ATTRIBUTE_CPP_PPDIAG (3, 4);
1431extern bool cpp_warning (cpp_reader *, enum cpp_warning_reason,
1432 const char *msgid, ...)
1433 ATTRIBUTE_CPP_PPDIAG (3, 4);
1434extern bool cpp_pedwarning (cpp_reader *, enum cpp_warning_reason,
1435 const char *msgid, ...)
1436 ATTRIBUTE_CPP_PPDIAG (3, 4);
1437extern bool cpp_warning_syshdr (cpp_reader *, enum cpp_warning_reason reason,
1438 const char *msgid, ...)
1439 ATTRIBUTE_CPP_PPDIAG (3, 4);
1440
1441/* As their counterparts above, but use RICHLOC. */
1442extern bool cpp_warning_at (cpp_reader *, enum cpp_warning_reason,
1443 rich_location *richloc, const char *msgid, ...)
1444 ATTRIBUTE_CPP_PPDIAG (4, 5);
1445extern bool cpp_pedwarning_at (cpp_reader *, enum cpp_warning_reason,
1446 rich_location *richloc, const char *msgid, ...)
1447 ATTRIBUTE_CPP_PPDIAG (4, 5);
1448
1449/* Output a diagnostic with "MSGID: " preceding the
1450 error string of errno. No location is printed. */
1451extern bool cpp_errno (cpp_reader *, enum cpp_diagnostic_level,
1452 const char *msgid);
1453/* Similarly, but with "FILENAME: " instead of "MSGID: ", where
1454 the filename is not localized. */
1455extern bool cpp_errno_filename (cpp_reader *, enum cpp_diagnostic_level,
1456 const char *filename, location_t loc);
1457
1458/* Same as cpp_error, except additionally specifies a position as a
1459 (translation unit) physical line and physical column. If the line is
1460 zero, then no location is printed. */
1461extern bool cpp_error_with_line (cpp_reader *, enum cpp_diagnostic_level,
1462 location_t, unsigned,
1463 const char *msgid, ...)
1464 ATTRIBUTE_CPP_PPDIAG (5, 6);
1465extern bool cpp_warning_with_line (cpp_reader *, enum cpp_warning_reason,
1466 location_t, unsigned,
1467 const char *msgid, ...)
1468 ATTRIBUTE_CPP_PPDIAG (5, 6);
1469extern bool cpp_pedwarning_with_line (cpp_reader *, enum cpp_warning_reason,
1470 location_t, unsigned,
1471 const char *msgid, ...)
1472 ATTRIBUTE_CPP_PPDIAG (5, 6);
1473extern bool cpp_warning_with_line_syshdr (cpp_reader *, enum cpp_warning_reason,
1474 location_t, unsigned,
1475 const char *msgid, ...)
1476 ATTRIBUTE_CPP_PPDIAG (5, 6);
1477
1478extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
1479 location_t src_loc, const char *msgid, ...)
1480 ATTRIBUTE_CPP_PPDIAG (4, 5);
1481
1482extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
1483 rich_location *richloc, const char *msgid, ...)
1484 ATTRIBUTE_CPP_PPDIAG (4, 5);
1485
1486/* In lex.cc */
1487extern int cpp_ideq (const cpp_token *, const char *);
1488extern void cpp_output_line (cpp_reader *, FILE *);
1489extern unsigned char *cpp_output_line_to_string (cpp_reader *,
1490 const unsigned char *);
1491extern const unsigned char *cpp_alloc_token_string
1492 (cpp_reader *, const unsigned char *, unsigned);
1493extern void cpp_output_token (const cpp_token *, FILE *);
1494extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);
1495/* Returns the value of an escape sequence, truncated to the correct
1496 target precision. PSTR points to the input pointer, which is just
1497 after the backslash. LIMIT is how much text we have. WIDE is true
1498 if the escape sequence is part of a wide character constant or
1499 string literal. Handles all relevant diagnostics. */
1500extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr,
1501 const unsigned char *limit, int wide);
1502
1503/* Structure used to hold a comment block at a given location in the
1504 source code. */
1505
1506typedef struct
1507{
1508 /* Text of the comment including the terminators. */
1509 char *comment;
1510
1511 /* source location for the given comment. */
1512 location_t sloc;
1513} cpp_comment;
1514
1515/* Structure holding all comments for a given cpp_reader. */
1516
1517typedef struct
1518{
1519 /* table of comment entries. */
1520 cpp_comment *entries;
1521
1522 /* number of actual entries entered in the table. */
1523 int count;
1524
1525 /* number of entries allocated currently. */
1526 int allocated;
1527} cpp_comment_table;
1528
1529/* Returns the table of comments encountered by the preprocessor. This
1530 table is only populated when pfile->state.save_comments is true. */
1531extern cpp_comment_table *cpp_get_comments (cpp_reader *);
1532
1533/* In hash.c */
1534
1535/* Lookup an identifier in the hashtable. Puts the identifier in the
1536 table if it is not already there. */
1537extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *,
1538 unsigned int);
1539
1540/* Set NODE_WARN flag for NAME, such that there will be diagnostics
1541 for #define or #undef of NAME. */
1542
1543inline void
1544cpp_warn (cpp_reader *pfile, const char *name, unsigned int len)
1545{
1546 cpp_lookup (pfile, (const unsigned char *) name, len)->flags |= NODE_WARN;
1547}
1548
1549inline void
1550cpp_warn (cpp_reader *pfile, const char *name)
1551{
1552 cpp_warn (pfile, name, len: strlen (s: name));
1553}
1554
1555typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);
1556extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);
1557
1558/* In macro.cc */
1559extern void cpp_scan_nooutput (cpp_reader *);
1560extern int cpp_sys_macro_p (cpp_reader *);
1561extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
1562 unsigned int);
1563extern bool cpp_compare_macros (const cpp_macro *macro1,
1564 const cpp_macro *macro2);
1565
1566/* In files.cc */
1567extern bool cpp_included (cpp_reader *, const char *);
1568extern bool cpp_included_before (cpp_reader *, const char *, location_t);
1569extern void cpp_make_system_header (cpp_reader *, int, int);
1570extern bool cpp_push_include (cpp_reader *, const char *);
1571extern bool cpp_push_default_include (cpp_reader *, const char *);
1572extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *);
1573extern const char *_cpp_get_file_path (_cpp_file *);
1574extern const char *_cpp_get_file_name (_cpp_file *);
1575extern struct stat *_cpp_get_file_stat (_cpp_file *);
1576extern struct cpp_dir *_cpp_get_file_dir (_cpp_file *);
1577extern cpp_buffer *cpp_get_buffer (cpp_reader *);
1578extern struct _cpp_file *cpp_get_file (cpp_buffer *);
1579extern cpp_buffer *cpp_get_prev (cpp_buffer *);
1580extern void cpp_clear_file_cache (cpp_reader *);
1581
1582/* cpp_get_converted_source returns the contents of the given file, as it exists
1583 after cpplib has read it and converted it from the input charset to the
1584 source charset. Return struct will be zero-filled if the data could not be
1585 read for any reason. The data starts at the DATA pointer, but the TO_FREE
1586 pointer is what should be passed to free(), as there may be an offset. */
1587struct cpp_converted_source
1588{
1589 char *to_free;
1590 char *data;
1591 size_t len;
1592};
1593cpp_converted_source cpp_get_converted_source (const char *fname,
1594 const char *input_charset);
1595
1596/* In pch.cc */
1597struct save_macro_data;
1598extern int cpp_save_state (cpp_reader *, FILE *);
1599extern int cpp_write_pch_deps (cpp_reader *, FILE *);
1600extern int cpp_write_pch_state (cpp_reader *, FILE *);
1601extern int cpp_valid_state (cpp_reader *, const char *, int);
1602extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **);
1603extern int cpp_read_state (cpp_reader *, const char *, FILE *,
1604 struct save_macro_data *);
1605
1606/* In lex.cc */
1607extern void cpp_force_token_locations (cpp_reader *, location_t);
1608extern void cpp_stop_forcing_token_locations (cpp_reader *);
1609enum CPP_DO_task
1610{
1611 CPP_DO_print,
1612 CPP_DO_location,
1613 CPP_DO_token
1614};
1615
1616extern void cpp_directive_only_process (cpp_reader *pfile,
1617 void *data,
1618 void (*cb) (cpp_reader *,
1619 CPP_DO_task,
1620 void *data, ...));
1621
1622/* In expr.cc */
1623extern enum cpp_ttype cpp_userdef_string_remove_type
1624 (enum cpp_ttype type);
1625extern enum cpp_ttype cpp_userdef_string_add_type
1626 (enum cpp_ttype type);
1627extern enum cpp_ttype cpp_userdef_char_remove_type
1628 (enum cpp_ttype type);
1629extern enum cpp_ttype cpp_userdef_char_add_type
1630 (enum cpp_ttype type);
1631extern bool cpp_userdef_string_p
1632 (enum cpp_ttype type);
1633extern bool cpp_userdef_char_p
1634 (enum cpp_ttype type);
1635extern const char * cpp_get_userdef_suffix
1636 (const cpp_token *);
1637
1638/* In charset.cc */
1639
1640/* The result of attempting to decode a run of UTF-8 bytes. */
1641
1642struct cpp_decoded_char
1643{
1644 const char *m_start_byte;
1645 const char *m_next_byte;
1646
1647 bool m_valid_ch;
1648 cppchar_t m_ch;
1649};
1650
1651/* Information for mapping between code points and display columns.
1652
1653 This is a tabstop value, along with a callback for getting the
1654 widths of characters. Normally this callback is cpp_wcwidth, but we
1655 support other schemes for escaping non-ASCII unicode as a series of
1656 ASCII chars when printing the user's source code in
1657 gcc/diagnostics/source-printing.cc
1658
1659 For example, consider:
1660 - the Unicode character U+03C0 "GREEK SMALL LETTER PI" (UTF-8: 0xCF 0x80)
1661 - the Unicode character U+1F642 "SLIGHTLY SMILING FACE"
1662 (UTF-8: 0xF0 0x9F 0x99 0x82)
1663 - the byte 0xBF (a stray trailing byte of a UTF-8 character)
1664 Normally U+03C0 would occupy one display column, U+1F642
1665 would occupy two display columns, and the stray byte would be
1666 printed verbatim as one display column.
1667
1668 However when escaping them as unicode code points as "<U+03C0>"
1669 and "<U+1F642>" they occupy 8 and 9 display columns respectively,
1670 and when escaping them as bytes as "<CF><80>" and "<F0><9F><99><82>"
1671 they occupy 8 and 16 display columns respectively. In both cases
1672 the stray byte is escaped to <BF> as 4 display columns. */
1673
1674struct cpp_char_column_policy
1675{
1676 cpp_char_column_policy (int tabstop,
1677 int (*width_cb) (cppchar_t c))
1678 : m_tabstop (tabstop),
1679 m_undecoded_byte_width (1),
1680 m_width_cb (width_cb)
1681 {}
1682
1683 int m_tabstop;
1684 /* Width in display columns of a stray byte that isn't decodable
1685 as UTF-8. */
1686 int m_undecoded_byte_width;
1687 int (*m_width_cb) (cppchar_t c);
1688};
1689
1690/* A class to manage the state while converting a UTF-8 sequence to cppchar_t
1691 and computing the display width one character at a time. */
1692class cpp_display_width_computation {
1693 public:
1694 cpp_display_width_computation (const char *data, int data_length,
1695 const cpp_char_column_policy &policy);
1696 const char *next_byte () const { return m_next; }
1697 int bytes_processed () const { return m_next - m_begin; }
1698 int bytes_left () const { return m_bytes_left; }
1699 bool done () const { return !bytes_left (); }
1700 int display_cols_processed () const { return m_display_cols; }
1701
1702 int process_next_codepoint (cpp_decoded_char *out);
1703 int advance_display_cols (int n);
1704
1705 private:
1706 const char *const m_begin;
1707 const char *m_next;
1708 size_t m_bytes_left;
1709 const cpp_char_column_policy &m_policy;
1710 int m_display_cols;
1711};
1712
1713/* Convenience functions that are simple use cases for class
1714 cpp_display_width_computation. Tab characters will be expanded to spaces
1715 as determined by POLICY.m_tabstop, and non-printable-ASCII characters
1716 will be escaped as per POLICY. */
1717
1718int cpp_byte_column_to_display_column (const char *data, int data_length,
1719 int column,
1720 const cpp_char_column_policy &policy);
1721inline int cpp_display_width (const char *data, int data_length,
1722 const cpp_char_column_policy &policy)
1723{
1724 return cpp_byte_column_to_display_column (data, data_length, column: data_length,
1725 policy);
1726}
1727int cpp_display_column_to_byte_column (const char *data, int data_length,
1728 int display_col,
1729 const cpp_char_column_policy &policy);
1730int cpp_wcwidth (cppchar_t c);
1731
1732bool cpp_input_conversion_is_trivial (const char *input_charset);
1733int cpp_check_utf8_bom (const char *data, size_t data_length);
1734bool cpp_valid_utf8_p (const char *data, size_t num_bytes);
1735
1736bool cpp_is_combining_char (cppchar_t c);
1737bool cpp_is_printable_char (cppchar_t c);
1738
1739enum cpp_xid_property {
1740 CPP_XID_START = 1,
1741 CPP_XID_CONTINUE = 2
1742};
1743
1744unsigned int cpp_check_xid_property (cppchar_t c);
1745
1746/* In errors.cc */
1747
1748/* RAII class to suppress CPP diagnostics in the current scope. */
1749class cpp_auto_suppress_diagnostics
1750{
1751 public:
1752 explicit cpp_auto_suppress_diagnostics (cpp_reader *pfile);
1753 ~cpp_auto_suppress_diagnostics ();
1754 private:
1755 cpp_reader *const m_pfile;
1756 const decltype (cpp_callbacks::diagnostic) m_cb;
1757};
1758
1759#endif /* ! LIBCPP_CPPLIB_H */
1760

source code of libcpp/include/cpplib.h