Add AbstractDeclarationNavigationContext, and move the html-method from
[kdevelopdvcssupport.git] / language / duchain / topducontextdynamicdata.h
blobf193b0899c51ae149c341532dd52551799d34011
1 /* This is part of KDevelop
2 Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef TOPDUCONTEXTDYNAMICDATA_H
20 #define TOPDUCONTEXTDYNAMICDATA_H
22 #include <QtCore/QVector>
23 #include <QtCore/QMutex>
24 #include <QtCore/QByteArray>
25 #include <QtCore/QPair>
27 namespace KDevelop {
29 class TopDUContext;
30 class DUContext;
31 class Declaration;
32 class IndexedString;
34 typedef QPair<QByteArray, uint> ArrayWithPosition;
36 ///This class contains dynamic data of a top-context, and also the repository that contains all the data within this top-context.
37 class TopDUContextDynamicData {
38 public:
39 TopDUContextDynamicData(TopDUContext* topContext);
40 ~TopDUContextDynamicData();
42 /**
43 * Allocates an index for the given declaration in this top-context.
44 * The returned index is never zero.
45 * @param anonymous whether the declaration is temporary. If it is, it will be stored separately, not stored to disk,
46 * and a duchain write-lock is not needed. Else, you need a write-lock when calling this.
48 uint allocateDeclarationIndex(Declaration* decl, bool temporary);
50 Declaration* getDeclarationForIndex(uint index) const;
52 bool isDeclarationForIndexLoaded(uint index) const;
54 void clearDeclarationIndex(Declaration* decl);
56 /**
57 * Allocates an index for the given context in this top-context.
58 * The returned index is never zero.
59 * @param anonymous whether the context is temporary. If it is, it will be stored separately, not stored to disk,
60 * and a duchain write-lock is not needed. Else, you need a write-lock when calling this.
62 uint allocateContextIndex(DUContext* ctx, bool temporary);
64 DUContext* getContextForIndex(uint index) const;
66 bool isContextForIndexLoaded(uint index) const;
68 void clearContextIndex(DUContext* ctx);
70 ///Stores this top-context to disk
71 void store();
73 ///Whether this top-context is on disk(Either has been loaded, or has been stored)
74 bool isOnDisk() const;
76 ///Loads the top-context from disk, or returns zero on failure. The top-context will not be registered anywhere, and will have no ParsingEnvironmentFile assigned.
77 ///Also loads all imported contexts. The Declarations/Contexts will be correctly initialized, and put into the symbol tables if needed.
78 static TopDUContext* load(uint topContextIndex);
80 ///Loads only the url out of the data stored on disk for the top-context.
81 static IndexedString loadUrl(uint topContextIndex);
83 private:
84 struct ItemDataInfo {
85 //parentContext 0 means the global context
86 ItemDataInfo(uint _dataOffset = 0, uint _parentContext = 0) : dataOffset(_dataOffset), parentContext(_parentContext) {
88 uint dataOffset; //Offset of the data
89 uint parentContext; //Parent context of the data
92 TopDUContext* m_topContext;
93 //May contain zero contexts if they were deleted
94 mutable QVector<DUContext*> m_contexts;
95 mutable DUContext** m_fastContexts;
96 mutable int m_fastContextsSize;
97 //May contain zero declarations if they were deleted
98 mutable QVector<Declaration*> m_declarations;
99 mutable Declaration** m_fastDeclarations;
100 mutable int m_fastDeclarationsSize;
102 QVector<ItemDataInfo> m_contextDataOffsets;
104 QVector<ItemDataInfo> m_declarationDataOffsets;
106 //Protects m_temporaryDeclarations, must be locked before accessing that vector
107 static QMutex m_temporaryDataMutex;
108 //For temporary declarations that will not be stored to disk, like template instantiations
109 QVector<Declaration*> m_temporaryDeclarations;
110 QVector<DUContext*> m_temporaryContexts;
112 QList<ArrayWithPosition> m_data;
113 bool m_onDisk;
117 #endif