[cfe-dev] Query about new Attribute plugin API Capabilities
Aaron Ballman via cfe-dev
cfe-dev at lists.llvm.org
Wed May 20 06:13:02 PDT 2020
On Wed, May 20, 2020 at 3:21 AM Abelenda Diego via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hello here,
> I was really happy to see the new Attribute plugin API in clang because I had
> an idea for a long time and needing to patch every version of clang would have
> been hard.
> Now that it is being released (soon), I was wondering what are its
> So I was wondering if it would be possible to add new definitions
> (functions, structs, calls to functions, etc) using attributes? My goal is to
> auto-generate definitions using annotations (like runtime syntaxic/semantic
> checking of values of a parameter, to a function etc) I know this is an abuse
> of the annotation syntax, but it is not explicitly forbidden AFAIK, and it seems
> easier to add annotations than to add new custom syntax (basically forking the
> C language itself).
> I'm not quite clear on how to put everything together. Mostly where to create
> the new FunctionDecl & co to integrate correctly with the semantic checking.
I'm not certain the new plugin system will help you too much with
this. The plugin system, as it currently stands, allows you to create
new spellings for parsing attributes, but you're still responsible for
translating that into a concrete semantic attribute that's used by the
rest of the compiler. e.g., you might create a plugin to add
[[my::awesome_attr]] but then translate it to an AnnotateAttr (or some
other preexisting semantic attribute) that gets used by the rest of
the compiler. You may not be able to do everything you need from
within the plugin.
In order to do what you're looking for, you'd most likely have to add
some code to transform the AST into a new AST with the extra
declarations you want on it. To do this, you'd likely use
TreeTransform.h, which is the machinery used when instantiating
templates. You may want to look at SemaTemplateInstantiate.cpp for
some examples of how this works.
> Best Regards,
> Diego Abelenda
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
More information about the cfe-dev