[cfe-dev] Finding all references to a function overload or type.

Manuel Klimek klimek at google.com
Wed Nov 21 01:20:22 PST 2012


On Wed, Nov 21, 2012 at 10:18 AM, Holtgrewe, Manuel <
manuel.holtgrewe at fu-berlin.de> wrote:

>  Hi,
>
>  the location of the function declaration/definition appears to be easier
> to construct and would work fine for me.
>

Then you'll basically want to drill through the AST from the call to the
declaration, and get the location of the declaration via the SourceManager.

Cheers,
/Manuel


>
>  Thanks,
> Manuel
>
>  ------------------------------
> *From:* Manuel Klimek [klimek at google.com]
> *Sent:* Wednesday, November 21, 2012 10:10 AM
>
> *To:* Holtgrewe, Manuel
> *Cc:* cfe-dev at cs.uiuc.edu
> *Subject:* Re: [cfe-dev] Finding all references to a function overload or
> type.
>
>   On Wed, Nov 21, 2012 at 10:02 AM, Holtgrewe, Manuel <
> manuel.holtgrewe at fu-berlin.de> wrote:
>
>>  ping
>>
>>  Maybe I should elaborate a bit further.
>>
>>  Given the program [1] (written as a string in the test), I would like
>> to find out from which contextes the function overload bar(Foo<T, Tick>
>> const &) is called.
>>
>>  I tried dumping parts of the AST and from that it appears that it is
>> not directly possible to see the instantiation points. Is it possible to
>> see a "concrete AST" with instantiated class and function templates?
>>
>
>  What's your "key" for the overload of bar in this case?
> Possible keys:
> a) the location of the function declaration / definition
> b) the parameter list
>
>  Cheers,
> /Manuel
>
>
>>
>>  Thanks,
>> Manuel
>>
>>  [1]
>> https://github.com/holtgrewe/func_references/blob/master/src/test.cpp#L114
>>
>>  ------------------------------
>> *From:* cfe-dev-bounces at cs.uiuc.edu [cfe-dev-bounces at cs.uiuc.edu] on
>> behalf of Holtgrewe, Manuel [manuel.holtgrewe at fu-berlin.de]
>> *Sent:* Monday, November 19, 2012 9:11 AM
>> *To:* cfe-dev at cs.uiuc.edu
>>
>> *Subject:* Re: [cfe-dev] Finding all references to a function overload
>> or type.
>>
>>    Thank you for your answer.
>>
>>  I was able to write a small test program with an RecursiveASTVisitor
>> [1] by using some example code I found on github.
>>
>>  However, now I'm stuck. I could not find out how to find out that the
>> function overload bar(Foo<int, Tick> const &) is called from the AST.
>>
>>  Can someone help me with this and point me into the right direction
>> again?
>>
>>  Thanks,
>> Manuel
>>
>>  [1]
>> https://github.com/holtgrewe/func_references/blob/master/src/test.cpp
>>
>>  ------------------------------
>> *From:* Manuel Klimek [klimek at google.com]
>> *Sent:* Thursday, November 15, 2012 5:12 PM
>> *To:* Holtgrewe, Manuel
>> *Cc:* cfe-dev at cs.uiuc.edu
>> *Subject:* Re: [cfe-dev] Finding all references to a function overload
>> or type.
>>
>>   On Thu, Nov 15, 2012 at 12:47 AM, Holtgrewe, Manuel <
>> manuel.holtgrewe at fu-berlin.de> wrote:
>>
>>> Dear all,
>>>
>>> I would like to use the clang infrastructure (libclang, libtooling, ...)
>>> to find all references to a function overload or a type in a program. This
>>> should also work if the program has templates.
>>>
>>> Consider the following example:
>>>
>>> void f(int i)
>>> {}
>>>
>>> template <typename T>
>>> void f(T x)
>>> {
>>>   X<T> y;
>>> }
>>>
>>> template <typename T>
>>> struct X
>>> {};
>>>
>>> template <>
>>> struct X<long>
>>> {};
>>>
>>> main ()
>>> {
>>>   f(3.0);
>>>   f(1);
>>>   f(1l);
>>>
>>>   return 0;
>>> }
>>>
>>> For example, I would like to find all occurences of the overload "void
>>> f(int i)" (result should be the line with "f(1)" or all occurences of the
>>> specialization "X<long>" (in the line with "X<T> y" when f is called with a
>>> long value.
>>>
>>> Is this possible with clang? If so, can anyone point me in the right
>>> direction?
>>>
>>
>>  Yes. Start here: http://clang.llvm.org/docs/Tooling.html
>>
>>  Cheers,
>> /Manuel
>>
>>
>>>
>>> Thanks,
>>> Manuel
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>>
>> _______________________________________________
>> 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/20121121/218d8d85/attachment.html>


More information about the cfe-dev mailing list