[PATCH] D157394: [clang][DeclPrinter] Improve AST print of function attributes

Giuliano Belinassi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 05:32:01 PDT 2023


giulianobelinassi added subscribers: erichkeane, giulianobelinassi.
giulianobelinassi added a comment.

This patch do not address attributes in variables nor the __declspec case, as D141714 <https://reviews.llvm.org/D141714> do. His patch looks cleaner and I can surely coordinate with @strimo378 to also fix those cases, but I want an answer to the tblgen question first to see if we decide to drop the tblgen solution or not.



================
Comment at: clang/lib/AST/DeclPrinter.cpp:259
+    case attr::Final:
+    case attr::Override:
+      return AttrLocation::AfterDecl;
----------------
@aaron.ballman @erichkeane 

Is this enough to describe the position of the attribute kind, or should it go for a tblgen approach, as I did in D141714? This here looks much cleaner than the tblgen IMHO.


================
Comment at: clang/lib/AST/DeclPrinter.cpp:267
+    // C2x/C++11-style attributes must appear before the declarator.
+    if (S == Attr::AS_CXX11 || S == Attr::AS_C2x)
+      return AttrLocation::BeforeDecl;
----------------
You can use A->isStandardAttributeSyntax()


================
Comment at: clang/lib/AST/DeclPrinter.cpp:280
 
-void DeclPrinter::prettyPrintPragmas(Decl *D) {
+void DeclPrinter::prettyPrintAttributes(Decl *D, AttrLocation AL) {
   if (Policy.PolishForDeclaration)
----------------
I am pretty sure this function when called with AttrLocation::BeforeDecl will print an extra space before it prints out the attribute. Unfortunately to fix this it needs to be print into a string and then remove the first space from the generated string. Or do something more clever and patch printPretty so it does not do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157394/new/

https://reviews.llvm.org/D157394



More information about the cfe-commits mailing list