Query about new Attribute plugin API Capabilities

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Query about new Attribute plugin API Capabilities

Fangrui Song via cfe-dev
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
possibilities.

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.

Best Regards,
Diego Abelenda

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

attachment0 (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Query about new Attribute plugin API Capabilities

Fangrui Song via cfe-dev
On Wed, May 20, 2020 at 3:21 AM Abelenda Diego via cfe-dev
<[hidden email]> 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
> possibilities.
>
> 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.

HTH!

~Aaron

>
> Best Regards,
> Diego Abelenda
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev