diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-28 22:39:52 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-28 22:39:52 +0000 |
commit | 601d6e4c7b012ff5dcda4089029c416014cb85c6 (patch) | |
tree | 299b7cb29b633a8dbb53d0529add060607b0878e | |
parent | d517ac0682b012d407434806f2a97bf1dfcf18bb (diff) | |
download | bcm5719-llvm-601d6e4c7b012ff5dcda4089029c416014cb85c6.tar.gz bcm5719-llvm-601d6e4c7b012ff5dcda4089029c416014cb85c6.zip |
Add printing of access specifiers to DeclPrinter. The formatting is pretty bad but it works :)
llvm-svn: 80402
-rw-r--r-- | clang/lib/AST/DeclPrinter.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 1dea2238bc3..51e15bdbe0f 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -33,6 +33,8 @@ namespace { 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::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) { } +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 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { 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 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { 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 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { 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); } } |