• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

dumpchain.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
00003     Copyright 2006 Hamish Rodda <rodda@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
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       //IdentifiedType* idType = dynamic_cast<IdentifiedType*>(dec->abstractType().data());
00085       
00086       kDebug() << QString((indent+1) * 2, ' ') << "Declaration: " << dec->toString() << /*(idType ? (" (type-identity: " + idType->identifier().toString() + ")") : QString()) <<*/ " [" << 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 }

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal