History

gcc 12.2.0 and newlib 4.2.0 (484d2ebf8d82)

Wolfgang Thaller committed 4 years ago

Commit 70cf4d11 parent f485e1261892 files · +7228600 −3976878Browse files

Showing the changes to gcc/libcpp/include/cpplib.h (1 of 61892 files). Show all

Unified · Split

gcc/libcpp/include/cpplib.h+299−36
@@ -1,5 +1,5 @@
11 /* Definitions for CPP library.
2− Copyright (C) 1995-2019 Free Software Foundation, Inc.
2+ Copyright (C) 1995-2022 Free Software Foundation, Inc.
33 Written by Per Bothner, 1994-95.
44
55 This program is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@ struct _cpp_file; · 40 unmodified lines
4646 '='. The lexer needs operators ending in '=', like ">>=", to be in
4747 the same order as their counterparts without the '=', like ">>".
4848
49− See the cpp_operator table optab in expr.c if you change the order or
49+ See the cpp_operator table optab in expr.cc if you change the order or
5050 add or remove anything in the first group. */
5151
5252 #define TTYPE_TABLE \
@@ -78,6 +78,7 @@ struct _cpp_file; · 25 unmodified lines
7878 OP(NOT_EQ, "!=") \
7979 OP(GREATER_EQ, ">=") \
8080 OP(LESS_EQ, "<=") \
81+ OP(SPACESHIP, "<=>") \
8182 \
8283 /* These two are unary + / - in preprocessor expressions. */ \
8384 OP(PLUS_EQ, "+=") /* math */ \
@@ -172,7 +173,8 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X, · 88 unmodified lines
172173 CLK_STDC2X,
173174 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
174175 CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
175− CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
176+ CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
177+ CLK_ASM};
176178
177179 /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
178180 struct GTY(()) cpp_string {
@@ -190,12 +192,13 @@ struct GTY(()) cpp_string { · 11 unmodified lines
190192 comment. */
191193 #define BOL (1 << 6) /* Token at beginning of line. */
192194 #define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend,
193− set in c-lex.c. */
195+ set in c-lex.cc. */
194196 #define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */
195197 #define SP_PREV_WHITE (1 << 9) /* If whitespace before a ##
196198 operator, or before this token
197199 after a # operator. */
198200 #define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */
201+#define PRAGMA_OP (1 << 11) /* _Pragma token. */
199202
200203 /* Specify which field, if any, of the cpp_token union is used. */
201204
@@ -307,13 +310,31 @@ enum cpp_normalize_level { · 105 unmodified lines
307310 normalized_none
308311 };
309312
313+enum cpp_main_search
314+{
315+ CMS_none, /* A regular source file. */
316+ CMS_header, /* Is a directly-specified header file (eg PCH or
317+ header-unit). */
318+ CMS_user, /* Search the user INCLUDE path. */
319+ CMS_system, /* Search the system INCLUDE path. */
320+};
321+
322+/* The possible bidirectional control characters checking levels. */
323+enum cpp_bidirectional_level {
324+ /* No checking. */
325+ bidirectional_none = 0,
326+ /* Only detect unpaired uses of bidirectional control characters. */
327+ bidirectional_unpaired = 1,
328+ /* Detect any use of bidirectional control characters. */
329+ bidirectional_any = 2,
330+ /* Also warn about UCNs. */
331+ bidirectional_ucn = 4
332+};
333+
310334 /* This structure is nested inside struct cpp_reader, and
311335 carries all the options visible to the command line. */
312336 struct cpp_options
313337 {
314− /* Characters between tab stops. */
315− unsigned int tabstop;
316−
317338 /* The language we're preprocessing. */
318339 enum c_lang lang;
319340
@@ -471,7 +492,7 @@ struct cpp_options · 151 unmodified lines
471492 unsigned char ext_numeric_literals;
472493
473494 /* Nonzero means extended identifiers allow the characters specified
474− in C11 and C++11. */
495+ in C11. */
475496 unsigned char c11_identifiers;
476497
477498 /* Nonzero for C++ 2014 Standard binary constants. */
@@ -480,9 +501,24 @@ struct cpp_options · 2 unmodified lines
480501 /* Nonzero for C++ 2014 Standard digit separators. */
481502 unsigned char digit_separators;
482503
483− /* Nonzero for C++2a __VA_OPT__ feature. */
504+ /* Nonzero for C2X decimal floating-point constants. */
505+ unsigned char dfp_constants;
506+
507+ /* Nonzero for C++20 __VA_OPT__ feature. */
484508 unsigned char va_opt;
485509
510+ /* Nonzero for the '::' token. */
511+ unsigned char scope;
512+
513+ /* Nonzero for the '#elifdef' and '#elifndef' directives. */
514+ unsigned char elifdef;
515+
516+ /* Nonzero means tokenize C++20 module directives. */
517+ unsigned char module_directives;
518+
519+ /* Nonzero for C++23 size_t literals. */
520+ unsigned char size_t_literals;
521+
486522 /* Holds the name of the target (execution) character set. */
487523 const char *narrow_charset;
488524
@@ -505,9 +541,16 @@ struct cpp_options · 16 unmodified lines
505541 /* True if warn about differences between C90 and C99. */
506542 signed char cpp_warn_c90_c99_compat;
507543
544+ /* True if warn about differences between C11 and C2X. */
545+ signed char cpp_warn_c11_c2x_compat;
546+
508547 /* True if warn about differences between C++98 and C++11. */
509548 bool cpp_warn_cxx11_compat;
510549
550+ /* Nonzero if bidirectional control characters checking is on. See enum
551+ cpp_bidirectional_level. */
552+ unsigned char cpp_warn_bidirectional;
553+
511554 /* Dependency generation. */
512555 struct
513556 {
@@ -521,6 +564,9 @@ struct cpp_options · 7 unmodified lines
521564 one. */
522565 bool phony_targets;
523566
567+ /* Generate dependency info for modules. */
568+ bool modules;
569+
524570 /* If true, no dependency is generated on the main file. */
525571 bool ignore_main_file;
526572
@@ -550,6 +596,11 @@ struct cpp_options · 23 unmodified lines
550596
551597 /* True enables canonicalization of system header file paths. */
552598 bool canonical_system_headers;
599+
600+ /* The maximum depth of the nested #include. */
601+ unsigned int max_include_depth;
602+
603+ cpp_main_search main_search : 8;
553604 };
554605
555606 /* Diagnostic levels. To get a diagnostic without associating a
@@ -598,11 +649,14 @@ enum cpp_warning_reason { · 42 unmodified lines
598649 CPP_W_INVALID_PCH,
599650 CPP_W_WARNING_DIRECTIVE,
600651 CPP_W_LITERAL_SUFFIX,
652+ CPP_W_SIZE_T_LITERALS,
601653 CPP_W_DATE_TIME,
602654 CPP_W_PEDANTIC,
603655 CPP_W_C90_C99_COMPAT,
656+ CPP_W_C11_C2X_COMPAT,
604657 CPP_W_CXX11_COMPAT,
605− CPP_W_EXPANSION_TO_DEFINED
658+ CPP_W_EXPANSION_TO_DEFINED,
659+ CPP_W_BIDIRECTIONAL
606660 };
607661
608662 /* Callback for header lookup for HEADER, which is the name of a
@@ -661,11 +715,17 @@ struct cpp_callbacks · 52 unmodified lines
661715 void (*used) (cpp_reader *, location_t, cpp_hashnode *);
662716
663717 /* Callback to identify whether an attribute exists. */
664− int (*has_attribute) (cpp_reader *);
718+ int (*has_attribute) (cpp_reader *, bool);
719+
720+ /* Callback to determine whether a built-in function is recognized. */
721+ int (*has_builtin) (cpp_reader *);
665722
666723 /* Callback that can change a user lazy into normal macro. */
667724 void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);
668725
726+ /* Callback to handle deferred cpp_macros. */
727+ cpp_macro *(*user_deferred_macro) (cpp_reader *, location_t, cpp_hashnode *);
728+
669729 /* Callback to parse SOURCE_DATE_EPOCH from environment. */
670730 time_t (*get_source_date_epoch) (cpp_reader *);
671731
@@ -684,14 +744,27 @@ struct cpp_callbacks · 12 unmodified lines
684744 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
685745 expansions. */
686746 const char *(*remap_filename) (const char*);
747+
748+ /* Maybe translate a #include into something else. Return a
749+ cpp_buffer containing the translation if translating. */
750+ char *(*translate_include) (cpp_reader *, line_maps *, location_t,
751+ const char *path);
687752 };
688753
689754 #ifdef VMS
690755 #define INO_T_CPP ino_t ino[3]
756+#elif defined (_AIX) && SIZEOF_INO_T == 4
757+#define INO_T_CPP ino64_t ino
691758 #else
692759 #define INO_T_CPP ino_t ino
693760 #endif
694761
762+#if defined (_AIX) && SIZEOF_DEV_T == 4
763+#define DEV_T_CPP dev64_t dev
764+#else
765+#define DEV_T_CPP dev_t dev
766+#endif
767+
695768 /* Chain of directories to look for include files in. */
696769 struct cpp_dir
697770 {
@@ -726,7 +799,7 @@ struct cpp_dir · 28 unmodified lines
726799 /* The C front end uses these to recognize duplicated
727800 directories in the search path. */
728801 INO_T_CPP;
729− dev_t dev;
802+ DEV_T_CPP;
730803 };
731804
732805 /* The kind of the cpp_macro. */
@@ -787,7 +860,10 @@ struct GTY(()) cpp_macro { · 54 unmodified lines
787860 tokens. */
788861 unsigned int extra_tokens : 1;
789862
790− /* 1 bits spare (32-bit). 33 on 64-bit target. */
863+ /* Imported C++20 macro (from a header unit). */
864+ unsigned int imported_p : 1;
865+
866+ /* 0 bits spare (32-bit). 32 on 64-bit target. */
791867
792868 union cpp_exp_u
793869 {
@@ -817,6 +893,7 @@ struct GTY(()) cpp_macro { · 23 unmodified lines
817893 #define NODE_USED (1 << 5) /* Dumped with -dU. */
818894 #define NODE_CONDITIONAL (1 << 6) /* Conditional macro */
819895 #define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */
896+#define NODE_MODULE (1 << 8) /* C++-20 module-related name. */
820897
821898 /* Different flavors of hash node. */
822899 enum node_type
@@ -835,6 +912,7 @@ enum cpp_builtin_type · 12 unmodified lines
835912 BT_SPECLINE = 0, /* `__LINE__' */
836913 BT_DATE, /* `__DATE__' */
837914 BT_FILE, /* `__FILE__' */
915+ BT_FILE_NAME, /* `__FILE_NAME__' */
838916 BT_BASE_FILE, /* `__BASE_FILE__' */
839917 BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
840918 BT_TIME, /* `__TIME__' */
@@ -842,7 +920,11 @@ enum cpp_builtin_type · 1 unmodified line
842920 BT_PRAGMA, /* `_Pragma' operator */
843921 BT_TIMESTAMP, /* `__TIMESTAMP__' */
844922 BT_COUNTER, /* `__COUNTER__' */
845− BT_HAS_ATTRIBUTE /* `__has_attribute__(x)' */
923+ BT_HAS_ATTRIBUTE, /* `__has_attribute(x)' */
924+ BT_HAS_STD_ATTRIBUTE, /* `__has_c_attribute(x)' */
925+ BT_HAS_BUILTIN, /* `__has_builtin(x)' */
926+ BT_HAS_INCLUDE, /* `__has_include(x)' */
927+ BT_HAS_INCLUDE_NEXT /* `__has_include_next(x)' */
846928 };
847929
848930 #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
@@ -857,7 +939,7 @@ enum cpp_builtin_type · 8 unmodified lines
857939 union GTY(()) _cpp_hashnode_value {
858940 /* Assert (maybe NULL) */
859941 cpp_macro * GTY((tag ("NT_VOID"))) answers;
860− /* Macro (never NULL) */
942+ /* Macro (maybe NULL) */
861943 cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
862944 /* Code for a builtin macro. */
863945 enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
@@ -871,11 +953,17 @@ struct GTY(()) cpp_hashnode { · 7 unmodified lines
871953 unsigned int directive_index : 7; /* If is_directive,
872954 then index into directive table.
873955 Otherwise, a NODE_OPERATOR. */
874− unsigned char rid_code; /* Rid code - for front ends. */
956+ unsigned int rid_code : 8; /* Rid code - for front ends. */
957+ unsigned int flags : 9; /* CPP flags. */
875958 ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */
876− unsigned int flags : 8; /* CPP flags. */
877959
878− /* 6 bits spare (plus another 32 on 64-bit hosts). */
960+ /* 5 bits spare. */
961+
962+ /* The deferred cookie is applicable to NT_USER_MACRO or NT_VOID.
963+ The latter for when a macro had a prevailing undef.
964+ On a 64-bit system there would be 32-bits of padding to the value
965+ field. So placing the deferred index here is not costly. */
966+ unsigned deferred; /* Deferred cookie */
879967
880968 union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
881969 };
@@ -894,7 +982,6 @@ class cpp_string_location_reader { · 12 unmodified lines
894982 private:
895983 location_t m_loc;
896984 int m_offset_per_column;
897− line_maps *m_line_table;
898985 };
899986
900987 /* A class for storing the source ranges of all of the characters within
@@ -932,11 +1019,11 @@ class cpp_substring_ranges · 31 unmodified lines
9321019 that cpplib will share; this technique is used by the C front
9331020 ends. */
9341021 extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
935− struct line_maps *);
1022+ class line_maps *);
9361023
9371024 /* Reset the cpp_reader's line_map. This is only used after reading a
9381025 PCH file. */
939−extern void cpp_set_line_map (cpp_reader *, struct line_maps *);
1026+extern void cpp_set_line_map (cpp_reader *, class line_maps *);
9401027
9411028 /* Call this to change the selected language standard (e.g. because of
9421029 command line options). */
@@ -950,17 +1037,30 @@ extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); · 7 unmodified lines
9501037 call cpp_finish on that reader. You can either edit the callbacks
9511038 through the pointer returned from cpp_get_callbacks, or set them
9521039 with cpp_set_callbacks. */
953−extern cpp_options *cpp_get_options (cpp_reader *);
954−extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
1040+extern cpp_options *cpp_get_options (cpp_reader *) ATTRIBUTE_PURE;
1041+extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) ATTRIBUTE_PURE;
9551042 extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
956−extern struct deps *cpp_get_deps (cpp_reader *);
1043+extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE;
1044+
1045+extern const char *cpp_probe_header_unit (cpp_reader *, const char *file,
1046+ bool angle_p, location_t);
1047+
1048+/* Call these to get name data about the various compile-time
1049+ charsets. */
1050+extern const char *cpp_get_narrow_charset_name (cpp_reader *) ATTRIBUTE_PURE;
1051+extern const char *cpp_get_wide_charset_name (cpp_reader *) ATTRIBUTE_PURE;
9571052
9581053 /* This function reads the file, but does not start preprocessing. It
9591054 returns the name of the original file; this is the same as the
9601055 input file, except for preprocessed input. This will generate at
9611056 least one file change callback, and possibly a line change callback
9621057 too. If there was an error opening the file, it returns NULL. */
963−extern const char *cpp_read_main_file (cpp_reader *, const char *);
1058+extern const char *cpp_read_main_file (cpp_reader *, const char *,
1059+ bool injecting = false);
1060+extern location_t cpp_main_loc (const cpp_reader *);
1061+
1062+/* Adjust for the main file to be an include. */
1063+extern void cpp_retrofit_as_include (cpp_reader *);
9641064
9651065 /* Set up built-ins with special behavior. Use cpp_init_builtins()
9661066 instead unless your know what you are doing. */
@@ -1010,6 +1110,18 @@ inline bool cpp_macro_p (const cpp_hashnode *node) · 43 unmodified lines
10101110 {
10111111 return node->type & NT_MACRO_MASK;
10121112 }
1113+inline cpp_macro *cpp_set_deferred_macro (cpp_hashnode *node,
1114+ cpp_macro *forced = NULL)
1115+{
1116+ cpp_macro *old = node->value.macro;
1117+
1118+ node->value.macro = forced;
1119+ node->type = NT_USER_MACRO;
1120+ node->flags &= ~NODE_USED;
1121+
1122+ return old;
1123+}
1124+cpp_macro *cpp_get_deferred_macro (cpp_reader *, cpp_hashnode *, location_t);
10131125
10141126 /* Returns true if NODE is a function-like user macro. */
10151127 inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
@@ -1017,12 +1129,23 @@ inline bool cpp_fun_like_macro_p (cpp_hashnode *node) · 1 unmodified line
10171129 return cpp_user_macro_p (node) && node->value.macro->fun_like;
10181130 }
10191131
1020−extern const unsigned char *cpp_macro_definition (cpp_reader *,
1021− cpp_hashnode *);
1132+extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *);
1133+extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *,
1134+ const cpp_macro *);
10221135 inline location_t cpp_macro_definition_location (cpp_hashnode *node)
10231136 {
1024− return node->value.macro->line;
1137+ const cpp_macro *macro = node->value.macro;
1138+ return macro ? macro->line : 0;
10251139 }
1140+/* Return an idempotent time stamp (possibly from SOURCE_DATE_EPOCH). */
1141+enum class CPP_time_kind
1142+{
1143+ FIXED = -1, /* Fixed time via source epoch. */
1144+ DYNAMIC = -2, /* Dynamic via time(2). */
1145+ UNKNOWN = -3 /* Wibbly wobbly, timey wimey. */
1146+};
1147+extern CPP_time_kind cpp_get_date (cpp_reader *, time_t *);
1148+
10261149 extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
10271150 extern const cpp_token *cpp_peek_token (cpp_reader *, int);
10281151
@@ -1049,8 +1172,12 @@ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); · 20 unmodified lines
10491172 /* Used to register macros and assertions, perhaps from the command line.
10501173 The text is the same as the command line argument. */
10511174 extern void cpp_define (cpp_reader *, const char *);
1175+extern void cpp_define_unused (cpp_reader *, const char *);
10521176 extern void cpp_define_formatted (cpp_reader *pfile,
10531177 const char *fmt, ...) ATTRIBUTE_PRINTF_2;
1178+extern void cpp_define_formatted_unused (cpp_reader *pfile,
1179+ const char *fmt,
1180+ ...) ATTRIBUTE_PRINTF_2;
10541181 extern void cpp_assert (cpp_reader *, const char *);
10551182 extern void cpp_undef (cpp_reader *, const char *);
10561183 extern void cpp_unassert (cpp_reader *, const char *);
@@ -1069,7 +1196,7 @@ extern int cpp_defined (cpp_reader *, const unsigned char *, int); · 12 unmodified lines
10691196 the double integer are set to zero. */
10701197
10711198 /* This type has to be equal to unsigned HOST_WIDE_INT, see
1072− gcc/c-family/c-lex.c. */
1199+ gcc/c-family/c-lex.cc. */
10731200 typedef uint64_t cpp_num_part;
10741201 typedef struct cpp_num cpp_num;
10751202 struct cpp_num
@@ -1118,7 +1245,9 @@ struct cpp_num · 42 unmodified lines
11181245 #define CPP_N_FLOATN 0x400000 /* _FloatN types. */
11191246 #define CPP_N_FLOATNX 0x800000 /* _FloatNx types. */
11201247
1121−#define CPP_N_USERDEF 0x1000000 /* C++0x user-defined literal. */
1248+#define CPP_N_USERDEF 0x1000000 /* C++11 user-defined literal. */
1249+
1250+#define CPP_N_SIZE_T 0x2000000 /* C++23 size_t literal. */
11221251
11231252 #define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value
11241253 of N, divided by 16. */
@@ -1160,6 +1289,14 @@ extern bool cpp_warning_syshdr (cpp_reader *, enum cpp_warning_reason reason, · 35 unmodified lines
11601289 const char *msgid, ...)
11611290 ATTRIBUTE_PRINTF_3;
11621291
1292+/* As their counterparts above, but use RICHLOC. */
1293+extern bool cpp_warning_at (cpp_reader *, enum cpp_warning_reason,
1294+ rich_location *richloc, const char *msgid, ...)
1295+ ATTRIBUTE_PRINTF_4;
1296+extern bool cpp_pedwarning_at (cpp_reader *, enum cpp_warning_reason,
1297+ rich_location *richloc, const char *msgid, ...)
1298+ ATTRIBUTE_PRINTF_4;
1299+
11631300 /* Output a diagnostic with "MSGID: " preceding the
11641301 error string of errno. No location is printed. */
11651302 extern bool cpp_errno (cpp_reader *, enum cpp_diagnostic_level,
@@ -1197,11 +1334,13 @@ extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level, · 31 unmodified lines
11971334 rich_location *richloc, const char *msgid, ...)
11981335 ATTRIBUTE_PRINTF_4;
11991336
1200−/* In lex.c */
1337+/* In lex.cc */
12011338 extern int cpp_ideq (const cpp_token *, const char *);
12021339 extern void cpp_output_line (cpp_reader *, FILE *);
12031340 extern unsigned char *cpp_output_line_to_string (cpp_reader *,
12041341 const unsigned char *);
1342+extern const unsigned char *cpp_alloc_token_string
1343+ (cpp_reader *, const unsigned char *, unsigned);
12051344 extern void cpp_output_token (const cpp_token *, FILE *);
12061345 extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);
12071346 /* Returns the value of an escape sequence, truncated to the correct
@@ -1252,13 +1391,15 @@ extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, · 44 unmodified lines
12521391 typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);
12531392 extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);
12541393
1255−/* In macro.c */
1394+/* In macro.cc */
12561395 extern void cpp_scan_nooutput (cpp_reader *);
12571396 extern int cpp_sys_macro_p (cpp_reader *);
12581397 extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
12591398 unsigned int);
1399+extern bool cpp_compare_macros (const cpp_macro *macro1,
1400+ const cpp_macro *macro2);
12601401
1261−/* In files.c */
1402+/* In files.cc */
12621403 extern bool cpp_included (cpp_reader *, const char *);
12631404 extern bool cpp_included_before (cpp_reader *, const char *, location_t);
12641405 extern void cpp_make_system_header (cpp_reader *, int, int);
@@ -1272,7 +1413,21 @@ extern struct _cpp_file *cpp_get_file (cpp_buffer *); · 7 unmodified lines
12721413 extern cpp_buffer *cpp_get_prev (cpp_buffer *);
12731414 extern void cpp_clear_file_cache (cpp_reader *);
12741415
1275−/* In pch.c */
1416+/* cpp_get_converted_source returns the contents of the given file, as it exists
1417+ after cpplib has read it and converted it from the input charset to the
1418+ source charset. Return struct will be zero-filled if the data could not be
1419+ read for any reason. The data starts at the DATA pointer, but the TO_FREE
1420+ pointer is what should be passed to free(), as there may be an offset. */
1421+struct cpp_converted_source
1422+{
1423+ char *to_free;
1424+ char *data;
1425+ size_t len;
1426+};
1427+cpp_converted_source cpp_get_converted_source (const char *fname,
1428+ const char *input_charset);
1429+
1430+/* In pch.cc */
12761431 struct save_macro_data;
12771432 extern int cpp_save_state (cpp_reader *, FILE *);
12781433 extern int cpp_write_pch_deps (cpp_reader *, FILE *);
@@ -1282,11 +1437,23 @@ extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); · 3 unmodified lines
12821437 extern int cpp_read_state (cpp_reader *, const char *, FILE *,
12831438 struct save_macro_data *);
12841439
1285−/* In lex.c */
1440+/* In lex.cc */
12861441 extern void cpp_force_token_locations (cpp_reader *, location_t);
12871442 extern void cpp_stop_forcing_token_locations (cpp_reader *);
1443+enum CPP_DO_task
1444+{
1445+ CPP_DO_print,
1446+ CPP_DO_location,
1447+ CPP_DO_token
1448+};
1449+
1450+extern void cpp_directive_only_process (cpp_reader *pfile,
1451+ void *data,
1452+ void (*cb) (cpp_reader *,
1453+ CPP_DO_task,
1454+ void *data, ...));
12881455
1289−/* In expr.c */
1456+/* In expr.cc */
12901457 extern enum cpp_ttype cpp_userdef_string_remove_type
12911458 (enum cpp_ttype type);
12921459 extern enum cpp_ttype cpp_userdef_string_add_type
@@ -1302,4 +1469,100 @@ extern bool cpp_userdef_char_p · 9 unmodified lines
13021469 extern const char * cpp_get_userdef_suffix
13031470 (const cpp_token *);
13041471
1472+/* In charset.cc */
1473+
1474+/* The result of attempting to decode a run of UTF-8 bytes. */
1475+
1476+struct cpp_decoded_char
1477+{
1478+ const char *m_start_byte;
1479+ const char *m_next_byte;
1480+
1481+ bool m_valid_ch;
1482+ cppchar_t m_ch;
1483+};
1484+
1485+/* Information for mapping between code points and display columns.
1486+
1487+ This is a tabstop value, along with a callback for getting the
1488+ widths of characters. Normally this callback is cpp_wcwidth, but we
1489+ support other schemes for escaping non-ASCII unicode as a series of
1490+ ASCII chars when printing the user's source code in diagnostic-show-locus.cc
1491+
1492+ For example, consider:
1493+ - the Unicode character U+03C0 "GREEK SMALL LETTER PI" (UTF-8: 0xCF 0x80)
1494+ - the Unicode character U+1F642 "SLIGHTLY SMILING FACE"
1495+ (UTF-8: 0xF0 0x9F 0x99 0x82)
1496+ - the byte 0xBF (a stray trailing byte of a UTF-8 character)
1497+ Normally U+03C0 would occupy one display column, U+1F642
1498+ would occupy two display columns, and the stray byte would be
1499+ printed verbatim as one display column.
1500+
1501+ However when escaping them as unicode code points as "<U+03C0>"
1502+ and "<U+1F642>" they occupy 8 and 9 display columns respectively,
1503+ and when escaping them as bytes as "<CF><80>" and "<F0><9F><99><82>"
1504+ they occupy 8 and 16 display columns respectively. In both cases
1505+ the stray byte is escaped to <BF> as 4 display columns. */
1506+
1507+struct cpp_char_column_policy
1508+{
1509+ cpp_char_column_policy (int tabstop,
1510+ int (*width_cb) (cppchar_t c))
1511+ : m_tabstop (tabstop),
1512+ m_undecoded_byte_width (1),
1513+ m_width_cb (width_cb)
1514+ {}
1515+
1516+ int m_tabstop;
1517+ /* Width in display columns of a stray byte that isn't decodable
1518+ as UTF-8. */
1519+ int m_undecoded_byte_width;
1520+ int (*m_width_cb) (cppchar_t c);
1521+};
1522+
1523+/* A class to manage the state while converting a UTF-8 sequence to cppchar_t
1524+ and computing the display width one character at a time. */
1525+class cpp_display_width_computation {
1526+ public:
1527+ cpp_display_width_computation (const char *data, int data_length,
1528+ const cpp_char_column_policy &policy);
1529+ const char *next_byte () const { return m_next; }
1530+ int bytes_processed () const { return m_next - m_begin; }
1531+ int bytes_left () const { return m_bytes_left; }
1532+ bool done () const { return !bytes_left (); }
1533+ int display_cols_processed () const { return m_display_cols; }
1534+
1535+ int process_next_codepoint (cpp_decoded_char *out);
1536+ int advance_display_cols (int n);
1537+
1538+ private:
1539+ const char *const m_begin;
1540+ const char *m_next;
1541+ size_t m_bytes_left;
1542+ const cpp_char_column_policy &m_policy;
1543+ int m_display_cols;
1544+};
1545+
1546+/* Convenience functions that are simple use cases for class
1547+ cpp_display_width_computation. Tab characters will be expanded to spaces
1548+ as determined by POLICY.m_tabstop, and non-printable-ASCII characters
1549+ will be escaped as per POLICY. */
1550+
1551+int cpp_byte_column_to_display_column (const char *data, int data_length,
1552+ int column,
1553+ const cpp_char_column_policy &policy);
1554+inline int cpp_display_width (const char *data, int data_length,
1555+ const cpp_char_column_policy &policy)
1556+{
1557+ return cpp_byte_column_to_display_column (data, data_length, data_length,
1558+ policy);
1559+}
1560+int cpp_display_column_to_byte_column (const char *data, int data_length,
1561+ int display_col,
1562+ const cpp_char_column_policy &policy);
1563+int cpp_wcwidth (cppchar_t c);
1564+
1565+bool cpp_input_conversion_is_trivial (const char *input_charset);
1566+int cpp_check_utf8_bom (const char *data, size_t data_length);
1567+
13051568 #endif /* ! LIBCPP_CPPLIB_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t