<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.n
        {mso-style-name:n;}
span.p
        {mso-style-name:p;}
span.o
        {mso-style-name:o;}
span.mi
        {mso-style-name:mi;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<p class="MsoNormal">I’m new to clang and having a little trouble. Would be happy to get some help.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m trying to build a tool that (among other things) combines two code parts: The first one is a c file that is given by the user and the second is a fixed c function.<o:p></o:p></p>
<p class="MsoNormal">I want to have access to the AST nodes of both code parts, extract the relevant stmts from each, and build from them a new compoundStmt node (initiated with a vector<Stmt*>), which will be transformed back to c code.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m having trouble with getting access to both AST’s simultaneously.<o:p></o:p></p>
<p class="MsoNormal">I tried to access the input code with libTooling by running the following command from main:<o:p></o:p></p>
<div style="mso-element:para-border-div;border:dotted #0C3762 1.0pt;padding:10.0pt 10.0pt 10.0pt 10.0pt;background:#F0F0F0">
<p class="MsoNormal" style="margin-bottom:9.0pt;background:#F0F0F0;border:none;padding:0in">
<span style="font-size:10.0pt;font-family:"Courier New";color:#333333">Tool.run(newFrontendActionFactory</span><span style="font-size:10.0pt;font-family:"Courier New";color:#666666"><</span><span style="font-size:10.0pt;font-family:"Courier New";color:#333333">clang</span><span style="font-size:10.0pt;font-family:"Courier New";color:#666666">::</span><span style="font-size:10.0pt;font-family:"Courier New";color:#333333">MyAction</span><span style="font-size:10.0pt;font-family:"Courier New";color:#666666">></span><span style="font-size:10.0pt;font-family:"Courier New";color:#333333">().get());<o:p></o:p></span></p>
</div>
<p class="MsoNormal">And access to the fixed code using runToolOnCode and then pass the compoundStmt pointer of the function body to the main:
<o:p></o:p></p>
<div style="mso-element:para-border-div;border:dotted #0C3762 1.0pt;padding:10.0pt 10.0pt 10.0pt 10.0pt;background:#F0F0F0">
<pre style="margin-bottom:9.0pt;background:#F0F0F0;border:none;padding:0in"><span class="n"><span style="color:#333333">clang</span></span><span class="p"><span style="color:#333333">::</span></span><span class="n"><span style="color:#333333">tooling</span></span><span class="p"><span style="color:#333333">::</span></span><span class="n"><span style="color:#333333">runToolOnCode</span></span><span class="p"><span style="color:#333333">(</span></span><span class="n"><span style="color:#333333">new</span></span><span style="color:#333333"> <span class="n">MyOtherAction</span><span class="p">,</span> <span class="n">MyFixedText</span><span class="p">);</span><o:p></o:p></span></pre>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">but it seems like both tools are running independently with no ability to pass information from one to the other.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Can anyone give me a hint on this or give me a link to a code that does something similar?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Rachel.<o:p></o:p></p>
</div>
</body>
</html>