Is there anyway I can add some custom information to the AST?

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

Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
Hi, all.
I'm writing some tools to convert a C++ class to something else, and I want to add  some custom information to the AST.

At first, I decided to add some comments to mark some classes, but I found that the AST does not contain comments.

Secondly, I want to customize an attribute, but I found that it needs to recompile the Clang, I didn't find a "plug-in" way.  Since my tools are designed for public usage, a customized compiler is not very considerable.

Currently I have to force the user to declare their class names and field names with some special rules, but this is not very acceptable to me.

So anyone knows if there's a better way to add some custom information to the AST?

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
Hi Yafei,

You can use the Attribute system to decorate AST nodes, they can also
be loaded via plugins. See `clang/examples/Attrbiute/` to see how they
are created and registered.

Then you can add an attribute to the class decl, for example
> class [[convert]] MyVector {};

Hope this helps,
Nathan James

On Sun, 2020-07-05 at 00:05 +0800, Yafei Liu via cfe-dev wrote:

> Hi, all.
> I'm writing some tools to convert a C++ class to something else, and
> I want to add  some custom information to the AST.
>
> At first, I decided to add some comments to mark some classes, but I
> found that the AST does not contain comments.
>
> Secondly, I want to customize an attribute, but I found that it needs
> to recompile the Clang, I didn't find a "plug-in" way.  Since my
> tools are designed for public usage, a customized compiler is not
> very considerable.
>
> Currently I have to force the user to declare their class names and
> field names with some special rules, but this is not very acceptable
> to me.
>
> So anyone knows if there's a better way to add some custom
> information to the AST?
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
Hi Nathan, I found that this example is based on clang11, my clang10 libraries do not have corresponding classes. I read the clang11 release note, which is in progressing, and found that in https://clang.llvm.org/docs/ReleaseNotes.html#attribute-changes-in-clang, attribute plugin is a new feature.

So does it mean:
1. Even if I implemented an attribute plugin (with the code on master branch), I have to wait until Clang11 has released? 
2. Or, the attribute plugin can be used in older versions of Clang?

On Sun, Jul 5, 2020 at 12:34 AM Nathan James <[hidden email]> wrote:
Hi Yafei,

You can use the Attribute system to decorate AST nodes, they can also
be loaded via plugins. See `clang/examples/Attrbiute/` to see how they
are created and registered.

Then you can add an attribute to the class decl, for example
> class [[convert]] MyVector {};

Hope this helps,
Nathan James

On Sun, 2020-07-05 at 00:05 +0800, Yafei Liu via cfe-dev wrote:
> Hi, all.
> I'm writing some tools to convert a C++ class to something else, and
> I want to add  some custom information to the AST.
>
> At first, I decided to add some comments to mark some classes, but I
> found that the AST does not contain comments.
>
> Secondly, I want to customize an attribute, but I found that it needs
> to recompile the Clang, I didn't find a "plug-in" way.  Since my
> tools are designed for public usage, a customized compiler is not
> very considerable.
>
> Currently I have to force the user to declare their class names and
> field names with some special rules, but this is not very acceptable
> to me.
>
> So anyone knows if there's a better way to add some custom
> information to the AST?
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
By means " I have to wait until Clang11 has released", I mean I have to wait for Clang11 to make my plugin a public use (used by others).

On Sun, Jul 5, 2020 at 1:58 AM Yafei Liu <[hidden email]> wrote:
Hi Nathan, I found that this example is based on clang11, my clang10 libraries do not have corresponding classes. I read the clang11 release note, which is in progressing, and found that in https://clang.llvm.org/docs/ReleaseNotes.html#attribute-changes-in-clang, attribute plugin is a new feature.

So does it mean:
1. Even if I implemented an attribute plugin (with the code on master branch), I have to wait until Clang11 has released? 
2. Or, the attribute plugin can be used in older versions of Clang?

On Sun, Jul 5, 2020 at 12:34 AM Nathan James <[hidden email]> wrote:
Hi Yafei,

You can use the Attribute system to decorate AST nodes, they can also
be loaded via plugins. See `clang/examples/Attrbiute/` to see how they
are created and registered.

Then you can add an attribute to the class decl, for example
> class [[convert]] MyVector {};

Hope this helps,
Nathan James

On Sun, 2020-07-05 at 00:05 +0800, Yafei Liu via cfe-dev wrote:
> Hi, all.
> I'm writing some tools to convert a C++ class to something else, and
> I want to add  some custom information to the AST.
>
> At first, I decided to add some comments to mark some classes, but I
> found that the AST does not contain comments.
>
> Secondly, I want to customize an attribute, but I found that it needs
> to recompile the Clang, I didn't find a "plug-in" way.  Since my
> tools are designed for public usage, a customized compiler is not
> very considerable.
>
> Currently I have to force the user to declare their class names and
> field names with some special rules, but this is not very acceptable
> to me.
>
> So anyone knows if there's a better way to add some custom
> information to the AST?
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
In reply to this post by David Chisnall via cfe-dev
On Sat, Jul 4, 2020 at 12:06 PM Yafei Liu via cfe-dev
<[hidden email]> wrote:
>
> Hi, all.
> I'm writing some tools to convert a C++ class to something else, and I want to add  some custom information to the AST.
>
> At first, I decided to add some comments to mark some classes, but I found that the AST does not contain comments.
>
> Secondly, I want to customize an attribute, but I found that it needs to recompile the Clang, I didn't find a "plug-in" way.  Since my tools are designed for public usage, a customized compiler is not very considerable.

You might be able to use the annotate attribute, as that's one of the
purposes it serves: https://godbolt.org/z/_Ggr6e

~Aaron
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Is there anyway I can add some custom information to the AST?

David Chisnall via cfe-dev
In reply to this post by David Chisnall via cfe-dev

Consider using the attribute ‘annotate’.    It doesn’t seem to be documented on our page unfortunately, but it applies to a declaration and takes an arbitrary string:  [[clang::annotate("asdf")]]

 

OR: __attribute__((annotate(“asdf”)))

 

From: cfe-dev <[hidden email]> On Behalf Of Yafei Liu via cfe-dev
Sent: Saturday, July 4, 2020 9:06 AM
To: Clang Dev <[hidden email]>
Subject: [cfe-dev] Is there anyway I can add some custom information to the AST?

 

Hi, all.

I'm writing some tools to convert a C++ class to something else, and I want to add  some custom information to the AST.

 

At first, I decided to add some comments to mark some classes, but I found that the AST does not contain comments.

 

Secondly, I want to customize an attribute, but I found that it needs to recompile the Clang, I didn't find a "plug-in" way.  Since my tools are designed for public usage, a customized compiler is not very considerable.

 

Currently I have to force the user to declare their class names and field names with some special rules, but this is not very acceptable to me.

 

So anyone knows if there's a better way to add some custom information to the AST?


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