[PATCH] Improve attributes printing.

Michael Han fragmentshaders at gmail.com
Tue Mar 19 16:13:49 PDT 2013



================
Comment at: utils/TableGen/ClangAttrEmitter.cpp:811
@@ +810,3 @@
+    if (Variety == "CXX11")
+      OS << "    if (LK == 0 || LK == 1 || LK == 3) {\n";
+
----------------
Richard Smith wrote:
> Each attribute should only be printed at one location.
This seems not possible using current approach since an attribute could legitimately appear at several source locations, with each source location being encoded as a LocationKind enum. For example, C++11 attribute could appear at start of a statement, or appear between class-head and class-name. So unless we use a single enum value to encode both positions, we have to check both enum value and print appropriately.

================
Comment at: lib/AST/DeclPrinter.cpp:365
@@ -364,3 +364,3 @@
   }
-  prettyPrintAttributes(D);
+  prettyPrintAttributes(D, Attr::LK_AfterDeclaratorID);
 }
----------------
Richard Smith wrote:
> This one looks really odd. We should be printing attributes after the enum/enum class/enum struct keywords (the closest match is LK_AfterDeclaratorID for those, even though they're before the declarator-id). I don't think there are *any* attributes which appertain to an enum, and go here, after the enum body.
Indeed. 

================
Comment at: lib/AST/DeclPrinter.cpp:338
@@ -337,3 +337,3 @@
   D->getUnderlyingType().print(Out, Policy, D->getName());
-  prettyPrintAttributes(D);
+  prettyPrintAttributes(D, Attr::LK_AfterDeclaratorID);
 }
----------------
Richard Smith wrote:
> Isn't this LK_EndOfDecl?
Technically yes. I use 'LK_AfterDeclaratorID' because that is the only enum value that allows print all kinds of attributes. 'LK_EndOfDecl' will not print C++11 attribute, since in the cases of a function declaration, a C++11 attribute at end of declaration appertain to function types. I need to think about this and use a better approach to deal with such cases.

================
Comment at: lib/AST/DeclPrinter.cpp:391
@@ -390,2 +390,3 @@
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
+  prettyPrintAttributes(D, Attr::LK_StartOfDecl);
   CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
----------------
Richard Smith wrote:
> Can we generalize this to print LK_StartOfDecl attributes at the start of *every* declaration?
Sounds good.


http://llvm-reviews.chandlerc.com/D395



More information about the cfe-commits mailing list