History

gcc-9.1

Wolfgang Thaller committed 7 years ago

Commit 6fbf4221 parent ec13cc931387 files · +2442466 −1054331Browse files

Showing the changes to gcc/libcpp/include (5 of 31387 files). Show all

Unified · Split

5 files
  1. gcc/libcpp/include/cpp-id-data.h +0 −82
  2. gcc/libcpp/include/cpplib.h +238 −150
  3. gcc/libcpp/include/line-map.h +310 −210
  4. gcc/libcpp/include/mkdeps.h +1 −1
  5. gcc/libcpp/include/symtab.h +1 −1
gcc/libcpp/include/cpp-id-data.h+0−82
@@ -1,82 +0,0 @@
1/* Structures that hang off cpp_identifier, for PCH.
2 Copyright (C) 1986-2018 Free Software Foundation, Inc.
3
4This program is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the
6Free Software Foundation; either version 3, or (at your option) any
7later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; see the file COPYING3. If not see
16<http://www.gnu.org/licenses/>. */
17
18#include "cpplib.h"
19
20#if !defined (HAVE_UCHAR) && !defined (IN_GCC)
21typedef unsigned char uchar;
22#endif
23
24#define UC (const unsigned char *) /* Intended use: UC"string" */
25
26/* Chained list of answers to an assertion. */
27struct GTY(()) answer {
28 struct answer *next;
29 unsigned int count;
30 cpp_token GTY ((length ("%h.count"))) first[1];
31};
32
33/* Each macro definition is recorded in a cpp_macro structure.
34 Variadic macros cannot occur with traditional cpp. */
35struct GTY(()) cpp_macro {
36 /* Parameters, if any. If parameter names use extended identifiers,
37 the original spelling of those identifiers, not the canonical
38 UTF-8 spelling, goes here. */
39 cpp_hashnode ** GTY ((nested_ptr (union tree_node,
40 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
41 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
42 length ("%h.paramc")))
43 params;
44
45 /* Replacement tokens (ISO) or replacement text (traditional). See
46 comment at top of cpptrad.c for how traditional function-like
47 macros are encoded. */
48 union cpp_macro_u
49 {
50 cpp_token * GTY ((tag ("0"), length ("%0.count"))) tokens;
51 const unsigned char * GTY ((tag ("1"))) text;
52 } GTY ((desc ("%1.traditional"))) exp;
53
54 /* Definition line number. */
55 source_location line;
56
57 /* Number of tokens in expansion, or bytes for traditional macros. */
58 unsigned int count;
59
60 /* Number of parameters. */
61 unsigned short paramc;
62
63 /* If a function-like macro. */
64 unsigned int fun_like : 1;
65
66 /* If a variadic macro. */
67 unsigned int variadic : 1;
68
69 /* If macro defined in system header. */
70 unsigned int syshdr : 1;
71
72 /* Nonzero if it has been expanded or had its existence tested. */
73 unsigned int used : 1;
74
75 /* Indicate which field of 'exp' is in use. */
76 unsigned int traditional : 1;
77
78 /* Indicate whether the tokens include extra CPP_PASTE tokens at the
79 end to track invalid redefinitions with consecutive CPP_PASTE
80 tokens. */
81 unsigned int extra_tokens : 1;
82};
gcc/libcpp/include/cpplib.h+238−150
@@ -1,5 +1,5 @@
1/* Definitions for CPP library.1/* Definitions for CPP library.
2 Copyright (C) 1995-2018 Free Software Foundation, Inc.2 Copyright (C) 1995-2019 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
@@ -36,7 +36,6 @@ typedef struct cpp_macro cpp_macro; · 30 unmodified lines
36typedef struct cpp_callbacks cpp_callbacks;36typedef struct cpp_callbacks cpp_callbacks;
37typedef struct cpp_dir cpp_dir;37typedef struct cpp_dir cpp_dir;
38 38
39struct answer;
40struct _cpp_file;39struct _cpp_file;
41 40
42/* The first three groups, apart from '=', can appear in preprocessor41/* The first three groups, apart from '=', can appear in preprocessor
@@ -168,8 +167,9 @@ enum cpp_ttype · 125 unmodified lines
168#undef TK167#undef TK
169 168
170/* C language kind, used when calling cpp_create_reader. */169/* C language kind, used when calling cpp_create_reader. */
171enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17,170enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
172 CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,171 CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,
172 CLK_STDC2X,
173 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,173 CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
174 CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,174 CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
175 CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};175 CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
@@ -240,8 +240,10 @@ struct GTY(()) cpp_identifier { · 64 unmodified lines
240/* A preprocessing token. This has been carefully packed and should240/* A preprocessing token. This has been carefully packed and should
241 occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */241 occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */
242struct GTY(()) cpp_token {242struct GTY(()) cpp_token {
243 source_location src_loc; /* Location of first char of token,243
244 together with range of full token. */244 /* Location of first char of token, together with range of full token. */
245 location_t src_loc;
246
245 ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */247 ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */
246 unsigned short flags; /* flags - see above */248 unsigned short flags; /* flags - see above */
247 249
@@ -550,6 +552,59 @@ struct cpp_options · 302 unmodified lines
550 bool canonical_system_headers;552 bool canonical_system_headers;
551};553};
552 554
555/* Diagnostic levels. To get a diagnostic without associating a
556 position in the translation unit with it, use cpp_error_with_line
557 with a line number of zero. */
558
559enum cpp_diagnostic_level {
560 /* Warning, an error with -Werror. */
561 CPP_DL_WARNING = 0,
562 /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */
563 CPP_DL_WARNING_SYSHDR,
564 /* Warning, an error with -pedantic-errors or -Werror. */
565 CPP_DL_PEDWARN,
566 /* An error. */
567 CPP_DL_ERROR,
568 /* An internal consistency check failed. Prints "internal error: ",
569 otherwise the same as CPP_DL_ERROR. */
570 CPP_DL_ICE,
571 /* An informative note following a warning. */
572 CPP_DL_NOTE,
573 /* A fatal error. */
574 CPP_DL_FATAL
575};
576
577/* Warning reason codes. Use a reason code of CPP_W_NONE for unclassified
578 warnings and diagnostics that are not warnings. */
579
580enum cpp_warning_reason {
581 CPP_W_NONE = 0,
582 CPP_W_DEPRECATED,
583 CPP_W_COMMENTS,
584 CPP_W_MISSING_INCLUDE_DIRS,
585 CPP_W_TRIGRAPHS,
586 CPP_W_MULTICHAR,
587 CPP_W_TRADITIONAL,
588 CPP_W_LONG_LONG,
589 CPP_W_ENDIF_LABELS,
590 CPP_W_NUM_SIGN_CHANGE,
591 CPP_W_VARIADIC_MACROS,
592 CPP_W_BUILTIN_MACRO_REDEFINED,
593 CPP_W_DOLLARS,
594 CPP_W_UNDEF,
595 CPP_W_UNUSED_MACROS,
596 CPP_W_CXX_OPERATOR_NAMES,
597 CPP_W_NORMALIZE,
598 CPP_W_INVALID_PCH,
599 CPP_W_WARNING_DIRECTIVE,
600 CPP_W_LITERAL_SUFFIX,
601 CPP_W_DATE_TIME,
602 CPP_W_PEDANTIC,
603 CPP_W_C90_C99_COMPAT,
604 CPP_W_CXX11_COMPAT,
605 CPP_W_EXPANSION_TO_DEFINED
606};
607
553/* Callback for header lookup for HEADER, which is the name of a608/* Callback for header lookup for HEADER, which is the name of a
554 source file. It is used as a method of last resort to find headers609 source file. It is used as a method of last resort to find headers
555 that are not otherwise found during the normal include processing.610 that are not otherwise found during the normal include processing.
@@ -571,12 +626,12 @@ struct cpp_callbacks · 15 unmodified lines
571 void (*file_change) (cpp_reader *, const line_map_ordinary *);626 void (*file_change) (cpp_reader *, const line_map_ordinary *);
572 627
573 void (*dir_change) (cpp_reader *, const char *);628 void (*dir_change) (cpp_reader *, const char *);
574 void (*include) (cpp_reader *, source_location, const unsigned char *,629 void (*include) (cpp_reader *, location_t, const unsigned char *,
575 const char *, int, const cpp_token **);630 const char *, int, const cpp_token **);
576 void (*define) (cpp_reader *, source_location, cpp_hashnode *);631 void (*define) (cpp_reader *, location_t, cpp_hashnode *);
577 void (*undef) (cpp_reader *, source_location, cpp_hashnode *);632 void (*undef) (cpp_reader *, location_t, cpp_hashnode *);
578 void (*ident) (cpp_reader *, source_location, const cpp_string *);633 void (*ident) (cpp_reader *, location_t, const cpp_string *);
579 void (*def_pragma) (cpp_reader *, source_location);634 void (*def_pragma) (cpp_reader *, location_t);
580 int (*valid_pch) (cpp_reader *, const char *, int);635 int (*valid_pch) (cpp_reader *, const char *, int);
581 void (*read_pch) (cpp_reader *, const char *, int, const char *);636 void (*read_pch) (cpp_reader *, const char *, int, const char *);
582 missing_header_cb missing_header;637 missing_header_cb missing_header;
@@ -587,26 +642,29 @@ struct cpp_callbacks · 4 unmodified lines
587 642
588 /* Called to emit a diagnostic. This callback receives the643 /* Called to emit a diagnostic. This callback receives the
589 translated message. */644 translated message. */
590 bool (*error) (cpp_reader *, int, int, rich_location *,645 bool (*diagnostic) (cpp_reader *,
591 const char *, va_list *)646 enum cpp_diagnostic_level,
647 enum cpp_warning_reason,
648 rich_location *,
649 const char *, va_list *)
592 ATTRIBUTE_FPTR_PRINTF(5,0);650 ATTRIBUTE_FPTR_PRINTF(5,0);
593 651
594 /* Callbacks for when a macro is expanded, or tested (whether652 /* Callbacks for when a macro is expanded, or tested (whether
595 defined or not at the time) in #ifdef, #ifndef or "defined". */653 defined or not at the time) in #ifdef, #ifndef or "defined". */
596 void (*used_define) (cpp_reader *, source_location, cpp_hashnode *);654 void (*used_define) (cpp_reader *, location_t, cpp_hashnode *);
597 void (*used_undef) (cpp_reader *, source_location, cpp_hashnode *);655 void (*used_undef) (cpp_reader *, location_t, cpp_hashnode *);
598 /* Called before #define and #undef or other macro definition656 /* Called before #define and #undef or other macro definition
599 changes are processed. */657 changes are processed. */
600 void (*before_define) (cpp_reader *);658 void (*before_define) (cpp_reader *);
601 /* Called whenever a macro is expanded or tested.659 /* Called whenever a macro is expanded or tested.
602 Second argument is the location of the start of the current expansion. */660 Second argument is the location of the start of the current expansion. */
603 void (*used) (cpp_reader *, source_location, cpp_hashnode *);661 void (*used) (cpp_reader *, location_t, cpp_hashnode *);
604 662
605 /* Callback to identify whether an attribute exists. */663 /* Callback to identify whether an attribute exists. */
606 int (*has_attribute) (cpp_reader *);664 int (*has_attribute) (cpp_reader *);
607 665
608 /* Callback that can change a user builtin into normal macro. */666 /* Callback that can change a user lazy into normal macro. */
609 bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *);667 void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned);
610 668
611 /* Callback to parse SOURCE_DATE_EPOCH from environment. */669 /* Callback to parse SOURCE_DATE_EPOCH from environment. */
612 time_t (*get_source_date_epoch) (cpp_reader *);670 time_t (*get_source_date_epoch) (cpp_reader *);
@@ -620,7 +678,7 @@ struct cpp_callbacks · 7 unmodified lines
620 The content contains the opening slash-star (or slash-slash),678 The content contains the opening slash-star (or slash-slash),
621 and for C-style comments contains the closing star-slash. For679 and for C-style comments contains the closing star-slash. For
622 C++-style comments it does not include the terminating newline. */680 C++-style comments it does not include the terminating newline. */
623 void (*comment) (cpp_reader *, source_location, const unsigned char *,681 void (*comment) (cpp_reader *, location_t, const unsigned char *,
624 size_t);682 size_t);
625 683
626 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro684 /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
@@ -671,14 +729,81 @@ struct cpp_dir · 44 unmodified lines
671 dev_t dev;729 dev_t dev;
672};730};
673 731
674/* The structure of a node in the hash table. The hash table has732/* The kind of the cpp_macro. */
675 entries for all identifiers: either macros defined by #define733enum cpp_macro_kind {
676 commands (type NT_MACRO), assertions created with #assert734 cmk_macro, /* An ISO macro (token expansion). */
677 (NT_ASSERTION), or neither of the above (NT_VOID). Builtin macros735 cmk_assert, /* An assertion. */
678 like __LINE__ are flagged NODE_BUILTIN. Poisoned identifiers are736 cmk_traditional /* A traditional macro (text expansion). */
679 flagged NODE_POISONED. NODE_OPERATOR (C++ only) indicates an737};
680 identifier that behaves like an operator such as "xor".738
681 NODE_DIAGNOSTIC is for speed in lex_token: it indicates a739/* Each macro definition is recorded in a cpp_macro structure.
740 Variadic macros cannot occur with traditional cpp. */
741struct GTY(()) cpp_macro {
742 union cpp_parm_u
743 {
744 /* Parameters, if any. If parameter names use extended identifiers,
745 the original spelling of those identifiers, not the canonical
746 UTF-8 spelling, goes here. */
747 cpp_hashnode ** GTY ((tag ("false"),
748 nested_ptr (union tree_node,
749 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
750 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
751 length ("%1.paramc"))) params;
752
753 /* If this is an assertion, the next one in the chain. */
754 cpp_macro *GTY ((tag ("true"))) next;
755 } GTY ((desc ("%1.kind == cmk_assert"))) parm;
756
757 /* Definition line number. */
758 location_t line;
759
760 /* Number of tokens in body, or bytes for traditional macros. */
761 /* Do we really need 2^32-1 range here? */
762 unsigned int count;
763
764 /* Number of parameters. */
765 unsigned short paramc;
766
767 /* Non-zero if this is a user-lazy macro, value provided by user. */
768 unsigned char lazy;
769
770 /* The kind of this macro (ISO, trad or assert) */
771 unsigned kind : 2;
772
773 /* If a function-like macro. */
774 unsigned int fun_like : 1;
775
776 /* If a variadic macro. */
777 unsigned int variadic : 1;
778
779 /* If macro defined in system header. */
780 unsigned int syshdr : 1;
781
782 /* Nonzero if it has been expanded or had its existence tested. */
783 unsigned int used : 1;
784
785 /* Indicate whether the tokens include extra CPP_PASTE tokens at the
786 end to track invalid redefinitions with consecutive CPP_PASTE
787 tokens. */
788 unsigned int extra_tokens : 1;
789
790 /* 1 bits spare (32-bit). 33 on 64-bit target. */
791
792 union cpp_exp_u
793 {
794 /* Trailing array of replacement tokens (ISO), or assertion body value. */
795 cpp_token GTY ((tag ("false"), length ("%1.count"))) tokens[1];
796
797 /* Pointer to replacement text (traditional). See comment at top
798 of cpptrad.c for how traditional function-like macros are
799 encoded. */
800 const unsigned char *GTY ((tag ("true"))) text;
801 } GTY ((desc ("%1.kind == cmk_traditional"))) exp;
802};
803
804/* Poisoned identifiers are flagged NODE_POISONED. NODE_OPERATOR (C++
805 only) indicates an identifier that behaves like an operator such as
806 "xor". NODE_DIAGNOSTIC is for speed in lex_token: it indicates a
682 diagnostic may be required for this node. Currently this only807 diagnostic may be required for this node. Currently this only
683 applies to __VA_ARGS__, poisoned identifiers, and -Wc++-compat808 applies to __VA_ARGS__, poisoned identifiers, and -Wc++-compat
684 warnings about NODE_OPERATOR. */809 warnings about NODE_OPERATOR. */
@@ -686,21 +811,21 @@ struct cpp_dir · 1 unmodified line
686/* Hash node flags. */811/* Hash node flags. */
687#define NODE_OPERATOR (1 << 0) /* C++ named operator. */812#define NODE_OPERATOR (1 << 0) /* C++ named operator. */
688#define NODE_POISONED (1 << 1) /* Poisoned identifier. */813#define NODE_POISONED (1 << 1) /* Poisoned identifier. */
689#define NODE_BUILTIN (1 << 2) /* Builtin macro. */814#define NODE_DIAGNOSTIC (1 << 2) /* Possible diagnostic when lexed. */
690#define NODE_DIAGNOSTIC (1 << 3) /* Possible diagnostic when lexed. */815#define NODE_WARN (1 << 3) /* Warn if redefined or undefined. */
691#define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */816#define NODE_DISABLED (1 << 4) /* A disabled macro. */
692#define NODE_DISABLED (1 << 5) /* A disabled macro. */817#define NODE_USED (1 << 5) /* Dumped with -dU. */
693#define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */818#define NODE_CONDITIONAL (1 << 6) /* Conditional macro */
694#define NODE_USED (1 << 7) /* Dumped with -dU. */819#define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */
695#define NODE_CONDITIONAL (1 << 8) /* Conditional macro */
696#define NODE_WARN_OPERATOR (1 << 9) /* Warn about C++ named operator. */
697 820
698/* Different flavors of hash node. */821/* Different flavors of hash node. */
699enum node_type822enum node_type
700{823{
701 NT_VOID = 0, /* No definition yet. */824 NT_VOID = 0, /* Maybe an assert? */
702 NT_MACRO, /* A macro of some form. */825 NT_MACRO_ARG, /* A macro arg. */
703 NT_ASSERTION /* Predicate for #assert. */826 NT_USER_MACRO, /* A user macro. */
827 NT_BUILTIN_MACRO, /* A builtin macro. */
828 NT_MACRO_MASK = NT_USER_MACRO /* Mask for either macro kind. */
704};829};
705 830
706/* Different flavors of builtin macro. _Pragma is an operator, but we831/* Different flavors of builtin macro. _Pragma is an operator, but we
@@ -717,46 +842,27 @@ enum cpp_builtin_type · 10 unmodified lines
717 BT_PRAGMA, /* `_Pragma' operator */842 BT_PRAGMA, /* `_Pragma' operator */
718 BT_TIMESTAMP, /* `__TIMESTAMP__' */843 BT_TIMESTAMP, /* `__TIMESTAMP__' */
719 BT_COUNTER, /* `__COUNTER__' */844 BT_COUNTER, /* `__COUNTER__' */
720 BT_HAS_ATTRIBUTE, /* `__has_attribute__(x)' */845 BT_HAS_ATTRIBUTE /* `__has_attribute__(x)' */
721 BT_FIRST_USER, /* User defined builtin macros. */
722 BT_LAST_USER = BT_FIRST_USER + 63
723};846};
724 847
725#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))848#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
726#define HT_NODE(NODE) ((ht_identifier *) (NODE))849#define HT_NODE(NODE) (&(NODE)->ident)
727#define NODE_LEN(NODE) HT_LEN (&(NODE)->ident)850#define NODE_LEN(NODE) HT_LEN (HT_NODE (NODE))
728#define NODE_NAME(NODE) HT_STR (&(NODE)->ident)851#define NODE_NAME(NODE) HT_STR (HT_NODE (NODE))
729
730/* Specify which field, if any, of the union is used. */
731
732enum {
733 NTV_MACRO,
734 NTV_ANSWER,
735 NTV_BUILTIN,
736 NTV_ARGUMENT,
737 NTV_NONE
738};
739
740#define CPP_HASHNODE_VALUE_IDX(HNODE) \
741 ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \
742 : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \
743 ? NTV_BUILTIN : NTV_MACRO) \
744 : HNODE.type == NT_ASSERTION ? NTV_ANSWER \
745 : NTV_NONE)
746 852
747/* The common part of an identifier node shared amongst all 3 C front853/* The common part of an identifier node shared amongst all 3 C front
748 ends. Also used to store CPP identifiers, which are a superset of854 ends. Also used to store CPP identifiers, which are a superset of
749 identifiers in the grammatical sense. */855 identifiers in the grammatical sense. */
750 856
751union GTY(()) _cpp_hashnode_value {857union GTY(()) _cpp_hashnode_value {
752 /* If a macro. */858 /* Assert (maybe NULL) */
753 cpp_macro * GTY((tag ("NTV_MACRO"))) macro;859 cpp_macro * GTY((tag ("NT_VOID"))) answers;
754 /* Answers to an assertion. */860 /* Macro (never NULL) */
755 struct answer * GTY ((tag ("NTV_ANSWER"))) answers;861 cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
756 /* Code for a builtin macro. */862 /* Code for a builtin macro. */
757 enum cpp_builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin;863 enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
758 /* Macro argument index. */864 /* Macro argument index. */
759 unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index;865 unsigned short GTY ((tag ("NT_MACRO_ARG"))) arg_index;
760};866};
761 867
762struct GTY(()) cpp_hashnode {868struct GTY(()) cpp_hashnode {
@@ -766,10 +872,12 @@ struct GTY(()) cpp_hashnode { · 3 unmodified lines
766 then index into directive table.872 then index into directive table.
767 Otherwise, a NODE_OPERATOR. */873 Otherwise, a NODE_OPERATOR. */
768 unsigned char rid_code; /* Rid code - for front ends. */874 unsigned char rid_code; /* Rid code - for front ends. */
769 ENUM_BITFIELD(node_type) type : 6; /* CPP node type. */875 ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */
770 unsigned int flags : 10; /* CPP flags. */876 unsigned int flags : 8; /* CPP flags. */
877
878 /* 6 bits spare (plus another 32 on 64-bit hosts). */
771 879
772 union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value;880 union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
773};881};
774 882
775/* A class for iterating through the source locations within a883/* A class for iterating through the source locations within a
@@ -778,13 +886,13 @@ struct GTY(()) cpp_hashnode { · 2 unmodified lines
778 886
779class cpp_string_location_reader {887class cpp_string_location_reader {
780 public:888 public:
781 cpp_string_location_reader (source_location src_loc,889 cpp_string_location_reader (location_t src_loc,
782 line_maps *line_table);890 line_maps *line_table);
783 891
784 source_range get_next ();892 source_range get_next ();
785 893
786 private:894 private:
787 source_location m_loc;895 location_t m_loc;
788 int m_offset_per_column;896 int m_offset_per_column;
789 line_maps *m_line_table;897 line_maps *m_line_table;
790};898};
@@ -889,11 +997,32 @@ extern int cpp_avoid_paste (cpp_reader *, const cpp_token *, · 98 unmodified lines
889 const cpp_token *);997 const cpp_token *);
890extern const cpp_token *cpp_get_token (cpp_reader *);998extern const cpp_token *cpp_get_token (cpp_reader *);
891extern const cpp_token *cpp_get_token_with_location (cpp_reader *,999extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
892 source_location *);1000 location_t *);
893extern bool cpp_fun_like_macro_p (cpp_hashnode *);1001inline bool cpp_user_macro_p (const cpp_hashnode *node)
1002{
1003 return node->type == NT_USER_MACRO;
1004}
1005inline bool cpp_builtin_macro_p (const cpp_hashnode *node)
1006{
1007 return node->type == NT_BUILTIN_MACRO;
1008}
1009inline bool cpp_macro_p (const cpp_hashnode *node)
1010{
1011 return node->type & NT_MACRO_MASK;
1012}
1013
1014/* Returns true if NODE is a function-like user macro. */
1015inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
1016{
1017 return cpp_user_macro_p (node) && node->value.macro->fun_like;
1018}
1019
894extern const unsigned char *cpp_macro_definition (cpp_reader *,1020extern const unsigned char *cpp_macro_definition (cpp_reader *,
895 cpp_hashnode *);1021 cpp_hashnode *);
896extern source_location cpp_macro_definition_location (cpp_hashnode *);1022inline location_t cpp_macro_definition_location (cpp_hashnode *node)
1023{
1024 return node->value.macro->line;
1025}
897extern void _cpp_backup_tokens (cpp_reader *, unsigned int);1026extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
898extern const cpp_token *cpp_peek_token (cpp_reader *, int);1027extern const cpp_token *cpp_peek_token (cpp_reader *, int);
899 1028
@@ -926,6 +1055,9 @@ extern void cpp_assert (cpp_reader *, const char *); · 26 unmodified lines
926extern void cpp_undef (cpp_reader *, const char *);1055extern void cpp_undef (cpp_reader *, const char *);
927extern void cpp_unassert (cpp_reader *, const char *);1056extern void cpp_unassert (cpp_reader *, const char *);
928 1057
1058/* Mark a node as a lazily defined macro. */
1059extern void cpp_define_lazily (cpp_reader *, cpp_hashnode *node, unsigned N);
1060
929/* Undefine all macros and assertions. */1061/* Undefine all macros and assertions. */
930extern void cpp_undef_all (cpp_reader *);1062extern void cpp_undef_all (cpp_reader *);
931 1063
@@ -996,7 +1128,7 @@ struct cpp_num · 64 unmodified lines
996/* Classify a CPP_NUMBER token. The return value is a combination of1128/* Classify a CPP_NUMBER token. The return value is a combination of
997 the flags from the above sets. */1129 the flags from the above sets. */
998extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,1130extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
999 const char **, source_location);1131 const char **, location_t);
1000 1132
1001/* Return the classification flags for a float suffix. */1133/* Return the classification flags for a float suffix. */
1002extern unsigned int cpp_interpret_float_suffix (cpp_reader *, const char *,1134extern unsigned int cpp_interpret_float_suffix (cpp_reader *, const char *,
@@ -1014,99 +1146,55 @@ extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *, · 11 unmodified lines
1014 others assumed clear, to fill out a cpp_num structure. */1146 others assumed clear, to fill out a cpp_num structure. */
1015cpp_num cpp_num_sign_extend (cpp_num, size_t);1147cpp_num cpp_num_sign_extend (cpp_num, size_t);
1016 1148
1017/* Diagnostic levels. To get a diagnostic without associating a
1018 position in the translation unit with it, use cpp_error_with_line
1019 with a line number of zero. */
1020
1021enum {
1022 /* Warning, an error with -Werror. */
1023 CPP_DL_WARNING = 0,
1024 /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */
1025 CPP_DL_WARNING_SYSHDR,
1026 /* Warning, an error with -pedantic-errors or -Werror. */
1027 CPP_DL_PEDWARN,
1028 /* An error. */
1029 CPP_DL_ERROR,
1030 /* An internal consistency check failed. Prints "internal error: ",
1031 otherwise the same as CPP_DL_ERROR. */
1032 CPP_DL_ICE,
1033 /* An informative note following a warning. */
1034 CPP_DL_NOTE,
1035 /* A fatal error. */
1036 CPP_DL_FATAL
1037};
1038
1039/* Warning reason codes. Use a reason code of zero for unclassified warnings
1040 and errors that are not warnings. */
1041enum {
1042 CPP_W_NONE = 0,
1043 CPP_W_DEPRECATED,
1044 CPP_W_COMMENTS,
1045 CPP_W_MISSING_INCLUDE_DIRS,
1046 CPP_W_TRIGRAPHS,
1047 CPP_W_MULTICHAR,
1048 CPP_W_TRADITIONAL,
1049 CPP_W_LONG_LONG,
1050 CPP_W_ENDIF_LABELS,
1051 CPP_W_NUM_SIGN_CHANGE,
1052 CPP_W_VARIADIC_MACROS,
1053 CPP_W_BUILTIN_MACRO_REDEFINED,
1054 CPP_W_DOLLARS,
1055 CPP_W_UNDEF,
1056 CPP_W_UNUSED_MACROS,
1057 CPP_W_CXX_OPERATOR_NAMES,
1058 CPP_W_NORMALIZE,
1059 CPP_W_INVALID_PCH,
1060 CPP_W_WARNING_DIRECTIVE,
1061 CPP_W_LITERAL_SUFFIX,
1062 CPP_W_DATE_TIME,
1063 CPP_W_PEDANTIC,
1064 CPP_W_C90_C99_COMPAT,
1065 CPP_W_CXX11_COMPAT,
1066 CPP_W_EXPANSION_TO_DEFINED
1067};
1068
1069/* Output a diagnostic of some kind. */1149/* Output a diagnostic of some kind. */
1070extern bool cpp_error (cpp_reader *, int, const char *msgid, ...)1150extern bool cpp_error (cpp_reader *, enum cpp_diagnostic_level,
1151 const char *msgid, ...)
1071 ATTRIBUTE_PRINTF_3;1152 ATTRIBUTE_PRINTF_3;
1072extern bool cpp_warning (cpp_reader *, int, const char *msgid, ...)1153extern bool cpp_warning (cpp_reader *, enum cpp_warning_reason,
1154 const char *msgid, ...)
1073 ATTRIBUTE_PRINTF_3;1155 ATTRIBUTE_PRINTF_3;
1074extern bool cpp_pedwarning (cpp_reader *, int, const char *msgid, ...)1156extern bool cpp_pedwarning (cpp_reader *, enum cpp_warning_reason,
1157 const char *msgid, ...)
1075 ATTRIBUTE_PRINTF_3;1158 ATTRIBUTE_PRINTF_3;
1076extern bool cpp_warning_syshdr (cpp_reader *, int, const char *msgid, ...)1159extern bool cpp_warning_syshdr (cpp_reader *, enum cpp_warning_reason reason,
1160 const char *msgid, ...)
1077 ATTRIBUTE_PRINTF_3;1161 ATTRIBUTE_PRINTF_3;
1078 1162
1079/* Output a diagnostic with "MSGID: " preceding the1163/* Output a diagnostic with "MSGID: " preceding the
1080 error string of errno. No location is printed. */1164 error string of errno. No location is printed. */
1081extern bool cpp_errno (cpp_reader *, int, const char *msgid);1165extern bool cpp_errno (cpp_reader *, enum cpp_diagnostic_level,
1166 const char *msgid);
1082/* Similarly, but with "FILENAME: " instead of "MSGID: ", where1167/* Similarly, but with "FILENAME: " instead of "MSGID: ", where
1083 the filename is not localized. */1168 the filename is not localized. */
1084extern bool cpp_errno_filename (cpp_reader *, int, const char *filename,1169extern bool cpp_errno_filename (cpp_reader *, enum cpp_diagnostic_level,
1085 source_location loc);1170 const char *filename, location_t loc);
1086 1171
1087/* Same as cpp_error, except additionally specifies a position as a1172/* Same as cpp_error, except additionally specifies a position as a
1088 (translation unit) physical line and physical column. If the line is1173 (translation unit) physical line and physical column. If the line is
1089 zero, then no location is printed. */1174 zero, then no location is printed. */
1090extern bool cpp_error_with_line (cpp_reader *, int, source_location,1175extern bool cpp_error_with_line (cpp_reader *, enum cpp_diagnostic_level,
1091 unsigned, const char *msgid, ...)1176 location_t, unsigned,
1177 const char *msgid, ...)
1092 ATTRIBUTE_PRINTF_5;1178 ATTRIBUTE_PRINTF_5;
1093extern bool cpp_warning_with_line (cpp_reader *, int, source_location,1179extern bool cpp_warning_with_line (cpp_reader *, enum cpp_warning_reason,
1094 unsigned, const char *msgid, ...)1180 location_t, unsigned,
1181 const char *msgid, ...)
1095 ATTRIBUTE_PRINTF_5;1182 ATTRIBUTE_PRINTF_5;
1096extern bool cpp_pedwarning_with_line (cpp_reader *, int, source_location,1183extern bool cpp_pedwarning_with_line (cpp_reader *, enum cpp_warning_reason,
1097 unsigned, const char *msgid, ...)1184 location_t, unsigned,
1185 const char *msgid, ...)
1098 ATTRIBUTE_PRINTF_5;1186 ATTRIBUTE_PRINTF_5;
1099extern bool cpp_warning_with_line_syshdr (cpp_reader *, int, source_location,1187extern bool cpp_warning_with_line_syshdr (cpp_reader *, enum cpp_warning_reason,
1100 unsigned, const char *msgid, ...)1188 location_t, unsigned,
1189 const char *msgid, ...)
1101 ATTRIBUTE_PRINTF_5;1190 ATTRIBUTE_PRINTF_5;
1102 1191
1103extern bool cpp_error_at (cpp_reader * pfile, int level,1192extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
1104 source_location src_loc, const char *msgid, ...)1193 location_t src_loc, const char *msgid, ...)
1105 ATTRIBUTE_PRINTF_4;1194 ATTRIBUTE_PRINTF_4;
1106 1195
1107extern bool cpp_error_at (cpp_reader * pfile, int level,1196extern bool cpp_error_at (cpp_reader * pfile, enum cpp_diagnostic_level,
1108 rich_location *richloc, const char *msgid,1197 rich_location *richloc, const char *msgid, ...)
1109 ...)
1110 ATTRIBUTE_PRINTF_4;1198 ATTRIBUTE_PRINTF_4;
1111 1199
1112/* In lex.c */1200/* In lex.c */
@@ -1133,7 +1221,7 @@ typedef struct · 20 unmodified lines
1133 char *comment;1221 char *comment;
1134 1222
1135 /* source location for the given comment. */1223 /* source location for the given comment. */
1136 source_location sloc;1224 location_t sloc;
1137} cpp_comment;1225} cpp_comment;
1138 1226
1139/* Structure holding all comments for a given cpp_reader. */1227/* Structure holding all comments for a given cpp_reader. */
@@ -1172,7 +1260,7 @@ extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, · 32 unmodified lines
1172 1260
1173/* In files.c */1261/* In files.c */
1174extern bool cpp_included (cpp_reader *, const char *);1262extern bool cpp_included (cpp_reader *, const char *);
1175extern bool cpp_included_before (cpp_reader *, const char *, source_location);1263extern bool cpp_included_before (cpp_reader *, const char *, location_t);
1176extern void cpp_make_system_header (cpp_reader *, int, int);1264extern void cpp_make_system_header (cpp_reader *, int, int);
1177extern bool cpp_push_include (cpp_reader *, const char *);1265extern bool cpp_push_include (cpp_reader *, const char *);
1178extern bool cpp_push_default_include (cpp_reader *, const char *);1266extern bool cpp_push_default_include (cpp_reader *, const char *);
@@ -1195,7 +1283,7 @@ extern int cpp_read_state (cpp_reader *, const char *, FILE *, · 16 unmodified lines
1195 struct save_macro_data *);1283 struct save_macro_data *);
1196 1284
1197/* In lex.c */1285/* In lex.c */
1198extern void cpp_force_token_locations (cpp_reader *, source_location *);1286extern void cpp_force_token_locations (cpp_reader *, location_t);
1199extern void cpp_stop_forcing_token_locations (cpp_reader *);1287extern void cpp_stop_forcing_token_locations (cpp_reader *);
1200 1288
1201/* In expr.c */1289/* In expr.c */
gcc/libcpp/include/line-map.h+310−210
@@ -1,5 +1,5 @@
1/* Map (unsigned int) keys to (source file, line, column) triples.1/* Map (unsigned int) keys to (source file, line, column) triples.
2 Copyright (C) 2001-2018 Free Software Foundation, Inc.2 Copyright (C) 2001-2019 Free Software Foundation, Inc.
3 3
4This program is free software; you can redistribute it and/or modify it4This program is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the5under the terms of the GNU General Public License as published by the
@@ -49,36 +49,34 @@ along with this program; see the file COPYING3. If not see · 43 unmodified lines
49/* The type of line numbers. */49/* The type of line numbers. */
50typedef unsigned int linenum_type;50typedef unsigned int linenum_type;
51 51
52/* A type for doing arithmetic on line numbers. */
53typedef long long linenum_arith_t;
54
52/* A function for for use by qsort for comparing line numbers. */55/* A function for for use by qsort for comparing line numbers. */
53 56
54inline int compare (linenum_type lhs, linenum_type rhs)57inline int compare (linenum_type lhs, linenum_type rhs)
55{58{
56 /* Avoid truncation issues by using long long for the comparison,59 /* Avoid truncation issues by using linenum_arith_t for the comparison,
57 and only consider the sign of the result. */60 and only consider the sign of the result. */
58 long long diff = (long long)lhs - (long long)rhs;61 linenum_arith_t diff = (linenum_arith_t)lhs - (linenum_arith_t)rhs;
59 if (diff)62 if (diff)
60 return diff > 0 ? 1 : -1;63 return diff > 0 ? 1 : -1;
61 return 0;64 return 0;
62}65}
63 66
64/* Reason for creating a new line map with linemap_add. LC_ENTER is67/* Reason for creating a new line map with linemap_add. */
65 when including a new file, e.g. a #include directive in C.
66 LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
67 name or line number changes for neither of the above reasons
68 (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
69 but a filename of "" is not specially interpreted as standard
70 input. LC_ENTER_MACRO is when a macro expansion is about to start. */
71enum lc_reason68enum lc_reason
72{69{
73 LC_ENTER = 0,70 LC_ENTER = 0, /* Begin #include. */
74 LC_LEAVE,71 LC_LEAVE, /* Return to including file. */
75 LC_RENAME,72 LC_RENAME, /* Other reason for name change. */
76 LC_RENAME_VERBATIM,73 LC_RENAME_VERBATIM, /* Likewise, but "" != stdin. */
77 LC_ENTER_MACRO74 LC_ENTER_MACRO, /* Begin macro expansion. */
78 /* FIXME: add support for stringize and paste. */75 /* FIXME: add support for stringize and paste. */
76 LC_HWM /* High Water Mark. */
79};77};
80 78
81/* The typedef "source_location" is a key within the location database,79/* The typedef "location_t" is a key within the location database,
82 identifying a source location or macro expansion, along with range80 identifying a source location or macro expansion, along with range
83 information, and (optionally) a pointer for use by gcc.81 information, and (optionally) a pointer for use by gcc.
84 82
@@ -168,7 +166,7 @@ enum lc_reason · 83 unmodified lines
168 | Beyond this point, ordinary linemaps have 0 bits per column:166 | Beyond this point, ordinary linemaps have 0 bits per column:
169 | each increment of the value corresponds to a new source line.167 | each increment of the value corresponds to a new source line.
170 |168 |
171 0x70000000 | LINE_MAP_MAX_SOURCE_LOCATION169 0x70000000 | LINE_MAP_MAX_LOCATION
172 | Beyond the point, we give up on ordinary maps; attempts to170 | Beyond the point, we give up on ordinary maps; attempts to
173 | create locations in them lead to UNKNOWN_LOCATION (0).171 | create locations in them lead to UNKNOWN_LOCATION (0).
174 |172 |
@@ -187,7 +185,7 @@ enum lc_reason · 12 unmodified lines
187 | macromap[1]->start_location | Start of macro map 1185 | macromap[1]->start_location | Start of macro map 1
188 -----------+-------------------------------+-------------------------------186 -----------+-------------------------------+-------------------------------
189 | macromap[0]->start_location | Start of macro map 0187 | macromap[0]->start_location | Start of macro map 0
190 0x7fffffff | MAX_SOURCE_LOCATION | Also used as a mask for188 0x7fffffff | MAX_LOCATION_T | Also used as a mask for
191 | | accessing the ad-hoc data table189 | | accessing the ad-hoc data table
192 -----------+-------------------------------+-------------------------------190 -----------+-------------------------------+-------------------------------
193 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index191 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index
@@ -288,9 +286,9 @@ enum lc_reason · 94 unmodified lines
288 finish == ordmap->start + (23 << 12) + (19 << 5)286 finish == ordmap->start + (23 << 12) + (19 << 5)
289 == ordmap->start + 0x17260287 == ordmap->start + 0x17260
290 288
291 To further see how source_location works in practice, see the289 To further see how location_t works in practice, see the
292 worked example in libcpp/location-example.txt. */290 worked example in libcpp/location-example.txt. */
293typedef unsigned int source_location;291typedef unsigned int location_t;
294 292
295/* Do not track column numbers higher than this one. As a result, the293/* Do not track column numbers higher than this one. As a result, the
296 range of column_bits is [12, 18] (or 0 if column numbers are294 range of column_bits is [12, 18] (or 0 if column numbers are
@@ -300,12 +298,15 @@ const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); · 3 unmodified lines
300/* Do not pack ranges if locations get higher than this.298/* Do not pack ranges if locations get higher than this.
301 If you change this, update:299 If you change this, update:
302 gcc.dg/plugin/location-overflow-test-*.c. */300 gcc.dg/plugin/location-overflow-test-*.c. */
303const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;301const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;
304 302
305/* Do not track column numbers if locations get higher than this.303/* Do not track column numbers if locations get higher than this.
306 If you change this, update:304 If you change this, update:
307 gcc.dg/plugin/location-overflow-test-*.c. */305 gcc.dg/plugin/location-overflow-test-*.c. */
308const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;306const location_t LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;
307
308/* Highest possible source location encoded within an ordinary map. */
309const location_t LINE_MAP_MAX_LOCATION = 0x70000000;
309 310
310/* A range of source locations.311/* A range of source locations.
311 312
@@ -317,15 +318,15 @@ const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; · 5 unmodified lines
317 let's do it the simple way, as a pair. */318 let's do it the simple way, as a pair. */
318struct GTY(()) source_range319struct GTY(()) source_range
319{320{
320 source_location m_start;321 location_t m_start;
321 source_location m_finish;322 location_t m_finish;
322 323
323 /* We avoid using constructors, since various structs that324 /* We avoid using constructors, since various structs that
324 don't yet have constructors will embed instances of325 don't yet have constructors will embed instances of
325 source_range. */326 source_range. */
326 327
327 /* Make a source_range from a source_location. */328 /* Make a source_range from a location_t. */
328 static source_range from_location (source_location loc)329 static source_range from_location (location_t loc)
329 {330 {
330 source_range result;331 source_range result;
331 result.m_start = loc;332 result.m_start = loc;
@@ -333,9 +334,9 @@ struct GTY(()) source_range · 1 unmodified line
333 return result;334 return result;
334 }335 }
335 336
336 /* Make a source_range from a pair of source_location. */337 /* Make a source_range from a pair of location_t. */
337 static source_range from_locations (source_location start,338 static source_range from_locations (location_t start,
338 source_location finish)339 location_t finish)
339 {340 {
340 source_range result;341 source_range result;
341 result.m_start = start;342 result.m_start = start;
@@ -377,11 +378,13 @@ typedef size_t (*line_map_round_alloc_size_func) (size_t); · 35 unmodified lines
377 location of the expansion point of PLUS. That location is mapped in378 location of the expansion point of PLUS. That location is mapped in
378 the map that is active right before the location of the invocation379 the map that is active right before the location of the invocation
379 of PLUS. */380 of PLUS. */
380struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map {
381 source_location start_location;
382 381
383 /* The reason for creation of this line map. */382/* This contains GTY mark-up to support precompiled headers.
384 ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;383 line_map is an abstract class, only derived objects exist. */
384struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map {
385 location_t start_location;
386
387 /* Size and alignment is (usually) 4 bytes. */
385};388};
386 389
387/* An ordinary line map encodes physical source locations. Those390/* An ordinary line map encodes physical source locations. Those
@@ -395,15 +398,14 @@ struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map { · 7 unmodified lines
395 (The top line is line 1 and the leftmost column is column 1; line/column 0398 (The top line is line 1 and the leftmost column is column 1; line/column 0
396 means "entire file/line" or "unknown line/column" or "not applicable".)399 means "entire file/line" or "unknown line/column" or "not applicable".)
397 400
398 The highest possible source location is MAX_SOURCE_LOCATION. */401 The highest possible source location is MAX_LOCATION_T. */
399struct GTY((tag ("1"))) line_map_ordinary : public line_map {402struct GTY((tag ("1"))) line_map_ordinary : public line_map {
400 const char *to_file;403 /* Base class is 4 bytes. */
401 linenum_type to_line;
402 404
403 /* An index into the set that gives the line mapping at whose end405 /* 4 bytes of integers, each 1 byte for easy extraction/insertion. */
404 the current one was included. File(s) at the bottom of the406
405 include stack have this set to -1. */407 /* The reason for creation of this line map. */
406 int included_from;408 ENUM_BITFIELD (lc_reason) reason : 8;
407 409
408 /* SYSP is one for a system header, two for a C system header file410 /* SYSP is one for a system header, two for a C system header file
409 that therefore needs to be extern "C" protected in C++, and zero411 that therefore needs to be extern "C" protected in C++, and zero
@@ -411,7 +413,7 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { · 1 unmodified line
411 cpp_buffer. */413 cpp_buffer. */
412 unsigned char sysp;414 unsigned char sysp;
413 415
414 /* Number of the low-order source_location bits used for column numbers416 /* Number of the low-order location_t bits used for column numbers
415 and ranges. */417 and ranges. */
416 unsigned int m_column_and_range_bits : 8;418 unsigned int m_column_and_range_bits : 8;
417 419
@@ -429,11 +431,23 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { · 11 unmodified lines
429 | | (e.g. 7) | (e.g. 5) |431 | | (e.g. 7) | (e.g. 5) |
430 +-------------------------+-----------------------+-------------------+ */432 +-------------------------+-----------------------+-------------------+ */
431 unsigned int m_range_bits : 8;433 unsigned int m_range_bits : 8;
434
435 /* Pointer alignment boundary on both 32 and 64-bit systems. */
436
437 const char *to_file;
438 linenum_type to_line;
439
440 /* Location from whence this line map was included. For regular
441 #includes, this location will be the last location of a map. For
442 outermost file, this is 0. */
443 location_t included_from;
444
445 /* Size is 20 or 24 bytes, no padding */
432};446};
433 447
434/* This is the highest possible source location encoded within an448/* This is the highest possible source location encoded within an
435 ordinary or macro map. */449 ordinary or macro map. */
436const source_location MAX_SOURCE_LOCATION = 0x7FFFFFFF;450const location_t MAX_LOCATION_T = 0x7FFFFFFF;
437 451
438struct cpp_hashnode;452struct cpp_hashnode;
439 453
@@ -443,15 +457,20 @@ struct cpp_hashnode; · 3 unmodified lines
443 The offset from START_LOCATION is used to index into457 The offset from START_LOCATION is used to index into
444 MACRO_LOCATIONS; this holds the original location of the token. */458 MACRO_LOCATIONS; this holds the original location of the token. */
445struct GTY((tag ("2"))) line_map_macro : public line_map {459struct GTY((tag ("2"))) line_map_macro : public line_map {
446 /* The cpp macro which expansion gave birth to this macro map. */460 /* Base is 4 bytes. */
447 struct cpp_hashnode * GTY ((nested_ptr (union tree_node,
448 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
449 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
450 macro;
451 461
452 /* The number of tokens inside the replacement-list of MACRO. */462 /* The number of tokens inside the replacement-list of MACRO. */
453 unsigned int n_tokens;463 unsigned int n_tokens;
454 464
465 /* Pointer alignment boundary. */
466
467 /* The cpp macro whose expansion gave birth to this macro map. */
468 struct cpp_hashnode *
469 GTY ((nested_ptr (union tree_node,
470 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
471 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
472 macro;
473
455 /* This array of location is actually an array of pairs of474 /* This array of location is actually an array of pairs of
456 locations. The elements inside it thus look like:475 locations. The elements inside it thus look like:
457 476
@@ -505,14 +524,16 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { · 47 unmodified lines
505 In the example above x1 (for token "+") is going to be the same524 In the example above x1 (for token "+") is going to be the same
506 as y1. x0 is the spelling location for the argument token "1",525 as y1. x0 is the spelling location for the argument token "1",
507 and x2 is the spelling location for the argument token "2". */526 and x2 is the spelling location for the argument token "2". */
508 source_location * GTY((atomic)) macro_locations;527 location_t * GTY((atomic)) macro_locations;
509 528
510 /* This is the location of the expansion point of the current macro529 /* This is the location of the expansion point of the current macro
511 map. It's the location of the macro name. That location is held530 map. It's the location of the macro name. That location is held
512 by the map that was current right before the current one. It531 by the map that was current right before the current one. It
513 could have been either a macro or an ordinary map, depending on532 could have been either a macro or an ordinary map, depending on
514 if we are in a nested expansion context not. */533 if we are in a nested expansion context not. */
515 source_location expansion;534 location_t expansion;
535
536 /* Size is 20 or 32 (4 bytes padding on 64-bit). */
516};537};
517 538
518#if CHECKING_P && (GCC_VERSION >= 2007)539#if CHECKING_P && (GCC_VERSION >= 2007)
@@ -540,6 +561,34 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { · 21 unmodified lines
540#define linemap_assert_fails(EXPR) (! (EXPR))561#define linemap_assert_fails(EXPR) (! (EXPR))
541#endif562#endif
542 563
564/* Get whether location LOC is an ad-hoc, ordinary or macro location. */
565
566inline bool
567IS_ORDINARY_LOC (location_t loc)
568{
569 return loc < LINE_MAP_MAX_LOCATION;
570}
571
572inline bool
573IS_ADHOC_LOC (location_t loc)
574{
575 return loc > MAX_LOCATION_T;
576}
577
578inline bool
579IS_MACRO_LOC (location_t loc)
580{
581 return !IS_ORDINARY_LOC (loc) && !IS_ADHOC_LOC (loc);
582}
583
584/* Categorize line map kinds. */
585
586inline bool
587MAP_ORDINARY_P (const line_map *map)
588{
589 return IS_ORDINARY_LOC (map->start_location);
590}
591
543/* Return TRUE if MAP encodes locations coming from a macro592/* Return TRUE if MAP encodes locations coming from a macro
544 replacement-list at macro expansion point. */593 replacement-list at macro expansion point. */
545bool594bool
@@ -552,7 +601,7 @@ linemap_macro_expansion_map_p (const struct line_map *); · 6 unmodified lines
552inline line_map_ordinary *601inline line_map_ordinary *
553linemap_check_ordinary (struct line_map *map)602linemap_check_ordinary (struct line_map *map)
554{603{
555 linemap_assert (!linemap_macro_expansion_map_p (map));604 linemap_assert (MAP_ORDINARY_P (map));
556 return (line_map_ordinary *)map;605 return (line_map_ordinary *)map;
557}606}
558 607
@@ -563,7 +612,7 @@ linemap_check_ordinary (struct line_map *map) · 4 unmodified lines
563inline const line_map_ordinary *612inline const line_map_ordinary *
564linemap_check_ordinary (const struct line_map *map)613linemap_check_ordinary (const struct line_map *map)
565{614{
566 linemap_assert (!linemap_macro_expansion_map_p (map));615 linemap_assert (MAP_ORDINARY_P (map));
567 return (const line_map_ordinary *)map;616 return (const line_map_ordinary *)map;
568}617}
569 618
@@ -572,7 +621,7 @@ linemap_check_ordinary (const struct line_map *map) · 2 unmodified lines
572 621
573inline line_map_macro *linemap_check_macro (line_map *map)622inline line_map_macro *linemap_check_macro (line_map *map)
574{623{
575 linemap_assert (linemap_macro_expansion_map_p (map));624 linemap_assert (!MAP_ORDINARY_P (map));
576 return (line_map_macro *)map;625 return (line_map_macro *)map;
577}626}
578 627
@@ -582,13 +631,13 @@ inline line_map_macro *linemap_check_macro (line_map *map) · 3 unmodified lines
582inline const line_map_macro *631inline const line_map_macro *
583linemap_check_macro (const line_map *map)632linemap_check_macro (const line_map *map)
584{633{
585 linemap_assert (linemap_macro_expansion_map_p (map));634 linemap_assert (!MAP_ORDINARY_P (map));
586 return (const line_map_macro *)map;635 return (const line_map_macro *)map;
587}636}
588 637
589/* Read the start location of MAP. */638/* Read the start location of MAP. */
590 639
591inline source_location640inline location_t
592MAP_START_LOCATION (const line_map *map)641MAP_START_LOCATION (const line_map *map)
593{642{
594 return map->start_location;643 return map->start_location;
@@ -602,17 +651,6 @@ ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map_ordinary *ord_map) · 7 unmodified lines
602 return ord_map->to_line;651 return ord_map->to_line;
603}652}
604 653
605/* Get the index of the ordinary map at whose end
606 ordinary map MAP was included.
607
608 File(s) at the bottom of the include stack have this set. */
609
610inline int
611ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map_ordinary *ord_map)
612{
613 return ord_map->included_from;
614}
615
616/* Return a positive value if map encodes locations from a system654/* Return a positive value if map encodes locations from a system
617 header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations655 header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations
618 in a system header and 2 if it encodes locations in a C system header656 in a system header and 2 if it encodes locations in a C system header
@@ -652,7 +690,7 @@ MACRO_MAP_NUM_MACRO_TOKENS (const line_map_macro *macro_map) · 33 unmodified lines
652/* Get the array of pairs of locations within macro map MAP.690/* Get the array of pairs of locations within macro map MAP.
653 See the declaration of line_map_macro for more information. */691 See the declaration of line_map_macro for more information. */
654 692
655inline source_location *693inline location_t *
656MACRO_MAP_LOCATIONS (const line_map_macro *macro_map)694MACRO_MAP_LOCATIONS (const line_map_macro *macro_map)
657{695{
658 return macro_map->macro_locations;696 return macro_map->macro_locations;
@@ -660,7 +698,7 @@ MACRO_MAP_LOCATIONS (const line_map_macro *macro_map) · 1 unmodified line
660 698
661/* Get the location of the expansion point of the macro map MAP. */699/* Get the location of the expansion point of the macro map MAP. */
662 700
663inline source_location701inline location_t
664MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map)702MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map)
665{703{
666 return macro_map->expansion;704 return macro_map->expansion;
@@ -707,7 +745,7 @@ struct GTY(()) maps_info_macro { · 40 unmodified lines
707/* Data structure to associate a source_range together with an arbitrary745/* Data structure to associate a source_range together with an arbitrary
708 data pointer with a source location. */746 data pointer with a source location. */
709struct GTY(()) location_adhoc_data {747struct GTY(()) location_adhoc_data {
710 source_location locus;748 location_t locus;
711 source_range src_range;749 source_range src_range;
712 void * GTY((skip)) data;750 void * GTY((skip)) data;
713};751};
@@ -726,7 +764,7 @@ struct htab; · 12 unmodified lines
726 764
727struct GTY(()) location_adhoc_data_map {765struct GTY(()) location_adhoc_data_map {
728 struct htab * GTY((skip)) htab;766 struct htab * GTY((skip)) htab;
729 source_location curr_loc;767 location_t curr_loc;
730 unsigned int allocated;768 unsigned int allocated;
731 struct location_adhoc_data GTY((length ("%h.allocated"))) *data;769 struct location_adhoc_data GTY((length ("%h.allocated"))) *data;
732};770};
@@ -746,18 +784,17 @@ struct GTY(()) line_maps { · 13 unmodified lines
746 /* If true, prints an include trace a la -H. */784 /* If true, prints an include trace a la -H. */
747 bool trace_includes;785 bool trace_includes;
748 786
749 /* Highest source_location "given out". */787 /* Highest location_t "given out". */
750 source_location highest_location;788 location_t highest_location;
751 789
752 /* Start of line of highest source_location "given out". */790 /* Start of line of highest location_t "given out". */
753 source_location highest_line;791 location_t highest_line;
754 792
755 /* The maximum column number we can quickly allocate. Higher numbers793 /* The maximum column number we can quickly allocate. Higher numbers
756 may require allocating a new line_map. */794 may require allocating a new line_map. */
757 unsigned int max_column_hint;795 unsigned int max_column_hint;
758 796
759 /* If non-null, the allocator to use when resizing 'maps'. If null,797 /* The allocator to use when resizing 'maps', defaults to xrealloc. */
760 xrealloc is used. */
761 line_map_realloc reallocator;798 line_map_realloc reallocator;
762 799
763 /* The allocators' function used to know the actual size it800 /* The allocators' function used to know the actual size it
@@ -768,7 +805,7 @@ struct GTY(()) line_maps { · 4 unmodified lines
768 805
769 /* The special location value that is used as spelling location for806 /* The special location value that is used as spelling location for
770 built-in tokens. */807 built-in tokens. */
771 source_location builtin_location;808 location_t builtin_location;
772 809
773 /* True if we've seen a #line or # 44 "file" directive. */810 /* True if we've seen a #line or # 44 "file" directive. */
774 bool seen_line_directive;811 bool seen_line_directive;
@@ -998,12 +1035,12 @@ LINEMAPS_LAST_MACRO_MAP (const line_maps *set) · 223 unmodified lines
998 1035
999/* Returns the lowest location [of a token resulting from macro1036/* Returns the lowest location [of a token resulting from macro
1000 expansion] encoded in this line table. */1037 expansion] encoded in this line table. */
1001inline source_location1038inline location_t
1002LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)1039LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
1003{1040{
1004 return LINEMAPS_MACRO_USED (set)1041 return LINEMAPS_MACRO_USED (set)
1005 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))1042 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))
1006 : MAX_SOURCE_LOCATION;1043 : MAX_LOCATION_T + 1;
1007}1044}
1008 1045
1009/* Returns the last macro map allocated in the line table SET. */1046/* Returns the last macro map allocated in the line table SET. */
@@ -1013,41 +1050,33 @@ LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) · 3 unmodified lines
1013 return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);1050 return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);
1014}1051}
1015 1052
1016extern source_location get_combined_adhoc_loc (struct line_maps *,1053extern location_t get_combined_adhoc_loc (struct line_maps *,
1017 source_location,1054 location_t,
1018 source_range,1055 source_range,
1019 void *);1056 void *);
1020extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);1057extern void *get_data_from_adhoc_loc (struct line_maps *, location_t);
1021extern source_location get_location_from_adhoc_loc (struct line_maps *,1058extern location_t get_location_from_adhoc_loc (struct line_maps *,
1022 source_location);1059 location_t);
1023 1060
1024extern source_range get_range_from_loc (line_maps *set, source_location loc);1061extern source_range get_range_from_loc (line_maps *set, location_t loc);
1025
1026/* Get whether location LOC is an ad-hoc location. */
1027
1028inline bool
1029IS_ADHOC_LOC (source_location loc)
1030{
1031 return (loc & MAX_SOURCE_LOCATION) != loc;
1032}
1033 1062
1034/* Get whether location LOC is a "pure" location, or1063/* Get whether location LOC is a "pure" location, or
1035 whether it is an ad-hoc location, or embeds range information. */1064 whether it is an ad-hoc location, or embeds range information. */
1036 1065
1037bool1066bool
1038pure_location_p (line_maps *set, source_location loc);1067pure_location_p (line_maps *set, location_t loc);
1039 1068
1040/* Given location LOC within SET, strip away any packed range information1069/* Given location LOC within SET, strip away any packed range information
1041 or ad-hoc information. */1070 or ad-hoc information. */
1042 1071
1043extern source_location get_pure_location (line_maps *set,1072extern location_t get_pure_location (line_maps *set,
1044 source_location loc);1073 location_t loc);
1045 1074
1046/* Combine LOC and BLOCK, giving a combined adhoc location. */1075/* Combine LOC and BLOCK, giving a combined adhoc location. */
1047 1076
1048inline source_location1077inline location_t
1049COMBINE_LOCATION_DATA (struct line_maps *set,1078COMBINE_LOCATION_DATA (struct line_maps *set,
1050 source_location loc,1079 location_t loc,
1051 source_range src_range,1080 source_range src_range,
1052 void *block)1081 void *block)
1053{1082{
@@ -1061,19 +1090,19 @@ extern void rebuild_location_adhoc_htab (struct line_maps *); · 7 unmodified lines
1061 spelling location for built-in tokens. This BUILTIN_LOCATION has1090 spelling location for built-in tokens. This BUILTIN_LOCATION has
1062 to be strictly less than RESERVED_LOCATION_COUNT. */1091 to be strictly less than RESERVED_LOCATION_COUNT. */
1063extern void linemap_init (struct line_maps *set,1092extern void linemap_init (struct line_maps *set,
1064 source_location builtin_location);1093 location_t builtin_location);
1065 1094
1066/* Check for and warn about line_maps entered but not exited. */1095/* Check for and warn about line_maps entered but not exited. */
1067 1096
1068extern void linemap_check_files_exited (struct line_maps *);1097extern void linemap_check_files_exited (struct line_maps *);
1069 1098
1070/* Return a source_location for the start (i.e. column==0) of1099/* Return a location_t for the start (i.e. column==0) of
1071 (physical) line TO_LINE in the current source file (as in the1100 (physical) line TO_LINE in the current source file (as in the
1072 most recent linemap_add). MAX_COLUMN_HINT is the highest column1101 most recent linemap_add). MAX_COLUMN_HINT is the highest column
1073 number we expect to use in this line (but it does not change1102 number we expect to use in this line (but it does not change
1074 the highest_location). */1103 the highest_location). */
1075 1104
1076extern source_location linemap_line_start1105extern location_t linemap_line_start
1077(struct line_maps *set, linenum_type to_line, unsigned int max_column_hint);1106(struct line_maps *set, linenum_type to_line, unsigned int max_column_hint);
1078 1107
1079/* Add a mapping of logical source line to physical source file and1108/* Add a mapping of logical source line to physical source file and
@@ -1100,7 +1129,7 @@ extern const struct line_map *linemap_add · 20 unmodified lines
1100 binary search. If no line map have been allocated yet, this1129 binary search. If no line map have been allocated yet, this
1101 function returns NULL. */1130 function returns NULL. */
1102extern const struct line_map *linemap_lookup1131extern const struct line_map *linemap_lookup
1103 (struct line_maps *, source_location);1132 (struct line_maps *, location_t);
1104 1133
1105/* Returns TRUE if the line table set tracks token locations across1134/* Returns TRUE if the line table set tracks token locations across
1106 macro expansion, FALSE otherwise. */1135 macro expansion, FALSE otherwise. */
@@ -1119,114 +1148,86 @@ const char* linemap_map_get_macro_name (const line_map_macro *); · 12 unmodified lines
1119 that is part of a macro replacement-list defined in a system1148 that is part of a macro replacement-list defined in a system
1120 header, but expanded in a non-system file. */1149 header, but expanded in a non-system file. */
1121int linemap_location_in_system_header_p (struct line_maps *,1150int linemap_location_in_system_header_p (struct line_maps *,
1122 source_location);1151 location_t);
1123 1152
1124/* Return TRUE if LOCATION is a source code location of a token that is part of1153/* Return TRUE if LOCATION is a source code location of a token that is part of
1125 a macro expansion, FALSE otherwise. */1154 a macro expansion, FALSE otherwise. */
1126bool linemap_location_from_macro_expansion_p (const struct line_maps *,1155bool linemap_location_from_macro_expansion_p (const struct line_maps *,
1127 source_location);1156 location_t);
1128 1157
1129/* TRUE if LOCATION is a source code location of a token that is part of the1158/* TRUE if LOCATION is a source code location of a token that is part of the
1130 definition of a macro, FALSE otherwise. */1159 definition of a macro, FALSE otherwise. */
1131bool linemap_location_from_macro_definition_p (struct line_maps *,1160bool linemap_location_from_macro_definition_p (struct line_maps *,
1132 source_location);1161 location_t);
1133 1162
1134/* With the precondition that LOCATION is the locus of a token that is1163/* With the precondition that LOCATION is the locus of a token that is
1135 an argument of a function-like macro MACRO_MAP and appears in the1164 an argument of a function-like macro MACRO_MAP and appears in the
1136 expansion of MACRO_MAP, return the locus of that argument in the1165 expansion of MACRO_MAP, return the locus of that argument in the
1137 context of the caller of MACRO_MAP. */1166 context of the caller of MACRO_MAP. */
1138 1167
1139extern source_location linemap_macro_map_loc_unwind_toward_spelling1168extern location_t linemap_macro_map_loc_unwind_toward_spelling
1140 (line_maps *set, const line_map_macro *macro_map, source_location location);1169 (line_maps *set, const line_map_macro *macro_map, location_t location);
1141 1170
1142/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will1171/* location_t values from 0 to RESERVED_LOCATION_COUNT-1 will
1143 be reserved for libcpp user as special values, no token from libcpp1172 be reserved for libcpp user as special values, no token from libcpp
1144 will contain any of those locations. */1173 will contain any of those locations. */
1145const source_location RESERVED_LOCATION_COUNT = 2;1174const location_t RESERVED_LOCATION_COUNT = 2;
1146 1175
1147/* Converts a map and a source_location to source line. */1176/* Converts a map and a location_t to source line. */
1148inline linenum_type1177inline linenum_type
1149SOURCE_LINE (const line_map_ordinary *ord_map, source_location loc)1178SOURCE_LINE (const line_map_ordinary *ord_map, location_t loc)
1150{1179{
1151 return ((loc - ord_map->start_location)1180 return ((loc - ord_map->start_location)
1152 >> ord_map->m_column_and_range_bits) + ord_map->to_line;1181 >> ord_map->m_column_and_range_bits) + ord_map->to_line;
1153}1182}
1154 1183
1155/* Convert a map and source_location to source column number. */1184/* Convert a map and location_t to source column number. */
1156inline linenum_type1185inline linenum_type
1157SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc)1186SOURCE_COLUMN (const line_map_ordinary *ord_map, location_t loc)
1158{1187{
1159 return ((loc - ord_map->start_location)1188 return ((loc - ord_map->start_location)
1160 & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits;1189 & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits;
1161}1190}
1162 1191
1163/* Return the location of the last source line within an ordinary
1164 map. */
1165inline source_location
1166LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map)
1167{
1168 return (((map[1].start_location - 1
1169 - map->start_location)
1170 & ~((1 << map->m_column_and_range_bits) - 1))
1171 + map->start_location);
1172}
1173
1174/* Returns the last source line number within an ordinary map. This
1175 is the (last) line of the #include, or other directive, that caused
1176 a map change. */
1177inline linenum_type
1178LAST_SOURCE_LINE (const line_map_ordinary *map)
1179{
1180 return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
1181}
1182
1183/* Return the last column number within an ordinary map. */
1184 1192
1185inline linenum_type1193inline location_t
1186LAST_SOURCE_COLUMN (const line_map_ordinary *map)1194linemap_included_from (const line_map_ordinary *ord_map)
1187{1195{
1188 return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map));1196 return ord_map->included_from;
1189}1197}
1190 1198
1191/* Returns the map a given map was included from, or NULL if the map1199/* The linemap containing the included-from location of MAP. */
1192 belongs to the main file, i.e, a file that wasn't included by1200const line_map_ordinary *linemap_included_from_linemap
1193 another one. */1201 (line_maps *set, const line_map_ordinary *map);
1194inline line_map_ordinary *
1195INCLUDED_FROM (struct line_maps *set, const line_map_ordinary *ord_map)
1196{
1197 return ((ord_map->included_from == -1)
1198 ? NULL
1199 : LINEMAPS_ORDINARY_MAP_AT (set, ord_map->included_from));
1200}
1201 1202
1202/* True if the map is at the bottom of the include stack. */1203/* True if the map is at the bottom of the include stack. */
1203 1204
1204inline bool1205inline bool
1205MAIN_FILE_P (const line_map_ordinary *ord_map)1206MAIN_FILE_P (const line_map_ordinary *ord_map)
1206{1207{
1207 return ord_map->included_from < 0;1208 return ord_map->included_from == 0;
1208}1209}
1209 1210
1210/* Encode and return a source_location from a column number. The1211/* Encode and return a location_t from a column number. The
1211 source line considered is the last source line used to call1212 source line considered is the last source line used to call
1212 linemap_line_start, i.e, the last source line which a location was1213 linemap_line_start, i.e, the last source line which a location was
1213 encoded from. */1214 encoded from. */
1214extern source_location1215extern location_t
1215linemap_position_for_column (struct line_maps *, unsigned int);1216linemap_position_for_column (struct line_maps *, unsigned int);
1216 1217
1217/* Encode and return a source location from a given line and1218/* Encode and return a source location from a given line and
1218 column. */1219 column. */
1219source_location1220location_t
1220linemap_position_for_line_and_column (line_maps *set,1221linemap_position_for_line_and_column (line_maps *set,
1221 const line_map_ordinary *,1222 const line_map_ordinary *,
1222 linenum_type, unsigned int);1223 linenum_type, unsigned int);
1223 1224
1224/* Encode and return a source_location starting from location LOC and1225/* Encode and return a location_t starting from location LOC and
1225 shifting it by OFFSET columns. This function does not support1226 shifting it by OFFSET columns. This function does not support
1226 virtual locations. */1227 virtual locations. */
1227source_location1228location_t
1228linemap_position_for_loc_and_offset (struct line_maps *set,1229linemap_position_for_loc_and_offset (struct line_maps *set,
1229 source_location loc,1230 location_t loc,
1230 unsigned int offset);1231 unsigned int offset);
1231 1232
1232/* Return the file this map is for. */1233/* Return the file this map is for. */
@@ -1258,16 +1259,16 @@ LINEMAP_SYSP (const line_map_ordinary *ord_map) · 25 unmodified lines
1258 the same token as the token for POST, and a negative value1259 the same token as the token for POST, and a negative value
1259 otherwise. */1260 otherwise. */
1260int linemap_compare_locations (struct line_maps *set,1261int linemap_compare_locations (struct line_maps *set,
1261 source_location pre,1262 location_t pre,
1262 source_location post);1263 location_t post);
1263 1264
1264/* Return TRUE if LOC_A denotes the location a token that comes1265/* Return TRUE if LOC_A denotes the location a token that comes
1265 topogically before the token denoted by location LOC_B, or if they1266 topogically before the token denoted by location LOC_B, or if they
1266 are equal. */1267 are equal. */
1267inline bool1268inline bool
1268linemap_location_before_p (struct line_maps *set,1269linemap_location_before_p (struct line_maps *set,
1269 source_location loc_a,1270 location_t loc_a,
1270 source_location loc_b)1271 location_t loc_b)
1271{1272{
1272 return linemap_compare_locations (set, loc_a, loc_b) >= 0;1273 return linemap_compare_locations (set, loc_a, loc_b) >= 0;
1273}1274}
@@ -1288,23 +1289,50 @@ typedef struct · 14 unmodified lines
1288 bool sysp;1289 bool sysp;
1289} expanded_location;1290} expanded_location;
1290 1291
1291/* A location within a rich_location: a caret&range, with1292class range_label;
1292 the caret potentially flagged for display. */
1293 1293
1294struct location_range1294/* A hint to diagnostic_show_locus on how to print a source range within a
1295{1295 rich_location.
1296 source_location m_loc;
1297 1296
1298 /* Should a caret be drawn for this range? Typically this is1297 Typically this is SHOW_RANGE_WITH_CARET for the 0th range, and
1299 true for the 0th range, and false for subsequent ranges,1298 SHOW_RANGE_WITHOUT_CARET for subsequent ranges,
1300 but the Fortran frontend overrides this for rendering things like:1299 but the Fortran frontend uses SHOW_RANGE_WITH_CARET repeatedly for
1300 printing things like:
1301 1301
1302 x = x + y1302 x = x + y
1303 1 21303 1 2
1304 Error: Shapes for operands at (1) and (2) are not conformable1304 Error: Shapes for operands at (1) and (2) are not conformable
1305 1305
1306 where "1" and "2" are notionally carets. */1306 where "1" and "2" are notionally carets. */
1307 bool m_show_caret_p;1307
1308enum range_display_kind
1309{
1310 /* Show the pertinent source line(s), the caret, and underline(s). */
1311 SHOW_RANGE_WITH_CARET,
1312
1313 /* Show the pertinent source line(s) and underline(s), but don't
1314 show the caret (just an underline). */
1315 SHOW_RANGE_WITHOUT_CARET,
1316
1317 /* Just show the source lines; don't show the range itself.
1318 This is for use when displaying some line-insertion fix-it hints (for
1319 showing the user context on the change, for when it doesn't make sense
1320 to highlight the first column on the next line). */
1321 SHOW_LINES_WITHOUT_RANGE
1322};
1323
1324/* A location within a rich_location: a caret&range, with
1325 the caret potentially flagged for display, and an optional
1326 label. */
1327
1328struct location_range
1329{
1330 location_t m_loc;
1331
1332 enum range_display_kind m_range_display_kind;
1333
1334 /* If non-NULL, the label for this range. */
1335 const range_label *m_label;
1308};1336};
1309 1337
1310/* A partially-embedded vec for use within rich_location for storing1338/* A partially-embedded vec for use within rich_location for storing
@@ -1446,6 +1474,8 @@ class fixit_hint; · 135 unmodified lines
1446 Additional ranges may be added to help the user identify other1474 Additional ranges may be added to help the user identify other
1447 pertinent clauses in a diagnostic.1475 pertinent clauses in a diagnostic.
1448 1476
1477 Ranges can (optionally) be given labels via class range_label.
1478
1449 rich_location instances are intended to be allocated on the stack1479 rich_location instances are intended to be allocated on the stack
1450 when generating diagnostics, and to be short-lived.1480 when generating diagnostics, and to be short-lived.
1451 1481
@@ -1491,18 +1521,22 @@ class fixit_hint; · 39 unmodified lines
1491 equal to their caret point. The frontend overrides the diagnostic1521 equal to their caret point. The frontend overrides the diagnostic
1492 context's default caret character for these ranges.1522 context's default caret character for these ranges.
1493 1523
1494 Example E1524 Example E (range labels)
1495 *********1525 ************************
1496 printf ("arg0: %i arg1: %s arg2: %i",1526 printf ("arg0: %i arg1: %s arg2: %i",
1497 ^~1527 ^~
1528 |
1529 const char *
1498 100, 101, 102);1530 100, 101, 102);
1499 ~~~1531 ~~~
1532 |
1533 int
1500 This rich location has two ranges:1534 This rich location has two ranges:
1501 - range 0 is at the "%s" with start = caret = "%" and finish at1535 - range 0 is at the "%s" with start = caret = "%" and finish at
1502 the "s".1536 the "s". It has a range_label ("const char *").
1503 - range 1 has start/finish covering the "101" and is not flagged for1537 - range 1 has start/finish covering the "101" and is not flagged for
1504 caret printing; it is perhaps at the start of "101".1538 caret printing. The caret is at the start of "101", where its
1505 1539 range_label is printed ("int").
1506 1540
1507 Fix-it hints1541 Fix-it hints
1508 ------------1542 ------------
@@ -1562,9 +1596,21 @@ class fixit_hint; · 53 unmodified lines
1562 added via1596 added via
1563 richloc.add_fixit_replace ("color");1597 richloc.add_fixit_replace ("color");
1564 1598
1599 Example J: fix-it hint: line insertion
1600 **************************************
1601
1602 3 | #include <stddef.h>
1603 + |+#include <stdio.h>
1604 4 | int the_next_line;
1605
1606 This rich location has a single range at line 4 column 1, marked
1607 with SHOW_LINES_WITHOUT_RANGE (to avoid printing a meaningless caret
1608 on the "i" of int). It has a insertion fix-it hint of the string
1609 "#include <stdio.h>\n".
1610
1565 Adding a fix-it hint can fail: for example, attempts to insert content1611 Adding a fix-it hint can fail: for example, attempts to insert content
1566 at the transition between two line maps may fail due to there being no1612 at the transition between two line maps may fail due to there being no
1567 source_location (aka location_t) value to express the new location.1613 location_t value to express the new location.
1568 1614
1569 Attempts to add a fix-it hint within a macro expansion will fail.1615 Attempts to add a fix-it hint within a macro expansion will fail.
1570 1616
@@ -1594,21 +1640,25 @@ class rich_location · 23 unmodified lines
1594 /* Constructors. */1640 /* Constructors. */
1595 1641
1596 /* Constructing from a location. */1642 /* Constructing from a location. */
1597 rich_location (line_maps *set, source_location loc);1643 rich_location (line_maps *set, location_t loc,
1644 const range_label *label = NULL);
1598 1645
1599 /* Destructor. */1646 /* Destructor. */
1600 ~rich_location ();1647 ~rich_location ();
1601 1648
1602 /* Accessors. */1649 /* Accessors. */
1603 source_location get_loc () const { return get_loc (0); }1650 location_t get_loc () const { return get_loc (0); }
1604 source_location get_loc (unsigned int idx) const;1651 location_t get_loc (unsigned int idx) const;
1605 1652
1606 void1653 void
1607 add_range (source_location loc, bool show_caret_p);1654 add_range (location_t loc,
1655 enum range_display_kind range_display_kind
1656 = SHOW_RANGE_WITHOUT_CARET,
1657 const range_label *label = NULL);
1608 1658
1609 void1659 void
1610 set_range (line_maps *set, unsigned int idx, source_location loc,1660 set_range (unsigned int idx, location_t loc,
1611 bool show_caret_p);1661 enum range_display_kind range_display_kind);
1612 1662
1613 unsigned int get_num_locations () const { return m_ranges.count (); }1663 unsigned int get_num_locations () const { return m_ranges.count (); }
1614 1664
@@ -1631,7 +1681,7 @@ class rich_location · 16 unmodified lines
1631 1681
1632 /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */1682 /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */
1633 void1683 void
1634 add_fixit_insert_before (source_location where,1684 add_fixit_insert_before (location_t where,
1635 const char *new_content);1685 const char *new_content);
1636 1686
1637 /* Suggest inserting NEW_CONTENT immediately after the end of the primary1687 /* Suggest inserting NEW_CONTENT immediately after the end of the primary
@@ -1641,7 +1691,7 @@ class rich_location · 3 unmodified lines
1641 1691
1642 /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */1692 /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */
1643 void1693 void
1644 add_fixit_insert_after (source_location where,1694 add_fixit_insert_after (location_t where,
1645 const char *new_content);1695 const char *new_content);
1646 1696
1647 /* Methods for adding removal fix-it hints. */1697 /* Methods for adding removal fix-it hints. */
@@ -1653,7 +1703,7 @@ class rich_location · 5 unmodified lines
1653 /* Suggest removing the content covered between the start and finish1703 /* Suggest removing the content covered between the start and finish
1654 of WHERE. */1704 of WHERE. */
1655 void1705 void
1656 add_fixit_remove (source_location where);1706 add_fixit_remove (location_t where);
1657 1707
1658 /* Suggest removing the content covered by SRC_RANGE. */1708 /* Suggest removing the content covered by SRC_RANGE. */
1659 void1709 void
@@ -1668,7 +1718,7 @@ class rich_location · 8 unmodified lines
1668 /* Suggest replacing the content between the start and finish of1718 /* Suggest replacing the content between the start and finish of
1669 WHERE with NEW_CONTENT. */1719 WHERE with NEW_CONTENT. */
1670 void1720 void
1671 add_fixit_replace (source_location where,1721 add_fixit_replace (location_t where,
1672 const char *new_content);1722 const char *new_content);
1673 1723
1674 /* Suggest replacing the content covered by SRC_RANGE with1724 /* Suggest replacing the content covered by SRC_RANGE with
@@ -1704,10 +1754,10 @@ class rich_location · 29 unmodified lines
1704 }1754 }
1705 1755
1706private:1756private:
1707 bool reject_impossible_fixit (source_location where);1757 bool reject_impossible_fixit (location_t where);
1708 void stop_supporting_fixits ();1758 void stop_supporting_fixits ();
1709 void maybe_add_fixit (source_location start,1759 void maybe_add_fixit (location_t start,
1710 source_location next_loc,1760 location_t next_loc,
1711 const char *new_content);1761 const char *new_content);
1712 1762
1713public:1763public:
@@ -1729,6 +1779,56 @@ protected: · 15 unmodified lines
1729 bool m_fixits_cannot_be_auto_applied;1779 bool m_fixits_cannot_be_auto_applied;
1730};1780};
1731 1781
1782/* A struct for the result of range_label::get_text: a NUL-terminated buffer
1783 of localized text, and a flag to determine if the caller should "free" the
1784 buffer. */
1785
1786struct label_text
1787{
1788 label_text ()
1789 : m_buffer (NULL), m_caller_owned (false)
1790 {}
1791
1792 label_text (char *buffer, bool caller_owned)
1793 : m_buffer (buffer), m_caller_owned (caller_owned)
1794 {}
1795
1796 void maybe_free ()
1797 {
1798 if (m_caller_owned)
1799 free (m_buffer);
1800 }
1801
1802 char *m_buffer;
1803 bool m_caller_owned;
1804};
1805
1806/* Abstract base class for labelling a range within a rich_location
1807 (e.g. for labelling expressions with their type).
1808
1809 Generating the text could require non-trivial work, so this work
1810 is delayed (via the "get_text" virtual function) until the diagnostic
1811 printing code "knows" it needs it, thus avoiding doing it e.g. for
1812 warnings that are filtered by command-line flags. This virtual
1813 function also isolates libcpp and the diagnostics subsystem from
1814 the front-end and middle-end-specific code for generating the text
1815 for the labels.
1816
1817 Like the rich_location instances they annotate, range_label instances
1818 are intended to be allocated on the stack when generating diagnostics,
1819 and to be short-lived. */
1820
1821class range_label
1822{
1823 public:
1824 virtual ~range_label () {}
1825
1826 /* Get localized text for the label.
1827 The RANGE_IDX is provided, allowing for range_label instances to be
1828 shared by multiple ranges if need be (the "flyweight" design pattern). */
1829 virtual label_text get_text (unsigned range_idx) const = 0;
1830};
1831
1732/* A fix-it hint: a suggested insertion, replacement, or deletion of text.1832/* A fix-it hint: a suggested insertion, replacement, or deletion of text.
1733 We handle these three types of edit with one class, by representing1833 We handle these three types of edit with one class, by representing
1734 them as replacement of a half-open range:1834 them as replacement of a half-open range:
@@ -1746,16 +1846,16 @@ protected: · 11 unmodified lines
1746class fixit_hint1846class fixit_hint
1747{1847{
1748 public:1848 public:
1749 fixit_hint (source_location start,1849 fixit_hint (location_t start,
1750 source_location next_loc,1850 location_t next_loc,
1751 const char *new_content);1851 const char *new_content);
1752 ~fixit_hint () { free (m_bytes); }1852 ~fixit_hint () { free (m_bytes); }
1753 1853
1754 bool affects_line_p (const char *file, int line) const;1854 bool affects_line_p (const char *file, int line) const;
1755 source_location get_start_loc () const { return m_start; }1855 location_t get_start_loc () const { return m_start; }
1756 source_location get_next_loc () const { return m_next_loc; }1856 location_t get_next_loc () const { return m_next_loc; }
1757 bool maybe_append (source_location start,1857 bool maybe_append (location_t start,
1758 source_location next_loc,1858 location_t next_loc,
1759 const char *new_content);1859 const char *new_content);
1760 1860
1761 const char *get_string () const { return m_bytes; }1861 const char *get_string () const { return m_bytes; }
@@ -1770,8 +1870,8 @@ class fixit_hint · 8 unmodified lines
1770 this is a half-open/half-closed range:1870 this is a half-open/half-closed range:
1771 [start, next_loc)1871 [start, next_loc)
1772 so that we can support insertion via start == next_loc. */1872 so that we can support insertion via start == next_loc. */
1773 source_location m_start;1873 location_t m_start;
1774 source_location m_next_loc;1874 location_t m_next_loc;
1775 char *m_bytes;1875 char *m_bytes;
1776 size_t m_len;1876 size_t m_len;
1777};1877};
@@ -1835,10 +1935,10 @@ enum location_resolution_kind · 57 unmodified lines
1835 resolves to a location reserved for the client code, like1935 resolves to a location reserved for the client code, like
1836 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */1936 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
1837 1937
1838source_location linemap_resolve_location (struct line_maps *,1938location_t linemap_resolve_location (struct line_maps *,
1839 source_location loc,1939 location_t loc,
1840 enum location_resolution_kind lrk,1940 enum location_resolution_kind lrk,
1841 const line_map_ordinary **loc_map);1941 const line_map_ordinary **loc_map);
1842 1942
1843/* Suppose that LOC is the virtual location of a token coming from the1943/* Suppose that LOC is the virtual location of a token coming from the
1844 expansion of a macro M. This function then steps up to get the1944 expansion of a macro M. This function then steps up to get the
@@ -1847,9 +1947,9 @@ source_location linemap_resolve_location (struct line_maps *, · 2 unmodified lines
1847 the point where M' was expanded. LOC_MAP is an output parameter.1947 the point where M' was expanded. LOC_MAP is an output parameter.
1848 When non-NULL, *LOC_MAP is set to the map of the returned1948 When non-NULL, *LOC_MAP is set to the map of the returned
1849 location. */1949 location. */
1850source_location linemap_unwind_toward_expansion (struct line_maps *,1950location_t linemap_unwind_toward_expansion (struct line_maps *,
1851 source_location loc,1951 location_t loc,
1852 const struct line_map **loc_map);1952 const struct line_map **loc_map);
1853 1953
1854/* If LOC is the virtual location of a token coming from the expansion1954/* If LOC is the virtual location of a token coming from the expansion
1855 of a macro M and if its spelling location is reserved (e.g, a1955 of a macro M and if its spelling location is reserved (e.g, a
@@ -1865,9 +1965,9 @@ source_location linemap_unwind_toward_expansion (struct line_maps *, · 9 unmodified lines
1865 1965
1866 *MAP is set to the map of the returned location if the later is1966 *MAP is set to the map of the returned location if the later is
1867 different from LOC. */1967 different from LOC. */
1868source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *,1968location_t linemap_unwind_to_first_non_reserved_loc (struct line_maps *,
1869 source_location loc,1969 location_t loc,
1870 const struct line_map **map);1970 const struct line_map **map);
1871 1971
1872/* Expand source code location LOC and return a user readable source1972/* Expand source code location LOC and return a user readable source
1873 code location. LOC must be a spelling (non-virtual) location. If1973 code location. LOC must be a spelling (non-virtual) location. If
@@ -1875,7 +1975,7 @@ source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *, · 1 unmodified line
1875 location is returned. */1975 location is returned. */
1876expanded_location linemap_expand_location (struct line_maps *,1976expanded_location linemap_expand_location (struct line_maps *,
1877 const struct line_map *,1977 const struct line_map *,
1878 source_location loc);1978 location_t loc);
1879 1979
1880/* Statistics about maps allocation and usage as returned by1980/* Statistics about maps allocation and usage as returned by
1881 linemap_get_statistics. */1981 linemap_get_statistics. */
@@ -1902,7 +2002,7 @@ struct linemap_stats · 20 unmodified lines
1902 location emitted for that file. */2002 location emitted for that file. */
1903bool linemap_get_file_highest_location (struct line_maps * set,2003bool linemap_get_file_highest_location (struct line_maps * set,
1904 const char *file_name,2004 const char *file_name,
1905 source_location *loc);2005 location_t *loc);
1906 2006
1907/* Compute and return statistics about the memory consumption of some2007/* Compute and return statistics about the memory consumption of some
1908 parts of the line table SET. */2008 parts of the line table SET. */
@@ -1910,7 +2010,7 @@ void linemap_get_statistics (struct line_maps *, struct linemap_stats *); · 1 unmodified line
1910 2010
1911/* Dump debugging information about source location LOC into the file2011/* Dump debugging information about source location LOC into the file
1912 stream STREAM. SET is the line map set LOC comes from. */2012 stream STREAM. SET is the line map set LOC comes from. */
1913void linemap_dump_location (struct line_maps *, source_location, FILE *);2013void linemap_dump_location (struct line_maps *, location_t, FILE *);
1914 2014
1915/* Dump line map at index IX in line table SET to STREAM. If STREAM2015/* Dump line map at index IX in line table SET to STREAM. If STREAM
1916 is NULL, use stderr. IS_MACRO is true if the caller wants to2016 is NULL, use stderr. IS_MACRO is true if the caller wants to
@@ -1922,7 +2022,7 @@ void linemap_dump (FILE *, struct line_maps *, unsigned, bool); · 5 unmodified lines
1922 specifies how many macro maps to dump. */2022 specifies how many macro maps to dump. */
1923void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int);2023void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int);
1924 2024
1925/* An enum for distinguishing the various parts within a source_location. */2025/* An enum for distinguishing the various parts within a location_t. */
1926 2026
1927enum location_aspect2027enum location_aspect
1928{2028{
@@ -1931,14 +2031,14 @@ enum location_aspect · 2 unmodified lines
1931 LOCATION_ASPECT_FINISH2031 LOCATION_ASPECT_FINISH
1932};2032};
1933 2033
1934/* The rich_location class requires a way to expand source_location instances.2034/* The rich_location class requires a way to expand location_t instances.
1935 We would directly use expand_location_to_spelling_point, which is2035 We would directly use expand_location_to_spelling_point, which is
1936 implemented in gcc/input.c, but we also need to use it for rich_location2036 implemented in gcc/input.c, but we also need to use it for rich_location
1937 within genmatch.c.2037 within genmatch.c.
1938 Hence we require client code of libcpp to implement the following2038 Hence we require client code of libcpp to implement the following
1939 symbol. */2039 symbol. */
1940extern expanded_location2040extern expanded_location
1941linemap_client_expand_location_to_spelling_point (source_location,2041linemap_client_expand_location_to_spelling_point (location_t,
1942 enum location_aspect);2042 enum location_aspect);
1943 2043
1944#endif /* !LIBCPP_LINE_MAP_H */2044#endif /* !LIBCPP_LINE_MAP_H */
gcc/libcpp/include/mkdeps.h+1−1
@@ -1,5 +1,5 @@
1/* Dependency generator for Makefile fragments.1/* Dependency generator for Makefile fragments.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.2 Copyright (C) 2000-2019 Free Software Foundation, Inc.
3 Contributed by Zack Weinberg, Mar 20003 Contributed by Zack Weinberg, Mar 2000
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
gcc/libcpp/include/symtab.h+1−1
@@ -1,5 +1,5 @@
1/* Hash tables.1/* Hash tables.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.2 Copyright (C) 2000-2019 Free Software Foundation, Inc.
3 3
4This program is free software; you can redistribute it and/or modify it4This program is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the5under the terms of the GNU General Public License as published by the

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