<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
You can have a plugin AST action run before the 'main' action (i.e. before compilation) which means that the AST after</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
the action has run is what is compiled. There's an example at</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
 <a href="https://github.com/llvm/llvm-project/blob/master/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp" id="LPlnk364349">https://github.com/llvm/llvm-project/blob/master/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp</a></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
which modifies the AST by adding function attributes.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
John</div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> on behalf of Yafei Liu via cfe-dev <cfe-dev@lists.llvm.org><br>
<b>Sent:</b> 02 September 2020 13:25<br>
<b>To:</b> Miklos Vajna <vmiklos@vmiklos.hu><br>
<b>Cc:</b> Clang Dev <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [cfe-dev] can Clang Plugin modify the AST and send it back to the next step of compliation?</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi Miklos, I think applying replacements to original source file is not what I expect, it does not act as a "dialect" to me.
<div><br>
</div>
<div>What I want to do gives a feeling of "AST programming" (I just made up this term). </div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, Sep 2, 2020 at 5:24 PM Miklos Vajna <<a href="mailto:vmiklos@vmiklos.hu">vmiklos@vmiklos.hu</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
Hi,<br>
<br>
On Wed, Sep 02, 2020 at 02:36:38PM +0800, Yafei Liu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> All the examples of Clang plugin and FrontendActions I've read are to get<br>
> the AST and print some information, I'm curious if I can modify the AST to<br>
> make some dialect C++ language?<br>
> <br>
> I got some examples I think is easy to do if AST could be modified:<br>
> 1. make all subclasses inherit baseclasses' friend class<br>
> 2. make all method virtual (like Java)<br>
<br>
The typical workflow is to emit fixits/replacements and then apply them,<br>
rather than modifying the AST. clang-tidy has plenty of checks which do<br>
this already.<br>
<br>
Regards,<br>
<br>
Miklos<br>
</blockquote>
</div>
</div>
</div>
</body>
</html>