[cfe-dev] Using Rewriter to remove a function call argument along with preceding comma?
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Jun 11 14:13:54 PDT 2013
On Jun 11, 2013, at 1:34 PM, Stephan Bergmann <sbergman at redhat.com> wrote:
> On 06/07/2013 08:19 PM, Argyrios Kyrtzidis wrote:
>> On Jun 7, 2013, at 5:31 AM, Stephan Bergmann <sbergman at redhat.com
>> <mailto:sbergman at redhat.com>> wrote:
>>> Anyway, what I want to do is a rewriting Clang plugin that removes one
>>> argument from specific function calls. But where I'm lost is how to
>>> determine the SourceLocation of the comma preceding the given
>>> argument, to do something like
>>
>> You could remove this range:
>>
>> [loc-for-end-of-token of end location of preceding argument, end
>> location of removed argument]
>
> Yeah, but how do I get that loc-for-end-of-token?
See Lexer::getLocForEndOfToken() or Preprocessor::getLocForEndOfToken() (the latter delegates to the former).
> I must confess that studying the header files left me clueless. Continuing with my below example, what would replace the /*TODO*/ if I wanted to remove starting past the tokens for callExpr->getArg(0)?
You pass the end location to one of the above functions.
>
> Thanks again,
> Stephan
>
>>> Rewriter.RemoveText(
>>> SourceRange(
>>> /*TODO*/,
>>> callExpr->getArg(1)->getLocEnd()));
>
More information about the cfe-dev
mailing list