mirror of https://github.com/microsoft/clang.git
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250017 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
72c2907b9a
commit
52bc812d7e
|
@ -2048,17 +2048,15 @@ def LoopHint : Attr {
|
||||||
unsigned SpellingIndex = getSpellingListIndex();
|
unsigned SpellingIndex = getSpellingListIndex();
|
||||||
// For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
|
// For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
|
||||||
// "nounroll" is already emitted as the pragma name.
|
// "nounroll" is already emitted as the pragma name.
|
||||||
if (SpellingIndex == Pragma_nounroll) {
|
if (SpellingIndex == Pragma_nounroll)
|
||||||
OS << "\n";
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
else if (SpellingIndex == Pragma_unroll) {
|
else if (SpellingIndex == Pragma_unroll) {
|
||||||
OS << getValueString(Policy) << "\n";
|
OS << getValueString(Policy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
|
assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling");
|
||||||
OS << getOptionName(option) << getValueString(Policy) << "\n";
|
OS << getOptionName(option) << getValueString(Policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a string containing the loop hint argument including the
|
// Return a string containing the loop hint argument including the
|
||||||
|
|
|
@ -96,6 +96,7 @@ namespace {
|
||||||
void PrintTemplateParameters(const TemplateParameterList *Params,
|
void PrintTemplateParameters(const TemplateParameterList *Params,
|
||||||
const TemplateArgumentList *Args = nullptr);
|
const TemplateArgumentList *Args = nullptr);
|
||||||
void prettyPrintAttributes(Decl *D);
|
void prettyPrintAttributes(Decl *D);
|
||||||
|
void prettyPrintPragmas(Decl *D);
|
||||||
void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
|
void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -197,12 +198,40 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
|
||||||
void DeclPrinter::prettyPrintAttributes(Decl *D) {
|
void DeclPrinter::prettyPrintAttributes(Decl *D) {
|
||||||
if (Policy.PolishForDeclaration)
|
if (Policy.PolishForDeclaration)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (D->hasAttrs()) {
|
if (D->hasAttrs()) {
|
||||||
AttrVec &Attrs = D->getAttrs();
|
AttrVec &Attrs = D->getAttrs();
|
||||||
for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
|
for (auto *A : Attrs) {
|
||||||
Attr *A = *i;
|
switch (A->getKind()) {
|
||||||
A->printPretty(Out, Policy);
|
#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) {
|
void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
|
||||||
|
if (!D->getDescribedFunctionTemplate() &&
|
||||||
|
!D->isFunctionTemplateSpecialization())
|
||||||
|
prettyPrintPragmas(D);
|
||||||
|
|
||||||
CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
|
CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
|
||||||
CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
|
CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
|
||||||
if (!Policy.SuppressSpecifiers) {
|
if (!Policy.SuppressSpecifiers) {
|
||||||
|
@ -643,6 +676,7 @@ void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
|
void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
|
||||||
|
// FIXME: add printing of pragma attributes if required.
|
||||||
if (!Policy.SuppressSpecifiers && D->isMutable())
|
if (!Policy.SuppressSpecifiers && D->isMutable())
|
||||||
Out << "mutable ";
|
Out << "mutable ";
|
||||||
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
|
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
|
||||||
|
@ -672,6 +706,7 @@ void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclPrinter::VisitVarDecl(VarDecl *D) {
|
void DeclPrinter::VisitVarDecl(VarDecl *D) {
|
||||||
|
prettyPrintPragmas(D);
|
||||||
if (!Policy.SuppressSpecifiers) {
|
if (!Policy.SuppressSpecifiers) {
|
||||||
StorageClass SC = D->getStorageClass();
|
StorageClass SC = D->getStorageClass();
|
||||||
if (SC != SC_None)
|
if (SC != SC_None)
|
||||||
|
@ -779,6 +814,7 @@ void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
||||||
|
// FIXME: add printing of pragma attributes if required.
|
||||||
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
|
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
|
||||||
Out << "__module_private__ ";
|
Out << "__module_private__ ";
|
||||||
Out << D->getKindName();
|
Out << D->getKindName();
|
||||||
|
@ -914,11 +950,13 @@ void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
|
||||||
if (PrintInstantiation) {
|
if (PrintInstantiation) {
|
||||||
TemplateParameterList *Params = D->getTemplateParameters();
|
TemplateParameterList *Params = D->getTemplateParameters();
|
||||||
for (auto *I : D->specializations()) {
|
for (auto *I : D->specializations()) {
|
||||||
|
prettyPrintPragmas(I);
|
||||||
PrintTemplateParameters(Params, I->getTemplateSpecializationArgs());
|
PrintTemplateParameters(Params, I->getTemplateSpecializationArgs());
|
||||||
Visit(I);
|
Visit(I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prettyPrintPragmas(D->getTemplatedDecl());
|
||||||
return VisitRedeclarableTemplateDecl(D);
|
return VisitRedeclarableTemplateDecl(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
|
// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
|
||||||
|
// RUN: %clang_cc1 -DMS_EXT -fsyntax-only -fms-extensions %s -triple x86_64-pc-win32 -ast-print | FileCheck %s --check-prefix=MS-EXT
|
||||||
|
|
||||||
// FIXME: A bug in ParsedAttributes causes the order of the attributes to be
|
// FIXME: A bug in ParsedAttributes causes the order of the attributes to be
|
||||||
// reversed. The checks are consequently in the reverse order below.
|
// reversed. The checks are consequently in the reverse order below.
|
||||||
|
@ -53,3 +54,11 @@ void test_nontype_template_param(int *List, int Length) {
|
||||||
void test_templates(int *List, int Length) {
|
void test_templates(int *List, int Length) {
|
||||||
test_nontype_template_param<2, 4>(List, Length);
|
test_nontype_template_param<2, 4>(List, Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MS_EXT
|
||||||
|
#pragma init_seg(compiler)
|
||||||
|
// MS-EXT: #pragma init_seg (.CRT$XCC)
|
||||||
|
// MS-EXT-NEXT: int x = 3 __declspec(thread);
|
||||||
|
int __declspec(thread) x = 3;
|
||||||
|
#endif //MS_EXT
|
||||||
|
|
||||||
|
|
|
@ -1180,6 +1180,7 @@ writePrettyPrintFunction(Record &R,
|
||||||
if (Variety == "Pragma") {
|
if (Variety == "Pragma") {
|
||||||
OS << " \";\n";
|
OS << " \";\n";
|
||||||
OS << " printPrettyPragma(OS, Policy);\n";
|
OS << " printPrettyPragma(OS, Policy);\n";
|
||||||
|
OS << " OS << \"\\n\";";
|
||||||
OS << " break;\n";
|
OS << " break;\n";
|
||||||
OS << " }\n";
|
OS << " }\n";
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue