[cfe-dev] Rewriter in a macro

Manuel Klimek klimek at google.com
Wed Jan 30 02:14:27 PST 2013


On Tue, Jan 29, 2013 at 9:42 PM, JohnH <jan.hoogerbrugge at gmail.com> wrote:

> I am not interested in code such as the token paste example. I mentioned
> the
> hypothetical for to while
> loop transformation. Code like this is not uncommon:
>
> #define copy_array(a, b, n)  { int i; for(i = 0; i < n; i++) a[i] = b[i]; }
>
>   copy_array(foo, bar)
>
> I would like that the for loop inside the expanded macro will also be
> rewritten.
>
> If clang is able to rewrite the definition of the macro. What would happen
> when the macro is expanded
> multiple times? In the for to while loop rewrite example, a for loop will
> be
> detected multiple times but
> it needs to be rewritten only once.
>

Yes, you need to generally deduplicate rewrites. This is even true for
simple things as includes :)

Note that
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring.h?view=markup
has some infrastructure around the rewriter to help with that :)

Cheers,
/Manuel


>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/Rewriter-in-a-macro-tp4030056p4030134.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130130/e84f6be3/attachment.html>


More information about the cfe-dev mailing list