diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTTypeTraits.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTTypeTraits.cpp b/clang/lib/AST/ASTTypeTraits.cpp index 7cf07593a7a..ae47ea98882 100644 --- a/clang/lib/AST/ASTTypeTraits.cpp +++ b/clang/lib/AST/ASTTypeTraits.cpp @@ -14,6 +14,8 @@ //===----------------------------------------------------------------------===// #include "clang/AST/ASTTypeTraits.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" namespace clang { namespace ast_type_traits { @@ -54,5 +56,50 @@ bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived) { StringRef ASTNodeKind::asStringRef() const { return AllKindInfo[KindId].Name; } +void DynTypedNode::print(llvm::raw_ostream &OS, + const PrintingPolicy &PP) const { + if (const TemplateArgument *TA = get<TemplateArgument>()) + TA->print(PP, OS); + else if (const NestedNameSpecifier *NNS = get<NestedNameSpecifier>()) + NNS->print(OS, PP); + else if (const NestedNameSpecifierLoc *NNSL = get<NestedNameSpecifierLoc>()) + NNSL->getNestedNameSpecifier()->print(OS, PP); + else if (const QualType *QT = get<QualType>()) + QT->print(OS, PP); + else if (const TypeLoc *TL = get<TypeLoc>()) + TL->getType().print(OS, PP); + else if (const Decl *D = get<Decl>()) + D->print(OS, PP); + else if (const Stmt *S = get<Stmt>()) + S->printPretty(OS, 0, PP); + else if (const Type *T = get<Type>()) + QualType(T, 0).print(OS, PP); + else + OS << "Unable to print values of type " << NodeKind.asStringRef() << "\n"; +} + +void DynTypedNode::dump(llvm::raw_ostream &OS, SourceManager &SM) const { + if (const Decl *D = get<Decl>()) + D->dump(OS); + else if (const Stmt *S = get<Stmt>()) + S->dump(OS, SM); + else + OS << "Unable to dump values of type " << NodeKind.asStringRef() << "\n"; +} + +SourceRange DynTypedNode::getSourceRange() const { + if (const CXXCtorInitializer *CCI = get<CXXCtorInitializer>()) + return CCI->getSourceRange(); + if (const NestedNameSpecifierLoc *NNSL = get<NestedNameSpecifierLoc>()) + return NNSL->getSourceRange(); + if (const TypeLoc *TL = get<TypeLoc>()) + return TL->getSourceRange(); + if (const Decl *D = get<Decl>()) + return D->getSourceRange(); + if (const Stmt *S = get<Stmt>()) + return S->getSourceRange(); + return SourceRange(); +} + } // end namespace ast_type_traits } // end namespace clang |