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

Anders Bakken agbakken at gmail.com
Thu Jan 12 19:06:19 PST 2012


Hi Guys

First off I want to thank you for the efforts on clang and llvm. Awesome job.

We're a couple of people who are writing a tagger for C/C++ (and I
suppose we could use it for objective-c and c++ as well) using clang.

We started off using the clang_visitChildren API and friends but have
recently to using clang_indexSourceFile which is nicer to work with
and seemingly faster. We've noticed however that we no longer seem to
get declarations/references of parameters and local variables. Is this
intentional? We're able to get to it using clang_visitChildren to
handle CXCursor_ParmDecl, CXCursor_VarDecl and CXCursor_DeclRefExpr
but this comes at a pretty hefty price in turns of performance.

Please find a small test attached.

To compile do:
g++ main.cpp -lclang

The app essentially dumps out some info for each call to the
indexDeclaration and indexReference callbacks. It's running on this
file:

int foo(int param)
{
    const int local = param * param;
    return (local - param);
}

int main()
{
    return foo(12);
}

// When I run this I get:

1:5: foo Function
7:5: main Function
9:12: ref of Function foo

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.

If anyone has any interest in the project or want to see how we use
clang it can be found here:

https://github.com/AndersBakken/rtags

The clang-usage is mostly in RBuild.cpp

regards

Anders Bakken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120112/d912baeb/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: text/x-c++src
Size: 124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120112/d912baeb/attachment-0001.cpp>


More information about the cfe-dev mailing list