diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2015-10-12 06:59:48 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-10-12 06:59:48 +0000 |
| commit | 6d45532961baeb6d84e033a1bb7d6256fbe55efb (patch) | |
| tree | e55394185c1adf1a6ce9c1137ae9f71b4f4ab601 /clang/lib/AST | |
| parent | 8d2e6bc25b2eb33ea21c804687674e78d4c595d4 (diff) | |
| download | bcm5719-llvm-6d45532961baeb6d84e033a1bb7d6256fbe55efb.tar.gz bcm5719-llvm-6d45532961baeb6d84e033a1bb7d6256fbe55efb.zip | |
[ATTR] Automatic line feed after pragma-like attribute.
Automatically insert line feed after pretty printing of all pragma-like attributes + fix printing of pragma-like pragmas on declarations.
Differential Revision: http://reviews.llvm.org/D13546
llvm-svn: 250017
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/DeclPrinter.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index e09c331d4f7..5c6002d55c0 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -96,6 +96,7 @@ namespace { void PrintTemplateParameters(const TemplateParameterList *Params, const TemplateArgumentList *Args = nullptr); void prettyPrintAttributes(Decl *D); + void prettyPrintPragmas(Decl *D); void printDeclType(QualType T, StringRef DeclName, bool Pack = false); }; } @@ -197,12 +198,40 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) { void DeclPrinter::prettyPrintAttributes(Decl *D) { if (Policy.PolishForDeclaration) return; - + 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, Policy); + for (auto *A : Attrs) { + switch (A->getKind()) { +#define ATTR(X) +#define PRAGMA_SPELLING_ATTR(X) case attr::X: +#include "clang/Basic/AttrList.inc" + break; + default: + A->printPretty(Out, Policy); + break; + } + } + } +} + +void DeclPrinter::prettyPrintPragmas(Decl *D) { + if (Policy.PolishForDeclaration) + return; + + if (D->hasAttrs()) { + AttrVec &Attrs = D->getAttrs(); + for (auto *A : Attrs) { + switch (A->getKind()) { +#define ATTR(X) +#define PRAGMA_SPELLING_ATTR(X) case attr::X: +#include "clang/Basic/AttrList.inc" + A->printPretty(Out, Policy); + Indent(); + break; + default: + break; + } } } } @@ -408,6 +437,10 @@ void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { } void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { + if (!D->getDescribedFunctionTemplate() && + !D->isFunctionTemplateSpecialization()) + prettyPrintPragmas(D); + CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D); CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D); if (!Policy.SuppressSpecifiers) { @@ -643,6 +676,7 @@ void DeclPrinter::VisitFriendDecl(FriendDecl *D) { } void DeclPrinter::VisitFieldDecl(FieldDecl *D) { + // FIXME: add printing of pragma attributes if required. if (!Policy.SuppressSpecifiers && D->isMutable()) Out << "mutable "; if (!Policy.SuppressSpecifiers && D->isModulePrivate()) @@ -672,6 +706,7 @@ void DeclPrinter::VisitLabelDecl(LabelDecl *D) { } void DeclPrinter::VisitVarDecl(VarDecl *D) { + prettyPrintPragmas(D); if (!Policy.SuppressSpecifiers) { StorageClass SC = D->getStorageClass(); if (SC != SC_None) @@ -779,6 +814,7 @@ void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { } void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { + // FIXME: add printing of pragma attributes if required. if (!Policy.SuppressSpecifiers && D->isModulePrivate()) Out << "__module_private__ "; Out << D->getKindName(); @@ -914,11 +950,13 @@ void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { if (PrintInstantiation) { TemplateParameterList *Params = D->getTemplateParameters(); for (auto *I : D->specializations()) { + prettyPrintPragmas(I); PrintTemplateParameters(Params, I->getTemplateSpecializationArgs()); Visit(I); } } + prettyPrintPragmas(D->getTemplatedDecl()); return VisitRedeclarableTemplateDecl(D); } |

