Kdevelop DUChain usage help

Milian Wolff mail at milianw.de
Fri Jul 23 15:39:41 UTC 2010


On Friday 23 July 2010 17:25:42 Konstantin Karganov wrote:
> Hi Milian,
> 
> yesterday we've talked at #kdevelop, I asked for advice how to find
> identifiers referenced in a given line of code, you told me to use
> DUChain.
> 
> I've looked at the class, it's quite big and it's not obvious at all
> how it is to be used.
> 
> Can you please give me some explanations, directions or conventions on
> its usage?
> Not the code fragments, I'll find that myself, just some ideas and
> general design, in brief.
> The link where to read that would be enough, but it seems there are none..
> 
> I'll continue browsing the code myself but your explanations could
> save me a lot of time and keep me from silly mistakes when using the
> code.
> Thanks in advance for using your time and for any help from your side.

Take a look at DUContext (base class of TopDUContext). The latter you get via 
DUChain::self()->chainForDocument();

Also take a look at duchainutils.h and e.g. declarationInLine().

To get all, uses and declarations, in a given line, you'd have to iterate over 
them, afaiks the current API has no functions to give you that in one simple 
call.

Instead do something like 

ReferencedTopDUContext ctx = KDevelop::standardContextForUrl(...);

DUContext* ctx = KDevelop::findContextAt(yourLinePos);

foreach(Declaration* dec, ctx->localDeclarations() {
  // find declarations in given line by comparing against dec->range()
}

FOREACH_FUNCTION(const KDevelop::Use& use, ctx->uses) {
  // same as above
}

good luck

PS: sending to the developer ML, please register there and point your future 
questions there.

Bye
-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20100723/e022a6a7/attachment.sig>


More information about the KDevelop-devel mailing list