Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/duchain/topducontextdynamicdata.h
1 | /* This is part of KDevelop | 1 | /* This is part of KDevelop | ||
---|---|---|---|---|---|
2 | Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de> | 2 | Copyright 2018 R.J.V. Bertin <rjvbertin@gmail.com> | ||
3 | 3 | | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License version 2 as published by the Free Software Foundation. | 6 | License version 2 as published by the Free Software Foundation. | ||
7 | 7 | | |||
8 | This library is distributed in the hope that it will be useful, | 8 | This library is distributed in the hope that it will be useful, | ||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | Library General Public License for more details. | 11 | Library General Public License for more details. | ||
12 | 12 | | |||
13 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
16 | Boston, MA 02110-1301, USA. | 16 | Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #ifndef KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_H | 19 | #ifndef KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_H | ||
20 | #define KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_H | 20 | #define KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_H | ||
21 | 21 | | |||
22 | #include <QVector> | 22 | #include <QVector> | ||
23 | #include <QByteArray> | 23 | #include <QByteArray> | ||
24 | #include <QFile> | ||||
24 | #include "problem.h" | 25 | #include "problem.h" | ||
25 | 26 | | |||
26 | class QFile; | | |||
27 | | ||||
28 | namespace KDevelop { | 27 | namespace KDevelop { | ||
29 | 28 | | |||
30 | class TopDUContext; | 29 | class TopDUContext; | ||
31 | class DUContext; | 30 | class DUContext; | ||
32 | class Declaration; | 31 | class Declaration; | ||
33 | class IndexedString; | 32 | class IndexedString; | ||
34 | class IndexedDUContext; | 33 | class IndexedDUContext; | ||
35 | class DUChainBaseData; | 34 | class DUChainBaseData; | ||
36 | 35 | | |||
36 | #ifdef KDEV_TOPCONTEXTS_USE_FILES | ||||
37 | using TopDUContextStore = TopDUContextFile; | ||||
38 | #elif defined(KDEV_TOPCONTEXTS_USE_LMDB) | ||||
39 | using TopDUContextStore = TopDUContextLMDB; | ||||
40 | #elif defined(KDEV_TOPCONTEXTS_USE_LEVELDB) | ||||
41 | using TopDUContextStore = TopDUContextLevelDB; | ||||
42 | #elif defined(KDEV_TOPCONTEXTS_USE_KYOTO) | ||||
43 | using TopDUContextStore = TopDUContextKyotoCabinet; | ||||
44 | #else | ||||
45 | class TopDUContextStore; | ||||
46 | #endif | ||||
47 | | ||||
37 | ///This class contains dynamic data of a top-context, and also the repository that contains all the data within this top-context. | 48 | ///This class contains dynamic data of a top-context, and also the repository that contains all the data within this top-context. | ||
38 | class TopDUContextDynamicData { | 49 | class TopDUContextDynamicData { | ||
39 | public: | 50 | public: | ||
40 | explicit TopDUContextDynamicData(TopDUContext* topContext); | 51 | explicit TopDUContextDynamicData(TopDUContext* topContext); | ||
41 | ~TopDUContextDynamicData(); | 52 | ~TopDUContextDynamicData(); | ||
42 | 53 | | |||
43 | void clear(); | 54 | void clear(); | ||
44 | 55 | | |||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
113 | }; | 124 | }; | ||
114 | 125 | | |||
115 | struct ArrayWithPosition | 126 | struct ArrayWithPosition | ||
116 | { | 127 | { | ||
117 | QByteArray array; | 128 | QByteArray array; | ||
118 | uint position; | 129 | uint position; | ||
119 | }; | 130 | }; | ||
120 | 131 | | |||
132 | static QString basePath(); | ||||
133 | static QString pathForTopContext(const uint topContextIndex); | ||||
134 | | ||||
121 | private: | 135 | private: | ||
122 | bool hasChanged() const; | 136 | bool hasChanged() const; | ||
123 | 137 | | |||
124 | void unmap(); | 138 | void unmap(); | ||
125 | //Converts away from an mmap opened file to a data array | 139 | //Converts away from an mmap opened file to a data array | ||
126 | 140 | | |||
127 | QString filePath() const; | 141 | QString filePath() const; | ||
128 | 142 | | |||
Show All 19 Lines | 153 | { | |||
148 | 162 | | |||
149 | void clearItemIndex(const Item& item, const uint index); | 163 | void clearItemIndex(const Item& item, const uint index); | ||
150 | 164 | | |||
151 | uint allocateItemIndex(const Item& item, const bool temporary); | 165 | uint allocateItemIndex(const Item& item, const bool temporary); | ||
152 | 166 | | |||
153 | void deleteOnDisk(); | 167 | void deleteOnDisk(); | ||
154 | bool isItemForIndexLoaded(uint index) const; | 168 | bool isItemForIndexLoaded(uint index) const; | ||
155 | 169 | | |||
156 | void loadData(QFile* file) const; | 170 | void loadData(TopDUContextStore* file) const; | ||
157 | void writeData(QFile* file); | 171 | void writeData(TopDUContextStore* file); | ||
158 | 172 | | |||
159 | //May contain zero items if they were deleted | 173 | //May contain zero items if they were deleted | ||
160 | mutable QVector<Item> items; | 174 | mutable QVector<Item> items; | ||
161 | mutable QVector<ItemDataInfo> offsets; | 175 | mutable QVector<ItemDataInfo> offsets; | ||
162 | QVector<Item> temporaryItems; | 176 | QVector<Item> temporaryItems; | ||
163 | TopDUContextDynamicData* const data; | 177 | TopDUContextDynamicData* const data; | ||
164 | }; | 178 | }; | ||
165 | 179 | | |||
166 | DUChainItemStorage<DUContext*> m_contexts; | 180 | DUChainItemStorage<DUContext*> m_contexts; | ||
167 | DUChainItemStorage<Declaration*> m_declarations; | 181 | DUChainItemStorage<Declaration*> m_declarations; | ||
168 | DUChainItemStorage<ProblemPointer> m_problems; | 182 | DUChainItemStorage<ProblemPointer> m_problems; | ||
169 | 183 | | |||
170 | //For temporary declarations that will not be stored to disk, like template instantiations | 184 | //For temporary declarations that will not be stored to disk, like template instantiations | ||
171 | 185 | | |||
172 | mutable QVector<ArrayWithPosition> m_data; | 186 | mutable QVector<ArrayWithPosition> m_data; | ||
173 | mutable QVector<ArrayWithPosition> m_topContextData; | 187 | mutable QVector<ArrayWithPosition> m_topContextData; | ||
174 | bool m_onDisk; | 188 | bool m_onDisk; | ||
175 | mutable bool m_dataLoaded; | 189 | mutable bool m_dataLoaded; | ||
176 | 190 | | |||
177 | mutable QFile* m_mappedFile; | 191 | mutable TopDUContextStore* m_mappedFile; | ||
178 | mutable uchar* m_mappedData; | 192 | mutable uchar* m_mappedData; | ||
179 | mutable size_t m_mappedDataSize; | 193 | mutable size_t m_mappedDataSize; | ||
180 | mutable bool m_itemRetrievalForbidden; | 194 | mutable bool m_itemRetrievalForbidden; | ||
181 | }; | 195 | }; | ||
182 | } | 196 | } | ||
183 | 197 | | |||
184 | Q_DECLARE_TYPEINFO(KDevelop::TopDUContextDynamicData::ItemDataInfo, Q_PRIMITIVE_TYPE); | 198 | Q_DECLARE_TYPEINFO(KDevelop::TopDUContextDynamicData::ItemDataInfo, Q_PRIMITIVE_TYPE); | ||
185 | Q_DECLARE_TYPEINFO(KDevelop::TopDUContextDynamicData::ArrayWithPosition, Q_MOVABLE_TYPE); | 199 | Q_DECLARE_TYPEINFO(KDevelop::TopDUContextDynamicData::ArrayWithPosition, Q_MOVABLE_TYPE); | ||
186 | 200 | | |||
187 | #endif | 201 | #endif |