DUContext types for source information
Martin Bednar
martin at serafean.cz
Sun Aug 9 19:15:34 BST 2026
Hi,
I'm trying to port the sourceinfo[1] plugin to new APIs, to actually make it
useful, and I'd appreciate insight into the DUChain.
What I'm trying to do at the moment is draw function parameter names at
callsites. So far I've tried :
- Creating a new interface that each language plugin could implement to
provide the ranges of the function arguments. This felt like a lot of work to
put on various language plugins. And with the language plugin having to rewalk
its AST specifically for function arguments (I did use IAST), it had a
discernible delay.
- Creating a DUContext of type Function for arguments at every callsite, with
all arguments being either Use or another DUContext. I had to hack in Literals
and implicit conversions as DUContext of type Other. Then I hit passing in an
address of an object:
> foo ( &value);
I'm stuck on this because AFAIU there is currently no DUChain reason to create
a cursor/range for '&' (unless it's overloaded).
I'm now thinking of creating a FunctionContext subclass of DUContext which
would contain a list of Cursors/Ranges that are the entire argument. This is
about as complex for language plugins as my first approach, but the info is
already in the DUChain, so at least it should be faster.
To be honest, my preferred approach is #2, but I'm unsure if it's workable.
Any insight would be more than welcome.
Second question : currently the clang plugin includes Template parameters in
the Function DUContext. Making the pattern of querying the function context
for all local declarations to get parameters wrong :
> fCtx->localDeclarations(decl->topContext());
This pattern is in the outline plugin, and in the signature assistant, making
them incorrect for templated functions.
My first idea is to create a separate Template type DUContext for template
params. What I do not see is how it gets connected to the function itself.
If anyone with DUChain knowledge could enlighten me, I'd be very grateful.
Thanks for any comments.
Martin.
[1] https://invent.kde.org/bednar/kdevelop/-/tree/sourceinfo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 265 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20260809/6dec6ebf/attachment.sig>
More information about the KDevelop-devel
mailing list