can Clang Plugin modify the AST and send it back to the next step of compliation?

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

can Clang Plugin modify the AST and send it back to the next step of compliation?

Hubert Tong via cfe-dev
All the examples of Clang plugin and FrontendActions I've read are to get the AST and print some information, I'm curious if I can modify the AST to make some dialect C++ language?

I got some examples I think is easy to do if AST could be modified:
1. make all subclasses inherit baseclasses' friend class
2. make all method virtual (like Java)

_______________________________________________
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: can Clang Plugin modify the AST and send it back to the next step of compliation?

Hubert Tong via cfe-dev
Hi,

On Wed, Sep 02, 2020 at 02:36:38PM +0800, Yafei Liu via cfe-dev <[hidden email]> wrote:
> All the examples of Clang plugin and FrontendActions I've read are to get
> the AST and print some information, I'm curious if I can modify the AST to
> make some dialect C++ language?
>
> I got some examples I think is easy to do if AST could be modified:
> 1. make all subclasses inherit baseclasses' friend class
> 2. make all method virtual (like Java)

The typical workflow is to emit fixits/replacements and then apply them,
rather than modifying the AST. clang-tidy has plenty of checks which do
this already.

Regards,

Miklos

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

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: can Clang Plugin modify the AST and send it back to the next step of compliation?

Hubert Tong via cfe-dev
Hi Miklos, I think applying replacements to original source file is not what I expect, it does not act as a "dialect" to me.

What I want to do gives a feeling of "AST programming" (I just made up this term). 

On Wed, Sep 2, 2020 at 5:24 PM Miklos Vajna <[hidden email]> wrote:
Hi,

On Wed, Sep 02, 2020 at 02:36:38PM +0800, Yafei Liu via cfe-dev <[hidden email]> wrote:
> All the examples of Clang plugin and FrontendActions I've read are to get
> the AST and print some information, I'm curious if I can modify the AST to
> make some dialect C++ language?
>
> I got some examples I think is easy to do if AST could be modified:
> 1. make all subclasses inherit baseclasses' friend class
> 2. make all method virtual (like Java)

The typical workflow is to emit fixits/replacements and then apply them,
rather than modifying the AST. clang-tidy has plenty of checks which do
this already.

Regards,

Miklos

_______________________________________________
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: can Clang Plugin modify the AST and send it back to the next step of compliation?

Hubert Tong via cfe-dev
You can have a plugin AST action run before the 'main' action (i.e. before compilation) which means that the AST after
the action has run is what is compiled. There's an example at
which modifies the AST by adding function attributes.

John


From: cfe-dev <[hidden email]> on behalf of Yafei Liu via cfe-dev <[hidden email]>
Sent: 02 September 2020 13:25
To: Miklos Vajna <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] can Clang Plugin modify the AST and send it back to the next step of compliation?
 
Hi Miklos, I think applying replacements to original source file is not what I expect, it does not act as a "dialect" to me.

What I want to do gives a feeling of "AST programming" (I just made up this term). 

On Wed, Sep 2, 2020 at 5:24 PM Miklos Vajna <[hidden email]> wrote:
Hi,

On Wed, Sep 02, 2020 at 02:36:38PM +0800, Yafei Liu via cfe-dev <[hidden email]> wrote:
> All the examples of Clang plugin and FrontendActions I've read are to get
> the AST and print some information, I'm curious if I can modify the AST to
> make some dialect C++ language?
>
> I got some examples I think is easy to do if AST could be modified:
> 1. make all subclasses inherit baseclasses' friend class
> 2. make all method virtual (like Java)

The typical workflow is to emit fixits/replacements and then apply them,
rather than modifying the AST. clang-tidy has plenty of checks which do
this already.

Regards,

Miklos

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