[cfe-dev] Clang rewriter: what can be effectively removed from the buffer?

GabrieleCocco cocco at di.unipi.it
Tue Oct 30 07:00:38 PDT 2012


Hi to everybody.
I'm finding problems in removing some elements inside a translation unit
using Rewriter.
The interesting elements are:

- Function declaration/definition: 
rewriter.RemoveText(function->getLocation()); removes only the function
name.
rewriter.RemoveText(function->getSourceRange()); doesn't remove anything
rewriter.RemoveText(function->getBody()->getSourceRange()); removes only the
body (obviously)

Is there a way to remove the entire declaration/definition?

- Attributes
Can be removed from the rewriter buffer? It seems it doesn't work.

- Macro expanded to function calls
Is there any way to remove macros that get expanded to function calls?
Example:

#define this_opencl_device(p, d) call_this_opencl_device(p, d);

...
int* a,*b,*c;

this_opencl_device(0, 1)  // <- remove this
foo(a, b, c, 1024);
...

- Include directives
Is there a way to insert or remove include directives? I would like the code
processed by my clang tool to be transformed into something that requires to
import a local header, and I would like to produce the appropriate include
directive.

Thank you very much!



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Clang-rewriter-what-can-be-effectively-removed-from-the-buffer-tp4027839.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list