DUContext lookup problem.

Bertjan Broeksema bertjan at kdab.net
Tue Sep 29 08:09:24 UTC 2009


On Monday 28 September 2009 03:18:09 pm Bertjan Broeksema wrote:
> Hi David,
>
> I've the following piece of code:
>
> bool CppQueryEngine::useMatchesRestrictions(IndexedString const &url,
>                                             QMap<int, QString> const
> &restrictions,
>                                             SimpleRange const &use) const
> {
>   if (!use.isValid())
>     return false;
>
>   TopDUContext* ctx = DUChain::self()->chainForDocument(url.toUrl());
>   if (!ctx) {
>     qDebug() << "Could not get TopDUContext for" << url.str();
>     return false;
>   }
>
>   DUContext* ductx = ctx->findContextAt(SimpleCursor(use.start.line,
> use.start.column));
>   if (!ductx) {
>     qDebug() << "[CppQueryEngine::useMatchesRestrictions] Context not
> found."; return false;
>   }
>   ...
> }
>
> The strange thing is that this sometimes works (as in it does find the
> specific DUContext ductx). But very often it also doesn't find it.
> Currently I'm quite sure that the TopDUContext is updated with the
> following call:
>
> DUChain::self()->updateContextForUrl(IndexedString(parseJob->document()),
>                                         
> TopDUContext::AllDeclarationsContextsUsesAndAST);
>
> Any ideas what the reason might be that the context for the use cannot be
> found? (Btw for the times it does work it also showed that the use mapping
> does "work", as in I can retrieve an AST node).

I've looked a bit more into it and it seems that the range of the TopDuContext 
is not initialized properly. Enabling the debug statements in 
ducontext.cpp:1613 and further gives me a lot of sequences like:

searchign (536, 14) in: "" [ (0, 0)  ->  (0, 0) ] false                                                                                        
mismatch                                                                                                                                       
[CppQueryEngine::useMatchesRestrictions] Context not found.

Though I've no clue yet why the range is not properly initialized.

Cheers,

Bertjan





More information about the KDevelop-devel mailing list