forked from qt-creator/qt-creator
CppEditor: Change parsing opposite bracket
Fixed behavior: - when comparing sign was determined as angle bracket - when in complex combination brackets, an opposite bracket was detected not correct - not correct mismatch case highlightning Added tests for the cases form bug 26395 Fixes: QTCREATORBUG-26400 Fixes: QTCREATORBUG-26395 Change-Id: Ic45566d2677f80fb9a8e4fe830307254dd1db51d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -225,7 +225,7 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
|
|||||||
} else if (result.kind == DoubleAngleBracketClose) {
|
} else if (result.kind == DoubleAngleBracketClose) {
|
||||||
Parenthesis extraParen = {Parenthesis::Closed, '>', result.column - 1};
|
Parenthesis extraParen = {Parenthesis::Closed, '>', result.column - 1};
|
||||||
extraParen.source = parenSource();
|
extraParen.source = parenSource();
|
||||||
parentheses.second.append(extraParen);
|
insertSorted(parentheses.second, extraParen);
|
||||||
paren = {Parenthesis::Closed, '>', result.column};
|
paren = {Parenthesis::Closed, '>', result.column};
|
||||||
} else if (result.kind == TernaryIf) {
|
} else if (result.kind == TernaryIf) {
|
||||||
paren = {Parenthesis::Opened, '?', result.column - 1};
|
paren = {Parenthesis::Opened, '?', result.column - 1};
|
||||||
|
|||||||
@@ -607,7 +607,11 @@ void TokenInfo::punctuationOrOperatorKind()
|
|||||||
&& m_types.mixinHighlightingTypes.empty()
|
&& m_types.mixinHighlightingTypes.empty()
|
||||||
&& kind != CXCursor_OverloadedDeclRef
|
&& kind != CXCursor_OverloadedDeclRef
|
||||||
&& kind != CXCursor_InclusionDirective
|
&& kind != CXCursor_InclusionDirective
|
||||||
&& kind != CXCursor_PreprocessingDirective) {
|
&& kind != CXCursor_PreprocessingDirective
|
||||||
|
&& kind != CXCursor_MacroDefinition
|
||||||
|
&& kind != CXCursor_DeclStmt
|
||||||
|
&& kind != CXCursor_CompoundStmt
|
||||||
|
&& kind != CXCursor_FirstInvalid) {
|
||||||
const ClangString spelling = m_token->spelling();
|
const ClangString spelling = m_token->spelling();
|
||||||
if (spelling == "<")
|
if (spelling == "<")
|
||||||
m_types.mixinHighlightingTypes.push_back(HighlightingType::AngleBracketOpen);
|
m_types.mixinHighlightingTypes.push_back(HighlightingType::AngleBracketOpen);
|
||||||
|
|||||||
@@ -794,3 +794,18 @@ const char *cyrillic = "б";
|
|||||||
struct foo {
|
struct foo {
|
||||||
#define blubb
|
#define blubb
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define test_micro(A,B) ((A##B>1?A:B))
|
||||||
|
|
||||||
|
int a = (a1 > 0);
|
||||||
|
|
||||||
|
int func() {
|
||||||
|
int a = (a1 > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template<typename T1, typename T2> struct pair;
|
||||||
|
template<typename T> struct vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::pair<int, int>> pvr;
|
||||||
|
|||||||
@@ -1794,11 +1794,10 @@ TEST_F(TokenProcessor, TemplateSeparateDeclDef)
|
|||||||
ASSERT_THAT(infos[37], IsHighlightingMark(764u, 5u, 9u, HighlightingType::GlobalVariable));
|
ASSERT_THAT(infos[37], IsHighlightingMark(764u, 5u, 9u, HighlightingType::GlobalVariable));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TokenProcessor, NestedTemplate)
|
TEST_F(TokenProcessor, NestedTemplateIncorrect)
|
||||||
{
|
{
|
||||||
const auto infos = translationUnit.tokenInfosInRange(sourceRange(773, 44));
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(773, 44));
|
||||||
ASSERT_THAT(infos[12], HasTwoTypes(HighlightingType::Punctuation,
|
ASSERT_THAT(infos[12], HasOnlyType(HighlightingType::Punctuation));
|
||||||
HighlightingType::DoubleAngleBracketClose));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TokenProcessor, OperatorInTemplate)
|
TEST_F(TokenProcessor, OperatorInTemplate)
|
||||||
@@ -1819,6 +1818,32 @@ TEST_F(TokenProcessor, PreProcessorInStruct)
|
|||||||
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor));
|
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TokenProcessor, DefinitionWithComparison)
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(798, 39));
|
||||||
|
ASSERT_THAT(infos[13], HasOnlyType(HighlightingType::Punctuation));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TokenProcessor, GlobalVariableWithComparison)
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(800, 18));
|
||||||
|
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TokenProcessor, VariableWithComparison)
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(803, 22));
|
||||||
|
ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_F(TokenProcessor, NestedTemplate)
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(811, 44));
|
||||||
|
ASSERT_THAT(infos[12], HasTwoTypes(HighlightingType::Punctuation,
|
||||||
|
HighlightingType::DoubleAngleBracketClose));
|
||||||
|
}
|
||||||
|
|
||||||
Data *TokenProcessor::d;
|
Data *TokenProcessor::d;
|
||||||
|
|
||||||
void TokenProcessor::SetUpTestCase()
|
void TokenProcessor::SetUpTestCase()
|
||||||
|
|||||||
Reference in New Issue
Block a user