diff options
author | Patrick Palka <ppalka@redhat.com> | 2024-08-09 21:13:03 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2024-08-09 21:13:03 -0400 |
commit | cf7feae517d4819cd33ef6bb123217ea39845fd1 (patch) | |
tree | 22655cecf39e90133460994c6388ff79178f7116 /gcc/cp | |
parent | 6b4b27a0f57c9b44a3d2c5aded17f37543821039 (diff) | |
download | gcc-cf7feae517d4819cd33ef6bb123217ea39845fd1.zip gcc-cf7feae517d4819cd33ef6bb123217ea39845fd1.tar.gz gcc-cf7feae517d4819cd33ef6bb123217ea39845fd1.tar.bz2 |
c++: clean up cp_identifier_kind checks
The predicates for checking an IDENTIFIER node's cp_identifier_kind
currently directly test the three flag bits that encode the kind. This
patch instead makes the checks first reconstruct the cp_identifier_kind
in its entirety and then compare that.
gcc/cp/ChangeLog:
* cp-tree.h (get_identifier_kind): Define.
(IDENTIFIER_KEYWORD_P): Redefine in terms of get_identifier_kind.
(IDENTIFIER_CDTOR_P): Likewise.
(IDENTIFIER_CTOR_P): Likewise.
(IDENTIFIER_DTOR_P): Likewise.
(IDENTIFIER_ANY_OP_P): Likewise.
(IDENTIFIER_OVL_OP_P): Likewise.
(IDENTIFIER_ASSIGN_OP_P): Likewise.
(IDENTIFIER_CONV_OP_P): Likewise.
(IDENTIFIER_TRAIT_P): Likewise.
* parser.cc (cp_lexer_peek_trait): Mark IDENTIFIER_TRAIT_P
check UNLIKELY.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-tree.h | 41 | ||||
-rw-r--r-- | gcc/cp/parser.cc | 3 |
2 files changed, 23 insertions, 21 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index b169305..5807f4e 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1255,56 +1255,57 @@ enum cp_identifier_kind { #define IDENTIFIER_VIRTUAL_P(NODE) \ TREE_LANG_FLAG_5 (IDENTIFIER_NODE_CHECK (NODE)) +/* Return the cp_identifier_kind of the given IDENTIFIER node ID. */ + +ATTRIBUTE_PURE inline cp_identifier_kind +get_identifier_kind (tree id) +{ + unsigned bit0 = IDENTIFIER_KIND_BIT_0 (id); + unsigned bit1 = IDENTIFIER_KIND_BIT_1 (id); + unsigned bit2 = IDENTIFIER_KIND_BIT_2 (id); + return cp_identifier_kind ((bit2 << 2) | (bit1 << 1) | bit0); +} + /* True if this identifier is a reserved word. C_RID_CODE (node) is then the RID_* value of the keyword. Value 1. */ #define IDENTIFIER_KEYWORD_P(NODE) \ - ((!IDENTIFIER_KIND_BIT_2 (NODE)) \ - & (!IDENTIFIER_KIND_BIT_1 (NODE)) \ - & IDENTIFIER_KIND_BIT_0 (NODE)) + (get_identifier_kind (NODE) == cik_keyword) /* True if this identifier is the name of a constructor or destructor. Value 2 or 3. */ #define IDENTIFIER_CDTOR_P(NODE) \ - ((!IDENTIFIER_KIND_BIT_2 (NODE)) \ - & IDENTIFIER_KIND_BIT_1 (NODE)) + (IDENTIFIER_CTOR_P (NODE) || IDENTIFIER_DTOR_P (NODE)) /* True if this identifier is the name of a constructor. Value 2. */ #define IDENTIFIER_CTOR_P(NODE) \ - (IDENTIFIER_CDTOR_P(NODE) \ - & (!IDENTIFIER_KIND_BIT_0 (NODE))) + (get_identifier_kind (NODE) == cik_ctor) /* True if this identifier is the name of a destructor. Value 3. */ #define IDENTIFIER_DTOR_P(NODE) \ - (IDENTIFIER_CDTOR_P(NODE) \ - & IDENTIFIER_KIND_BIT_0 (NODE)) + (get_identifier_kind (NODE) == cik_dtor) /* True if this identifier is for any operator name (including conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) + (IDENTIFIER_OVL_OP_P (NODE) || IDENTIFIER_CONV_OP_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ - (IDENTIFIER_ANY_OP_P (NODE) \ - & (!IDENTIFIER_KIND_BIT_1 (NODE))) + (get_identifier_kind (NODE) == cik_simple_op \ + || get_identifier_kind (NODE) == cik_assign_op) /* True if this identifier is for any assignment. Values 5. */ #define IDENTIFIER_ASSIGN_OP_P(NODE) \ - (IDENTIFIER_OVL_OP_P (NODE) \ - & IDENTIFIER_KIND_BIT_0 (NODE)) + (get_identifier_kind (NODE) == cik_assign_op) /* True if this identifier is the name of a type-conversion operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ - (IDENTIFIER_ANY_OP_P (NODE) \ - & IDENTIFIER_KIND_BIT_1 (NODE) \ - & (!IDENTIFIER_KIND_BIT_0 (NODE))) + (get_identifier_kind (NODE) == cik_conv_op) /* True if this identifier is the name of a built-in trait. */ #define IDENTIFIER_TRAIT_P(NODE) \ - (IDENTIFIER_KIND_BIT_0 (NODE) \ - & IDENTIFIER_KIND_BIT_1 (NODE) \ - & IDENTIFIER_KIND_BIT_2 (NODE)) + (get_identifier_kind (NODE) == cik_trait) /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 82f3903..852efe4 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -1198,7 +1198,8 @@ static const cp_trait * cp_lexer_peek_trait (cp_lexer *lexer) { const cp_token *token1 = cp_lexer_peek_token (lexer); - if (token1->type == CPP_NAME && IDENTIFIER_TRAIT_P (token1->u.value)) + if (token1->type == CPP_NAME + && UNLIKELY (IDENTIFIER_TRAIT_P (token1->u.value))) { const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (token1->u.value)]; const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT); |