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