diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-11-19 19:22:57 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-11-19 19:22:57 +0000 |
commit | 1bea8807bcd2be10bf6309a3a848489434464ced (patch) | |
tree | f3297b8516e1c0c85cebcae0613143e0242066db /lib/AST/DeclPrinter.cpp | |
parent | 1a026803b7886ed265fc63dfddaaa5d3712760e3 (diff) |
Add support for pretty-printing attributes, from Richard Membarth!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclPrinter.cpp')
-rw-r--r-- | lib/AST/DeclPrinter.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 1553af1b13..e5b4b0431b 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -85,6 +85,7 @@ namespace { void PrintTemplateParameters(const TemplateParameterList *Params, const TemplateArgumentList *Args); + void prettyPrintAttributes(Decl *D); }; } @@ -182,6 +183,16 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) { return Out; } +void DeclPrinter::prettyPrintAttributes(Decl *D) { + if (D->hasAttrs()) { + AttrVec &Attrs = D->getAttrs(); + for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) { + Attr *A = *i; + A->printPretty(Out, Context); + } + } +} + void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) { this->Indent(); Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation); @@ -320,6 +331,7 @@ void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) { Out << "__module_private__ "; } Out << S; + prettyPrintAttributes(D); } void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) { @@ -350,6 +362,7 @@ void DeclPrinter::VisitEnumDecl(EnumDecl *D) { VisitDeclContext(D); Indent() << "}"; } + prettyPrintAttributes(D); } void DeclPrinter::VisitRecordDecl(RecordDecl *D) { @@ -466,12 +479,6 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } } - if (D->hasAttr<NoReturnAttr>()) - Proto += " __attribute((noreturn))"; - - if (D->hasAttr<ReturnsTwiceAttr>()) - Proto += " __attribute((returns_twice))"; - if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) { bool HasInitializerList = false; for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(), @@ -542,6 +549,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } Out << Proto; + prettyPrintAttributes(D); if (D->isPure()) Out << " = 0"; @@ -588,6 +596,7 @@ void DeclPrinter::VisitFieldDecl(FieldDecl *D) { Out << " = "; Init->printPretty(Out, Context, 0, Policy, Indentation); } + prettyPrintAttributes(D); } void DeclPrinter::VisitLabelDecl(LabelDecl *D) { @@ -624,6 +633,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (D->hasCXXDirectInitializer()) Out << ")"; } + prettyPrintAttributes(D); } void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { |