diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index d99e49934de..fbf27666060 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -285,7 +285,10 @@ protected: static bool sortByLinePredicate(const CheckSymbols::Use &lhs, const CheckSymbols::Use &rhs) { - return lhs.line < rhs.line; + if (lhs.line == rhs.line) + return lhs.column < rhs.column; + else + return lhs.line < rhs.line; } @@ -325,7 +328,7 @@ CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, cons unsigned line = 0; getTokenEndPosition(translationUnit()->ast()->lastToken(), &line, 0); - _chunkSize = qMin(50U, line / 200); + _chunkSize = qMax(50U, line / 200); _usages.reserve(_chunkSize); _astStack.reserve(200); diff --git a/src/plugins/texteditor/semantichighlighter.h b/src/plugins/texteditor/semantichighlighter.h index 9def1c0db65..e068d3b351e 100644 --- a/src/plugins/texteditor/semantichighlighter.h +++ b/src/plugins/texteditor/semantichighlighter.h @@ -65,6 +65,15 @@ public: : line(0), column(0), length(0), kind(-1) {} Result(unsigned line, unsigned column, unsigned length, int kind) : line(line), column(column), length(length), kind(kind) {} + + bool operator==(const Result& other) const + { + return + line == other.line && + column == other.column && + length == other.length && + kind == other.kind; + } }; // Applies the future results [from, to) and applies the extra formats diff --git a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp index ff43c68e3bd..168772f17d3 100644 --- a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp +++ b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp @@ -81,15 +81,6 @@ static QString useKindToString(UseKind useKind) // The following two functions are "enhancements" for QCOMPARE(). namespace QTest { -bool operator==(const Use& lhs, const Use& rhs) -{ - return - lhs.line == rhs.line && - lhs.column == rhs.column && - lhs.length == rhs.length && - lhs.kind == rhs.kind; -} - template<> char *toString(const Use &use) { @@ -216,11 +207,11 @@ void tst_CheckSymbols::test_checksymbols_LocalUse() void tst_CheckSymbols::test_checksymbols_FieldUse() { const QByteArray source = - "struct F {\n" + "struct F {\n" // 1 " int i;\n" " F() { i = 0; }\n" "};\n" - "int f()\n" + "int f()\n" // 5 "{\n" " F s;\n" " s.i = 2;\n" @@ -233,8 +224,9 @@ void tst_CheckSymbols::test_checksymbols_FieldUse() << Use(5, 5, 1, SemanticInfo::FunctionUse) << Use(7, 5, 1, SemanticInfo::TypeUse) << Use(7, 7, 1, SemanticInfo::LocalUse) + << Use(8, 5, 1, SemanticInfo::LocalUse) << Use(8, 7, 1, SemanticInfo::FieldUse) - << Use(8, 5, 1, SemanticInfo::LocalUse); + ; TestData::check(source, expectedUses); } @@ -245,10 +237,11 @@ void tst_CheckSymbols::test_checksymbols_EnumerationUse() "enum E { Red, Green, Blue };\n" "E e = Red\n"; const QList expectedUses = QList() - << Use(1, 22, 4, SemanticInfo::EnumerationUse) - << Use(1, 15, 5, SemanticInfo::EnumerationUse) << Use(1, 6, 1, SemanticInfo::TypeUse) - << Use(1, 10, 3, SemanticInfo::EnumerationUse); + << Use(1, 10, 3, SemanticInfo::EnumerationUse) + << Use(1, 15, 5, SemanticInfo::EnumerationUse) + << Use(1, 22, 4, SemanticInfo::EnumerationUse) + ; TestData::check(source, expectedUses); } @@ -256,18 +249,18 @@ void tst_CheckSymbols::test_checksymbols_EnumerationUse() void tst_CheckSymbols::test_checksymbols_VirtualMethodUse() { const QByteArray source = - "class B {\n" - " virtual isThere();\n" - "};\n" - "class D: public B {\n" - " isThere();\n" + "class B {\n" // 1 + " virtual bool isThere();\n" // 2 + "};\n" // 3 + "class D: public B {\n" // 4 + " bool isThere();\n" // 5 "};\n"; const QList expectedUses = QList() - << Use(1, 7, 1, SemanticInfo::TypeUse) - << Use(2, 13, 7, SemanticInfo::VirtualMethodUse) - << Use(4, 17, 1, SemanticInfo::TypeUse) - << Use(4, 7, 1, SemanticInfo::TypeUse) - << Use(5, 5, 7, SemanticInfo::VirtualMethodUse); + << Use(1, 7, 1, SemanticInfo::TypeUse) // B + << Use(2, 18, 7, SemanticInfo::VirtualMethodUse) // isThere + << Use(4, 7, 1, SemanticInfo::TypeUse) // D + << Use(4, 17, 1, SemanticInfo::TypeUse) // B + << Use(5, 10, 7, SemanticInfo::VirtualMethodUse); // isThere TestData::check(source, expectedUses); } @@ -298,8 +291,9 @@ void tst_CheckSymbols::test_checksymbols_MacroUse() << Use(2, 11, 3, SemanticInfo::MacroUse); const QList expectedUses = QList() << Use(1, 9, 3, SemanticInfo::MacroUse) + << Use(2, 5, 1, SemanticInfo::FunctionUse) << Use(2, 11, 3, SemanticInfo::MacroUse) - << Use(2, 5, 1, SemanticInfo::FunctionUse); + ; TestData::check(source, expectedUses, macroUses); } @@ -361,17 +355,17 @@ void tst_CheckSymbols::test_checksymbols_StaticUse() << Use(1, 8, 5, SemanticInfo::TypeUse) << Use(3, 16, 3, SemanticInfo::FieldUse) << Use(4, 12, 5, SemanticInfo::TypeUse) - << Use(6, 16, 5, SemanticInfo::FieldUse) << Use(6, 9, 5, SemanticInfo::TypeUse) + << Use(6, 16, 5, SemanticInfo::FieldUse) << Use(7, 14, 3, SemanticInfo::FunctionUse) - << Use(11, 12, 3, SemanticInfo::FieldUse) << Use(11, 5, 5, SemanticInfo::TypeUse) - << Use(13, 20, 3, SemanticInfo::FunctionUse) + << Use(11, 12, 3, SemanticInfo::FieldUse) << Use(13, 6, 5, SemanticInfo::TypeUse) << Use(13, 13, 5, SemanticInfo::TypeUse) + << Use(13, 20, 3, SemanticInfo::FunctionUse) << Use(15, 5, 3, SemanticInfo::FieldUse) - << Use(16, 12, 3, SemanticInfo::FieldUse) << Use(16, 5, 5, SemanticInfo::TypeUse) + << Use(16, 12, 3, SemanticInfo::FieldUse) << Use(17, 5, 5, SemanticInfo::FieldUse) << Use(17, 12, 3, SemanticInfo::FieldUse) ; @@ -396,9 +390,9 @@ void tst_CheckSymbols::test_checksymbols_VariableHasTheSameNameAsEnumUse() ; const QList expectedUses = QList() << Use(1, 8, 3, SemanticInfo::TypeUse) - << Use(3, 19, 3, SemanticInfo::EnumerationUse) - << Use(3, 14, 3, SemanticInfo::EnumerationUse) << Use(3, 10, 1, SemanticInfo::TypeUse) + << Use(3, 14, 3, SemanticInfo::EnumerationUse) + << Use(3, 19, 3, SemanticInfo::EnumerationUse) << Use(6, 8, 3, SemanticInfo::TypeUse) << Use(8, 9, 3, SemanticInfo::FieldUse) << Use(9, 9, 3, SemanticInfo::FieldUse) @@ -431,18 +425,18 @@ void tst_CheckSymbols::test_checksymbols_NestedClassOfEnclosingTemplateUse() << Use(1, 18, 3, SemanticInfo::FieldUse) << Use(3, 19, 1, SemanticInfo::TypeUse) << Use(4, 8, 5, SemanticInfo::TypeUse) - << Use(6, 23, 2, SemanticInfo::FieldUse) << Use(6, 12, 6, SemanticInfo::TypeUse) - << Use(6, 29, 6, SemanticInfo::FieldUse) << Use(6, 21, 1, SemanticInfo::TypeUse) + << Use(6, 23, 2, SemanticInfo::FieldUse) + << Use(6, 29, 6, SemanticInfo::FieldUse) << Use(9, 6, 3, SemanticInfo::FunctionUse) + << Use(11, 5, 5, SemanticInfo::TypeUse) << Use(11, 11, 3, SemanticInfo::TypeUse) << Use(11, 16, 4, SemanticInfo::LocalUse) - << Use(11, 5, 5, SemanticInfo::TypeUse) - << Use(12, 20, 3, SemanticInfo::FieldUse) - << Use(12, 17, 2, SemanticInfo::FieldUse) - << Use(12, 10, 6, SemanticInfo::FieldUse) << Use(12, 5, 4, SemanticInfo::LocalUse) + << Use(12, 10, 6, SemanticInfo::FieldUse) + << Use(12, 17, 2, SemanticInfo::FieldUse) + << Use(12, 20, 3, SemanticInfo::FieldUse) ; TestData::check(source, expectedUses);