[cfe-commits] r72617 - in /cfe/trunk: lib/AST/DeclPrinter.cpp test/Coverage/cxx-language-features.inc

Douglas Gregor dgregor at apple.com
Fri May 29 23:58:37 PDT 2009


Author: dgregor
Date: Sat May 30 01:58:37 2009
New Revision: 72617

URL: http://llvm.org/viewvc/llvm-project?rev=72617&view=rev
Log:
AST printing for C++ base classes

Modified:
    cfe/trunk/lib/AST/DeclPrinter.cpp
    cfe/trunk/test/Coverage/cxx-language-features.inc

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=72617&r1=72616&r2=72617&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat May 30 01:58:37 2009
@@ -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;
   }

Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=72617&r1=72616&r2=72617&view=diff

==============================================================================
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Sat May 30 01:58:37 2009
@@ -12,3 +12,10 @@
 using namespace std;
 
 namespace safestl = ::std::debug;
+
+class Base1 { 
+};
+
+class Base2 { };
+
+class Derived1 : Base1, virtual public Base2 { };





More information about the cfe-commits mailing list