summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-08-31 09:58:40 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-08-31 10:53:21 +0200
commit9f7a2194f7fd7a453acaa1d96b3c7a3ba571f044 (patch)
tree6a2d7123828bbbda2a0ddf52066eb2cb29bbbd47
parent7bc8dd18a3f9a81f11ad993bb6b3219ddb6af56f (diff)
downloadqt-creator-9f7a2194f7fd7a453acaa1d96b3c7a3ba571f044.tar.gz
QmlJS: Fix infinite loop when scanning for exported C++ types.
Setting extra diagnostics would call updateDocument which would in turn trigger another scan. Change-Id: I3810a380cdf716a12767d94ff82dc30f8ae3954d Reviewed-on: http://codereview.qt.nokia.com/3917 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
-rw-r--r--src/libs/cplusplus/CppDocument.cpp16
-rw-r--r--src/libs/cplusplus/CppDocument.h3
-rw-r--r--src/libs/cplusplus/ModelManagerInterface.h1
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp28
-rw-r--r--src/plugins/cpptools/cppmodelmanager.h3
5 files changed, 44 insertions, 7 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index e337d7624e..9714bbf11a 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -603,6 +603,22 @@ void Document::releaseSourceAndAST()
}
}
+bool Document::DiagnosticMessage::operator==(const Document::DiagnosticMessage &other) const
+{
+ return
+ _line == other._line &&
+ _column == other._column &&
+ _length == other._length &&
+ _level == other._level &&
+ _fileName == other._fileName &&
+ _text == other._text;
+}
+
+bool Document::DiagnosticMessage::operator!=(const Document::DiagnosticMessage &other) const
+{
+ return !operator==(other);
+}
+
Snapshot::Snapshot()
{
}
diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h
index 930eb15efa..20284810f9 100644
--- a/src/libs/cplusplus/CppDocument.h
+++ b/src/libs/cplusplus/CppDocument.h
@@ -177,6 +177,9 @@ public:
QString text() const
{ return _text; }
+ bool operator==(const DiagnosticMessage &other) const;
+ bool operator!=(const DiagnosticMessage &other) const;
+
private:
int _level;
QString _fileName;
diff --git a/src/libs/cplusplus/ModelManagerInterface.h b/src/libs/cplusplus/ModelManagerInterface.h
index cf5f719e0e..0c2f976de2 100644
--- a/src/libs/cplusplus/ModelManagerInterface.h
+++ b/src/libs/cplusplus/ModelManagerInterface.h
@@ -154,6 +154,7 @@ public:
Q_SIGNALS:
void documentUpdated(CPlusPlus::Document::Ptr doc);
void sourceFilesRefreshed(const QStringList &files);
+ void extraDiagnosticsUpdated(QString fileName);
public Q_SLOTS:
virtual void updateModifiedSourceFiles() = 0;
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 9a3fca3935..6856bc1f97 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -694,6 +694,8 @@ CppModelManager::CppModelManager(QObject *parent)
// thread connections
connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)));
+ connect(this, SIGNAL(extraDiagnosticsUpdated(QString)),
+ this, SLOT(onExtraDiagnosticsUpdated(QString)));
// Listen for editor closed and opened events so that we can keep track of changing files
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
@@ -968,6 +970,22 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
if (outdated)
return;
+ updateEditor(doc);
+}
+
+void CppModelManager::onExtraDiagnosticsUpdated(const QString &fileName)
+{
+ protectSnapshot.lock();
+ Document::Ptr doc = m_snapshot.document(fileName);
+ protectSnapshot.unlock();
+ if (doc)
+ updateEditor(doc);
+}
+
+void CppModelManager::updateEditor(Document::Ptr doc)
+{
+ const QString fileName = doc->fileName();
+
QList<Core::IEditor *> openedEditors = m_core->editorManager()->openedEditors();
foreach (Core::IEditor *editor, openedEditors) {
if (editor->file()->fileName() == fileName) {
@@ -1297,15 +1315,11 @@ void CppModelManager::setExtraDiagnostics(const QString &fileName, int kind,
{
{
QMutexLocker locker(&protectExtraDiagnostics);
+ if (m_extraDiagnostics[fileName][kind] == diagnostics)
+ return;
m_extraDiagnostics[fileName].insert(kind, diagnostics);
}
- Document::Ptr doc;
- {
- QMutexLocker locker(&protectSnapshot);
- doc = m_snapshot.document(fileName);
- }
- if (doc)
- emit documentUpdated(doc);
+ emit extraDiagnosticsUpdated(fileName);
}
QList<Document::DiagnosticMessage> CppModelManager::extraDiagnostics(const QString &fileName, int kind) const
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index 4bc06f60f0..5909fffe3c 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -150,6 +150,7 @@ public Q_SLOTS:
private Q_SLOTS:
// this should be executed in the GUI thread.
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
+ void onExtraDiagnosticsUpdated(const QString &fileName);
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onAboutToUnloadSession();
void onProjectAdded(ProjectExplorer::Project *project);
@@ -157,6 +158,8 @@ private Q_SLOTS:
void updateEditorSelections();
private:
+ void updateEditor(CPlusPlus::Document::Ptr doc);
+
WorkingCopy buildWorkingCopyList();
QStringList projectFiles()