<div dir="ltr">Hello Richard,<div><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><div><i>The AST is neither designed nor intended to support in-place modification -- it's supposed to be essentially immutable once created. TreeTransform is a better approach (since it creates new AST rather than updating existing AST nodes in-place).</i></div>

</div></div></div></blockquote><div><br></div><div>This is what I have been reading here on previous messages, hence our attempt to use TreeTransform.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><i>In your overridden TransformStringLiteral, how are you creating the new StringLiteral? We don't seem to have any relevant functions on Sema for this, so I think you'd need to compute the relevant type yourself and call StringLiteral::Create.</i></div>



</div></div></div>
</blockquote></div><div class="gmail_extra"><br></div><div class="gmail_extra">This is what we tried, here is the code snippet of our TreeTransform class :</div><div class="gmail_extra"><br></div><div class="gmail_extra">

<div class="gmail_extra"><div class="gmail_extra"><b>class HmIdTransform : public TreeTransform<HmIdTransform></b></div><div class="gmail_extra"><b>{</b></div></div></div></div><div class="gmail_extra"><div class="gmail_extra">

<div class="gmail_extra"><div class="gmail_extra"><b><span class="" style="white-space:pre">    </span>Sema& m_Sema;</b></div></div></div></div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra">
<div class="gmail_extra">
<b><span class="" style="white-space:pre">      </span>ASTContext& m_Context;</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">        </span>std::string m_NewString;</b><br></div><div class="gmail_extra">

<b><br></b></div><div class="gmail_extra"><b>public:</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">     </span>HmIdTransform(Sema& semaRef, std::string newString)</b></div><div class="gmail_extra">

<b><span class="" style="white-space:pre">              </span>: TreeTransform(semaRef)</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">          </span>, m_Sema(semaRef)</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">         </span>, m_Context(semaRef.getASTContext())</b></div>

<div class="gmail_extra"><b><span class="" style="white-space:pre">             </span>, m_NewString(newString)</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">  </span>{</b></div><div class="gmail_extra">

<b><br></b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">    </span>}</b></div><div class="gmail_extra"><b><br></b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">       </span>bool AlwaysRebuild() { return true; }</b></div>

<div class="gmail_extra"><b><br></b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">   </span>ExprResult TransformStringLiteral(StringLiteral* strLiteral)</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">      </span>{</b></div>

<div class="gmail_extra"><b><span class="" style="white-space:pre">             </span>QualType StrType = m_Context.getConstantArrayType(m_Context.CharTy, llvm::APInt(32, m_NewString.size() + 1), ArrayType::Normal, 0);</b></div><div class="gmail_extra">

<b><br></b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">            </span>return m_Sema.Owned(StringLiteral::Create(m_Context, m_NewString, StringLiteral::Ascii, false, StrType, strLiteral->getLocStart()));</b></div>

<div class="gmail_extra"><b><span class="" style="white-space:pre">     </span>}</b></div><div class="gmail_extra"><b>};</b></div></div></div><div class="gmail_extra">
<br></div><div class="gmail_extra">Here is an extract of our RecursiveASTVisitor::TraverseFieldDecl method :</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra">

<span style="white-space:pre"><b>bool TraverseFieldDecl(FieldDecl* decl)</b></span></div><div class="gmail_extra"><span style="white-space:pre"><b>{</b></span></div><div class="gmail_extra"><b><span class="" style="white-space:pre">        </span>if(decl->hasInClassInitializer())</b><br>

</div><div class="gmail_extra"><b><span class="" style="white-space:pre"> </span>{</b><br></div><div class="gmail_extra"><b><span class="" style="white-space:pre">               </span>Expr* initializer = decl->getInClassInitializer();</b></div>

<div class="gmail_extra"><b><span class="" style="white-space:pre"><br></span></b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">             </span>if(initializer && initializer->children())</b><br>

</div><div class="gmail_extra"><b><span class="" style="white-space:pre">         </span>{</b></div><div class="gmail_extra"><b><span class="" style="white-space:pre">                 </span>HmIdTransform initTransform(m_CI.getSema(), "ModifiedString");</b><br>

</div><div class="gmail_extra"><span style="white-space:pre"><b><br></b></span></div><div class="gmail_extra"><b><span class="" style="white-space:pre">                    </span>initTransform.TransformInitializer(initializer, true);</b></div>

<div class="gmail_extra"><b><span class="" style="white-space:pre">             </span>}</b><br></div><div class="gmail_extra"><b><span class="" style="white-space:pre">       </span>}</b></div><div class="gmail_extra"><br></div><div class="gmail_extra">

<b><span class="" style="white-space:pre">      </span>return true;</b></div><div class="gmail_extra"><span style="white-space:pre"><b>}</b></span></div></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">
Now, it seems the node doesn't get rebuild, do we have to invoke a method to rebuild the modified node?</div>
<div class="gmail_extra">I though the TreeTransform would do it (knowing that it has a reference to the Sema) but I guess I am mistaken. </div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for your help !</div>

</div></div>