diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-09-30 11:06:54 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-09-30 11:06:54 -0400 |
commit | 1e2c124d71ac051373a30495793883c45bcc5415 (patch) | |
tree | 281e8aa9254d44be03e336282fc885c29eab597c /gcc/cp/constraint.cc | |
parent | 3bb2d70d38027c43b437dee98ee1a7a15843682f (diff) | |
download | gcc-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/constraint.cc')
-rw-r--r-- | gcc/cp/constraint.cc | 12 |
1 files changed, 5 insertions, 7 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. */ |