[PATCH] Improved plugin/tool support by expanding an existing attribute

Marcwell Helpdesk via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 9 01:50:21 PST 2017


Friendly ping.

> On 4 feb 2017, at 14:26, Marcwell Helpdesk <helpdesk at marcwell.se> wrote:
> 
> Many plugins/tools could benefit from having a generic way for communicating control directives directly from the source code to itself (via the AST) when acting, for example, as source code transformers, generators, collectors and the like. Attributes are a suitable way of doing this but most available attributes have predefined functionality and modifying the compiler for every plugin/tool is obviously not an option. There is however one undocumented but existing attribute that could be used for a generic solution if it was slightly modified and expanded - the annotate attribute.
> 
> The current functionality of the annotate attribute encompass annotating declarations with arbitrary strings using the GNU spelling. The attached patch expands on this functionality by adding annotation of statements, C++11 spelling and documentation. With the patch applied most of the code could be annotated for the use by any Clang plugin or tool. For a more detailed description of the updated attribute, see patch for "AttrDocs.td".
> 
> An example demonstratiing the use and syntax of the updated attribute:
> 
>  class [[annotate("plain")]] Object
>  { . . . };
> 
>  int main(int argc, char* argv[]) __attribute((annotate("entry-point")))
>  {
>    [[annotate("local_var")]]   // Decl annotation
>    int n = 1 ;
> 
>    // Multiple Stmt annotations
>    [[annotate("group-A"), annotate("opt-1:2")]]
>    switch(n)
>    { . . . }
>    return 0;
>  }
> 
> Cheers,
> Chris
> 
> Modified:
>  include/clang/Basic/Attr.td
>  include/clang/Basic/AttrDocs.td
>  lib/Sema/SemaStmtAttr.cpp
> Added:
>  test/SemaCXX/attr-annotate.cpp
> <attrib-annotate.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: attrib-annotate.patch
Type: application/octet-stream
Size: 7480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170209/f16e92b8/attachment.obj>


More information about the cfe-commits mailing list