AST printing for C++ base classes
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72617 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index 2858c0a..1b627ef 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -54,9 +54,10 @@
void VisitOriginalParmVarDecl(OriginalParmVarDecl *D);
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
+ void VisitNamespaceDecl(NamespaceDecl *D);
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
- void VisitNamespaceDecl(NamespaceDecl *D);
+ void VisitCXXRecordDecl(CXXRecordDecl *D);
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitTemplateDecl(TemplateDecl *D);
void VisitObjCMethodDecl(ObjCMethodDecl *D);
@@ -270,7 +271,6 @@
}
void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
- // print a free standing tag decl (e.g. "struct x;").
Out << D->getKindName();
if (D->getIdentifier()) {
Out << " ";
@@ -429,6 +429,12 @@
"OverloadedFunctionDecls aren't really decls and are never printed");
}
+void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
+ Out << "namespace " << D->getNameAsString() << " {\n";
+ VisitDeclContext(D);
+ Indent() << "}";
+}
+
void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Out << "using namespace ";
if (D->getQualifier())
@@ -443,10 +449,42 @@
Out << D->getAliasedNamespace()->getNameAsString();
}
-void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
- Out << "namespace " << D->getNameAsString() << " {\n";
- VisitDeclContext(D);
- Indent() << "}";
+void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
+ Out << D->getKindName();
+ if (D->getIdentifier()) {
+ Out << " ";
+ Out << D->getNameAsString();
+ }
+
+ if (D->isDefinition()) {
+ // Print the base classes
+ if (D->getNumBases()) {
+ Out << " : ";
+ for(CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
+ BaseEnd = D->bases_end();
+ Base != BaseEnd; ++Base) {
+ if (Base != D->bases_begin())
+ Out << ", ";
+
+ if (Base->isVirtual())
+ Out << "virtual ";
+
+ switch(Base->getAccessSpecifierAsWritten()) {
+ case AS_none: break;
+ case AS_public: Out << "public "; break;
+ case AS_protected: Out << "protected "; break;
+ case AS_private: Out << " private "; break;
+ }
+
+ Out << Base->getType().getAsString(Policy);
+ }
+ }
+
+ // Print the class definition
+ Out << " {\n";
+ VisitDeclContext(D);
+ Indent() << "}";
+ }
}
void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
@@ -493,7 +531,7 @@
else
Out << "+ ";
if (!OMD->getResultType().isNull())
- Out << '(' << OMD->getResultType().getAsString() << ")";
+ Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
std::string name = OMD->getSelector().getAsString();
std::string::size_type pos, lastPos = 0;
@@ -502,7 +540,7 @@
// FIXME: selector is missing here!
pos = name.find_first_of(":", lastPos);
Out << " " << name.substr(lastPos, pos - lastPos);
- Out << ":(" << (*PI)->getType().getAsString() << ")"
+ Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
<< (*PI)->getNameAsString();
lastPos = pos + 1;
}
diff --git a/test/Coverage/cxx-language-features.inc b/test/Coverage/cxx-language-features.inc
index bac6bc7..51c1104 100644
--- a/test/Coverage/cxx-language-features.inc
+++ b/test/Coverage/cxx-language-features.inc
@@ -12,3 +12,10 @@
using namespace std;
namespace safestl = ::std::debug;
+
+class Base1 {
+};
+
+class Base2 { };
+
+class Derived1 : Base1, virtual public Base2 { };