-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the double space and double attribute printing of the final keyword. #88600
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,7 @@ namespace { | |
| void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args, | ||
| const TemplateParameterList *Params); | ||
| enum class AttrPosAsWritten { Default = 0, Left, Right }; | ||
| void | ||
| bool | ||
| prettyPrintAttributes(const Decl *D, | ||
| AttrPosAsWritten Pos = AttrPosAsWritten::Default); | ||
| void prettyPrintPragmas(Decl *D); | ||
|
|
@@ -252,16 +252,19 @@ static DeclPrinter::AttrPosAsWritten getPosAsWritten(const Attr *A, | |
| return DeclPrinter::AttrPosAsWritten::Right; | ||
| } | ||
|
|
||
| void DeclPrinter::prettyPrintAttributes(const Decl *D, | ||
| // returns true if an attribute was printed. | ||
| bool DeclPrinter::prettyPrintAttributes(const Decl *D, | ||
| AttrPosAsWritten Pos /*=Default*/) { | ||
| if (Policy.PolishForDeclaration) | ||
| return; | ||
| bool hasPrinted = false; | ||
|
|
||
| if (D->hasAttrs()) { | ||
| const AttrVec &Attrs = D->getAttrs(); | ||
| for (auto *A : Attrs) { | ||
| if (A->isInherited() || A->isImplicit()) | ||
| continue; | ||
| // Print out the keyword attributes, they aren't regular attributes. | ||
| if (Policy.PolishForDeclaration && !A->isKeywordAttribute()) | ||
| continue; | ||
| switch (A->getKind()) { | ||
| #define ATTR(X) | ||
| #define PRAGMA_SPELLING_ATTR(X) case attr::X: | ||
|
|
@@ -275,13 +278,15 @@ void DeclPrinter::prettyPrintAttributes(const Decl *D, | |
| if (Pos != AttrPosAsWritten::Left) | ||
| Out << ' '; | ||
| A->printPretty(Out, Policy); | ||
| hasPrinted = true; | ||
| if (Pos == AttrPosAsWritten::Left) | ||
| Out << ' '; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return hasPrinted; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking to use something like that but I believe the boolean flag is more readable. I'd like to keep it the way it is. |
||
| } | ||
|
|
||
| void DeclPrinter::prettyPrintPragmas(Decl *D) { | ||
|
|
@@ -1060,12 +1065,15 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { | |
| // FIXME: add printing of pragma attributes if required. | ||
| if (!Policy.SuppressSpecifiers && D->isModulePrivate()) | ||
| Out << "__module_private__ "; | ||
| Out << D->getKindName(); | ||
|
|
||
| prettyPrintAttributes(D); | ||
| Out << D->getKindName() << ' '; | ||
|
|
||
| if (D->getIdentifier()) { | ||
| // FIXME: Move before printing the decl kind to match the behavior of the | ||
| // attribute printing for variables and function where they are printed first. | ||
| if (prettyPrintAttributes(D, AttrPosAsWritten::Left)) | ||
| Out << ' '; | ||
|
|
||
| if (D->getIdentifier()) { | ||
| if (auto *NNS = D->getQualifier()) | ||
| NNS->print(Out, Policy); | ||
| Out << *D; | ||
|
|
@@ -1082,16 +1090,13 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { | |
| } | ||
| } | ||
|
|
||
| if (D->hasDefinition()) { | ||
| if (D->hasAttr<FinalAttr>()) { | ||
| Out << " final"; | ||
| } | ||
| } | ||
| prettyPrintAttributes(D, AttrPosAsWritten::Right); | ||
|
|
||
| if (D->isCompleteDefinition()) { | ||
| Out << ' '; | ||
| // Print the base classes | ||
| if (D->getNumBases()) { | ||
| Out << " : "; | ||
| Out << ": "; | ||
| for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(), | ||
| BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) { | ||
| if (Base != D->bases_begin()) | ||
|
|
@@ -1110,14 +1115,15 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { | |
| if (Base->isPackExpansion()) | ||
| Out << "..."; | ||
| } | ||
| Out << ' '; | ||
| } | ||
|
|
||
| // Print the class definition | ||
| // FIXME: Doesn't print access specifiers, e.g., "public:" | ||
| if (Policy.TerseOutput) { | ||
| Out << " {}"; | ||
| Out << "{}"; | ||
| } else { | ||
| Out << " {\n"; | ||
| Out << "{\n"; | ||
| VisitDeclContext(D); | ||
| Indent() << "}"; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,11 @@ typedef vector<float, 3> float3; | |
| RWBuffer<float3> Buffer; | ||
|
|
||
| // expected-error@+2 {{class template 'RWBuffer' requires template arguments}} | ||
| // expected-note@*:* {{template declaration from hidden source: template <class element_type> class RWBuffer final}} | ||
| // expected-note@*:* {{template declaration from hidden source: template <class element_type> class RWBuffer}} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We remove the |
||
| RWBuffer BufferErr1; | ||
|
|
||
| // expected-error@+2 {{too few template arguments for class template 'RWBuffer'}} | ||
| // expected-note@*:* {{template declaration from hidden source: template <class element_type> class RWBuffer final}} | ||
| // expected-note@*:* {{template declaration from hidden source: template <class element_type> class RWBuffer}} | ||
| RWBuffer<> BufferErr2; | ||
|
|
||
| [numthreads(1,1,1)] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I was about to suggest something like this, but didn't know
isKeywordAttributeexisted.