The general advise is to only do code transformations on valid code. I don't know enough about your problem to understand why that is not possible.<br><br><div class="gmail_quote">On Tue Oct 07 2014 at 4:37:52 PM Marc Greim <<a href="mailto:marc.greim@mytum.de">marc.greim@mytum.de</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hello,<br><br></div>I'm using clang to rewrite (generated) source code. Usually that can be done by running matchers on the ast in combination with a rewriter instance. <br><br>Unfortunately this fails in the case of operator[] where the index argument cannot be converted to a valid type (e.g. class X{} x; int * array; int i = array[x]; ). The corresponding ast nodes are missing since the "array[x]" statement has no valid representation.<br><br></div><div>How can I detect and rewrite the code in cases like above example? "array[x]" -> "someFunc(array,x)"<br><br></div><div>ExternalSemaSource::CorrectTypo dosen't get called in this case (maybe because all tokens are valid?) so that attempt failed.<br><br></div><div>Using ExternalSemaSource::LookupUnqualified also failed so far, because i haven't found a method to get a valid SourceRange for that code part. It would also require manual parsing of that code part which seem like a "dirty" solution to me.<br></div><div><br></div><div>The only idea that I have left is to declare builtin operators for any type with Sema::AddBuiltinCandidate, but that may result in many operator definitions. Also I have no idea how to iterate over all types and how to declare these functions. However this may be the best solution, because then matchers can be used to find and rewrite those code parts.<br><br></div><div>I would appreciate any help to find a solution.<br><br></div><div>Regards,<br></div><div>Marc<br><br></div><div><br></div><div>P.S. I am aware that adding operator int() to class X of above example would allow those statements but that is not an option, since X cannot be represented as int in my case and additional operations need to be performed; such an operator may also mess up other parts of the code.<br></div></div></div></div></div>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>