aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-objcp-common.cc
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/cp-objcp-common.cc
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/cp-objcp-common.cc')
-rw-r--r--gcc/cp/cp-objcp-common.cc44
1 files changed, 4 insertions, 40 deletions
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;