21 namespace ast_type_traits {
23 const ASTNodeKind::KindInfo ASTNodeKind::AllKindInfo[] = {
24 { NKI_None,
"<None>" },
25 { NKI_None,
"TemplateArgument" },
26 { NKI_None,
"NestedNameSpecifierLoc" },
27 { NKI_None,
"QualType" },
28 { NKI_None,
"TypeLoc" },
29 { NKI_None,
"CXXCtorInitializer" },
30 { NKI_None,
"NestedNameSpecifier" },
32 #define DECL(DERIVED, BASE) { NKI_##BASE, #DERIVED "Decl" },
33 #include "clang/AST/DeclNodes.inc"
35 #define STMT(DERIVED, BASE) { NKI_##BASE, #DERIVED },
36 #include "clang/AST/StmtNodes.inc"
38 #define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" },
39 #include "clang/AST/TypeNodes.def"
43 return isBaseOf(KindId, Other.KindId, Distance);
48 if (Base == NKI_None || Derived == NKI_None)
return false;
50 while (Derived != Base && Derived != NKI_None) {
51 Derived = AllKindInfo[Derived].ParentId;
56 return Derived == Base;
63 if (Kind1.
isBaseOf(Kind2))
return Kind2;
64 if (Kind2.
isBaseOf(Kind1))
return Kind1;
70 NodeKindId Parent = Kind1.KindId;
71 while (!
isBaseOf(Parent, Kind2.KindId,
nullptr) && Parent != NKI_None) {
72 Parent = AllKindInfo[Parent].ParentId;
78 switch (D.getKind()) {
79 #define DECL(DERIVED, BASE) \
80 case Decl::DERIVED: return ASTNodeKind(NKI_##DERIVED##Decl);
81 #define ABSTRACT_DECL(D)
82 #include "clang/AST/DeclNodes.inc"
84 llvm_unreachable(
"invalid decl kind");
88 switch (S.getStmtClass()) {
89 case Stmt::NoStmtClass:
return NKI_None;
90 #define STMT(CLASS, PARENT) \
91 case Stmt::CLASS##Class: return ASTNodeKind(NKI_##CLASS);
92 #define ABSTRACT_STMT(S)
93 #include "clang/AST/StmtNodes.inc"
95 llvm_unreachable(
"invalid stmt kind");
100 #define TYPE(Class, Base) \
101 case Type::Class: return ASTNodeKind(NKI_##Class##Type);
102 #define ABSTRACT_TYPE(Class, Base)
103 #include "clang/AST/TypeNodes.def"
105 llvm_unreachable(
"invalid type kind");
115 NNSL->getNestedNameSpecifier()->print(OS, PP);
116 else if (
const QualType *QT = get<QualType>())
118 else if (
const TypeLoc *TL = get<TypeLoc>())
119 TL->getType().print(OS, PP);
120 else if (
const Decl *D = get<Decl>())
122 else if (
const Stmt *
S = get<Stmt>())
123 S->printPretty(OS,
nullptr, PP);
124 else if (
const Type *T = get<Type>())
127 OS <<
"Unable to print values of type " << NodeKind.
asStringRef() <<
"\n";
131 if (
const Decl *D = get<Decl>())
133 else if (
const Stmt *
S = get<Stmt>())
136 OS <<
"Unable to dump values of type " << NodeKind.
asStringRef() <<
"\n";
141 return CCI->getSourceRange();
143 return NNSL->getSourceRange();
144 if (
const TypeLoc *TL = get<TypeLoc>())
145 return TL->getSourceRange();
146 if (
const Decl *D = get<Decl>())
147 return D->getSourceRange();
148 if (
const Stmt *
S = get<Stmt>())
149 return S->getSourceRange();
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
static ASTNodeKind getFromNode(const Decl &D)
Construct an identifier for the dynamic type of the node.
The base class of the type hierarchy.
Describes how types, statements, expressions, and declarations should be printed. ...
Base wrapper for a particular "section" of type source info.
A C++ nested-name-specifier augmented with source location information.
bool isBaseOf(ASTNodeKind Other, unsigned *Distance=nullptr) const
Returns true if this is a base kind of (or same as) Other.
ASTNodeKind()
Empty identifier. It matches nothing.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
TypeClass getTypeClass() const
void dump(llvm::raw_ostream &OS, SourceManager &SM) const
Dumps the node to the given output stream.
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
StringRef asStringRef() const
String representation of the kind.
Represents a template argument.
static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived common ancestor between Kind1 and Kind2.
Represents a C++ base or member initializer.
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
A trivial tuple used to represent a source range.
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
This class handles loading and caching of source files into memory.