Getting tentative definition with libclang

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Getting tentative definition with libclang

Don Hinton via cfe-dev
Hello,

I find that, with libclang, the only way to get the definition of a
declaration cursor is to use clang_getCursorDefinition(). But this
function calls VarDecl::getDefinition(), which can only return the
real definition. If there are only tentative definitions it returns
nullptr.

So I'd like to know if we can expose VarDecl::getActingDefinition() in
libclang as a function like clang_getCursorActingDefinition() so that
we can get the tentative definition. But I think this function would
be very much similar to clang_getCursorDefinition(), where we might
have a lot of code repeat. Perhaps a better way is to modify
VarDecl::getDefinition(), making it:

- return the real definition if we find one (what it does right now)
- return the last tentative definition if there's no real definition
but only tentative ones (like VarDecl::getActingDefinition())
- return nullptr if there are only declarations

This is what the attached patch does.

I haven't tested this change yet. If I'm on the right track I'd like
to spend some more time on testing this and possibly committing it.

Thanks!
--
Jing Peng

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev