[cfe-dev] Rewriter: How to rewrite an empty function argument list?

Alex L via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 31 00:53:22 PDT 2017


Once you get the TypeLoc of the function, you can try casting it to
function type loc using getAsAdjusted. Here's a snipped from SemaDecl that
emits a warning using the location of the '(':

        TypeSourceInfo *TI = FD->getTypeSourceInfo();

        TypeLoc TL = TI->getTypeLoc();

        FunctionTypeLoc FTL = TL.getAsAdjusted<FunctionTypeLoc>();

        Diag(FTL.getLParenLoc(), diag::warn_strict_prototypes) << 2;


On 31 July 2017 at 08:45, Marcel Schaible <marcel at schaible-consulting.de>
wrote:

> Alex thanks for your hint.
>
> I was playing around with getTypeLoc, but I am didn't find a way to get
> the location of the opening parenthesis of a function argument list.
>
> Maybe you have an idea?
>
> Marcel
> Am 30.07.2017 um 21:56 schrieb Alex L:
>
> Hi Marcel,
>
> I believe that you can get the location of '('/')' and insert a new
> parameter after/before that location. The locations of braces should be in
> the FunctionTypeLoc which you can extract from the TypeLoc value returned
> by calling ((FunctionDecl *)YourFunction)->getTypeSourceInfo->getTypeLoc
> ();
>
> Alex
>
> On 30 July 2017 at 16:44, Marcel Schaible via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hi everyone,
>>
>> I am trying to transform function arguments. For functions with a at
>> least one argument I can position the Rewriter on the paramdecl.
>>
>> But if the function has no arguments there is no paramdecl. So how can I
>> rewrite the argument list of such a function?
>>
>> Example:
>>
>> int foo() { return 42; } transform into int foo(int p1) { return 42;);
>>
>> Thanks
>>
>> Marcel
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170731/ab6e129b/attachment.html>


More information about the cfe-dev mailing list