summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-11-06 00:27:12 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-11-06 00:27:12 +0000
commitb23b39da218affebbe8d2a4e45b769b7ca198d2e (patch)
treed463babc9293bc45ee187525b8bf518f436ee003 /clang/lib
parent093a729e03472cba2e89fd2d2988a31cf56dbe5a (diff)
downloadbcm5719-llvm-b23b39da218affebbe8d2a4e45b769b7ca198d2e.tar.gz
bcm5719-llvm-b23b39da218affebbe8d2a4e45b769b7ca198d2e.zip
Introduce DynTypedNode::print, dump and getSourceRange.
These functions can generally be applied to multiple kinds of AST node, so it makes sense to add them to DynTypedNode. Differential Revision: http://llvm-reviews.chandlerc.com/D2096 llvm-svn: 194113
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTTypeTraits.cpp47
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
OpenPOWER on IntegriCloud