language/duchain
declaration.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef DECLARATION_H
00021 #define DECLARATION_H
00022
00023 #include <QtCore/QList>
00024 #include <QtCore/QMap>
00025
00026
00027 #include "../editor/documentrangeobject.h"
00028 #include "identifier.h"
00029 #include "indexedstring.h"
00030 #include "types/abstracttype.h"
00031 #include "duchainbase.h"
00032 #include "topducontext.h"
00033 #include "indexeditems.h"
00034
00035 class QByteArray;
00036
00037 namespace KTextEditor {
00038 class SmartRange;
00039 }
00040
00041 namespace KDevelop
00042 {
00043
00044 class AbstractType;
00045 class DUContext;
00046 class Use;
00047 class ForwardDeclaration;
00048 class DeclarationData;
00049 class DeclarationId;
00050 class Declaration;
00051 class IndexedTopDUContext;
00052
00053
00061 class KDEVPLATFORMLANGUAGE_EXPORT Declaration : public DUChainBase
00062 {
00063 public:
00065 enum AccessPolicy {
00066 Public ,
00067 Protected ,
00068 Private ,
00069 DefaultAccess
00070 };
00072 enum Kind {
00073 Type ,
00074 Instance ,
00075 NamespaceAlias,
00076 Alias,
00077 Namespace,
00078 Import
00079 };
00080
00090 Declaration(const SimpleRange& range, DUContext* parentContext);
00092 Declaration(const Declaration& rhs);
00094 virtual ~Declaration();
00096 Declaration( DeclarationData & dd );
00097
00098 virtual TopDUContext* topContext() const;
00099
00101 virtual bool isForwardDeclaration() const;
00103 ForwardDeclaration* toForwardDeclaration();
00105 const ForwardDeclaration* toForwardDeclaration() const;
00106
00108 virtual bool isFunctionDeclaration() const;
00109
00119 virtual bool inDUChain() const;
00120
00122 bool isDefinition() const;
00124 void setDeclarationIsDefinition(bool dd);
00125
00127 bool isTypeAlias() const;
00129 void setIsTypeAlias(bool typeAlias);
00130
00132 bool isFinal() const;
00134 void setFinal(bool final);
00135
00144 virtual Declaration* specialize(IndexedInstantiationInformation specialization, const TopDUContext* topContext, int upDistance = 0);
00145
00156 DUContext * internalContext() const;
00157
00163 void setInternalContext(DUContext* context);
00164
00176 virtual DUContext * logicalInternalContext(const TopDUContext* topContext) const;
00177
00184 const Declaration* logicalDeclaration(const TopDUContext* topContext) const;
00185
00187 Declaration* logicalDeclaration(const TopDUContext* topContext);
00188
00193 DUContext* context() const;
00194
00211 void setContext(DUContext* context, bool anonymous = false);
00212
00214 template <class T>
00215 TypePtr<T> type() const { return TypePtr<T>::dynamicCast(abstractType()); }
00216
00223 AbstractType::Ptr abstractType() const;
00224
00229 template <class T>
00230 void setType(TypePtr<T> type) { setAbstractType(AbstractType::Ptr::staticCast(type)); }
00231
00237 virtual void setAbstractType(AbstractType::Ptr type);
00238
00245 IndexedType indexedType() const;
00246
00252 void setIdentifier(const Identifier& identifier);
00253
00259 Identifier identifier() const;
00260
00267 IndexedIdentifier indexedIdentifier() const;
00268
00275 QualifiedIdentifier qualifiedIdentifier() const;
00276
00284 bool equalQualifiedIdentifier(const Declaration* rhs) const;
00285
00289 Kind kind() const;
00290
00296 void setKind(Kind kind);
00297
00302 QByteArray comment() const;
00303
00307 void setComment(const QByteArray& str);
00309 void setComment(const QString& str);
00310
00316 bool inSymbolTable() const;
00317
00323 void setInSymbolTable(bool inSymbolTable);
00324
00330 bool operator==(const Declaration& other) const;
00331
00335 virtual QString toString() const;
00336
00338
00346 QMap<IndexedString, QList<SimpleRange> > uses() const;
00347
00352 QList<KTextEditor::SmartRange*> smartUses() const;
00353
00361 virtual uint additionalIdentity() const;
00362
00366 virtual IndexedInstantiationInformation specialization() const;
00367
00372 virtual DeclarationId id(bool forceDirect = false) const;
00373
00383 uint ownIndex() const;
00384
00386 bool isAnonymous() const;
00387
00391 void clearOwnIndex();
00392
00396 void allocateOwnIndex();
00397
00407 Declaration* clone() const;
00408
00414 virtual void activateSpecialization();
00415
00416 enum {
00417 Identity = 7
00418 };
00419
00420 protected:
00421
00429 Declaration( DeclarationData & dd, const SimpleRange& range );
00430
00431 DUCHAIN_DECLARE_DATA(Declaration)
00432 private:
00439 virtual Declaration* clonePrivate() const;
00440
00441 void updateCodeModel();
00442
00443 void rebuildDynamicData(DUContext* parent, uint ownIndex);
00444
00445 friend class DUContext;
00446 friend class IndexedDeclaration;
00447 friend class LocalIndexedDeclaration;
00448 friend class TopDUContextDynamicData;
00449 DUContext* m_context;
00450 TopDUContext* m_topContext;
00451 int m_indexInTopContext;
00452 };
00453
00454 inline uint qHash(const IndexedDeclaration& decl) {
00455 return decl.hash();
00456 }
00457 }
00458
00459 Q_DECLARE_METATYPE(KDevelop::IndexedDeclaration)
00460
00461 #endif // DECLARATION_H
00462
00463