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 @@
1/* Definitions for CPP library.1/* Definitions for CPP library.
2 Copyright (C) 1995-2019 Free Software Foundation, Inc.2 Copyright (C) 1995-2022 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.3 Written by Per Bothner, 1994-95.
4 4
5This program is free software; you can redistribute it and/or modify it5This program is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@ struct _cpp_file; · 40 unmodified lines
46 '='. The lexer needs operators ending in '=', like ">>=", to be in46 '='. The lexer needs operators ending in '=', like ">>=", to be in
47 the same order as their counterparts without the '=', like ">>".47 the same order as their counterparts without the '=', like ">>".
48 48
49 See the cpp_operator table optab in expr.c if you change the order or49 See the cpp_operator table optab in expr.cc if you change the order or
50 add or remove anything in the first group. */50 add or remove anything in the first group. */
51 51
52#define TTYPE_TABLE \52#define TTYPE_TABLE \
@@ -78,6 +78,7 @@ struct _cpp_file; · 25 unmodified lines
78 OP(NOT_EQ, "!=") \78 OP(NOT_EQ, "!=") \
79 OP(GREATER_EQ, ">=") \79 OP(GREATER_EQ, ">=") \
80 OP(LESS_EQ, "<=") \80 OP(LESS_EQ, "<=") \
81 OP(SPACESHIP, "<=>") \
81 \82 \
82 /* These two are unary + / - in preprocessor expressions. */ \83 /* These two are unary + / - in preprocessor expressions. */ \
83 OP(PLUS_EQ, "+=") /* math */ \84 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
172 CLK_STDC2X,173 CLK_STDC2X,
173 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,174 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
174 CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,175 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};
176 178
177/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */179/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
178struct GTY(()) cpp_string {180struct GTY(()) cpp_string {
@@ -190,12 +192,13 @@ struct GTY(()) cpp_string { · 11 unmodified lines
190 comment. */192 comment. */
191#define BOL (1 << 6) /* Token at beginning of line. */193#define BOL (1 << 6) /* Token at beginning of line. */
192#define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend,194#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. */
194#define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */196#define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */
195#define SP_PREV_WHITE (1 << 9) /* If whitespace before a ##197#define SP_PREV_WHITE (1 << 9) /* If whitespace before a ##
196 operator, or before this token198 operator, or before this token
197 after a # operator. */199 after a # operator. */
198#define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */200#define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */
201#define PRAGMA_OP (1 << 11) /* _Pragma token. */
199 202
200/* Specify which field, if any, of the cpp_token union is used. */203/* Specify which field, if any, of the cpp_token union is used. */
201 204
@@ -307,13 +310,31 @@ enum cpp_normalize_level { · 105 unmodified lines
307 normalized_none310 normalized_none
308};311};
309 312
313enum 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. */
323enum 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
310/* This structure is nested inside struct cpp_reader, and334/* This structure is nested inside struct cpp_reader, and
311 carries all the options visible to the command line. */335 carries all the options visible to the command line. */
312struct cpp_options336struct cpp_options
313{337{
314 /* Characters between tab stops. */
315 unsigned int tabstop;
316
317 /* The language we're preprocessing. */338 /* The language we're preprocessing. */
318 enum c_lang lang;339 enum c_lang lang;
319 340
@@ -471,7 +492,7 @@ struct cpp_options · 151 unmodified lines
471 unsigned char ext_numeric_literals;492 unsigned char ext_numeric_literals;
472 493
473 /* Nonzero means extended identifiers allow the characters specified494 /* Nonzero means extended identifiers allow the characters specified
474 in C11 and C++11. */495 in C11. */
475 unsigned char c11_identifiers;496 unsigned char c11_identifiers;
476 497
477 /* Nonzero for C++ 2014 Standard binary constants. */498 /* Nonzero for C++ 2014 Standard binary constants. */
@@ -480,9 +501,24 @@ struct cpp_options · 2 unmodified lines
480 /* Nonzero for C++ 2014 Standard digit separators. */501 /* Nonzero for C++ 2014 Standard digit separators. */
481 unsigned char digit_separators;502 unsigned char digit_separators;
482 503
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. */
484 unsigned char va_opt;508 unsigned char va_opt;
485 509
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
486 /* Holds the name of the target (execution) character set. */522 /* Holds the name of the target (execution) character set. */
487 const char *narrow_charset;523 const char *narrow_charset;
488 524
@@ -505,9 +541,16 @@ struct cpp_options · 16 unmodified lines
505 /* True if warn about differences between C90 and C99. */541 /* True if warn about differences between C90 and C99. */
506 signed char cpp_warn_c90_c99_compat;542 signed char cpp_warn_c90_c99_compat;
507 543
544 /* True if warn about differences between C11 and C2X. */
545 signed char cpp_warn_c11_c2x_compat;
546
508 /* True if warn about differences between C++98 and C++11. */547 /* True if warn about differences between C++98 and C++11. */
509 bool cpp_warn_cxx11_compat;548 bool cpp_warn_cxx11_compat;
510 549
550 /* Nonzero if bidirectional control characters checking is on. See enum
551 cpp_bidirectional_level. */
552 unsigned char cpp_warn_bidirectional;
553
511 /* Dependency generation. */554 /* Dependency generation. */
512 struct555 struct
513 {556 {
@@ -521,6 +564,9 @@ struct cpp_options · 7 unmodified lines
521 one. */564 one. */
522 bool phony_targets;565 bool phony_targets;
523 566
567 /* Generate dependency info for modules. */
568 bool modules;
569
524 /* If true, no dependency is generated on the main file. */570 /* If true, no dependency is generated on the main file. */
525 bool ignore_main_file;571 bool ignore_main_file;
526 572
@@ -550,6 +596,11 @@ struct cpp_options · 23 unmodified lines
550 596
551 /* True enables canonicalization of system header file paths. */597 /* True enables canonicalization of system header file paths. */
552 bool canonical_system_headers;598 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;
553};604};
554 605
555/* Diagnostic levels. To get a diagnostic without associating a606/* Diagnostic levels. To get a diagnostic without associating a
@@ -598,11 +649,14 @@ enum cpp_warning_reason { · 42 unmodified lines
598 CPP_W_INVALID_PCH,649 CPP_W_INVALID_PCH,
599 CPP_W_WARNING_DIRECTIVE,650 CPP_W_WARNING_DIRECTIVE,
600 CPP_W_LITERAL_SUFFIX,651 CPP_W_LITERAL_SUFFIX,
652 CPP_W_SIZE_T_LITERALS,
601 CPP_W_DATE_TIME,653 CPP_W_DATE_TIME,
602 CPP_W_PEDANTIC,654 CPP_W_PEDANTIC,
603 CPP_W_C90_C99_COMPAT,655 CPP_W_C90_C99_COMPAT,
656 CPP_W_C11_C2X_COMPAT,
604 CPP_W_CXX11_COMPAT,657 CPP_W_CXX11_COMPAT,
605 CPP_W_EXPANSION_TO_DEFINED658 CPP_W_EXPANSION_TO_DEFINED,
659 CPP_W_BIDIRECTIONAL
606};660};
607 661
608/* Callback for header lookup for HEADER, which is the name of a662/* Callback for header lookup for HEADER, which is the name of a
@@ -661,11 +715,17 @@ struct cpp_callbacks · 52 unmodified lines
661 void (*used) (cpp_reader *, location_t, cpp_hashnode *);715 void (*used) (cpp_reader *, location_t, cpp_hashnode *);
662 716
663 /* Callback to identify whether an attribute exists. */717 /* 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 *);
665 722
666 /* Callback that can change a user lazy into normal macro. */723 /* Callback that can change a user lazy into normal macro. */
667 void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);724 void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);
668 725
726 /* Callback to handle deferred cpp_macros. */
727 cpp_macro *(*user_deferred_macro) (cpp_reader *, location_t, cpp_hashnode *);
728
669 /* Callback to parse SOURCE_DATE_EPOCH from environment. */729 /* Callback to parse SOURCE_DATE_EPOCH from environment. */
670 time_t (*get_source_date_epoch) (cpp_reader *);730 time_t (*get_source_date_epoch) (cpp_reader *);
671 731
@@ -684,14 +744,27 @@ struct cpp_callbacks · 12 unmodified lines
684 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro744 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
685 expansions. */745 expansions. */
686 const char *(*remap_filename) (const char*);746 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);
687};752};
688 753
689#ifdef VMS754#ifdef VMS
690#define INO_T_CPP ino_t ino[3]755#define INO_T_CPP ino_t ino[3]
756#elif defined (_AIX) && SIZEOF_INO_T == 4
757#define INO_T_CPP ino64_t ino
691#else758#else
692#define INO_T_CPP ino_t ino759#define INO_T_CPP ino_t ino
693#endif760#endif
694 761
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
695/* Chain of directories to look for include files in. */768/* Chain of directories to look for include files in. */
696struct cpp_dir769struct cpp_dir
697{770{
@@ -726,7 +799,7 @@ struct cpp_dir · 28 unmodified lines
726 /* The C front end uses these to recognize duplicated799 /* The C front end uses these to recognize duplicated
727 directories in the search path. */800 directories in the search path. */
728 INO_T_CPP;801 INO_T_CPP;
729 dev_t dev;802 DEV_T_CPP;
730};803};
731 804
732/* The kind of the cpp_macro. */805/* The kind of the cpp_macro. */
@@ -787,7 +860,10 @@ struct GTY(()) cpp_macro { · 54 unmodified lines
787 tokens. */860 tokens. */
788 unsigned int extra_tokens : 1;861 unsigned int extra_tokens : 1;
789 862
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. */
791 867
792 union cpp_exp_u868 union cpp_exp_u
793 {869 {
@@ -817,6 +893,7 @@ struct GTY(()) cpp_macro { · 23 unmodified lines
817#define NODE_USED (1 << 5) /* Dumped with -dU. */893#define NODE_USED (1 << 5) /* Dumped with -dU. */
818#define NODE_CONDITIONAL (1 << 6) /* Conditional macro */894#define NODE_CONDITIONAL (1 << 6) /* Conditional macro */
819#define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */895#define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */
896#define NODE_MODULE (1 << 8) /* C++-20 module-related name. */
820 897
821/* Different flavors of hash node. */898/* Different flavors of hash node. */
822enum node_type899enum node_type
@@ -835,6 +912,7 @@ enum cpp_builtin_type · 12 unmodified lines
835 BT_SPECLINE = 0, /* `__LINE__' */912 BT_SPECLINE = 0, /* `__LINE__' */
836 BT_DATE, /* `__DATE__' */913 BT_DATE, /* `__DATE__' */
837 BT_FILE, /* `__FILE__' */914 BT_FILE, /* `__FILE__' */
915 BT_FILE_NAME, /* `__FILE_NAME__' */
838 BT_BASE_FILE, /* `__BASE_FILE__' */916 BT_BASE_FILE, /* `__BASE_FILE__' */
839 BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */917 BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
840 BT_TIME, /* `__TIME__' */918 BT_TIME, /* `__TIME__' */
@@ -842,7 +920,11 @@ enum cpp_builtin_type · 1 unmodified line
842 BT_PRAGMA, /* `_Pragma' operator */920 BT_PRAGMA, /* `_Pragma' operator */
843 BT_TIMESTAMP, /* `__TIMESTAMP__' */921 BT_TIMESTAMP, /* `__TIMESTAMP__' */
844 BT_COUNTER, /* `__COUNTER__' */922 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)' */
846};928};
847 929
848#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))930#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
@@ -857,7 +939,7 @@ enum cpp_builtin_type · 8 unmodified lines
857union GTY(()) _cpp_hashnode_value {939union GTY(()) _cpp_hashnode_value {
858 /* Assert (maybe NULL) */940 /* Assert (maybe NULL) */
859 cpp_macro * GTY((tag ("NT_VOID"))) answers;941 cpp_macro * GTY((tag ("NT_VOID"))) answers;
860 /* Macro (never NULL) */942 /* Macro (maybe NULL) */
861 cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;943 cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
862 /* Code for a builtin macro. */944 /* Code for a builtin macro. */
863 enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;945 enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
@@ -871,11 +953,17 @@ struct GTY(()) cpp_hashnode { · 7 unmodified lines
871 unsigned int directive_index : 7; /* If is_directive,953 unsigned int directive_index : 7; /* If is_directive,
872 then index into directive table.954 then index into directive table.
873 Otherwise, a NODE_OPERATOR. */955 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. */
875 ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */958 ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */
876 unsigned int flags : 8; /* CPP flags. */
877 959
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 */
879 967
880 union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;968 union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
881};969};
@@ -894,7 +982,6 @@ class cpp_string_location_reader { · 12 unmodified lines
894 private:982 private:
895 location_t m_loc;983 location_t m_loc;
896 int m_offset_per_column;984 int m_offset_per_column;
897 line_maps *m_line_table;
898};985};
899 986
900/* A class for storing the source ranges of all of the characters within987/* A class for storing the source ranges of all of the characters within
@@ -932,11 +1019,11 @@ class cpp_substring_ranges · 31 unmodified lines
932 that cpplib will share; this technique is used by the C front1019 that cpplib will share; this technique is used by the C front
933 ends. */1020 ends. */
934extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,1021extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
935 struct line_maps *);1022 class line_maps *);
936 1023
937/* Reset the cpp_reader's line_map. This is only used after reading a1024/* Reset the cpp_reader's line_map. This is only used after reading a
938 PCH file. */1025 PCH file. */
939extern void cpp_set_line_map (cpp_reader *, struct line_maps *);1026extern void cpp_set_line_map (cpp_reader *, class line_maps *);
940 1027
941/* Call this to change the selected language standard (e.g. because of1028/* Call this to change the selected language standard (e.g. because of
942 command line options). */1029 command line options). */
@@ -950,17 +1037,30 @@ extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); · 7 unmodified lines
950 call cpp_finish on that reader. You can either edit the callbacks1037 call cpp_finish on that reader. You can either edit the callbacks
951 through the pointer returned from cpp_get_callbacks, or set them1038 through the pointer returned from cpp_get_callbacks, or set them
952 with cpp_set_callbacks. */1039 with cpp_set_callbacks. */
953extern cpp_options *cpp_get_options (cpp_reader *);1040extern cpp_options *cpp_get_options (cpp_reader *) ATTRIBUTE_PURE;
954extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);1041extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) ATTRIBUTE_PURE;
955extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);1042extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
956extern struct deps *cpp_get_deps (cpp_reader *);1043extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE;
1044
1045extern 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. */
1050extern const char *cpp_get_narrow_charset_name (cpp_reader *) ATTRIBUTE_PURE;
1051extern const char *cpp_get_wide_charset_name (cpp_reader *) ATTRIBUTE_PURE;
957 1052
958/* This function reads the file, but does not start preprocessing. It1053/* This function reads the file, but does not start preprocessing. It
959 returns the name of the original file; this is the same as the1054 returns the name of the original file; this is the same as the
960 input file, except for preprocessed input. This will generate at1055 input file, except for preprocessed input. This will generate at
961 least one file change callback, and possibly a line change callback1056 least one file change callback, and possibly a line change callback
962 too. If there was an error opening the file, it returns NULL. */1057 too. If there was an error opening the file, it returns NULL. */
963extern const char *cpp_read_main_file (cpp_reader *, const char *);1058extern const char *cpp_read_main_file (cpp_reader *, const char *,
1059 bool injecting = false);
1060extern location_t cpp_main_loc (const cpp_reader *);
1061
1062/* Adjust for the main file to be an include. */
1063extern void cpp_retrofit_as_include (cpp_reader *);
964 1064
965/* Set up built-ins with special behavior. Use cpp_init_builtins()1065/* Set up built-ins with special behavior. Use cpp_init_builtins()
966 instead unless your know what you are doing. */1066 instead unless your know what you are doing. */
@@ -1010,6 +1110,18 @@ inline bool cpp_macro_p (const cpp_hashnode *node) · 43 unmodified lines
1010{1110{
1011 return node->type & NT_MACRO_MASK;1111 return node->type & NT_MACRO_MASK;
1012}1112}
1113inline 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}
1124cpp_macro *cpp_get_deferred_macro (cpp_reader *, cpp_hashnode *, location_t);
1013 1125
1014/* Returns true if NODE is a function-like user macro. */1126/* Returns true if NODE is a function-like user macro. */
1015inline bool cpp_fun_like_macro_p (cpp_hashnode *node)1127inline 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
1017 return cpp_user_macro_p (node) && node->value.macro->fun_like;1129 return cpp_user_macro_p (node) && node->value.macro->fun_like;
1018}1130}
1019 1131
1020extern const unsigned char *cpp_macro_definition (cpp_reader *,1132extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *);
1021 cpp_hashnode *);1133extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *,
1134 const cpp_macro *);
1022inline location_t cpp_macro_definition_location (cpp_hashnode *node)1135inline location_t cpp_macro_definition_location (cpp_hashnode *node)
1023{1136{
1024 return node->value.macro->line;1137 const cpp_macro *macro = node->value.macro;
1138 return macro ? macro->line : 0;
1025}1139}
1140/* Return an idempotent time stamp (possibly from SOURCE_DATE_EPOCH). */
1141enum 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};
1147extern CPP_time_kind cpp_get_date (cpp_reader *, time_t *);
1148
1026extern void _cpp_backup_tokens (cpp_reader *, unsigned int);1149extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
1027extern const cpp_token *cpp_peek_token (cpp_reader *, int);1150extern const cpp_token *cpp_peek_token (cpp_reader *, int);
1028 1151
@@ -1049,8 +1172,12 @@ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); · 20 unmodified lines
1049/* Used to register macros and assertions, perhaps from the command line.1172/* Used to register macros and assertions, perhaps from the command line.
1050 The text is the same as the command line argument. */1173 The text is the same as the command line argument. */
1051extern void cpp_define (cpp_reader *, const char *);1174extern void cpp_define (cpp_reader *, const char *);
1175extern void cpp_define_unused (cpp_reader *, const char *);
1052extern void cpp_define_formatted (cpp_reader *pfile, 1176extern void cpp_define_formatted (cpp_reader *pfile,
1053 const char *fmt, ...) ATTRIBUTE_PRINTF_2;1177 const char *fmt, ...) ATTRIBUTE_PRINTF_2;
1178extern void cpp_define_formatted_unused (cpp_reader *pfile,
1179 const char *fmt,
1180 ...) ATTRIBUTE_PRINTF_2;
1054extern void cpp_assert (cpp_reader *, const char *);1181extern void cpp_assert (cpp_reader *, const char *);
1055extern void cpp_undef (cpp_reader *, const char *);1182extern void cpp_undef (cpp_reader *, const char *);
1056extern void cpp_unassert (cpp_reader *, const char *);1183extern void cpp_unassert (cpp_reader *, const char *);
@@ -1069,7 +1196,7 @@ extern int cpp_defined (cpp_reader *, const unsigned char *, int); · 12 unmodified lines
1069 the double integer are set to zero. */1196 the double integer are set to zero. */
1070 1197
1071/* This type has to be equal to unsigned HOST_WIDE_INT, see1198/* 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. */
1073typedef uint64_t cpp_num_part;1200typedef uint64_t cpp_num_part;
1074typedef struct cpp_num cpp_num;1201typedef struct cpp_num cpp_num;
1075struct cpp_num1202struct cpp_num
@@ -1118,7 +1245,9 @@ struct cpp_num · 42 unmodified lines
1118#define CPP_N_FLOATN 0x400000 /* _FloatN types. */1245#define CPP_N_FLOATN 0x400000 /* _FloatN types. */
1119#define CPP_N_FLOATNX 0x800000 /* _FloatNx types. */1246#define CPP_N_FLOATNX 0x800000 /* _FloatNx types. */
1120 1247
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. */
1122 1251
1123#define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value1252#define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value
1124 of N, divided by 16. */1253 of N, divided by 16. */
@@ -1160,6 +1289,14 @@ extern bool cpp_warning_syshdr (cpp_reader *, enum cpp_warning_reason reason, · 35 unmodified lines
1160 const char *msgid, ...)1289 const char *msgid, ...)
1161 ATTRIBUTE_PRINTF_3;1290 ATTRIBUTE_PRINTF_3;
1162 1291
1292/* As their counterparts above, but use RICHLOC. */
1293extern bool cpp_warning_at (cpp_reader *, enum cpp_warning_reason,
1294 rich_location *richloc, const char *msgid, ...)
1295 ATTRIBUTE_PRINTF_4;
1296extern bool cpp_pedwarning_at (cpp_reader *, enum cpp_warning_reason,
1297 rich_location *richloc, const char *msgid, ...)
1298 ATTRIBUTE_PRINTF_4;
1299
1163/* Output a diagnostic with "MSGID: " preceding the1300/* Output a diagnostic with "MSGID: " preceding the
1164 error string of errno. No location is printed. */1301 error string of errno. No location is printed. */
1165extern bool cpp_errno (cpp_reader *, enum cpp_diagnostic_level,1302extern 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
1197 rich_location *richloc, const char *msgid, ...)1334 rich_location *richloc, const char *msgid, ...)
1198 ATTRIBUTE_PRINTF_4;1335 ATTRIBUTE_PRINTF_4;
1199 1336
1200/* In lex.c */1337/* In lex.cc */
1201extern int cpp_ideq (const cpp_token *, const char *);1338extern int cpp_ideq (const cpp_token *, const char *);
1202extern void cpp_output_line (cpp_reader *, FILE *);1339extern void cpp_output_line (cpp_reader *, FILE *);
1203extern unsigned char *cpp_output_line_to_string (cpp_reader *,1340extern unsigned char *cpp_output_line_to_string (cpp_reader *,
1204 const unsigned char *);1341 const unsigned char *);
1342extern const unsigned char *cpp_alloc_token_string
1343 (cpp_reader *, const unsigned char *, unsigned);
1205extern void cpp_output_token (const cpp_token *, FILE *);1344extern void cpp_output_token (const cpp_token *, FILE *);
1206extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);1345extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);
1207/* Returns the value of an escape sequence, truncated to the correct1346/* 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
1252typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);1391typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);
1253extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);1392extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);
1254 1393
1255/* In macro.c */1394/* In macro.cc */
1256extern void cpp_scan_nooutput (cpp_reader *);1395extern void cpp_scan_nooutput (cpp_reader *);
1257extern int cpp_sys_macro_p (cpp_reader *);1396extern int cpp_sys_macro_p (cpp_reader *);
1258extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,1397extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
1259 unsigned int);1398 unsigned int);
1399extern bool cpp_compare_macros (const cpp_macro *macro1,
1400 const cpp_macro *macro2);
1260 1401
1261/* In files.c */1402/* In files.cc */
1262extern bool cpp_included (cpp_reader *, const char *);1403extern bool cpp_included (cpp_reader *, const char *);
1263extern bool cpp_included_before (cpp_reader *, const char *, location_t);1404extern bool cpp_included_before (cpp_reader *, const char *, location_t);
1264extern void cpp_make_system_header (cpp_reader *, int, int);1405extern 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
1272extern cpp_buffer *cpp_get_prev (cpp_buffer *);1413extern cpp_buffer *cpp_get_prev (cpp_buffer *);
1273extern void cpp_clear_file_cache (cpp_reader *);1414extern void cpp_clear_file_cache (cpp_reader *);
1274 1415
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. */
1421struct cpp_converted_source
1422{
1423 char *to_free;
1424 char *data;
1425 size_t len;
1426};
1427cpp_converted_source cpp_get_converted_source (const char *fname,
1428 const char *input_charset);
1429
1430/* In pch.cc */
1276struct save_macro_data;1431struct save_macro_data;
1277extern int cpp_save_state (cpp_reader *, FILE *);1432extern int cpp_save_state (cpp_reader *, FILE *);
1278extern int cpp_write_pch_deps (cpp_reader *, FILE *);1433extern 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
1282extern int cpp_read_state (cpp_reader *, const char *, FILE *,1437extern int cpp_read_state (cpp_reader *, const char *, FILE *,
1283 struct save_macro_data *);1438 struct save_macro_data *);
1284 1439
1285/* In lex.c */1440/* In lex.cc */
1286extern void cpp_force_token_locations (cpp_reader *, location_t);1441extern void cpp_force_token_locations (cpp_reader *, location_t);
1287extern void cpp_stop_forcing_token_locations (cpp_reader *);1442extern void cpp_stop_forcing_token_locations (cpp_reader *);
1443enum CPP_DO_task
1444{
1445 CPP_DO_print,
1446 CPP_DO_location,
1447 CPP_DO_token
1448};
1449
1450extern void cpp_directive_only_process (cpp_reader *pfile,
1451 void *data,
1452 void (*cb) (cpp_reader *,
1453 CPP_DO_task,
1454 void *data, ...));
1288 1455
1289/* In expr.c */1456/* In expr.cc */
1290extern enum cpp_ttype cpp_userdef_string_remove_type1457extern enum cpp_ttype cpp_userdef_string_remove_type
1291 (enum cpp_ttype type);1458 (enum cpp_ttype type);
1292extern enum cpp_ttype cpp_userdef_string_add_type1459extern enum cpp_ttype cpp_userdef_string_add_type
@@ -1302,4 +1469,100 @@ extern bool cpp_userdef_char_p · 9 unmodified lines
1302extern const char * cpp_get_userdef_suffix1469extern const char * cpp_get_userdef_suffix
1303 (const cpp_token *);1470 (const cpp_token *);
1304 1471
1472/* In charset.cc */
1473
1474/* The result of attempting to decode a run of UTF-8 bytes. */
1475
1476struct 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
1507struct 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. */
1525class 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
1551int cpp_byte_column_to_display_column (const char *data, int data_length,
1552 int column,
1553 const cpp_char_column_policy &policy);
1554inline 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}
1560int cpp_display_column_to_byte_column (const char *data, int data_length,
1561 int display_col,
1562 const cpp_char_column_policy &policy);
1563int cpp_wcwidth (cppchar_t c);
1564
1565bool cpp_input_conversion_is_trivial (const char *input_charset);
1566int cpp_check_utf8_bom (const char *data, size_t data_length);
1567
1305#endif /* ! LIBCPP_CPPLIB_H */1568#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