~ubuntu-branches/ubuntu/quantal/kdevplatform/quantal-proposed

« back to all changes in this revision

Viewing changes to language/duchain/declaration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bhargav Mangipudi
  • Date: 2010-12-16 19:31:23 UTC
  • mfrom: (0.3.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20101216193123-xe2keh5754zwsn1t
Tags: 1.1.80-0ubuntu1
* New upstream release
  - kdevplatform2-libs is now kdevplatform3-libs due to ABI changes
  - Update kdevplatform3-libs.install to include l10n files
  - Update kdevplatform-dev.install
* Removed localization packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <QtCore/QByteArray>
24
24
 
25
 
#include <ktexteditor/smartrange.h>
26
 
#include <ktexteditor/document.h>
27
 
 
28
25
#include <limits>
29
26
 
30
27
#include "topducontext.h"
39
36
#include "indexedstring.h"
40
37
#include "duchainregister.h"
41
38
#include "persistentsymboltable.h"
42
 
#include "repositories/stringrepository.h"
43
39
#include "types/identifiedtype.h"
44
40
#include "types/structuretype.h"
45
41
#include "functiondefinition.h"
48
44
#include "types/typeutils.h"
49
45
#include "types/typealiastype.h"
50
46
#include "classdeclaration.h"
51
 
 
52
 
using namespace KTextEditor;
 
47
#include "repositories/stringrepository.h"
53
48
 
54
49
namespace KDevelop
55
50
{
56
51
 
57
 
///@todo Use reference counting
58
 
static Repositories::StringRepository& commentRepository() {
59
 
    static Repositories::StringRepository commentRepositoryObject("Comment Repository");
60
 
    return commentRepositoryObject;
61
 
}
62
 
 
63
52
REGISTER_DUCHAIN_ITEM(Declaration);
64
53
 
65
54
DeclarationData::DeclarationData()
84
73
{
85
74
}
86
75
 
 
76
///@todo Use reference counting
 
77
static Repositories::StringRepository& commentRepository() {
 
78
    static Repositories::StringRepository commentRepositoryObject("Comment Repository");
 
79
    return commentRepositoryObject;
 
80
}
 
81
 
 
82
void initDeclarationRepositories() {
 
83
  commentRepository();
 
84
}
 
85
 
87
86
Declaration::Kind Declaration::kind() const {
88
87
  DUCHAIN_D(Declaration);
89
88
  return d->m_kind;
105
104
  return top && top->inDUChain();
106
105
}
107
106
 
108
 
Declaration::Declaration( const SimpleRange& range, DUContext* context )
 
107
Declaration::Declaration( const RangeInRevision& range, DUContext* context )
109
108
  : DUChainBase(*new DeclarationData, range)
110
109
{
111
110
  d_func_dynamic()->setClassId(this);
125
124
 
126
125
Declaration::Declaration(const Declaration& rhs)
127
126
  : DUChainBase(*new DeclarationData( *rhs.d_func() )) {
128
 
  setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
129
127
  m_topContext = 0;
130
128
  m_context = 0;
131
129
  m_indexInTopContext = 0;
138
136
  m_indexInTopContext = 0;
139
137
}
140
138
 
141
 
Declaration::Declaration( DeclarationData & dd, const SimpleRange& range )
 
139
Declaration::Declaration( DeclarationData & dd, const RangeInRevision& range )
142
140
  : DUChainBase(dd, range)
143
141
{
144
142
  m_topContext = 0;
722
720
  return m_context->equalScopeIdentifier(m_context);
723
721
}
724
722
 
725
 
QList<KTextEditor::SmartRange*> Declaration::smartUses() const
 
723
QMap<IndexedString, QList<RangeInRevision> > Declaration::uses() const
726
724
{
727
 
  Q_ASSERT(topContext());
728
725
  ENSURE_CAN_READ
729
 
  QSet<KTextEditor::SmartRange*> tempUses;
 
726
  QMap<IndexedString, QMap<RangeInRevision, bool> > tempUses;
 
727
 
730
728
  //First, search for uses within the own context
731
729
  {
732
 
    foreach(KTextEditor::SmartRange* range, allSmartUses(topContext(), const_cast<Declaration*>(this)))
733
 
      tempUses.insert(range);
 
730
    QMap<RangeInRevision, bool>& ranges(tempUses[topContext()->url()]);
 
731
    foreach(const RangeInRevision& range, allUses(topContext(), const_cast<Declaration*>(this)))
 
732
      ranges[range] = true;
734
733
  }
735
734
 
736
735
  KDevVarLengthArray<IndexedTopDUContext> useContexts = DUChain::uses()->uses(id());
737
736
 
738
737
  FOREACH_ARRAY(const IndexedTopDUContext& indexedContext, useContexts) {
739
 
    if(!indexedContext.isLoaded())
740
 
      continue;
741
738
    TopDUContext* context = indexedContext.data();
742
739
    if(context) {
743
 
      foreach(KTextEditor::SmartRange* range, allSmartUses(context, const_cast<Declaration*>(this)))
744
 
        tempUses.insert(range);
745
 
    }
746
 
  }
747
 
 
748
 
  return tempUses.toList();
 
740
      QMap<RangeInRevision, bool>& ranges(tempUses[context->url()]);
 
741
      foreach(const RangeInRevision& range, allUses(context, const_cast<Declaration*>(this)))
 
742
        ranges[range] = true;
 
743
    }
 
744
  }
 
745
 
 
746
  QMap<IndexedString, QList<RangeInRevision> > ret;
 
747
 
 
748
  for(QMap<IndexedString, QMap<RangeInRevision, bool> >::const_iterator it = tempUses.constBegin(); it != tempUses.constEnd(); ++it) {
 
749
    if(!(*it).isEmpty()) {
 
750
      QList<RangeInRevision>& list(ret[it.key()]);
 
751
      for(QMap<RangeInRevision, bool>::const_iterator it2 = (*it).constBegin(); it2 != (*it).constEnd(); ++it2)
 
752
        list << it2.key();
 
753
    }
 
754
  }
 
755
  return ret;
749
756
}
750
757
 
751
 
QMap<IndexedString, QList<SimpleRange> > Declaration::uses() const
 
758
QMap<IndexedString, QList<SimpleRange> > Declaration::usesCurrentRevision() const
752
759
{
753
760
  ENSURE_CAN_READ
754
761
  QMap<IndexedString, QMap<SimpleRange, bool> > tempUses;
756
763
  //First, search for uses within the own context
757
764
  {
758
765
    QMap<SimpleRange, bool>& ranges(tempUses[topContext()->url()]);
759
 
    foreach(const SimpleRange& range, allUses(topContext(), const_cast<Declaration*>(this)))
760
 
      ranges[range] = true;
 
766
    foreach(const RangeInRevision& range, allUses(topContext(), const_cast<Declaration*>(this)))
 
767
    {
 
768
      ranges[topContext()->transformFromLocalRevision(range)] = true;
 
769
    }
761
770
  }
762
771
 
763
772
  KDevVarLengthArray<IndexedTopDUContext> useContexts = DUChain::uses()->uses(id());
766
775
    TopDUContext* context = indexedContext.data();
767
776
    if(context) {
768
777
      QMap<SimpleRange, bool>& ranges(tempUses[context->url()]);
769
 
      foreach(const SimpleRange& range, allUses(context, const_cast<Declaration*>(this)))
770
 
        ranges[range] = true;
 
778
      foreach(const RangeInRevision& range, allUses(context, const_cast<Declaration*>(this)))
 
779
        ranges[context->transformFromLocalRevision(range)] = true;
771
780
    }
772
781
  }
773
782
 
774
 
  QMap<IndexedString, QList<SimpleRange> > ret;
 
783
QMap<IndexedString, QList<SimpleRange> > ret;
775
784
 
776
785
  for(QMap<IndexedString, QMap<SimpleRange, bool> >::const_iterator it = tempUses.constBegin(); it != tempUses.constEnd(); ++it) {
777
786
    if(!(*it).isEmpty()) {