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

Attachment: attrib-annotate.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to