forked from qt-creator/qt-creator
Check for undefined symbols.
This commit is contained in:
@@ -57,6 +57,7 @@
|
|||||||
#include <cplusplus/BackwardsScanner.h>
|
#include <cplusplus/BackwardsScanner.h>
|
||||||
#include <cplusplus/FastPreprocessor.h>
|
#include <cplusplus/FastPreprocessor.h>
|
||||||
#include <cplusplus/CppBindings.h>
|
#include <cplusplus/CppBindings.h>
|
||||||
|
#include <cplusplus/CheckUndefinedSymbols.h>
|
||||||
|
|
||||||
#include <cpptools/cppmodelmanagerinterface.h>
|
#include <cpptools/cppmodelmanagerinterface.h>
|
||||||
|
|
||||||
@@ -1839,7 +1840,8 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lastSemanticInfo = semanticInfo;
|
const SemanticInfo previousSemanticInfo = m_lastSemanticInfo;
|
||||||
|
m_lastSemanticInfo = semanticInfo; // update the semantic info
|
||||||
|
|
||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
convertPosition(position(), &line, &column);
|
convertPosition(position(), &line, &column);
|
||||||
@@ -1871,8 +1873,28 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
highlightUses(uses, semanticInfo, &m_renameSelections);
|
highlightUses(uses, semanticInfo, &m_renameSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_lastSemanticInfo.forced || previousSemanticInfo.revision != semanticInfo.revision) {
|
||||||
|
QList<QTextEdit::ExtraSelection> undefinedSymbolSelections;
|
||||||
|
foreach (const Document::DiagnosticMessage &m, semanticInfo.diagnosticMessages) {
|
||||||
|
QTextCursor cursor(document());
|
||||||
|
cursor.setPosition(document()->findBlockByNumber(m.line() - 1).position() + m.column() - 1);
|
||||||
|
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length());
|
||||||
|
|
||||||
|
QTextEdit::ExtraSelection sel;
|
||||||
|
sel.cursor = cursor;
|
||||||
|
sel.format.setUnderlineColor(Qt::darkYellow); // ### hardcoded
|
||||||
|
sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline); // ### hardcoded
|
||||||
|
sel.format.setToolTip(m.text());
|
||||||
|
undefinedSymbolSelections.append(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
setExtraSelections(UndefinedSymbolSelection, undefinedSymbolSelections);
|
||||||
|
}
|
||||||
|
|
||||||
setExtraSelections(UnusedSymbolSelection, unusedSelections);
|
setExtraSelections(UnusedSymbolSelection, unusedSelections);
|
||||||
setExtraSelections(CodeSemanticsSelection, m_renameSelections);
|
setExtraSelections(CodeSemanticsSelection, m_renameSelections); // ###
|
||||||
|
|
||||||
|
m_lastSemanticInfo.forced = false; // clear the forced flag
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticHighlighter::Source CPPEditor::currentSource(bool force)
|
SemanticHighlighter::Source CPPEditor::currentSource(bool force)
|
||||||
@@ -1964,11 +1986,13 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
|||||||
|
|
||||||
Snapshot snapshot;
|
Snapshot snapshot;
|
||||||
Document::Ptr doc;
|
Document::Ptr doc;
|
||||||
|
QList<Document::DiagnosticMessage> diagnosticMessages;
|
||||||
|
|
||||||
if (! source.force && revision == source.revision) {
|
if (! source.force && revision == source.revision) {
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
snapshot = m_lastSemanticInfo.snapshot;
|
snapshot = m_lastSemanticInfo.snapshot; // ### TODO: use the new snapshot.
|
||||||
doc = m_lastSemanticInfo.doc;
|
doc = m_lastSemanticInfo.doc;
|
||||||
|
diagnosticMessages = m_lastSemanticInfo.diagnosticMessages;
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1978,6 +2002,10 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
|||||||
snapshot = source.snapshot;
|
snapshot = source.snapshot;
|
||||||
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName);
|
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName);
|
||||||
doc->check();
|
doc->check();
|
||||||
|
|
||||||
|
// ### check undefined symbols.
|
||||||
|
CheckUndefinedSymbols checkUndefinedSymbols(doc, snapshot);
|
||||||
|
diagnosticMessages = checkUndefinedSymbols(doc->translationUnit()->ast());
|
||||||
}
|
}
|
||||||
|
|
||||||
TranslationUnit *translationUnit = doc->translationUnit();
|
TranslationUnit *translationUnit = doc->translationUnit();
|
||||||
@@ -1996,6 +2024,8 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
|||||||
semanticInfo.localUses = useTable.localUses;
|
semanticInfo.localUses = useTable.localUses;
|
||||||
semanticInfo.hasQ = useTable.hasQ;
|
semanticInfo.hasQ = useTable.hasQ;
|
||||||
semanticInfo.hasD = useTable.hasD;
|
semanticInfo.hasD = useTable.hasD;
|
||||||
|
semanticInfo.forced = source.force;
|
||||||
|
semanticInfo.diagnosticMessages = diagnosticMessages;
|
||||||
|
|
||||||
return semanticInfo;
|
return semanticInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,15 +79,17 @@ public:
|
|||||||
typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator;
|
typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator;
|
||||||
|
|
||||||
SemanticInfo()
|
SemanticInfo()
|
||||||
: revision(0), hasQ(false), hasD(false)
|
: revision(0), hasQ(false), hasD(false), forced(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
unsigned revision;
|
unsigned revision;
|
||||||
bool hasQ: 1;
|
bool hasQ: 1;
|
||||||
bool hasD: 1;
|
bool hasD: 1;
|
||||||
|
bool forced: 1;
|
||||||
CPlusPlus::Snapshot snapshot;
|
CPlusPlus::Snapshot snapshot;
|
||||||
CPlusPlus::Document::Ptr doc;
|
CPlusPlus::Document::Ptr doc;
|
||||||
LocalUseMap localUses;
|
LocalUseMap localUses;
|
||||||
|
QList<CPlusPlus::Document::DiagnosticMessage> diagnosticMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SemanticHighlighter: public QThread
|
class SemanticHighlighter: public QThread
|
||||||
|
|||||||
Reference in New Issue
Block a user