|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef CPPMODELMANAGER_H |
|
43 #define CPPMODELMANAGER_H |
|
44 |
|
45 #include <cpptools/cppmodelmanagerinterface.h> |
|
46 #ifndef ICHECK_BUILD |
|
47 # include <projectexplorer/project.h> |
|
48 #endif |
|
49 #include <cplusplus/CppDocument.h> |
|
50 #include <cplusplus/PreprocessorClient.h> |
|
51 #ifndef ICHECK_BUILD |
|
52 # include <texteditor/basetexteditor.h> |
|
53 #endif |
|
54 #include <cplusplus/PreprocessorEnvironment.h> |
|
55 #include <cplusplus/pp-engine.h> |
|
56 #ifdef ICHECK_BUILD |
|
57 # include "parsemanager.h" |
|
58 #else |
|
59 # include <QtCore/QHash> |
|
60 # include <QtCore/QFutureInterface> |
|
61 # include <QtCore/QFutureSynchronizer> |
|
62 # include <QtCore/QMutex> |
|
63 # include <QtCore/QTimer> |
|
64 # include <QtGui/QTextEdit> // for QTextEdit::ExtraSelection |
|
65 #endif |
|
66 |
|
67 namespace Core { |
|
68 class ICore; |
|
69 class IEditor; |
|
70 } |
|
71 |
|
72 namespace TextEditor { |
|
73 class ITextEditor; |
|
74 class BaseTextEditor; |
|
75 } |
|
76 |
|
77 namespace ProjectExplorer { |
|
78 class ProjectExplorerPlugin; |
|
79 } |
|
80 |
|
81 namespace CPlusPlus { |
|
82 class ParseManager; |
|
83 } |
|
84 |
|
85 namespace CppTools { |
|
86 |
|
87 namespace Internal { |
|
88 |
|
89 class CppEditorSupport; |
|
90 class CppPreprocessor; |
|
91 class CppFindReferences; |
|
92 |
|
93 #ifndef ICHECK_BUILD |
|
94 class CppModelManager : public CppModelManagerInterface |
|
95 { |
|
96 Q_OBJECT |
|
97 |
|
98 public: |
|
99 CppModelManager(QObject *parent); |
|
100 virtual ~CppModelManager(); |
|
101 |
|
102 virtual void updateSourceFiles(const QStringList &sourceFiles); |
|
103 virtual WorkingCopy workingCopy() const; |
|
104 |
|
105 virtual QList<ProjectInfo> projectInfos() const; |
|
106 virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const; |
|
107 virtual void updateProjectInfo(const ProjectInfo &pinfo); |
|
108 |
|
109 virtual QStringList includesInPath(const QString &path) const; |
|
110 |
|
111 virtual CPlusPlus::Snapshot snapshot() const; |
|
112 virtual void GC(); |
|
113 |
|
114 QFuture<void> refreshSourceFiles(const QStringList &sourceFiles); |
|
115 |
|
116 inline Core::ICore *core() const { return m_core; } |
|
117 |
|
118 bool isCppEditor(Core::IEditor *editor) const; // ### private |
|
119 |
|
120 CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const |
|
121 { return m_editorSupport.value(editor); } |
|
122 |
|
123 void emitDocumentUpdated(CPlusPlus::Document::Ptr doc); |
|
124 |
|
125 void stopEditorSelectionsUpdate() |
|
126 { m_updateEditorSelectionsTimer->stop(); } |
|
127 |
|
128 virtual void addEditorSupport(AbstractEditorSupport *editorSupport); |
|
129 virtual void removeEditorSupport(AbstractEditorSupport *editorSupport); |
|
130 |
|
131 virtual QList<int> references(CPlusPlus::Symbol *symbol, |
|
132 CPlusPlus::Document::Ptr doc, |
|
133 const CPlusPlus::Snapshot &snapshot); |
|
134 |
|
135 virtual void findUsages(CPlusPlus::Symbol *symbol); |
|
136 virtual void renameUsages(CPlusPlus::Symbol *symbol); |
|
137 |
|
138 virtual void findMacroUsages(const CPlusPlus::Macro ¯o); |
|
139 |
|
140 void setHeaderSuffixes(const QStringList &suffixes) |
|
141 { m_headerSuffixes = suffixes; } |
|
142 |
|
143 Q_SIGNALS: |
|
144 void projectPathChanged(const QString &projectPath); |
|
145 |
|
146 void documentUpdated(CPlusPlus::Document::Ptr doc); |
|
147 void aboutToRemoveFiles(const QStringList &files); |
|
148 |
|
149 public Q_SLOTS: |
|
150 void editorOpened(Core::IEditor *editor); |
|
151 void editorAboutToClose(Core::IEditor *editor); |
|
152 |
|
153 private Q_SLOTS: |
|
154 // this should be executed in the GUI thread. |
|
155 void onDocumentUpdated(CPlusPlus::Document::Ptr doc); |
|
156 void onAboutToRemoveProject(ProjectExplorer::Project *project); |
|
157 void onAboutToUnloadSession(); |
|
158 void onProjectAdded(ProjectExplorer::Project *project); |
|
159 void postEditorUpdate(); |
|
160 void updateEditorSelections(); |
|
161 |
|
162 private: |
|
163 WorkingCopy buildWorkingCopyList(); |
|
164 |
|
165 QStringList projectFiles() |
|
166 { |
|
167 ensureUpdated(); |
|
168 return m_projectFiles; |
|
169 } |
|
170 |
|
171 QStringList includePaths() |
|
172 { |
|
173 ensureUpdated(); |
|
174 return m_includePaths; |
|
175 } |
|
176 |
|
177 QStringList frameworkPaths() |
|
178 { |
|
179 ensureUpdated(); |
|
180 return m_frameworkPaths; |
|
181 } |
|
182 |
|
183 QByteArray definedMacros() |
|
184 { |
|
185 ensureUpdated(); |
|
186 return m_definedMacros; |
|
187 } |
|
188 |
|
189 void ensureUpdated(); |
|
190 QStringList internalProjectFiles() const; |
|
191 QStringList internalIncludePaths() const; |
|
192 QStringList internalFrameworkPaths() const; |
|
193 QByteArray internalDefinedMacros() const; |
|
194 |
|
195 void setIncludesInPaths(const QMap<QString, QStringList> &includesInPaths); |
|
196 |
|
197 static void updateIncludesInPaths(QFutureInterface<void> &future, |
|
198 CppModelManager *manager, |
|
199 QStringList paths, |
|
200 QStringList frameworkPaths, |
|
201 QStringList suffixes); |
|
202 |
|
203 static void parse(QFutureInterface<void> &future, |
|
204 CppPreprocessor *preproc, |
|
205 QStringList files); |
|
206 |
|
207 private: |
|
208 Core::ICore *m_core; |
|
209 CPlusPlus::Snapshot m_snapshot; |
|
210 |
|
211 // cache |
|
212 bool m_dirty; |
|
213 QStringList m_projectFiles; |
|
214 QStringList m_includePaths; |
|
215 QStringList m_frameworkPaths; |
|
216 QByteArray m_definedMacros; |
|
217 |
|
218 QMap<QString, QStringList> m_includesInPaths; |
|
219 QStringList m_headerSuffixes; |
|
220 |
|
221 // editor integration |
|
222 QMap<TextEditor::ITextEditor *, CppEditorSupport *> m_editorSupport; |
|
223 |
|
224 QSet<AbstractEditorSupport *> m_addtionalEditorSupport; |
|
225 |
|
226 // project integration |
|
227 QMap<ProjectExplorer::Project *, ProjectInfo> m_projects; |
|
228 |
|
229 mutable QMutex mutex; |
|
230 mutable QMutex protectSnapshot; |
|
231 |
|
232 struct Editor { |
|
233 Editor() |
|
234 : revision(-1) {} |
|
235 int revision; |
|
236 QPointer<TextEditor::ITextEditor> textEditor; |
|
237 QList<QTextEdit::ExtraSelection> selections; |
|
238 QList<TextEditor::BaseTextEditor::BlockRange> ifdefedOutBlocks; |
|
239 }; |
|
240 |
|
241 QList<Editor> m_todo; |
|
242 |
|
243 QTimer *m_updateEditorSelectionsTimer; |
|
244 |
|
245 QFutureSynchronizer<void> m_synchronizer; |
|
246 unsigned m_revision; |
|
247 |
|
248 CppFindReferences *m_findReferences; |
|
249 bool m_indexerEnabled; |
|
250 }; |
|
251 #endif |
|
252 |
|
253 using namespace CPlusPlus; |
|
254 class CppPreprocessor: public CPlusPlus::Client |
|
255 { |
|
256 public: |
|
257 #ifndef ICHECK_BUILD |
|
258 CppPreprocessor(QPointer<CppModelManager> modelManager); |
|
259 #else |
|
260 CppPreprocessor(QPointer<CPlusPlus::ParseManager> modelManager); |
|
261 #endif |
|
262 virtual ~CppPreprocessor(); |
|
263 |
|
264 void setRevision(unsigned revision); |
|
265 void setWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy); |
|
266 void setIncludePaths(const QStringList &includePaths); |
|
267 void setFrameworkPaths(const QStringList &frameworkPaths); |
|
268 void setProjectFiles(const QStringList &files); |
|
269 void setTodo(const QStringList &files); |
|
270 |
|
271 void run(const QString &fileName); |
|
272 |
|
273 void resetEnvironment(); |
|
274 |
|
275 const QSet<QString> &todo() const |
|
276 { return m_todo; } |
|
277 |
|
278 public: // attributes |
|
279 Snapshot snapshot; |
|
280 |
|
281 protected: |
|
282 CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc); |
|
283 |
|
284 bool includeFile(const QString &absoluteFilePath, QString *result, unsigned *revision); |
|
285 QString tryIncludeFile(QString &fileName, IncludeType type, unsigned *revision); |
|
286 |
|
287 void mergeEnvironment(CPlusPlus::Document::Ptr doc); |
|
288 |
|
289 virtual void macroAdded(const Macro ¯o); |
|
290 virtual void passedMacroDefinitionCheck(unsigned offset, const Macro ¯o); |
|
291 virtual void failedMacroDefinitionCheck(unsigned offset, const QByteArray &name); |
|
292 virtual void startExpandingMacro(unsigned offset, |
|
293 const Macro ¯o, |
|
294 const QByteArray &originalText, |
|
295 bool inCondition, |
|
296 const QVector<MacroArgumentReference> &actuals); |
|
297 virtual void stopExpandingMacro(unsigned offset, const Macro ¯o); |
|
298 virtual void startSkippingBlocks(unsigned offset); |
|
299 virtual void stopSkippingBlocks(unsigned offset); |
|
300 virtual void sourceNeeded(QString &fileName, IncludeType type, |
|
301 unsigned line); |
|
302 |
|
303 private: |
|
304 #ifndef ICHECK_BUILD |
|
305 QPointer<CppModelManager> m_modelManager; |
|
306 #endif |
|
307 Environment env; |
|
308 Preprocessor preprocess; |
|
309 QStringList m_includePaths; |
|
310 QStringList m_systemIncludePaths; |
|
311 CppModelManagerInterface::WorkingCopy m_workingCopy; |
|
312 QStringList m_projectFiles; |
|
313 QStringList m_frameworkPaths; |
|
314 QSet<QString> m_included; |
|
315 Document::Ptr m_currentDoc; |
|
316 QSet<QString> m_todo; |
|
317 QSet<QString> m_processed; |
|
318 unsigned m_revision; |
|
319 }; |
|
320 |
|
321 } // namespace Internal |
|
322 } // namespace CppTools |
|
323 |
|
324 #endif // CPPMODELMANAGER_H |