Go to the documentation of this file.
24 using namespace clang;
26 const ASTNodeKind::KindInfo ASTNodeKind::AllKindInfo[] = {
28 {NKI_None,
"TemplateArgument"},
29 {NKI_None,
"TemplateArgumentLoc"},
30 {NKI_None,
"LambdaCapture"},
31 {NKI_None,
"TemplateName"},
32 {NKI_None,
"NestedNameSpecifierLoc"},
33 {NKI_None,
"QualType"},
34 #define TYPELOC(CLASS, PARENT) {NKI_##PARENT, #CLASS "TypeLoc"},
35 #include "clang/AST/TypeLocNodes.def"
36 {NKI_None,
"TypeLoc"},
37 {NKI_None,
"CXXBaseSpecifier"},
38 {NKI_None,
"CXXCtorInitializer"},
39 {NKI_None,
"NestedNameSpecifier"},
41 #define DECL(DERIVED, BASE) { NKI_##BASE, #DERIVED "Decl" },
42 #include "clang/AST/DeclNodes.inc"
44 #define STMT(DERIVED, BASE) { NKI_##BASE, #DERIVED },
45 #include "clang/AST/StmtNodes.inc"
47 #define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" },
48 #include "clang/AST/TypeNodes.inc"
49 {NKI_None,
"OMPClause"},
50 #define GEN_CLANG_CLAUSE_CLASS
51 #define CLAUSE_CLASS(Enum, Str, Class) {NKI_OMPClause, #Class},
52 #include "llvm/Frontend/OpenMP/OMP.inc"
54 #define ATTR(A) {NKI_Attr, #A "Attr"},
55 #include "clang/Basic/AttrList.inc"
56 {NKI_None,
"ObjCProtocolLoc"},
60 return isBaseOf(KindId, Other.KindId, Distance);
65 if (
Base == NKI_None || Derived == NKI_None)
return false;
67 while (Derived !=
Base && Derived != NKI_None) {
68 Derived = AllKindInfo[Derived].ParentId;
73 return Derived ==
Base;
77 NodeKindId LastId = KindId;
79 NodeKindId ParentId = AllKindInfo[LastId].ParentId;
80 if (ParentId == NKI_None)
91 if (Kind1.
isBaseOf(Kind2))
return Kind2;
92 if (Kind2.
isBaseOf(Kind1))
return Kind1;
98 NodeKindId
Parent = Kind1.KindId;
107 #define DECL(DERIVED, BASE) \
108 case Decl::DERIVED: return ASTNodeKind(NKI_##DERIVED##Decl);
109 #define ABSTRACT_DECL(D)
110 #include "clang/AST/DeclNodes.inc"
112 llvm_unreachable(
"invalid decl kind");
116 switch (S.getStmtClass()) {
118 #define STMT(CLASS, PARENT) \
119 case Stmt::CLASS##Class: return ASTNodeKind(NKI_##CLASS);
120 #define ABSTRACT_STMT(S)
121 #include "clang/AST/StmtNodes.inc"
123 llvm_unreachable(
"invalid stmt kind");
128 #define TYPE(Class, Base) \
129 case Type::Class: return ASTNodeKind(NKI_##Class##Type);
130 #define ABSTRACT_TYPE(Class, Base)
131 #include "clang/AST/TypeNodes.inc"
133 llvm_unreachable(
"invalid type kind");
138 #define ABSTRACT_TYPELOC(CLASS, PARENT)
139 #define TYPELOC(CLASS, PARENT) \
140 case TypeLoc::CLASS: \
141 return ASTNodeKind(NKI_##CLASS##TypeLoc);
142 #include "clang/AST/TypeLocNodes.def"
144 llvm_unreachable(
"invalid typeloc kind");
148 switch (C.getClauseKind()) {
149 #define GEN_CLANG_CLAUSE_CLASS
150 #define CLAUSE_CLASS(Enum, Str, Class) \
151 case llvm::omp::Clause::Enum: \
152 return ASTNodeKind(NKI_##Class);
153 #define CLAUSE_NO_CLASS(Enum, Str) \
154 case llvm::omp::Clause::Enum: \
155 llvm_unreachable("unexpected OpenMP clause kind");
156 #include "llvm/Frontend/OpenMP/OMP.inc"
158 llvm_unreachable(
"invalid omp clause kind");
165 return ASTNodeKind(NKI_##A##Attr);
166 #include "clang/Basic/AttrList.inc"
168 llvm_unreachable(
"invalid attr kind");
174 TA->print(PP, OS,
true);
176 TAL->getArgument().print(PP, OS,
true);
185 OS <<
"(empty NestedNameSpecifierLoc)";
186 }
else if (
const QualType *QT = get<QualType>())
188 else if (
const TypeLoc *TL = get<TypeLoc>())
189 TL->getType().print(OS, PP);
190 else if (
const Decl *D = get<Decl>())
192 else if (
const Stmt *S = get<Stmt>())
193 S->printPretty(OS,
nullptr, PP);
194 else if (
const Type *T = get<Type>())
196 else if (
const Attr *A = get<Attr>())
197 A->printPretty(OS, PP);
199 P->getProtocol()->print(OS, PP);
201 OS <<
"Unable to print values of type " << NodeKind.
asStringRef() <<
"\n";
206 if (
const Decl *D = get<Decl>())
208 else if (
const Stmt *S = get<Stmt>())
209 S->dump(OS, Context);
210 else if (
const Type *T = get<Type>())
211 T->dump(OS, Context);
213 OS <<
"Unable to dump values of type " << NodeKind.
asStringRef() <<
"\n";
218 return CCI->getSourceRange();
220 return NNSL->getSourceRange();
221 if (
const TypeLoc *TL = get<TypeLoc>())
222 return TL->getSourceRange();
223 if (
const Decl *D = get<Decl>())
224 return D->getSourceRange();
225 if (
const Stmt *S = get<Stmt>())
226 return S->getSourceRange();
228 return TAL->getSourceRange();
229 if (
const auto *C = get<OMPClause>())
230 return SourceRange(C->getBeginLoc(), C->getEndLoc());
231 if (
const auto *CBS = get<CXXBaseSpecifier>())
232 return CBS->getSourceRange();
233 if (
const auto *A = get<Attr>())
234 return A->getRange();
236 return P->getSourceRange();
bool isBaseOf(ASTNodeKind Other, unsigned *Distance=nullptr) const
Returns true if this is a base kind of (or same as) Other.
A trivial tuple used to represent a source range.
void dump(llvm::raw_ostream &OS, const ASTContext &Context) const
Dumps the node to the given output stream.
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived common ancestor between Kind1 and Kind2.
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
A (possibly-)qualified type.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Describes how types, statements, expressions, and declarations should be printed.
ASTNodeKind()
Empty identifier. It matches nothing.
The base class of the type hierarchy.
This is a basic class for representing single OpenMP clause.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a template argument.
attr::Kind getKind() const
Location wrapper for a TemplateArgument.
A C++ nested-name-specifier augmented with source location information.
TypeClass getTypeClass() const
Represents a C++ template name within the type system.
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
Decl - This represents one declaration (or definition), e.g.
Base wrapper for a particular "section" of type source info.
TypeLocClass getTypeLocClass() const
Stmt - This represents one statement.
Attr - This represents one attribute.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
Represents a C++ base or member initializer.
ASTNodeKind getCladeKind() const
StringRef asStringRef() const
String representation of the kind.
static ASTNodeKind getFromNode(const Decl &D)