[cfe-dev] Getting tentative definition with libclang
Jing Peng via cfe-dev
cfe-dev at lists.llvm.org
Thu Jan 10 18:33:00 PST 2019
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 1114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190110/6e9bc1de/attachment.obj>
More information about the cfe-dev
mailing list