language/duchain
dumpchain.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "dumpchain.h"
00021
00022 #include <QtCore/QString>
00023 #include <QTextStream>
00024
00025 #include <kdebug.h>
00026 #include <ktexteditor/range.h>
00027 #include <ktexteditor/smartrange.h>
00028
00029 #include "ducontext.h"
00030 #include "topducontext.h"
00031 #include "declaration.h"
00032 #include "duchainpointer.h"
00033 #include "identifier.h"
00034 #include "use.h"
00035 #include "indexedstring.h"
00036 #include "functiondefinition.h"
00037
00038 using namespace KDevelop;
00039
00040
00041 DumpChain::DumpChain()
00042 : indent(0), top(0)
00043 {
00044 }
00045
00046 DumpChain::~ DumpChain( )
00047 {
00048 }
00049
00050 void DumpChain::dump( DUContext * context, int allowedDepth )
00051 {
00052 if(!top)
00053 top = context->topContext();
00054
00055 enum ContextType {
00056 Global ,
00057 Namespace ,
00058 Class ,
00059 Function ,
00060 Template ,
00061 Enum ,
00062 Helper ,
00063 Other
00064 };
00065 QString type;
00066 switch(context->type()) {
00067 case Global: type = "Global"; break;
00068 case Namespace: type = "Namespace"; break;
00069 case Class: type = "Class"; break;
00070 case Function: type = "Function"; break;
00071 case Template: type = "Template"; break;
00072 case Enum: type = "Enum"; break;
00073 case Helper: type = "Helper"; break;
00074 case Other: type = "Other"; break;
00075 }
00076 kDebug() << QString(indent * 2, ' ') << (indent ? "==import==> Context " : "New Context ") << type << context << "\"" << context->localScopeIdentifier() << "\" [" << context->scopeIdentifier() << "]" << context->range().textRange() << ' ' << (dynamic_cast<TopDUContext*>(context) ? "top-context" : "");
00077
00078
00079 if( !context )
00080 return;
00081 if (allowedDepth >= 0) {
00082 foreach (Declaration* dec, context->localDeclarations(top)) {
00083
00084
00085
00086 kDebug() << QString((indent+1) * 2, ' ') << "Declaration: " << dec->toString() << " [" << dec->qualifiedIdentifier() << "]" << dec << "(internal ctx" << dec->internalContext() << ")" << dec->range().textRange() << "smart range:" << dec->smartRange() << "," << (dec->isDefinition() ? "defined, " : (FunctionDefinition::definition(dec) ? "" : "no definition, ")) << dec->uses().count() << "use(s).";
00087 if (FunctionDefinition::definition(dec)) {
00088 kDebug() << QString((indent+1) * 2 + 1, ' ') << "Definition:" << FunctionDefinition::definition(dec)->range().textRange();
00089 }
00090 QMap<IndexedString, QList<SimpleRange> > uses = dec->uses();
00091 for(QMap<IndexedString, QList<SimpleRange> >::const_iterator it = uses.constBegin(); it != uses.constEnd(); ++it) {
00092 kDebug() << QString((indent+2) * 2, ' ') << "File:" << it.key().str();
00093 foreach (const SimpleRange& range, *it)
00094 kDebug() << QString((indent+2) * 2+1, ' ') << "Use:" << range.textRange();
00095 }
00096 }
00097 } else {
00098 kDebug() << QString((indent+1) * 2, ' ') << context->localDeclarations(top).count() << "Declarations, " << context->childContexts().size() << "child-contexts";
00099 }
00100
00101 ++indent;
00102 {
00103 foreach (const DUContext::Import &parent, context->importedParentContexts()) {
00104 DUContext* import = parent.context(top);
00105 if(!import) {
00106 kDebug() << QString((indent+2) * 2+1, ' ') << "Could not get parent, is it registered in the DUChain?";
00107 continue;
00108 }
00109
00110 if(had.contains(import)) {
00111 kDebug() << QString((indent+2) * 2+1, ' ') << "skipping" << import->scopeIdentifier(true) << "because it was already printed";
00112 continue;
00113 }
00114 had.insert(import);
00115
00116 dump(import, allowedDepth-1);
00117 }
00118
00119 foreach (DUContext* child, context->childContexts())
00120 dump(child);
00121 }
00122 --indent;
00123
00124 if(indent == 0) {
00125 top = 0;
00126 had.clear();
00127 }
00128 }
00129
00130 QString DumpChain::dumpRanges(KTextEditor::SmartRange* range, QString indent)
00131 {
00132 QString ret;
00133 QTextStream stream(&ret);
00134 stream << indent << range << "(" << range->start().line() << ", " << range->start().column() << ") -> (" << range->end().line() << ", " << range->end().column() << ')' << "\n";
00135 foreach(KTextEditor::SmartRange* child, range->childRanges())
00136 stream << dumpRanges(child, indent + ' ');
00137
00138 return ret;
00139 }