aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-09-30 11:06:54 -0400
committerPatrick Palka <ppalka@redhat.com>2022-09-30 11:06:54 -0400
commit1e2c124d71ac051373a30495793883c45bcc5415 (patch)
tree281e8aa9254d44be03e336282fc885c29eab597c /gcc/cp
parent3bb2d70d38027c43b437dee98ee1a7a15843682f (diff)
downloadgcc-1e2c124d71ac051373a30495793883c45bcc5415.zip
gcc-1e2c124d71ac051373a30495793883c45bcc5415.tar.gz
gcc-1e2c124d71ac051373a30495793883c45bcc5415.tar.bz2
c++: streamline built-in trait addition process
Adding a new built-in trait currently involves manual boilerplate consisting of defining an rid enumerator for the identifier as well as a corresponding cp_trait_kind enumerator and handling them in various switch statements, the exact set of which depends on whether the proposed trait yields (and thus is recognized as) a type or an expression. To streamline the process, this patch adds a central cp-trait.def file that tabulates the essential details about each built-in trait (whether it yields a type or an expression, its code, its spelling and its arity) and uses this file to automate away the manual boilerplate. It also migrates all the existing C++-specific built-in traits to use this approach. After this change, adding a new built-in trait just entails declaring it in cp-trait.def and defining its behavior in finish_trait_expr/type (and handling it in diagnose_trait_expr, if it's an expression-yielding trait). gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Use cp/cp-trait.def to handle C++ traits. * c-common.h (enum rid): Likewise. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Likewise. * cp-objcp-common.cc (names_builtin_p): Likewise. * cp-tree.h (enum cp_trait_kind): Likewise. * cxx-pretty-print.cc (pp_cxx_trait): Likewise. * parser.cc (cp_keyword_starts_decl_specifier_p): Likewise. (cp_parser_primary_expression): Likewise. (cp_parser_trait): Likewise. (cp_parser_simple_type_specifier): Likewise. * cp-trait.def: New file.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/constraint.cc12
-rw-r--r--gcc/cp/cp-objcp-common.cc44
-rw-r--r--gcc/cp/cp-trait.def106
-rw-r--r--gcc/cp/cp-tree.h46
-rw-r--r--gcc/cp/cxx-pretty-print.cc126
-rw-r--r--gcc/cp/parser.cc217
6 files changed, 146 insertions, 405 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index ca73aff..f414557 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3711,13 +3711,11 @@ diagnose_trait_expr (tree expr, tree args)
inform (loc, " %qT is not a reference that binds to a temporary "
"object of type %qT (copy-initialization)", t1, t2);
break;
- case CPTK_BASES:
- case CPTK_DIRECT_BASES:
- case CPTK_UNDERLYING_TYPE:
- case CPTK_REMOVE_CV:
- case CPTK_REMOVE_REFERENCE:
- case CPTK_REMOVE_CVREF:
- /* We shouldn't see these non-expression traits. */
+#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
+ case CPTK_##CODE:
+#include "cp-trait.def"
+#undef DEFTRAIT_TYPE
+ /* Type-yielding traits aren't expressions. */
gcc_unreachable ();
/* We deliberately omit the default case so that when adding a new
trait we'll get reminded (by way of a warning) to handle it here. */
diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 2d3f206..e4df30d 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -430,46 +430,10 @@ names_builtin_p (const char *name)
case RID_BUILTIN_ASSOC_BARRIER:
case RID_BUILTIN_BIT_CAST:
case RID_OFFSETOF:
- case RID_HAS_NOTHROW_ASSIGN:
- case RID_HAS_NOTHROW_CONSTRUCTOR:
- case RID_HAS_NOTHROW_COPY:
- case RID_HAS_TRIVIAL_ASSIGN:
- case RID_HAS_TRIVIAL_CONSTRUCTOR:
- case RID_HAS_TRIVIAL_COPY:
- case RID_HAS_TRIVIAL_DESTRUCTOR:
- case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS:
- case RID_HAS_VIRTUAL_DESTRUCTOR:
- case RID_IS_ABSTRACT:
- case RID_IS_AGGREGATE:
- case RID_IS_BASE_OF:
- case RID_IS_CLASS:
- case RID_IS_EMPTY:
- case RID_IS_ENUM:
- case RID_IS_FINAL:
- case RID_IS_LAYOUT_COMPATIBLE:
- case RID_IS_LITERAL_TYPE:
- case RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
- case RID_IS_POD:
- case RID_IS_POLYMORPHIC:
- case RID_IS_SAME_AS:
- case RID_IS_STD_LAYOUT:
- case RID_IS_TRIVIAL:
- case RID_IS_TRIVIALLY_ASSIGNABLE:
- case RID_IS_TRIVIALLY_CONSTRUCTIBLE:
- case RID_IS_TRIVIALLY_COPYABLE:
- case RID_IS_UNION:
- case RID_IS_ASSIGNABLE:
- case RID_IS_CONSTRUCTIBLE:
- case RID_IS_NOTHROW_ASSIGNABLE:
- case RID_IS_NOTHROW_CONSTRUCTIBLE:
- case RID_UNDERLYING_TYPE:
- case RID_IS_CONVERTIBLE:
- case RID_IS_NOTHROW_CONVERTIBLE:
- case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
- case RID_REF_CONVERTS_FROM_TEMPORARY:
- case RID_REMOVE_CV:
- case RID_REMOVE_REFERENCE:
- case RID_REMOVE_CVREF:
+#define DEFTRAIT(TCC, CODE, NAME, ARITY) \
+ case RID_##CODE:
+#include "cp-trait.def"
+#undef DEFTRAIT
return true;
default:
break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
new file mode 100644
index 0000000..922348a
--- /dev/null
+++ b/gcc/cp/cp-trait.def
@@ -0,0 +1,106 @@
+/* This file contains the definitions for C++-specific built-in traits.
+
+ Copyright The GNU Toolchain Authors.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* Add a DEFTRAIT_EXPR (CODE, NAME, N) line to this file to define an
+ expression-yielding built-in trait that has internal code name CODE, is
+ spelled as NAME and takes N type arguments (where N is either 1, 2, or
+ the special value -1 which denotes that it takes at least one argument).
+ Such traits are represented as TRAIT_EXPR tree whose TRAIT_EXPR_KIND is
+ CPTK_CODE. Define the behavior of the trait in finish_trait_expr. */
+
+/* Add a DEFTRAIT_TYPE (CODE, NAME, N) line to this file to define a
+ type-yielding built-in trait as described above. Such traits are
+ generally represented as a TRAIT_TYPE tree whose TRAIT_TYPE_KIND is
+ CPTK_CODE (exceptions are BASES and DIRECT_BASES below). Define the
+ behavior of the trait in finish_trait_type. */
+
+#ifdef DEFTRAIT
+#define DEFTRAIT_EXPR(CODE, NAME, ARITY) DEFTRAIT(tcc_expression, CODE, NAME, ARITY)
+#define DEFTRAIT_TYPE(CODE, NAME, ARITY) DEFTRAIT(tcc_type, CODE, NAME, ARITY)
+#define DEFTRAIT_EXPR_DEFAULTED
+#define DEFTRAIT_TYPE_DEFAULTED
+#endif
+
+#ifndef DEFTRAIT_EXPR
+#define DEFTRAIT_EXPR(CODE, NAME, ARITY)
+#define DEFTRAIT_EXPR_DEFAULTED
+#endif
+
+#ifndef DEFTRAIT_TYPE
+#define DEFTRAIT_TYPE(CODE, NAME, ARITY)
+#define DEFTRAIT_TYPE_DEFAULTED
+#endif
+
+DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1)
+DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1)
+DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1)
+DEFTRAIT_EXPR (HAS_TRIVIAL_ASSIGN, "__has_trivial_assign", 1)
+DEFTRAIT_EXPR (HAS_TRIVIAL_CONSTRUCTOR, "__has_trivial_constructor", 1)
+DEFTRAIT_EXPR (HAS_TRIVIAL_COPY, "__has_trivial_copy", 1)
+DEFTRAIT_EXPR (HAS_TRIVIAL_DESTRUCTOR, "__has_trivial_destructor", 1)
+DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representations", 1)
+DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1)
+DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1)
+DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1)
+DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2)
+DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2)
+DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1)
+DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1)
+DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2)
+DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1)
+DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1)
+DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1)
+DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2)
+DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1)
+DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2)
+DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1)
+DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2)
+DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2)
+DEFTRAIT_EXPR (IS_POD, "__is_pod", 1)
+DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1)
+DEFTRAIT_EXPR (IS_SAME_AS, "__is_same", 2)
+DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1)
+DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1)
+DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
+DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
+DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
+DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
+DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
+
+DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
+DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
+DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
+DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
+
+/* These traits yield a type pack, not a type, and are represented by
+ cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree. */
+DEFTRAIT_TYPE (BASES, "__bases", 1)
+DEFTRAIT_TYPE (DIRECT_BASES, "__direct_bases", 1)
+
+#ifdef DEFTRAIT_EXPR_DEFAULTED
+#undef DEFTRAIT_EXPR
+#undef DEFTRAIT_EXPR_DEFAULTED
+#endif
+
+#ifdef DEFTRAIT_TYPE_DEFAULTED
+#undef DEFTRAIT_TYPE
+#undef DEFTRAIT_TYPE_DEFAULTED
+#endif
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index d696fd5..67aea96 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1374,48 +1374,10 @@ struct GTY (()) tree_argument_pack_select {
enum cp_trait_kind
{
- CPTK_BASES,
- CPTK_DIRECT_BASES,
- CPTK_HAS_NOTHROW_ASSIGN,
- CPTK_HAS_NOTHROW_CONSTRUCTOR,
- CPTK_HAS_NOTHROW_COPY,
- CPTK_HAS_TRIVIAL_ASSIGN,
- CPTK_HAS_TRIVIAL_CONSTRUCTOR,
- CPTK_HAS_TRIVIAL_COPY,
- CPTK_HAS_TRIVIAL_DESTRUCTOR,
- CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS,
- CPTK_HAS_VIRTUAL_DESTRUCTOR,
- CPTK_IS_ABSTRACT,
- CPTK_IS_AGGREGATE,
- CPTK_IS_BASE_OF,
- CPTK_IS_CLASS,
- CPTK_IS_EMPTY,
- CPTK_IS_ENUM,
- CPTK_IS_FINAL,
- CPTK_IS_LAYOUT_COMPATIBLE,
- CPTK_IS_LITERAL_TYPE,
- CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF,
- CPTK_IS_POD,
- CPTK_IS_POLYMORPHIC,
- CPTK_IS_SAME_AS,
- CPTK_IS_STD_LAYOUT,
- CPTK_IS_TRIVIAL,
- CPTK_IS_TRIVIALLY_ASSIGNABLE,
- CPTK_IS_TRIVIALLY_CONSTRUCTIBLE,
- CPTK_IS_TRIVIALLY_COPYABLE,
- CPTK_IS_UNION,
- CPTK_UNDERLYING_TYPE,
- CPTK_IS_ASSIGNABLE,
- CPTK_IS_CONSTRUCTIBLE,
- CPTK_IS_NOTHROW_ASSIGNABLE,
- CPTK_IS_NOTHROW_CONSTRUCTIBLE,
- CPTK_IS_CONVERTIBLE,
- CPTK_IS_NOTHROW_CONVERTIBLE,
- CPTK_REF_CONSTRUCTS_FROM_TEMPORARY,
- CPTK_REF_CONVERTS_FROM_TEMPORARY,
- CPTK_REMOVE_CV,
- CPTK_REMOVE_REFERENCE,
- CPTK_REMOVE_CVREF,
+#define DEFTRAIT(TCC, CODE, NAME, ARITY) \
+ CPTK_##CODE,
+#include "cp-trait.def"
+#undef DEFTRAIT
};
/* The types that we are processing. */
diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index b916154..8ca1b8f 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -2617,128 +2617,12 @@ pp_cxx_trait (cxx_pretty_printer *pp, tree t)
switch (kind)
{
- case CPTK_HAS_NOTHROW_ASSIGN:
- pp_cxx_ws_string (pp, "__has_nothrow_assign");
+#define DEFTRAIT(TCC, CODE, NAME, ARITY) \
+ case CPTK_##CODE: \
+ pp_cxx_ws_string (pp, NAME); \
break;
- case CPTK_HAS_TRIVIAL_ASSIGN:
- pp_cxx_ws_string (pp, "__has_trivial_assign");
- break;
- case CPTK_HAS_NOTHROW_CONSTRUCTOR:
- pp_cxx_ws_string (pp, "__has_nothrow_constructor");
- break;
- case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
- pp_cxx_ws_string (pp, "__has_trivial_constructor");
- break;
- case CPTK_HAS_NOTHROW_COPY:
- pp_cxx_ws_string (pp, "__has_nothrow_copy");
- break;
- case CPTK_HAS_TRIVIAL_COPY:
- pp_cxx_ws_string (pp, "__has_trivial_copy");
- break;
- case CPTK_HAS_TRIVIAL_DESTRUCTOR:
- pp_cxx_ws_string (pp, "__has_trivial_destructor");
- break;
- case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
- pp_cxx_ws_string (pp, "__has_unique_object_representations");
- break;
- case CPTK_HAS_VIRTUAL_DESTRUCTOR:
- pp_cxx_ws_string (pp, "__has_virtual_destructor");
- break;
- case CPTK_IS_ABSTRACT:
- pp_cxx_ws_string (pp, "__is_abstract");
- break;
- case CPTK_IS_AGGREGATE:
- pp_cxx_ws_string (pp, "__is_aggregate");
- break;
- case CPTK_IS_BASE_OF:
- pp_cxx_ws_string (pp, "__is_base_of");
- break;
- case CPTK_IS_CLASS:
- pp_cxx_ws_string (pp, "__is_class");
- break;
- case CPTK_IS_EMPTY:
- pp_cxx_ws_string (pp, "__is_empty");
- break;
- case CPTK_IS_ENUM:
- pp_cxx_ws_string (pp, "__is_enum");
- break;
- case CPTK_IS_FINAL:
- pp_cxx_ws_string (pp, "__is_final");
- break;
- case CPTK_IS_LAYOUT_COMPATIBLE:
- pp_cxx_ws_string (pp, "__is_layout_compatible");
- break;
- case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
- pp_cxx_ws_string (pp, "__is_pointer_interconvertible_base_of");
- break;
- case CPTK_IS_POD:
- pp_cxx_ws_string (pp, "__is_pod");
- break;
- case CPTK_IS_POLYMORPHIC:
- pp_cxx_ws_string (pp, "__is_polymorphic");
- break;
- case CPTK_IS_SAME_AS:
- pp_cxx_ws_string (pp, "__is_same");
- break;
- case CPTK_IS_STD_LAYOUT:
- pp_cxx_ws_string (pp, "__is_std_layout");
- break;
- case CPTK_IS_TRIVIAL:
- pp_cxx_ws_string (pp, "__is_trivial");
- break;
- case CPTK_IS_TRIVIALLY_ASSIGNABLE:
- pp_cxx_ws_string (pp, "__is_trivially_assignable");
- break;
- case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
- pp_cxx_ws_string (pp, "__is_trivially_constructible");
- break;
- case CPTK_IS_TRIVIALLY_COPYABLE:
- pp_cxx_ws_string (pp, "__is_trivially_copyable");
- break;
- case CPTK_IS_UNION:
- pp_cxx_ws_string (pp, "__is_union");
- break;
- case CPTK_IS_LITERAL_TYPE:
- pp_cxx_ws_string (pp, "__is_literal_type");
- break;
- case CPTK_IS_ASSIGNABLE:
- pp_cxx_ws_string (pp, "__is_assignable");
- break;
- case CPTK_IS_CONSTRUCTIBLE:
- pp_cxx_ws_string (pp, "__is_constructible");
- break;
- case CPTK_IS_NOTHROW_ASSIGNABLE:
- pp_cxx_ws_string (pp, "__is_nothrow_assignable");
- break;
- case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
- pp_cxx_ws_string (pp, "__is_nothrow_constructible");
- break;
- case CPTK_IS_CONVERTIBLE:
- pp_cxx_ws_string (pp, "__is_convertible");
- break;
- case CPTK_IS_NOTHROW_CONVERTIBLE:
- pp_cxx_ws_string (pp, "__is_nothrow_convertible");
- break;
- case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
- pp_cxx_ws_string (pp, "__reference_constructs_from_temporary");
- break;
- case CPTK_REF_CONVERTS_FROM_TEMPORARY:
- pp_cxx_ws_string (pp, "__reference_converts_from_temporary");
- break;
- case CPTK_UNDERLYING_TYPE:
- pp_cxx_ws_string (pp, "__underlying_type");
- break;
- case CPTK_REMOVE_CV:
- pp_cxx_ws_string (pp, "__remove_cv");
- break;
- case CPTK_REMOVE_REFERENCE:
- pp_cxx_ws_string (pp, "__remove_reference");
- break;
- case CPTK_REMOVE_CVREF:
- pp_cxx_ws_string (pp, "__remove_cvref");
- break;
- default:
- gcc_unreachable ();
+#include "cp-trait.def"
+#undef DEFTRAIT
}
pp_cxx_left_paren (pp);
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index d592d78..8d0e0fa 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1146,16 +1146,18 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword)
case RID_TYPEOF:
/* C++11 extensions. */
case RID_DECLTYPE:
- case RID_UNDERLYING_TYPE:
- case RID_REMOVE_CV:
- case RID_REMOVE_REFERENCE:
- case RID_REMOVE_CVREF:
case RID_CONSTEXPR:
/* C++20 extensions. */
case RID_CONSTINIT:
case RID_CONSTEVAL:
return true;
+#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
+ case RID_##CODE:
+#include "cp-trait.def"
+#undef DEFTRAIT_TYPE
+ return true;
+
default:
if (keyword >= RID_FIRST_INT_N
&& keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
@@ -5895,42 +5897,10 @@ cp_parser_primary_expression (cp_parser *parser,
case RID_OFFSETOF:
return cp_parser_builtin_offsetof (parser);
- case RID_HAS_NOTHROW_ASSIGN:
- case RID_HAS_NOTHROW_CONSTRUCTOR:
- case RID_HAS_NOTHROW_COPY:
- case RID_HAS_TRIVIAL_ASSIGN:
- case RID_HAS_TRIVIAL_CONSTRUCTOR:
- case RID_HAS_TRIVIAL_COPY:
- case RID_HAS_TRIVIAL_DESTRUCTOR:
- case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS:
- case RID_HAS_VIRTUAL_DESTRUCTOR:
- case RID_IS_ABSTRACT:
- case RID_IS_AGGREGATE:
- case RID_IS_BASE_OF:
- case RID_IS_CLASS:
- case RID_IS_EMPTY:
- case RID_IS_ENUM:
- case RID_IS_FINAL:
- case RID_IS_LAYOUT_COMPATIBLE:
- case RID_IS_LITERAL_TYPE:
- case RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
- case RID_IS_POD:
- case RID_IS_POLYMORPHIC:
- case RID_IS_SAME_AS:
- case RID_IS_STD_LAYOUT:
- case RID_IS_TRIVIAL:
- case RID_IS_TRIVIALLY_ASSIGNABLE:
- case RID_IS_TRIVIALLY_CONSTRUCTIBLE:
- case RID_IS_TRIVIALLY_COPYABLE:
- case RID_IS_UNION:
- case RID_IS_ASSIGNABLE:
- case RID_IS_CONSTRUCTIBLE:
- case RID_IS_NOTHROW_ASSIGNABLE:
- case RID_IS_NOTHROW_CONSTRUCTIBLE:
- case RID_IS_CONVERTIBLE:
- case RID_IS_NOTHROW_CONVERTIBLE:
- case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
- case RID_REF_CONVERTS_FROM_TEMPORARY:
+#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
+ case RID_##CODE:
+#include "cp-trait.def"
+#undef DEFTRAIT_EXPR
return cp_parser_trait (parser, token->keyword);
// C++ concepts
@@ -10898,150 +10868,15 @@ cp_parser_trait (cp_parser* parser, enum rid keyword)
switch (keyword)
{
- case RID_HAS_NOTHROW_ASSIGN:
- kind = CPTK_HAS_NOTHROW_ASSIGN;
- break;
- case RID_HAS_NOTHROW_CONSTRUCTOR:
- kind = CPTK_HAS_NOTHROW_CONSTRUCTOR;
- break;
- case RID_HAS_NOTHROW_COPY:
- kind = CPTK_HAS_NOTHROW_COPY;
- break;
- case RID_HAS_TRIVIAL_ASSIGN:
- kind = CPTK_HAS_TRIVIAL_ASSIGN;
- break;
- case RID_HAS_TRIVIAL_CONSTRUCTOR:
- kind = CPTK_HAS_TRIVIAL_CONSTRUCTOR;
- break;
- case RID_HAS_TRIVIAL_COPY:
- kind = CPTK_HAS_TRIVIAL_COPY;
- break;
- case RID_HAS_TRIVIAL_DESTRUCTOR:
- kind = CPTK_HAS_TRIVIAL_DESTRUCTOR;
- break;
- case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS:
- kind = CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS;
- break;
- case RID_HAS_VIRTUAL_DESTRUCTOR:
- kind = CPTK_HAS_VIRTUAL_DESTRUCTOR;
- break;
- case RID_IS_ABSTRACT:
- kind = CPTK_IS_ABSTRACT;
- break;
- case RID_IS_AGGREGATE:
- kind = CPTK_IS_AGGREGATE;
- break;
- case RID_IS_BASE_OF:
- kind = CPTK_IS_BASE_OF;
- binary = true;
- break;
- case RID_IS_CLASS:
- kind = CPTK_IS_CLASS;
- break;
- case RID_IS_EMPTY:
- kind = CPTK_IS_EMPTY;
- break;
- case RID_IS_ENUM:
- kind = CPTK_IS_ENUM;
- break;
- case RID_IS_FINAL:
- kind = CPTK_IS_FINAL;
- break;
- case RID_IS_LAYOUT_COMPATIBLE:
- kind = CPTK_IS_LAYOUT_COMPATIBLE;
- binary = true;
- break;
- case RID_IS_LITERAL_TYPE:
- kind = CPTK_IS_LITERAL_TYPE;
- break;
- case RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
- kind = CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF;
- binary = true;
- break;
- case RID_IS_POD:
- kind = CPTK_IS_POD;
- break;
- case RID_IS_POLYMORPHIC:
- kind = CPTK_IS_POLYMORPHIC;
- break;
- case RID_IS_SAME_AS:
- kind = CPTK_IS_SAME_AS;
- binary = true;
- break;
- case RID_IS_STD_LAYOUT:
- kind = CPTK_IS_STD_LAYOUT;
- break;
- case RID_IS_TRIVIAL:
- kind = CPTK_IS_TRIVIAL;
- break;
- case RID_IS_TRIVIALLY_ASSIGNABLE:
- kind = CPTK_IS_TRIVIALLY_ASSIGNABLE;
- binary = true;
- break;
- case RID_IS_TRIVIALLY_CONSTRUCTIBLE:
- kind = CPTK_IS_TRIVIALLY_CONSTRUCTIBLE;
- variadic = true;
- break;
- case RID_IS_TRIVIALLY_COPYABLE:
- kind = CPTK_IS_TRIVIALLY_COPYABLE;
- break;
- case RID_IS_UNION:
- kind = CPTK_IS_UNION;
- break;
- case RID_UNDERLYING_TYPE:
- kind = CPTK_UNDERLYING_TYPE;
- type = true;
- break;
- case RID_BASES:
- kind = CPTK_BASES;
- break;
- case RID_DIRECT_BASES:
- kind = CPTK_DIRECT_BASES;
- break;
- case RID_IS_ASSIGNABLE:
- kind = CPTK_IS_ASSIGNABLE;
- binary = true;
- break;
- case RID_IS_CONSTRUCTIBLE:
- kind = CPTK_IS_CONSTRUCTIBLE;
- variadic = true;
- break;
- case RID_IS_NOTHROW_ASSIGNABLE:
- kind = CPTK_IS_NOTHROW_ASSIGNABLE;
- binary = true;
- break;
- case RID_IS_NOTHROW_CONSTRUCTIBLE:
- kind = CPTK_IS_NOTHROW_CONSTRUCTIBLE;
- variadic = true;
- break;
- case RID_IS_CONVERTIBLE:
- kind = CPTK_IS_CONVERTIBLE;
- binary = true;
- break;
- case RID_IS_NOTHROW_CONVERTIBLE:
- kind = CPTK_IS_NOTHROW_CONVERTIBLE;
- binary = true;
- break;
- case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
- kind = CPTK_REF_CONSTRUCTS_FROM_TEMPORARY;
- binary = true;
- break;
- case RID_REF_CONVERTS_FROM_TEMPORARY:
- kind = CPTK_REF_CONVERTS_FROM_TEMPORARY;
- binary = true;
- break;
- case RID_REMOVE_CV:
- kind = CPTK_REMOVE_CV;
- type = true;
- break;
- case RID_REMOVE_REFERENCE:
- kind = CPTK_REMOVE_REFERENCE;
- type = true;
- break;
- case RID_REMOVE_CVREF:
- kind = CPTK_REMOVE_CVREF;
- type = true;
+#define DEFTRAIT(TCC, CODE, NAME, ARITY) \
+ case RID_##CODE: \
+ kind = CPTK_##CODE; \
+ binary = (ARITY == 2); \
+ variadic = (ARITY == -1); \
+ type = (TCC == tcc_type); \
break;
+#include "cp-trait.def"
+#undef DEFTRAIT
default:
gcc_unreachable ();
}
@@ -19881,10 +19716,10 @@ cp_parser_simple_type_specifier (cp_parser* parser,
return type;
- case RID_UNDERLYING_TYPE:
- case RID_REMOVE_CV:
- case RID_REMOVE_REFERENCE:
- case RID_REMOVE_CVREF:
+#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
+ case RID_##CODE:
+#include "cp-trait.def"
+#undef DEFTRAIT_TYPE
type = cp_parser_trait (parser, token->keyword);
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs, type,
@@ -19893,14 +19728,6 @@ cp_parser_simple_type_specifier (cp_parser* parser,
return type;
- case RID_BASES:
- case RID_DIRECT_BASES:
- type = cp_parser_trait (parser, token->keyword);
- if (decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
- token,
- /*type_definition_p=*/false);
- return type;
default:
break;
}