Showing the changes to gcc/libcpp/include/cpplib.h (1 of 61892 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* Definitions for CPP library. |
| 2 | − Copyright (C) 1995-2019 Free Software Foundation, Inc. | |
| 2 | + Copyright (C) 1995-2022 Free Software Foundation, Inc. | |
| 3 | 3 | Written by Per Bothner, 1994-95. |
| 4 | 4 | |
| 5 | 5 | This program is free software; you can redistribute it and/or modify it |
| @@ -46,7 +46,7 @@ struct _cpp_file; · 40 unmodified lines | ||
| 46 | 46 | '='. The lexer needs operators ending in '=', like ">>=", to be in |
| 47 | 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 or | |
| 49 | + See the cpp_operator table optab in expr.cc if you change the order or | |
| 50 | 50 | add or remove anything in the first group. */ |
| 51 | 51 | |
| 52 | 52 | #define TTYPE_TABLE \ |
| @@ -78,6 +78,7 @@ struct _cpp_file; · 25 unmodified lines | ||
| 78 | 78 | OP(NOT_EQ, "!=") \ |
| 79 | 79 | OP(GREATER_EQ, ">=") \ |
| 80 | 80 | OP(LESS_EQ, "<=") \ |
| 81 | + OP(SPACESHIP, "<=>") \ | |
| 81 | 82 | \ |
| 82 | 83 | /* These two are unary + / - in preprocessor expressions. */ \ |
| 83 | 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 | 173 | CLK_STDC2X, |
| 173 | 174 | CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, |
| 174 | 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 | 179 | /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ |
| 178 | 180 | struct GTY(()) cpp_string { |
| @@ -190,12 +192,13 @@ struct GTY(()) cpp_string { · 11 unmodified lines | ||
| 190 | 192 | comment. */ |
| 191 | 193 | #define BOL (1 << 6) /* Token at beginning of line. */ |
| 192 | 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 | 196 | #define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */ |
| 195 | 197 | #define SP_PREV_WHITE (1 << 9) /* If whitespace before a ## |
| 196 | 198 | operator, or before this token |
| 197 | 199 | after a # operator. */ |
| 198 | 200 | #define NO_EXPAND (1 << 10) /* Do not macro-expand this token. */ |
| 201 | +#define PRAGMA_OP (1 << 11) /* _Pragma token. */ | |
| 199 | 202 | |
| 200 | 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 | 310 | normalized_none |
| 308 | 311 | }; |
| 309 | 312 | |
| 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 | + | |
| 310 | 334 | /* This structure is nested inside struct cpp_reader, and |
| 311 | 335 | carries all the options visible to the command line. */ |
| 312 | 336 | struct cpp_options |
| 313 | 337 | { |
| 314 | − /* Characters between tab stops. */ | |
| 315 | − unsigned int tabstop; | |
| 316 | − | |
| 317 | 338 | /* The language we're preprocessing. */ |
| 318 | 339 | enum c_lang lang; |
| 319 | 340 | |
| @@ -471,7 +492,7 @@ struct cpp_options · 151 unmodified lines | ||
| 471 | 492 | unsigned char ext_numeric_literals; |
| 472 | 493 | |
| 473 | 494 | /* Nonzero means extended identifiers allow the characters specified |
| 474 | − in C11 and C++11. */ | |
| 495 | + in C11. */ | |
| 475 | 496 | unsigned char c11_identifiers; |
| 476 | 497 | |
| 477 | 498 | /* Nonzero for C++ 2014 Standard binary constants. */ |
| @@ -480,9 +501,24 @@ struct cpp_options · 2 unmodified lines | ||
| 480 | 501 | /* Nonzero for C++ 2014 Standard digit separators. */ |
| 481 | 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 | 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 | 522 | /* Holds the name of the target (execution) character set. */ |
| 487 | 523 | const char *narrow_charset; |
| 488 | 524 | |
| @@ -505,9 +541,16 @@ struct cpp_options · 16 unmodified lines | ||
| 505 | 541 | /* True if warn about differences between C90 and C99. */ |
| 506 | 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 | 547 | /* True if warn about differences between C++98 and C++11. */ |
| 509 | 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 | 554 | /* Dependency generation. */ |
| 512 | 555 | struct |
| 513 | 556 | { |
| @@ -521,6 +564,9 @@ struct cpp_options · 7 unmodified lines | ||
| 521 | 564 | one. */ |
| 522 | 565 | bool phony_targets; |
| 523 | 566 | |
| 567 | + /* Generate dependency info for modules. */ | |
| 568 | + bool modules; | |
| 569 | + | |
| 524 | 570 | /* If true, no dependency is generated on the main file. */ |
| 525 | 571 | bool ignore_main_file; |
| 526 | 572 | |
| @@ -550,6 +596,11 @@ struct cpp_options · 23 unmodified lines | ||
| 550 | 596 | |
| 551 | 597 | /* True enables canonicalization of system header file paths. */ |
| 552 | 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 | 606 | /* Diagnostic levels. To get a diagnostic without associating a |
| @@ -598,11 +649,14 @@ enum cpp_warning_reason { · 42 unmodified lines | ||
| 598 | 649 | CPP_W_INVALID_PCH, |
| 599 | 650 | CPP_W_WARNING_DIRECTIVE, |
| 600 | 651 | CPP_W_LITERAL_SUFFIX, |
| 652 | + CPP_W_SIZE_T_LITERALS, | |
| 601 | 653 | CPP_W_DATE_TIME, |
| 602 | 654 | CPP_W_PEDANTIC, |
| 603 | 655 | CPP_W_C90_C99_COMPAT, |
| 656 | + CPP_W_C11_C2X_COMPAT, | |
| 604 | 657 | CPP_W_CXX11_COMPAT, |
| 605 | − CPP_W_EXPANSION_TO_DEFINED | |
| 658 | + CPP_W_EXPANSION_TO_DEFINED, | |
| 659 | + CPP_W_BIDIRECTIONAL | |
| 606 | 660 | }; |
| 607 | 661 | |
| 608 | 662 | /* Callback for header lookup for HEADER, which is the name of a |
| @@ -661,11 +715,17 @@ struct cpp_callbacks · 52 unmodified lines | ||
| 661 | 715 | void (*used) (cpp_reader *, location_t, cpp_hashnode *); |
| 662 | 716 | |
| 663 | 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 | 723 | /* Callback that can change a user lazy into normal macro. */ |
| 667 | 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 | 729 | /* Callback to parse SOURCE_DATE_EPOCH from environment. */ |
| 670 | 730 | time_t (*get_source_date_epoch) (cpp_reader *); |
| 671 | 731 | |
| @@ -684,14 +744,27 @@ struct cpp_callbacks · 12 unmodified lines | ||
| 684 | 744 | /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro |
| 685 | 745 | expansions. */ |
| 686 | 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 | 754 | #ifdef VMS |
| 690 | 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 | 758 | #else |
| 692 | 759 | #define INO_T_CPP ino_t ino |
| 693 | 760 | #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 | 768 | /* Chain of directories to look for include files in. */ |
| 696 | 769 | struct cpp_dir |
| 697 | 770 | { |
| @@ -726,7 +799,7 @@ struct cpp_dir · 28 unmodified lines | ||
| 726 | 799 | /* The C front end uses these to recognize duplicated |
| 727 | 800 | directories in the search path. */ |
| 728 | 801 | INO_T_CPP; |
| 729 | − dev_t dev; | |
| 802 | + DEV_T_CPP; | |
| 730 | 803 | }; |
| 731 | 804 | |
| 732 | 805 | /* The kind of the cpp_macro. */ |
| @@ -787,7 +860,10 @@ struct GTY(()) cpp_macro { · 54 unmodified lines | ||
| 787 | 860 | tokens. */ |
| 788 | 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 | 868 | union cpp_exp_u |
| 793 | 869 | { |
| @@ -817,6 +893,7 @@ struct GTY(()) cpp_macro { · 23 unmodified lines | ||
| 817 | 893 | #define NODE_USED (1 << 5) /* Dumped with -dU. */ |
| 818 | 894 | #define NODE_CONDITIONAL (1 << 6) /* Conditional macro */ |
| 819 | 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 | 898 | /* Different flavors of hash node. */ |
| 822 | 899 | enum node_type |
| @@ -835,6 +912,7 @@ enum cpp_builtin_type · 12 unmodified lines | ||
| 835 | 912 | BT_SPECLINE = 0, /* `__LINE__' */ |
| 836 | 913 | BT_DATE, /* `__DATE__' */ |
| 837 | 914 | BT_FILE, /* `__FILE__' */ |
| 915 | + BT_FILE_NAME, /* `__FILE_NAME__' */ | |
| 838 | 916 | BT_BASE_FILE, /* `__BASE_FILE__' */ |
| 839 | 917 | BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ |
| 840 | 918 | BT_TIME, /* `__TIME__' */ |
| @@ -842,7 +920,11 @@ enum cpp_builtin_type · 1 unmodified line | ||
| 842 | 920 | BT_PRAGMA, /* `_Pragma' operator */ |
| 843 | 921 | BT_TIMESTAMP, /* `__TIMESTAMP__' */ |
| 844 | 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 | 930 | #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) |
| @@ -857,7 +939,7 @@ enum cpp_builtin_type · 8 unmodified lines | ||
| 857 | 939 | union GTY(()) _cpp_hashnode_value { |
| 858 | 940 | /* Assert (maybe NULL) */ |
| 859 | 941 | cpp_macro * GTY((tag ("NT_VOID"))) answers; |
| 860 | − /* Macro (never NULL) */ | |
| 942 | + /* Macro (maybe NULL) */ | |
| 861 | 943 | cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro; |
| 862 | 944 | /* Code for a builtin macro. */ |
| 863 | 945 | enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin; |
| @@ -871,11 +953,17 @@ struct GTY(()) cpp_hashnode { · 7 unmodified lines | ||
| 871 | 953 | unsigned int directive_index : 7; /* If is_directive, |
| 872 | 954 | then index into directive table. |
| 873 | 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 | 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 | 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 | 982 | private: |
| 895 | 983 | location_t m_loc; |
| 896 | 984 | int m_offset_per_column; |
| 897 | − line_maps *m_line_table; | |
| 898 | 985 | }; |
| 899 | 986 | |
| 900 | 987 | /* 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 | 1019 | that cpplib will share; this technique is used by the C front |
| 933 | 1020 | ends. */ |
| 934 | 1021 | extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *, |
| 935 | − struct line_maps *); | |
| 1022 | + class line_maps *); | |
| 936 | 1023 | |
| 937 | 1024 | /* Reset the cpp_reader's line_map. This is only used after reading a |
| 938 | 1025 | 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 *); | |
| 940 | 1027 | |
| 941 | 1028 | /* Call this to change the selected language standard (e.g. because of |
| 942 | 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 | 1037 | call cpp_finish on that reader. You can either edit the callbacks |
| 951 | 1038 | through the pointer returned from cpp_get_callbacks, or set them |
| 952 | 1039 | 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; | |
| 955 | 1042 | 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; | |
| 957 | 1052 | |
| 958 | 1053 | /* This function reads the file, but does not start preprocessing. It |
| 959 | 1054 | returns the name of the original file; this is the same as the |
| 960 | 1055 | input file, except for preprocessed input. This will generate at |
| 961 | 1056 | least one file change callback, and possibly a line change callback |
| 962 | 1057 | 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 *); | |
| 964 | 1064 | |
| 965 | 1065 | /* Set up built-ins with special behavior. Use cpp_init_builtins() |
| 966 | 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 | 1111 | return node->type & NT_MACRO_MASK; |
| 1012 | 1112 | } |
| 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); | |
| 1013 | 1125 | |
| 1014 | 1126 | /* Returns true if NODE is a function-like user macro. */ |
| 1015 | 1127 | 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 | ||
| 1017 | 1129 | return cpp_user_macro_p (node) && node->value.macro->fun_like; |
| 1018 | 1130 | } |
| 1019 | 1131 | |
| 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 *); | |
| 1022 | 1135 | inline 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). */ | |
| 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 | + | |
| 1026 | 1149 | extern void _cpp_backup_tokens (cpp_reader *, unsigned int); |
| 1027 | 1150 | extern 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 | 1172 | /* Used to register macros and assertions, perhaps from the command line. |
| 1050 | 1173 | The text is the same as the command line argument. */ |
| 1051 | 1174 | extern void cpp_define (cpp_reader *, const char *); |
| 1175 | +extern void cpp_define_unused (cpp_reader *, const char *); | |
| 1052 | 1176 | extern void cpp_define_formatted (cpp_reader *pfile, |
| 1053 | 1177 | const char *fmt, ...) ATTRIBUTE_PRINTF_2; |
| 1178 | +extern void cpp_define_formatted_unused (cpp_reader *pfile, | |
| 1179 | + const char *fmt, | |
| 1180 | + ...) ATTRIBUTE_PRINTF_2; | |
| 1054 | 1181 | extern void cpp_assert (cpp_reader *, const char *); |
| 1055 | 1182 | extern void cpp_undef (cpp_reader *, const char *); |
| 1056 | 1183 | 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 | ||
| 1069 | 1196 | the double integer are set to zero. */ |
| 1070 | 1197 | |
| 1071 | 1198 | /* 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. */ | |
| 1073 | 1200 | typedef uint64_t cpp_num_part; |
| 1074 | 1201 | typedef struct cpp_num cpp_num; |
| 1075 | 1202 | struct cpp_num |
| @@ -1118,7 +1245,9 @@ struct cpp_num · 42 unmodified lines | ||
| 1118 | 1245 | #define CPP_N_FLOATN 0x400000 /* _FloatN types. */ |
| 1119 | 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 | 1252 | #define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value |
| 1124 | 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 | 1289 | const char *msgid, ...) |
| 1161 | 1290 | ATTRIBUTE_PRINTF_3; |
| 1162 | 1291 | |
| 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 | + | |
| 1163 | 1300 | /* Output a diagnostic with "MSGID: " preceding the |
| 1164 | 1301 | error string of errno. No location is printed. */ |
| 1165 | 1302 | 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 | ||
| 1197 | 1334 | rich_location *richloc, const char *msgid, ...) |
| 1198 | 1335 | ATTRIBUTE_PRINTF_4; |
| 1199 | 1336 | |
| 1200 | −/* In lex.c */ | |
| 1337 | +/* In lex.cc */ | |
| 1201 | 1338 | extern int cpp_ideq (const cpp_token *, const char *); |
| 1202 | 1339 | extern void cpp_output_line (cpp_reader *, FILE *); |
| 1203 | 1340 | extern unsigned char *cpp_output_line_to_string (cpp_reader *, |
| 1204 | 1341 | const unsigned char *); |
| 1342 | +extern const unsigned char *cpp_alloc_token_string | |
| 1343 | + (cpp_reader *, const unsigned char *, unsigned); | |
| 1205 | 1344 | extern void cpp_output_token (const cpp_token *, FILE *); |
| 1206 | 1345 | extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags); |
| 1207 | 1346 | /* 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 | ||
| 1252 | 1391 | typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); |
| 1253 | 1392 | extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); |
| 1254 | 1393 | |
| 1255 | −/* In macro.c */ | |
| 1394 | +/* In macro.cc */ | |
| 1256 | 1395 | extern void cpp_scan_nooutput (cpp_reader *); |
| 1257 | 1396 | extern int cpp_sys_macro_p (cpp_reader *); |
| 1258 | 1397 | extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, |
| 1259 | 1398 | unsigned int); |
| 1399 | +extern bool cpp_compare_macros (const cpp_macro *macro1, | |
| 1400 | + const cpp_macro *macro2); | |
| 1260 | 1401 | |
| 1261 | −/* In files.c */ | |
| 1402 | +/* In files.cc */ | |
| 1262 | 1403 | extern bool cpp_included (cpp_reader *, const char *); |
| 1263 | 1404 | extern bool cpp_included_before (cpp_reader *, const char *, location_t); |
| 1264 | 1405 | 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 | ||
| 1272 | 1413 | extern cpp_buffer *cpp_get_prev (cpp_buffer *); |
| 1273 | 1414 | extern 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. */ | |
| 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 */ | |
| 1276 | 1431 | struct save_macro_data; |
| 1277 | 1432 | extern int cpp_save_state (cpp_reader *, FILE *); |
| 1278 | 1433 | 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 | ||
| 1282 | 1437 | extern int cpp_read_state (cpp_reader *, const char *, FILE *, |
| 1283 | 1438 | struct save_macro_data *); |
| 1284 | 1439 | |
| 1285 | −/* In lex.c */ | |
| 1440 | +/* In lex.cc */ | |
| 1286 | 1441 | extern void cpp_force_token_locations (cpp_reader *, location_t); |
| 1287 | 1442 | 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, ...)); | |
| 1288 | 1455 | |
| 1289 | −/* In expr.c */ | |
| 1456 | +/* In expr.cc */ | |
| 1290 | 1457 | extern enum cpp_ttype cpp_userdef_string_remove_type |
| 1291 | 1458 | (enum cpp_ttype type); |
| 1292 | 1459 | extern enum cpp_ttype cpp_userdef_string_add_type |
| @@ -1302,4 +1469,100 @@ extern bool cpp_userdef_char_p · 9 unmodified lines | ||
| 1302 | 1469 | extern const char * cpp_get_userdef_suffix |
| 1303 | 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 | + | |
| 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 | + | |
| 1305 | 1568 | #endif /* ! LIBCPP_CPPLIB_H */ |