21 namespace ast_type_traits {
23 const ASTNodeKind::KindInfo ASTNodeKind::AllKindInfo[] = {
24 { NKI_None,
"<None>" },
25 { NKI_None,
"TemplateArgument" },
26 { NKI_None,
"TemplateName" },
27 { NKI_None,
"NestedNameSpecifierLoc" },
28 { NKI_None,
"QualType" },
29 { NKI_None,
"TypeLoc" },
30 { NKI_None,
"CXXCtorInitializer" },
31 { NKI_None,
"NestedNameSpecifier" },
33 #define DECL(DERIVED, BASE) { NKI_##BASE, #DERIVED "Decl" },
34 #include "clang/AST/DeclNodes.inc"
36 #define STMT(DERIVED, BASE) { NKI_##BASE, #DERIVED },
37 #include "clang/AST/StmtNodes.inc"
39 #define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" },
40 #include "clang/AST/TypeNodes.def"
44 return isBaseOf(KindId, Other.KindId, Distance);
49 if (Base == NKI_None || Derived == NKI_None)
return false;
51 while (Derived != Base && Derived != NKI_None) {
52 Derived = AllKindInfo[Derived].ParentId;
57 return Derived == Base;
64 if (Kind1.
isBaseOf(Kind2))
return Kind2;
65 if (Kind2.
isBaseOf(Kind1))
return Kind1;
71 NodeKindId Parent = Kind1.KindId;
72 while (!
isBaseOf(Parent, Kind2.KindId,
nullptr) && Parent != NKI_None) {
73 Parent = AllKindInfo[Parent].ParentId;
80 #define DECL(DERIVED, BASE) \
81 case Decl::DERIVED: return ASTNodeKind(NKI_##DERIVED##Decl);
82 #define ABSTRACT_DECL(D)
83 #include "clang/AST/DeclNodes.inc"
85 llvm_unreachable(
"invalid decl kind");
91 #define STMT(CLASS, PARENT) \
92 case Stmt::CLASS##Class: return ASTNodeKind(NKI_##CLASS);
93 #define ABSTRACT_STMT(S)
94 #include "clang/AST/StmtNodes.inc"
96 llvm_unreachable(
"invalid stmt kind");
101 #define TYPE(Class, Base) \
102 case Type::Class: return ASTNodeKind(NKI_##Class##Type);
103 #define ABSTRACT_TYPE(Class, Base)
104 #include "clang/AST/TypeNodes.def"
106 llvm_unreachable(
"invalid type kind");
118 NNSL->getNestedNameSpecifier()->print(OS, PP);
119 else if (
const QualType *QT = get<QualType>())
121 else if (
const TypeLoc *TL = get<TypeLoc>())
122 TL->getType().print(OS, PP);
123 else if (
const Decl *D = get<Decl>())
125 else if (
const Stmt *
S = get<Stmt>())
126 S->printPretty(OS,
nullptr, PP);
127 else if (
const Type *T = get<Type>())
130 OS <<
"Unable to print values of type " << NodeKind.
asStringRef() <<
"\n";
134 if (
const Decl *D = get<Decl>())
136 else if (
const Stmt *
S = get<Stmt>())
138 else if (
const Type *T = get<Type>())
141 OS <<
"Unable to dump values of type " << NodeKind.
asStringRef() <<
"\n";
146 return CCI->getSourceRange();
148 return NNSL->getSourceRange();
149 if (
const TypeLoc *TL = get<TypeLoc>())
150 return TL->getSourceRange();
151 if (
const Decl *D = get<Decl>())
152 return D->getSourceRange();
153 if (
const Stmt *
S = get<Stmt>())
154 return S->getSourceRange();
Defines the clang::ASTContext interface.
StmtClass getStmtClass() const
A (possibly-)qualified type.
static ASTNodeKind getFromNode(const Decl &D)
Construct an identifier for the dynamic type of the node.
Stmt - This represents one statement.
Decl - This represents one declaration (or definition), e.g.
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.
Represents a C++ template name within the type system.
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.