clang 19.0.0git
TypeTraits.cpp
Go to the documentation of this file.
1//===--- TypeTraits.cpp - Type Traits Support -----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the type traits support functions.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/Support/ErrorHandling.h"
15#include <cassert>
16#include <cstring>
17using namespace clang;
18
19static constexpr const char *TypeTraitNames[] = {
20#define TYPE_TRAIT_1(Spelling, Name, Key) #Name,
21#include "clang/Basic/TokenKinds.def"
22#define TYPE_TRAIT_2(Spelling, Name, Key) #Name,
23#include "clang/Basic/TokenKinds.def"
24#define TYPE_TRAIT_N(Spelling, Name, Key) #Name,
25#include "clang/Basic/TokenKinds.def"
26};
27
28static constexpr const char *TypeTraitSpellings[] = {
29#define TYPE_TRAIT_1(Spelling, Name, Key) #Spelling,
30#include "clang/Basic/TokenKinds.def"
31#define TYPE_TRAIT_2(Spelling, Name, Key) #Spelling,
32#include "clang/Basic/TokenKinds.def"
33#define TYPE_TRAIT_N(Spelling, Name, Key) #Spelling,
34#include "clang/Basic/TokenKinds.def"
35};
36
37static constexpr const char *ArrayTypeTraitNames[] = {
38#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) #Name,
39#include "clang/Basic/TokenKinds.def"
40};
41
42static constexpr const char *ArrayTypeTraitSpellings[] = {
43#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) #Spelling,
44#include "clang/Basic/TokenKinds.def"
45};
46
47static constexpr const char *UnaryExprOrTypeTraitNames[] = {
48#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) #Name,
49#define CXX11_UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) #Name,
50#include "clang/Basic/TokenKinds.def"
51};
52
53static constexpr const char *UnaryExprOrTypeTraitSpellings[] = {
54#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) #Spelling,
55#define CXX11_UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) #Spelling,
56#include "clang/Basic/TokenKinds.def"
57};
58
59static constexpr const unsigned TypeTraitArities[] = {
60#define TYPE_TRAIT_1(Spelling, Name, Key) 1,
61#include "clang/Basic/TokenKinds.def"
62#define TYPE_TRAIT_2(Spelling, Name, Key) 2,
63#include "clang/Basic/TokenKinds.def"
64#define TYPE_TRAIT_N(Spelling, Name, Key) 0,
65#include "clang/Basic/TokenKinds.def"
66};
67
69 assert(T <= TT_Last && "invalid enum value!");
70 return TypeTraitNames[T];
71}
72
74 assert(T <= ATT_Last && "invalid enum value!");
75 return ArrayTypeTraitNames[T];
76}
77
79 assert(T <= UETT_Last && "invalid enum value!");
81}
82
84 assert(T <= TT_Last && "invalid enum value!");
85 if (T == BTT_IsDeducible) {
86 // The __is_deducible is an internal-only type trait. To hide it from
87 // external users, we define it with an empty spelling name, preventing the
88 // clang parser from recognizing its token kind.
89 // However, other components such as the AST dump still require the real
90 // type trait name. Therefore, we return the real name when needed.
91 assert(std::strlen(TypeTraitSpellings[T]) == 0);
92 return "__is_deducible";
93 }
94 return TypeTraitSpellings[T];
95}
96
98 assert(T <= ATT_Last && "invalid enum value!");
100}
101
103 assert(T <= UETT_Last && "invalid enum value!");
105}
106
108 assert(T <= TT_Last && "invalid enum value!");
109 return TypeTraitArities[T];
110}
static constexpr const char * UnaryExprOrTypeTraitSpellings[]
Definition: TypeTraits.cpp:53
static constexpr const char * TypeTraitNames[]
Definition: TypeTraits.cpp:19
static constexpr const char * ArrayTypeTraitNames[]
Definition: TypeTraits.cpp:37
static constexpr const char * ArrayTypeTraitSpellings[]
Definition: TypeTraits.cpp:42
static constexpr const unsigned TypeTraitArities[]
Definition: TypeTraits.cpp:59
static constexpr const char * TypeTraitSpellings[]
Definition: TypeTraits.cpp:28
static constexpr const char * UnaryExprOrTypeTraitNames[]
Definition: TypeTraits.cpp:47
Defines enumerations for the type traits support.
The JSON file list parser is used to communicate input to InstallAPI.
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
@ ATT_Last
Definition: TypeTraits.h:45
unsigned getTypeTraitArity(TypeTrait T) LLVM_READONLY
Return the arity of the type trait T.
Definition: TypeTraits.cpp:107
const char * getTraitName(ExpressionTrait T) LLVM_READONLY
Return the internal name of type trait T. Never null.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
@ UETT_Last
Definition: TypeTraits.h:55
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
const FunctionProtoType * T
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ TT_Last
Definition: TypeTraits.h:36