File: dumpchain.cpp

package info (click to toggle)
kdevelop-python 24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 12,640 kB
  • sloc: python: 183,048; cpp: 18,798; xml: 140; sh: 14; makefile: 9
file content (74 lines) | stat: -rw-r--r-- 2,630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    SPDX-FileCopyrightText: 2007 Piyush verma <piyush.verma@gmail.com>

    SPDX-License-Identifier: MIT
*/

#include "dumpchain.h"
#include "pythoneditorintegrator.h"

#include <language/duchain/types/identifiedtype.h>
#include <language/duchain/ducontext.h>
#include <language/duchain/topducontext.h>
#include <language/duchain/declaration.h>
#include <language/duchain/duchainpointer.h>
#include <language/duchain/use.h>

#include <QDebug>
#include "duchaindebug.h"

using namespace KDevelop;

namespace Python {


DumpChain::DumpChain()
    : indent(0)
{
}

void DumpChain::dump(const DUContext* context, bool imported)
{
    if( !context )
        return;
    qCDebug(KDEV_PYTHON_DUCHAIN) << QString(indent * 2, QLatin1Char(' '))
                                 << (imported ? "==import==> Context " : "New Context ")
                                 << context->scopeIdentifier(true)
                                 << context->transformFromLocalRevision(context->range()) << " " << context << " "
                                 << (dynamic_cast<const TopDUContext*>(context) ? "top-context" : "");
    if (!imported)
    {
        const auto localDeclarations = context->localDeclarations();
        for (Declaration* dec : localDeclarations) {
            const auto uses = dec->uses();
            qCDebug(KDEV_PYTHON_DUCHAIN) << QString( (indent+1)*2, QLatin1Char(' ') ) << "Declaration: " << dec->toString() << " [" << dec->qualifiedIdentifier() << "]  "<< dec << "(internal ctx" << dec->internalContext() << ")" << context->transformFromLocalRevision(dec->range()) << ", "<< ( dec->isDefinition() ? "definition, " : "declaration, " ) << uses.count() << "use(s)";
            for (auto it = uses.constBegin(); it != uses.constEnd(); ++it)
            {
                qCDebug(KDEV_PYTHON_DUCHAIN) << QString((indent+1)*2, QLatin1Char(' ')) << "File:" << it.key().str();
                for (const RangeInRevision& r : it.value())
                {
                    qCDebug(KDEV_PYTHON_DUCHAIN) << QString((indent+2)*2, QLatin1Char(' ')) << "Use:" << context->transformFromLocalRevision(r);
                }
            }
        }
    }
    ++indent;
    if (!imported)
    {
        const auto parentContexts = context->importedParentContexts();
        for (const DUContext::Import& parent : parentContexts) {
            dump(parent.context(dynamic_cast<const TopDUContext*>(context)), true);
        }
        const auto childContexts = context->childContexts();
        for (DUContext* child : childContexts) {
            dump(child);
        }
    }
    --indent;
}

DumpChain::~ DumpChain( )
{
}

}