[PATCH] D31343: Add an attribute plugin example

John Brawn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 09:45:26 PST 2020


john.brawn marked 5 inline comments as done.
john.brawn added inline comments.


================
Comment at: clang/examples/Attribute/Attribute.cpp:25
+struct ExampleAttrInfo : public ParsedAttrInfo {
+  ExampleAttrInfo() {
+    // Set the kind to NoSemaHandlerAttribute to make sure clang doesn't assume
----------------
aaron.ballman wrote:
> It would be really handy for the example to show how to list subjects for the declaration attribute, as that's a very common need.
This is done via diagAppertainsToDecl.


================
Comment at: clang/examples/Attribute/Attribute.cpp:35
+  }
+  virtual bool handleDeclAttribute(Sema &S, Decl *D,
+                                   const ParsedAttr &Attr) const {
----------------
aaron.ballman wrote:
> It is unclear to me how a user would add an attribute that needs to follow the merge pattern we use in `mergeDeclAttribute()`.
I'm guessing it's probably not possible, from a quick look at mergeDeclAttribute.


================
Comment at: clang/examples/Attribute/Attribute.cpp:53
+      } else {
+        S.Diag(ArgExpr->getExprLoc(), diag::err_attribute_argument_type)
+            << Attr.getAttrName() << AANT_ArgumentString;
----------------
aaron.ballman wrote:
> Do we have a way for plugin authors to introduce their own diagnostics, or are they limited to just what diagnostics we already provide?
Custom diagnostics can be done with getCustomDiagID, and there's an example on line 54.


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

https://reviews.llvm.org/D31343





More information about the cfe-commits mailing list