clang 24.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 <cassert>
15#include <cstring>
16using namespace clang;
17
18// static constexpr const char *TypeTraitNames[] = {...};
19// static constexpr const char *TypeTraitSpellings[] = {...};
20// static constexpr const char *ArrayTypeTraitNames[] = {...};
21// static constexpr const char *ArrayTypeTraitSpellings[] = {...};
22// static constexpr const char *UnaryExprOrTypeTraitNames[] = {...};
23// static constexpr const char *UnaryExprOrTypeTraitSpellings[] = {...};
24// static constexpr const unsigned TypeTraitArities[] = {...};
25#define EMIT_ARRAYS
26#include "clang/Basic/Traits.inc"
27
28const char *clang::getTraitName(TypeTrait T) {
29 assert(T <= TT_Last && "invalid enum value!");
30 return TypeTraitNames[T];
31}
32
33const char *clang::getTraitName(ArrayTypeTrait T) {
34 assert(T <= ATT_Last && "invalid enum value!");
35 return ArrayTypeTraitNames[T];
36}
37
38const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
39 assert(T <= UETT_Last && "invalid enum value!");
40 return UnaryExprOrTypeTraitNames[T];
41}
42
43const char *clang::getTraitSpelling(TypeTrait T) {
44 assert(T <= TT_Last && "invalid enum value!");
45 if (T == BTT_IsDeducible) {
46 // The __is_deducible is an internal-only type trait. To hide it from
47 // external users, we define it with an empty spelling name, preventing the
48 // clang parser from recognizing its token kind.
49 // However, other components such as the AST dump still require the real
50 // type trait name. Therefore, we return the real name when needed.
51 assert(std::strlen(TypeTraitSpellings[T]) == 0);
52 return "__is_deducible";
53 }
54 return TypeTraitSpellings[T];
55}
56
57const char *clang::getTraitSpelling(ArrayTypeTrait T) {
58 assert(T <= ATT_Last && "invalid enum value!");
59 return ArrayTypeTraitSpellings[T];
60}
61
62const char *clang::getTraitSpelling(UnaryExprOrTypeTrait T) {
63 assert(T <= UETT_Last && "invalid enum value!");
64 return UnaryExprOrTypeTraitSpellings[T];
65}
66
67unsigned clang::getTypeTraitArity(TypeTrait T) {
68 assert(T <= TT_Last && "invalid enum value!");
69 return TypeTraitArities[T];
70}
Defines enumerations for the type traits support.
The JSON file list parser is used to communicate input to InstallAPI.
unsigned getTypeTraitArity(TypeTrait T) LLVM_READONLY
Return the arity of the type trait T.
const char * getTraitName(ExpressionTrait T) LLVM_READONLY
Return the internal name of type trait T. Never null.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.