Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
3141edd2
Commit
3141edd2
authored
May 21, 2010
by
Roberto Raggi
Browse files
Check for undefined symbols.
parent
e6c377c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppeditor.cpp
View file @
3141edd2
...
...
@@ -57,6 +57,7 @@
#include
<cplusplus/BackwardsScanner.h>
#include
<cplusplus/FastPreprocessor.h>
#include
<cplusplus/CppBindings.h>
#include
<cplusplus/CheckUndefinedSymbols.h>
#include
<cpptools/cppmodelmanagerinterface.h>
...
...
@@ -1839,7 +1840,8 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
return
;
}
m_lastSemanticInfo
=
semanticInfo
;
const
SemanticInfo
previousSemanticInfo
=
m_lastSemanticInfo
;
m_lastSemanticInfo
=
semanticInfo
;
// update the semantic info
int
line
=
0
,
column
=
0
;
convertPosition
(
position
(),
&
line
,
&
column
);
...
...
@@ -1871,8 +1873,28 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
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
(
CodeSemanticsSelection
,
m_renameSelections
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
// ###
m_lastSemanticInfo
.
forced
=
false
;
// clear the forced flag
}
SemanticHighlighter
::
Source
CPPEditor
::
currentSource
(
bool
force
)
...
...
@@ -1964,11 +1986,13 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
Snapshot
snapshot
;
Document
::
Ptr
doc
;
QList
<
Document
::
DiagnosticMessage
>
diagnosticMessages
;
if
(
!
source
.
force
&&
revision
==
source
.
revision
)
{
m_mutex
.
lock
();
snapshot
=
m_lastSemanticInfo
.
snapshot
;
snapshot
=
m_lastSemanticInfo
.
snapshot
;
// ### TODO: use the new snapshot.
doc
=
m_lastSemanticInfo
.
doc
;
diagnosticMessages
=
m_lastSemanticInfo
.
diagnosticMessages
;
m_mutex
.
unlock
();
}
...
...
@@ -1978,6 +2002,10 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
snapshot
=
source
.
snapshot
;
doc
=
source
.
snapshot
.
documentFromSource
(
preprocessedCode
,
source
.
fileName
);
doc
->
check
();
// ### check undefined symbols.
CheckUndefinedSymbols
checkUndefinedSymbols
(
doc
,
snapshot
);
diagnosticMessages
=
checkUndefinedSymbols
(
doc
->
translationUnit
()
->
ast
());
}
TranslationUnit
*
translationUnit
=
doc
->
translationUnit
();
...
...
@@ -1996,6 +2024,8 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
semanticInfo
.
localUses
=
useTable
.
localUses
;
semanticInfo
.
hasQ
=
useTable
.
hasQ
;
semanticInfo
.
hasD
=
useTable
.
hasD
;
semanticInfo
.
forced
=
source
.
force
;
semanticInfo
.
diagnosticMessages
=
diagnosticMessages
;
return
semanticInfo
;
}
src/plugins/cppeditor/cppeditor.h
View file @
3141edd2
...
...
@@ -79,15 +79,17 @@ public:
typedef
QHashIterator
<
CPlusPlus
::
Symbol
*
,
QList
<
Use
>
>
LocalUseIterator
;
SemanticInfo
()
:
revision
(
0
),
hasQ
(
false
),
hasD
(
false
)
:
revision
(
0
),
hasQ
(
false
),
hasD
(
false
)
,
forced
(
false
)
{
}
unsigned
revision
;
bool
hasQ
:
1
;
bool
hasD
:
1
;
bool
forced
:
1
;
CPlusPlus
::
Snapshot
snapshot
;
CPlusPlus
::
Document
::
Ptr
doc
;
LocalUseMap
localUses
;
QList
<
CPlusPlus
::
Document
::
DiagnosticMessage
>
diagnosticMessages
;
};
class
SemanticHighlighter
:
public
QThread
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment