[cfe-commits] r80402 - /cfe/trunk/lib/AST/DeclPrinter.cpp

Anders Carlsson andersca at mac.com
Fri Aug 28 15:39:52 PDT 2009


Author: andersca
Date: Fri Aug 28 17:39:52 2009
New Revision: 80402

URL: http://llvm.org/viewvc/llvm-project?rev=80402&view=rev
Log:
Add printing of access specifiers to DeclPrinter. The formatting is pretty bad but it works :)

Modified:
    cfe/trunk/lib/AST/DeclPrinter.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Fri Aug 28 17:39:52 2009
@@ -33,6 +33,8 @@
     llvm::raw_ostream& Indent();
     void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls);
 
+    void Print(AccessSpecifier AS);
+    
   public:
     DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context, 
                 const PrintingPolicy &Policy,
@@ -165,6 +167,15 @@
 
 }
 
+void DeclPrinter::Print(AccessSpecifier AS) {
+  switch(AS) {
+  case AS_none:      break;
+  case AS_public:    Out << "public"; break;
+  case AS_protected: Out << "protected"; break;
+  case AS_private:   Out << " private"; break;
+  }
+}
+
 //----------------------------------------------------------------------------
 // Common C declarations
 //----------------------------------------------------------------------------
@@ -173,6 +184,9 @@
   if (Indent)
     Indentation += Policy.Indentation;
 
+  bool PrintAccess = isa<CXXRecordDecl>(DC);
+  AccessSpecifier CurAS = AS_none;
+  
   llvm::SmallVector<Decl*, 2> Decls;
   for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
        D != DEnd; ++D) {
@@ -186,6 +200,15 @@
         continue;
     }
 
+    if (PrintAccess) {
+      AccessSpecifier AS = D->getAccess();
+      if (AS != CurAS) {
+        Print(AS);
+        Out << ":\n";
+        CurAS = AS;
+      }
+    }
+    
     // The next bits of code handles stuff like "struct {int x;} a,b"; we're
     // forced to merge the declarations because there's no other way to
     // refer to the struct in question.  This limited merging is safe without
@@ -542,14 +565,8 @@
         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(Base->getAccessSpecifierAsWritten());
+        Out << " " << Base->getType().getAsString(Policy);
       }
     }
 





More information about the cfe-commits mailing list