[cfe-dev] clang_indexSourceFile and CXCursor_(ParmDecl|VarDecl|DeclRefExpr)

Anders Bakken agbakken at gmail.com
Fri Jan 13 22:11:26 PST 2012


Seems to work great except that I it gives me the references twice.

I get this output from the attached test:

test.cpp:2:7: CXXClass TemplateClass
test.cpp:5:5: CXXConstructor TemplateClass<T>
test.cpp:5:21: Variable t
test.cpp:5:30: Variable b
test.cpp:5:34: ref of Variable t test.cpp:5:21
test.cpp:5:34: ref of Variable t test.cpp:5:21
test.cpp:5:41: ref of Variable b test.cpp:5:30
test.cpp:5:45: ref of Variable t test.cpp:5:21
test.cpp:5:50: ref of Variable b test.cpp:5:30
test.cpp:8:7: CXXClass NonTemplateClass
test.cpp:11:5: CXXConstructor NonTemplateClass
test.cpp:14:5: Function main
test.cpp:16:24: Variable tt
test.cpp:16:24: ref of CXXConstructor TemplateClass test.cpp:5:5
test.cpp:16:24: ref of CXXConstructor TemplateClass test.cpp:5:5
test.cpp:17:22: Variable t
test.cpp:17:22: ref of CXXConstructor NonTemplateClass test.cpp:11:5
test.cpp:17:5: ref of CXXClass NonTemplateClass test.cpp:8:7
test.cpp:17:22: ref of CXXConstructor NonTemplateClass test.cpp:11:5

E.g.

$ ./clangtest | sort | uniq -c
      1 test.cpp:11:5: CXXConstructor NonTemplateClass
      1 test.cpp:14:5: Function main
      1 test.cpp:16:24: Variable tt
      2 test.cpp:16:24: ref of CXXConstructor TemplateClass test.cpp:5:5
      1 test.cpp:17:22: Variable t
      2 test.cpp:17:22: ref of CXXConstructor NonTemplateClass test.cpp:11:5
      1 test.cpp:17:5: ref of CXXClass NonTemplateClass test.cpp:8:7
      1 test.cpp:2:7: CXXClass TemplateClass
      1 test.cpp:5:21: Variable t
      1 test.cpp:5:30: Variable b
      2 test.cpp:5:34: ref of Variable t test.cpp:5:21
      1 test.cpp:5:41: ref of Variable b test.cpp:5:30
      1 test.cpp:5:45: ref of Variable t test.cpp:5:21
      1 test.cpp:5:50: ref of Variable b test.cpp:5:30
      1 test.cpp:5:5: CXXConstructor TemplateClass<T>
      1 test.cpp:8:7: CXXClass NonTemplateClass

On a not necessarily related topic. I was kinda expecting a reference
to TemplateClass at 16:5:

E.g. something like this:

 test.cpp:16:5: ref of CXXClass NonTemplateClass test.cpp:2:7

Is this expected behavior? Thanks again.

Anders


On Fri, Jan 13, 2012 at 6:48 PM, Anders Bakken <agbakken at gmail.com> wrote:
> Sweet. That sounds like just what we need. Will try out.
>
> Thanks
>
> Anders
>
> On Fri, Jan 13, 2012 at 6:14 PM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
>> Skipping function-local symbols was intentional, but it is a reasonable request to get callbacks for such symbols.
>> After r148160 & r148169 you can set CXIndexOpt_IndexFunctionLocalSymbols at indexing options to get callbacks for function-local symbols.
>>
>> I don't see issue with the 'diagnostic' callback. Try using 'c-index-test' like this:
>>
>> c-index-test -index-file <compiler args>
>>
>> on your source file. You should see 'diagnostic' getting called for errors/warnings.
>>
>> -Argyrios
>>
>> On Jan 13, 2012, at 1:10 PM, David Mirabito wrote:
>>
>>> Hi All,
>>>
>>> For the record once I got syntax colouring working (tokenise and attribute the resulting list) I moved on to flagging warnings / errors (a-la XCode). I too was surprised that only some declarations/references were raised to the callback functions - most seemed related to global and cross-translation unit. All the 'internal' stuff was stripped.
>>> Additionally, try as I might I cannot get the 'diagnostic' callback to be triggered, whether I introduce warnings or errors in the parsed code.
>>>
>>> At first I thought it was just me or my app doing something stupid :)
>>>
>>> I might try migrating to visitChildren and the explicit API calls to get and walk the diagnostic list of a TU.
>>>
>>> Cheers,
>>> DavidM
>>>
>>> On 13/01/2012, at 3:06 AM, Anders Bakken wrote:
>>> <snip>
>>>> No mention of either the local variable inside foo(int) or the
>>>> parameter. Is this the way it's supposed to be? I've noticed a lot
>>>> work has gone into these new APIs.
>>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 3741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120113/fe0d3671/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: text/x-c++src
Size: 258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120113/fe0d3671/attachment-0001.cpp>


More information about the cfe-dev mailing list