<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Fri, Dec 7, 2012 at 6:08 PM, Yin Qiu <span dir="ltr"><<a href="mailto:qiuyin@gmail.com" target="_blank">qiuyin@gmail.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Basically, I'd like to replace a class Bar with another class Baz. Most of their interfaces are identical except:<br>
<br>
* Some functions have incompatible order of parameters. So I need to re-arrange the order of argument for those Bar member functions calls.<br>
* Some functions in Bar don't have their counterparts in Baz. In this case, the original calls have to be rewritten. Usually they are transformed into calls to helper functions.<br>
<br>
I'm considering configuring the transformation with a simple template language. For example, this rule<br>
<br>
  Bar::foo(size_t, bool) => foo($2, $1)<br>
<br>
means reversing the 2 arguments.<br>
<br>
Supposing Bar::foo(size_t, bool) returns a bool, rewriting a call like<br>
<br>
  bar.foo(1, bar.foo(2, false))<br>
<br>
in two passes seems not working. Say first we refactor the code as<br>
<br>
  bar.foo(1, bar.foo(false, 2))<br>
<br>
Now the code obviously won't compile, no matter if we have rewritten the type of bar. I think it might be handy to have a replacement class that can reference source ranges in a rewrite rope.<br></blockquote><div><br>
</div><div style>If I'm not mistaken that's exactly the way the Rewriter handles changes (in a rewrite rope). I haven't extensively tested this, but I'd be interested in what the limitations are (most of our internal rewrites need multi-step processed anyway, due to code review constraints etc)</div>
<div style><br></div><div style>That said, you can easily special-case stuff up to a certain level - that will not get you the 100% case, but it's usually enough to get the 99% case even on very large code bases.</div>
<div style><br></div><div style>Cheers,</div><div style>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
在 2012-12-8,00:52,Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> 写道:<br>
<div class="HOEnZb"><div class="h5"><br>
> On Fri, Dec 7, 2012 at 5:42 PM, Yin Qiu <<a href="mailto:qiuyin@gmail.com">qiuyin@gmail.com</a>> wrote:<br>
><br>
> 在 2012-12-7,15:15,Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> 写道:<br>
><br>
> > On Fri, Dec 7, 2012 at 6:34 AM, <a href="mailto:qiuyin@gmail.com">qiuyin@gmail.com</a> <<a href="mailto:qiuyin@gmail.com">qiuyin@gmail.com</a>> wrote:<br>
> > Hi there,<br>
> ><br>
> > I am thinking about reverse the order of arguments in a call expression with clang. I'm leveraging the refactoring tool and the AST matcher framework. I use a matcher to find those calls i'm interested in, rewrite the expr, and  insert one replacement. Things go tricky for nested calls. Because the refactoring tool applies replacements one by one, and order adjustment does not change the total text length, one replacement could overwrite prior changes. Do i have to implement my own replacement applying algo (i'm thinking about adding source range references to a replacement object, and applying them recursively), or is there a simple and better way to do this?<br>

> ><br>
> > The problem is that I think the problem is not solvable in general - there is a class of replacements that's recursively applicable though. I think it makes sense to add support for those in the refactoring library. I have no clue yet how to do that though :)<br>

> ><br>
> > The easy workaround is to do one non-overlapping refactoring at a time (that has worked every time so far for us)[<br>
> ><br>
><br>
> Can you please share a little bit more details about your workaround? For this particular nested call case, did you mean running the refactoring tool for several passes? If so, I may not be able to adopt this approach because in my case a partially replaced function call cannot compile, which means the AST may not be well built.<br>

><br>
> If you tell me more about your specific case, I might be able to come up with ideas that apply to it directly :)<br>
><br>
> Cheers,<br>
> /Manuel<br>
><br>
<br>
</div></div></blockquote></div><br></div></div></div>