diff --git a/src/libs/clangbackendipc/clangbackendipc.qbs b/src/libs/clangbackendipc/clangbackendipc.qbs index 2f0f94e1f68..27a344e82e0 100644 --- a/src/libs/clangbackendipc/clangbackendipc.qbs +++ b/src/libs/clangbackendipc/clangbackendipc.qbs @@ -5,6 +5,7 @@ QtcLibrary { Depends { name: "Qt.network" } Depends { name: "Sqlite" } + Depends { name: "Utils" } cpp.defines: base.concat("CLANGBACKENDIPC_BUILD_LIB") cpp.includePaths: base.concat(".") @@ -18,6 +19,7 @@ QtcLibrary { Export { Depends { name: "Sqlite" } + Depends { name: "Utils" } Depends { name: "Qt.network" } cpp.includePaths: [ "." diff --git a/src/libs/clangbackendipc/clangbackendipc_dependencies.pri b/src/libs/clangbackendipc/clangbackendipc_dependencies.pri index 4813d6ce77e..3b52d130c3f 100644 --- a/src/libs/clangbackendipc/clangbackendipc_dependencies.pri +++ b/src/libs/clangbackendipc/clangbackendipc_dependencies.pri @@ -1,3 +1,3 @@ QTC_LIB_NAME = Clangbackendipc -QTC_LIB_DEPENDS += sqlite +QTC_LIB_DEPENDS += sqlite utils INCLUDEPATH *= $$IDE_SOURCE_TREE/src/libs/clangbackendipc diff --git a/src/libs/clangbackendipc/clangbackendipc_global.h b/src/libs/clangbackendipc/clangbackendipc_global.h index 28e0af9da74..12a5804fdc6 100644 --- a/src/libs/clangbackendipc/clangbackendipc_global.h +++ b/src/libs/clangbackendipc/clangbackendipc_global.h @@ -26,6 +26,8 @@ #ifndef CLANGBACKENDIPC_GLOBAL_H #define CLANGBACKENDIPC_GLOBAL_H +#include + #include #if defined(CLANGBACKENDIPC_BUILD_LIB) @@ -51,7 +53,7 @@ enum class DiagnosticSeverity // one to one mapping of the clang enum numbers Fatal = 4 }; -enum class HighlightingType +enum class HighlightingType : quint8 { Invalid, Keyword, @@ -70,7 +72,8 @@ enum class HighlightingType PreprocessorDefinition, PreprocessorExpansion, Label, - OutputArgument + OutputArgument, + Declaration }; enum class CompletionCorrection @@ -123,5 +126,12 @@ struct MessageTrait \ static const MessageType enumeration = MessageType::Message; \ }; +using MixinHighlightingTypes = Utils::SizedArray; + +struct HighlightingTypes { + HighlightingType mainHighlightingType; + MixinHighlightingTypes mixinHighlightingTypes; +}; + } #endif // CLANGBACKENDIPC_GLOBAL_H diff --git a/src/libs/clangbackendipc/highlightingmarkcontainer.cpp b/src/libs/clangbackendipc/highlightingmarkcontainer.cpp index d8ca90f31c2..441bc5203de 100644 --- a/src/libs/clangbackendipc/highlightingmarkcontainer.cpp +++ b/src/libs/clangbackendipc/highlightingmarkcontainer.cpp @@ -35,14 +35,25 @@ namespace ClangBackEnd { HighlightingMarkContainer::HighlightingMarkContainer(uint line, uint column, uint length, - HighlightingType type) + HighlightingTypes types) : line_(line), column_(column), length_(length), - type_(type) + types_(types) { } +HighlightingMarkContainer::HighlightingMarkContainer(uint line, + uint column, + uint length, + HighlightingType type) + : line_(line), + column_(column), + length_(length) +{ + types_.mainHighlightingType = type; +} + uint HighlightingMarkContainer::line() const { return line_; @@ -58,14 +69,21 @@ uint HighlightingMarkContainer::length() const return length_; } -HighlightingType HighlightingMarkContainer::type() const +HighlightingTypes HighlightingMarkContainer::types() const { - return type_; + return types_; } -quint32 &HighlightingMarkContainer::typeAsInt() +QDataStream &operator<<(QDataStream &out, HighlightingTypes highlightingTypes) { - return reinterpret_cast(type_); + out << reinterpret_cast(highlightingTypes.mainHighlightingType); + + out << highlightingTypes.mixinHighlightingTypes.size(); + + for (HighlightingType type : highlightingTypes.mixinHighlightingTypes) + out << reinterpret_cast(type); + + return out; } QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container) @@ -73,27 +91,55 @@ QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &conta out << container.line_; out << container.column_; out << container.length_; - out << quint32(container.type_); + out << container.types_; return out; } +QDataStream &operator>>(QDataStream &in, HighlightingTypes &highlightingTypes) +{ + in >> reinterpret_cast(highlightingTypes.mainHighlightingType); + + quint8 size; + in >> size; + + for (int counter = 0; counter < size; ++counter) { + HighlightingType type; + in >> reinterpret_cast(type); + highlightingTypes.mixinHighlightingTypes.push_back(type); + } + + return in; +} + QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container) { in >> container.line_; in >> container.column_; in >> container.length_; - in >> container.typeAsInt(); + in >> container.types_; return in; } +bool operator==(const MixinHighlightingTypes &first, const MixinHighlightingTypes &second) +{ + return first.size() == second.size() + && std::equal(first.begin(), first.end(), second.begin()); +} + +bool operator==(const HighlightingTypes &first, const HighlightingTypes &second) +{ + return first.mainHighlightingType == second.mainHighlightingType + && first.mixinHighlightingTypes == second.mixinHighlightingTypes; +} + bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second) { return first.line_ == second.line_ && first.column_ == second.column_ && first.length_ == second.length_ - && first.type_ == second.type_; + && first.types_ == second.types_; } #define RETURN_TEXT_FOR_CASE(enumValue) case HighlightingType::enumValue: return #enumValue @@ -129,7 +175,7 @@ QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container) << container.line() << ", " << container.column() << ", " << container.length() << ", " - << highlightingTypeToCStringLiteral(container.type()) << ", " + << highlightingTypeToCStringLiteral(container.types().mainHighlightingType) << ", " << ")"; return debug; @@ -140,13 +186,25 @@ void PrintTo(HighlightingType highlightingType, std::ostream *os) *os << highlightingTypeToCStringLiteral(highlightingType); } +void PrintTo(const HighlightingTypes &types, std::ostream *os) +{ + PrintTo(types.mainHighlightingType, os); + + *os << "["; + + for (HighlightingType type : types.mixinHighlightingTypes) + PrintTo(type, os); + + *os << "]"; +} + void PrintTo(const HighlightingMarkContainer& container, ::std::ostream *os) { *os << "HighlightingMarkContainer(" << container.line() << ", " << container.column() << ", " << container.length() << ", "; - PrintTo(container.type(), os); + PrintTo(container.types(), os); *os << ")"; } diff --git a/src/libs/clangbackendipc/highlightingmarkcontainer.h b/src/libs/clangbackendipc/highlightingmarkcontainer.h index 97cc402f921..6018381b1fb 100644 --- a/src/libs/clangbackendipc/highlightingmarkcontainer.h +++ b/src/libs/clangbackendipc/highlightingmarkcontainer.h @@ -36,29 +36,29 @@ class CMBIPC_EXPORT HighlightingMarkContainer friend CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second); public: HighlightingMarkContainer() = default; + HighlightingMarkContainer(uint line, uint column, uint length, HighlightingTypes types); HighlightingMarkContainer(uint line, uint column, uint length, HighlightingType type); uint line() const; uint column() const; uint length() const; - HighlightingType type() const; - -private: - quint32 &typeAsInt(); + HighlightingTypes types() const; private: uint line_; uint column_; uint length_; - HighlightingType type_; + HighlightingTypes types_; }; CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container); CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container); +CMBIPC_EXPORT bool operator==(const HighlightingTypes &first, const HighlightingTypes &second); CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second); CMBIPC_EXPORT QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container); CMBIPC_EXPORT void PrintTo(HighlightingType highlightingType, ::std::ostream *os); +CMBIPC_EXPORT void PrintTo(const HighlightingTypes &types, ::std::ostream *os); void PrintTo(const HighlightingMarkContainer &container, ::std::ostream *os); } // namespace ClangBackEnd diff --git a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp b/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp index 1054fa9e28f..5d29ff65f5f 100644 --- a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp +++ b/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp @@ -25,57 +25,67 @@ #include "clanghighlightingmarksreporter.h" -#include +#include #include namespace { -CppTools::SemanticHighlighter::Kind toCppToolsSemanticHighlighterKind( - ClangBackEnd::HighlightingType type) +TextEditor::TextStyle toTextStyle(ClangBackEnd::HighlightingType type) { using ClangBackEnd::HighlightingType; - using CppTools::SemanticHighlighter; switch (type) { - case HighlightingType::Keyword: - return SemanticHighlighter::PseudoKeywordUse; - case HighlightingType::Function: - return SemanticHighlighter::FunctionUse; - case HighlightingType::VirtualFunction: - return SemanticHighlighter::VirtualMethodUse; - case HighlightingType::Type: - return SemanticHighlighter::TypeUse; - case HighlightingType::LocalVariable: - return SemanticHighlighter::LocalUse; - case HighlightingType::Field: - return SemanticHighlighter::FieldUse; - case HighlightingType::GlobalVariable: - return SemanticHighlighter::Unknown; - case HighlightingType::Enumeration: - return SemanticHighlighter::EnumerationUse; - case HighlightingType::Label: - return SemanticHighlighter::LabelUse; - case HighlightingType::Preprocessor: - case HighlightingType::PreprocessorDefinition: - case HighlightingType::PreprocessorExpansion: - return SemanticHighlighter::MacroUse; - default: - return SemanticHighlighter::Unknown; + case HighlightingType::Keyword: + return TextEditor::C_KEYWORD; + case HighlightingType::Function: + return TextEditor::C_FUNCTION; + case HighlightingType::VirtualFunction: + return TextEditor::C_VIRTUAL_METHOD; + case HighlightingType::Type: + return TextEditor::C_TYPE; + case HighlightingType::LocalVariable: + return TextEditor::C_LOCAL; + case HighlightingType::Field: + return TextEditor::C_FIELD; + case HighlightingType::Enumeration: + return TextEditor::C_ENUMERATION; + case HighlightingType::Label: + return TextEditor::C_LABEL; + case HighlightingType::Preprocessor: + case HighlightingType::PreprocessorDefinition: + case HighlightingType::PreprocessorExpansion: + return TextEditor::C_PREPROCESSOR; + case HighlightingType::Declaration: + return TextEditor::C_DECLARATION; + default: + return TextEditor::C_TEXT; // never called } Q_UNREACHABLE(); } +TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types) +{ + TextEditor::TextStyles textStyles; + + textStyles.mainStyle = toTextStyle(types.mainHighlightingType); + + for (ClangBackEnd::HighlightingType type : types.mixinHighlightingTypes) + textStyles.mixinStyles.push_back(toTextStyle(type)); + + return textStyles; +} + TextEditor::HighlightingResult toHighlightingResult( const ClangBackEnd::HighlightingMarkContainer &highlightingMark) { - const auto highlighterKind = toCppToolsSemanticHighlighterKind(highlightingMark.type()); + const auto textStyles = toTextStyles(highlightingMark.types()); return TextEditor::HighlightingResult(highlightingMark.line(), highlightingMark.column(), highlightingMark.length(), - highlighterKind); + textStyles); } } // anonymous diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h index fea0ca5fd46..4daddfdd631 100644 --- a/src/plugins/texteditor/fontsettings.h +++ b/src/plugins/texteditor/fontsettings.h @@ -29,8 +29,7 @@ #include "texteditor_global.h" #include "colorscheme.h" - -#include +#include "textstyles.h" #include #include @@ -47,13 +46,6 @@ namespace TextEditor { class FormatDescription; -using MixinTextStyles = Utils::SizedArray; - -struct TextStyles { - TextStyle mainStyle; - MixinTextStyles mixinStyles; -}; - /** * Font settings (default font and enumerated list of formats). */ diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index 16a791de0bc..49da0c3e1a1 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -216,7 +216,8 @@ HEADERS += texteditorplugin.h \ codeassist/keywordscompletionassist.h \ textmarkregistry.h \ marginsettings.h \ - blockrange.h + blockrange.h \ + textstyles.h FORMS += \ displaysettingspage.ui \ diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index 532cdc03e23..a54d6352018 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -135,6 +135,7 @@ QtcPlugin { "textmark.cpp", "textmark.h", "textmarkregistry.h", + "textstyles.h", "typingsettings.cpp", "typingsettings.h", ] diff --git a/src/plugins/texteditor/textstyles.h b/src/plugins/texteditor/textstyles.h new file mode 100644 index 00000000000..f7d591b8323 --- /dev/null +++ b/src/plugins/texteditor/textstyles.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "texteditorconstants.h" + +#include + +namespace TextEditor { +using MixinTextStyles = Utils::SizedArray; + +struct TextStyles { + TextStyle mainStyle; + MixinTextStyles mixinStyles; +}; + +} // namespace TextEditor diff --git a/src/tools/clangbackend/ipcsource/highlightingmark.cpp b/src/tools/clangbackend/ipcsource/highlightingmark.cpp index 46568cc5555..255e7726349 100644 --- a/src/tools/clangbackend/ipcsource/highlightingmark.cpp +++ b/src/tools/clangbackend/ipcsource/highlightingmark.cpp @@ -50,20 +50,48 @@ HighlightingMark::HighlightingMark(const CXCursor &cxCursor, line = start.line(); column = start.column(); length = end.offset() - start.offset(); - type = kind(cxToken, originalCursor); + collectKinds(cxToken, originalCursor); +} + +HighlightingMark::HighlightingMark(uint line, uint column, uint length, HighlightingTypes types) + : line(line), + column(column), + length(length), + types(types) +{ } HighlightingMark::HighlightingMark(uint line, uint column, uint length, HighlightingType type) : line(line), column(column), length(length), - type(type) + types(HighlightingTypes()) { + types.mainHighlightingType = type; } -bool HighlightingMark::hasType(HighlightingType type) const +bool HighlightingMark::hasInvalidMainType() const { - return this->type == type; + return types.mainHighlightingType == HighlightingType::Invalid; +} + +bool HighlightingMark::hasMainType(HighlightingType type) const +{ + return types.mainHighlightingType == type; +} + +bool HighlightingMark::hasMixinType(HighlightingType type) const +{ + auto found = std::find(types.mixinHighlightingTypes.begin(), + types.mixinHighlightingTypes.end(), + type); + + return found != types.mixinHighlightingTypes.end(); +} + +bool HighlightingMark::hasOnlyType(HighlightingType type) const +{ + return types.mixinHighlightingTypes.size() == 0 && hasMainType(type); } bool HighlightingMark::hasFunctionArguments() const @@ -80,7 +108,7 @@ QVector HighlightingMark::outputFunctionArguments() const HighlightingMark::operator HighlightingMarkContainer() const { - return HighlightingMarkContainer(line, column, length, type); + return HighlightingMarkContainer(line, column, length, types); } namespace { @@ -90,8 +118,8 @@ bool isFinalFunction(const Cursor &cursor) auto referencedCursor = cursor.referenced(); if (referencedCursor.hasFinalFunctionAttribute()) return true; - - else return false; + else + return false; } bool isFunctionInFinalClass(const Cursor &cursor) @@ -104,20 +132,19 @@ bool isFunctionInFinalClass(const Cursor &cursor) } } -HighlightingType HighlightingMark::memberReferenceKind(const Cursor &cursor) const +void HighlightingMark::memberReferenceKind(const Cursor &cursor) { if (cursor.isDynamicCall()) { if (isFinalFunction(cursor) || isFunctionInFinalClass(cursor)) - return HighlightingType::Function; + types.mainHighlightingType = HighlightingType::Function; else - return HighlightingType::VirtualFunction; + types.mainHighlightingType = HighlightingType::VirtualFunction; + } else { + identifierKind(cursor.referenced(), Recursion::RecursivePass); } - - return identifierKind(cursor.referenced()); - } -HighlightingType HighlightingMark::referencedTypeKind(const Cursor &cursor) const +void HighlightingMark::referencedTypeKind(const Cursor &cursor) { const Cursor referencedCursor = cursor.referenced(); @@ -128,19 +155,17 @@ HighlightingType HighlightingMark::referencedTypeKind(const Cursor &cursor) cons case CXCursor_TypedefDecl: case CXCursor_TemplateTypeParameter: case CXCursor_TypeAliasDecl: - case CXCursor_EnumDecl: return HighlightingType::Type; - default: return HighlightingType::Invalid; + case CXCursor_EnumDecl: types.mainHighlightingType = HighlightingType::Type; break; + default: types.mainHighlightingType = HighlightingType::Invalid; break; } - - Q_UNREACHABLE(); } -HighlightingType HighlightingMark::variableKind(const Cursor &cursor) const +void HighlightingMark::variableKind(const Cursor &cursor) { if (cursor.isLocalVariable()) - return HighlightingType::LocalVariable; + types.mainHighlightingType = HighlightingType::LocalVariable; else - return HighlightingType::GlobalVariable; + types.mainHighlightingType = HighlightingType::GlobalVariable; } bool HighlightingMark::isVirtualMethodDeclarationOrDefinition(const Cursor &cursor) const @@ -157,32 +182,39 @@ bool isNotFinalFunction(const Cursor &cursor) } bool HighlightingMark::isRealDynamicCall(const Cursor &cursor) const { - return originalCursor.isDynamicCall() && isNotFinalFunction(cursor); } -HighlightingType HighlightingMark::functionKind(const Cursor &cursor) const +void HighlightingMark::addExtraTypeIfFirstPass(HighlightingType type, + Recursion recursion) { - if (isRealDynamicCall(cursor) || isVirtualMethodDeclarationOrDefinition(cursor)) - return HighlightingType::VirtualFunction; - else - return HighlightingType::Function; + if (recursion == Recursion::FirstPass) + types.mixinHighlightingTypes.push_back(type); } -HighlightingType HighlightingMark::identifierKind(const Cursor &cursor) const +void HighlightingMark::functionKind(const Cursor &cursor, Recursion recursion) +{ + if (isRealDynamicCall(cursor) || isVirtualMethodDeclarationOrDefinition(cursor)) + types.mainHighlightingType = HighlightingType::VirtualFunction; + else + types.mainHighlightingType = HighlightingType::Function; + + addExtraTypeIfFirstPass(HighlightingType::Declaration, recursion); +} + +void HighlightingMark::identifierKind(const Cursor &cursor, Recursion recursion) { switch (cursor.kind()) { case CXCursor_Destructor: case CXCursor_Constructor: case CXCursor_FunctionDecl: case CXCursor_CallExpr: - case CXCursor_CXXMethod: return functionKind(cursor); + case CXCursor_CXXMethod: functionKind(cursor, recursion); break; case CXCursor_NonTypeTemplateParameter: - case CXCursor_ParmDecl: return HighlightingType::LocalVariable; - case CXCursor_VarDecl: return variableKind(cursor); - case CXCursor_VariableRef: - case CXCursor_DeclRefExpr: return identifierKind(cursor.referenced()); - case CXCursor_MemberRefExpr: return memberReferenceKind(cursor); + case CXCursor_ParmDecl: types.mainHighlightingType = HighlightingType::LocalVariable; break; + case CXCursor_VarDecl: variableKind(cursor); break; + case CXCursor_DeclRefExpr: identifierKind(cursor.referenced(), Recursion::RecursivePass); break; + case CXCursor_MemberRefExpr: memberReferenceKind(cursor); break; case CXCursor_FieldDecl: case CXCursor_MemberRef: case CXCursor_ObjCIvarDecl: @@ -190,8 +222,8 @@ HighlightingType HighlightingMark::identifierKind(const Cursor &cursor) const case CXCursor_ObjCClassMethodDecl: case CXCursor_ObjCInstanceMethodDecl: case CXCursor_ObjCSynthesizeDecl: - case CXCursor_ObjCDynamicDecl: return HighlightingType::Field; - case CXCursor_TypeRef: return referencedTypeKind(cursor); + case CXCursor_ObjCDynamicDecl: types.mainHighlightingType = HighlightingType::Field; break; + case CXCursor_TypeRef: referencedTypeKind(cursor); break; case CXCursor_ClassDecl: case CXCursor_TemplateTypeParameter: case CXCursor_TemplateTemplateParameter: @@ -215,19 +247,17 @@ HighlightingType HighlightingMark::identifierKind(const Cursor &cursor) const case CXCursor_ObjCProtocolDecl: case CXCursor_ObjCProtocolRef: case CXCursor_ObjCClassRef: - case CXCursor_ObjCSuperClassRef: return HighlightingType::Type; - case CXCursor_FunctionTemplate: return HighlightingType::Function; - case CXCursor_EnumConstantDecl: return HighlightingType::Enumeration; - case CXCursor_PreprocessingDirective: return HighlightingType::Preprocessor; - case CXCursor_MacroExpansion: return HighlightingType::PreprocessorExpansion; - case CXCursor_MacroDefinition: return HighlightingType::PreprocessorDefinition; - case CXCursor_InclusionDirective: return HighlightingType::StringLiteral; + case CXCursor_ObjCSuperClassRef: types.mainHighlightingType = HighlightingType::Type; break; + case CXCursor_FunctionTemplate: types.mainHighlightingType = HighlightingType::Function; break; + case CXCursor_EnumConstantDecl: types.mainHighlightingType = HighlightingType::Enumeration; break; + case CXCursor_PreprocessingDirective: types.mainHighlightingType = HighlightingType::Preprocessor; break; + case CXCursor_MacroExpansion: types.mainHighlightingType = HighlightingType::PreprocessorExpansion; break; + case CXCursor_MacroDefinition: types.mainHighlightingType = HighlightingType::PreprocessorDefinition; break; + case CXCursor_InclusionDirective: types.mainHighlightingType = HighlightingType::StringLiteral; break; case CXCursor_LabelRef: - case CXCursor_LabelStmt: return HighlightingType::Label; - default: return HighlightingType::Invalid; + case CXCursor_LabelStmt: types.mainHighlightingType = HighlightingType::Label; break; + default: break; } - - Q_UNREACHABLE(); } namespace { @@ -268,25 +298,25 @@ HighlightingType punctationKind(const Cursor &cursor) } } -HighlightingType HighlightingMark::kind(CXToken *cxToken, const Cursor &cursor) const +void HighlightingMark::collectKinds(CXToken *cxToken, const Cursor &cursor) { auto cxTokenKind = clang_getTokenKind(*cxToken); - switch (cxTokenKind) { - case CXToken_Keyword: return HighlightingType::Keyword; - case CXToken_Punctuation: return punctationKind(cursor); - case CXToken_Identifier: return identifierKind(cursor); - case CXToken_Comment: return HighlightingType::Comment; - case CXToken_Literal: return literalKind(cursor); - } + types = {}; - Q_UNREACHABLE(); + switch (cxTokenKind) { + case CXToken_Keyword: types.mainHighlightingType = HighlightingType::Keyword; break; + case CXToken_Punctuation: types.mainHighlightingType = punctationKind(cursor); break; + case CXToken_Identifier: identifierKind(cursor, Recursion::FirstPass); break; + case CXToken_Comment: types.mainHighlightingType = HighlightingType::Comment; break; + case CXToken_Literal: types.mainHighlightingType = literalKind(cursor); break; + } } void PrintTo(const HighlightingMark &information, ::std::ostream *os) { *os << "type: "; - PrintTo(information.type, os); + PrintTo(information.types, os); *os << " line: " << information.line << " column: " << information.column << " length: " << information.length; diff --git a/src/tools/clangbackend/ipcsource/highlightingmark.h b/src/tools/clangbackend/ipcsource/highlightingmark.h index aad9351b5b0..010dec86079 100644 --- a/src/tools/clangbackend/ipcsource/highlightingmark.h +++ b/src/tools/clangbackend/ipcsource/highlightingmark.h @@ -39,32 +39,42 @@ class HighlightingMark friend bool operator==(const HighlightingMark &first, const HighlightingMark &second); friend void PrintTo(const HighlightingMark& highlightingMark, ::std::ostream *os); + enum class Recursion { + FirstPass, + RecursivePass + }; + public: HighlightingMark(const CXCursor &cxCursor, CXToken *cxToken, CXTranslationUnit cxTranslationUnit); + HighlightingMark(uint line, uint column, uint length, HighlightingTypes types); HighlightingMark(uint line, uint column, uint length, HighlightingType type); - bool hasType(HighlightingType type) const; + bool hasInvalidMainType() const; + bool hasMainType(HighlightingType type) const; + bool hasMixinType(HighlightingType type) const; + bool hasOnlyType(HighlightingType type) const; bool hasFunctionArguments() const; QVector outputFunctionArguments() const; operator HighlightingMarkContainer() const; private: - HighlightingType identifierKind(const Cursor &cursor) const; - HighlightingType referencedTypeKind(const Cursor &cursor) const; - HighlightingType variableKind(const Cursor &cursor) const; + void identifierKind(const Cursor &cursor, Recursion recursion); + void referencedTypeKind(const Cursor &cursor); + void variableKind(const Cursor &cursor); bool isVirtualMethodDeclarationOrDefinition(const Cursor &cursor) const; - HighlightingType functionKind(const Cursor &cursor) const; - HighlightingType memberReferenceKind(const Cursor &cursor) const; - HighlightingType kind(CXToken *cxToken, const Cursor &cursor) const; + void functionKind(const Cursor &cursor, Recursion recursion); + void memberReferenceKind(const Cursor &cursor); + void collectKinds(CXToken *cxToken, const Cursor &cursor); bool isRealDynamicCall(const Cursor &cursor) const; + void addExtraTypeIfFirstPass(HighlightingType type, Recursion recursion); private: Cursor originalCursor; uint line; uint column; uint length; - HighlightingType type; + HighlightingTypes types; }; void PrintTo(const HighlightingMark& highlightingMark, ::std::ostream *os); @@ -74,7 +84,7 @@ inline bool operator==(const HighlightingMark &first, const HighlightingMark &se return first.line == second.line && first.column == second.column && first.length == second.length - && first.type == second.type; + && first.types == second.types; } } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/ipcsource/highlightingmarks.cpp b/src/tools/clangbackend/ipcsource/highlightingmarks.cpp index 00aac0e3b6a..10cb2b5e82b 100644 --- a/src/tools/clangbackend/ipcsource/highlightingmarks.cpp +++ b/src/tools/clangbackend/ipcsource/highlightingmarks.cpp @@ -61,7 +61,10 @@ QVector HighlightingMarks::toHighlightingMarksContain containers.reserve(size()); const auto isValidHighlightMark = [] (const HighlightingMark &highlightMark) { - return !highlightMark.hasType(HighlightingType::Invalid); + return !highlightMark.hasInvalidMainType() + && !highlightMark.hasMainType(HighlightingType::StringLiteral) + && !highlightMark.hasMainType(HighlightingType::NumberLiteral) + && !highlightMark.hasMainType(HighlightingType::Comment); }; std::copy_if(begin(), end(), std::back_inserter(containers), isValidHighlightMark); diff --git a/src/tools/clangbackend/ipcsource/translationunits.cpp b/src/tools/clangbackend/ipcsource/translationunits.cpp index c6027fa75d3..1f08b448d85 100644 --- a/src/tools/clangbackend/ipcsource/translationunits.cpp +++ b/src/tools/clangbackend/ipcsource/translationunits.cpp @@ -369,7 +369,7 @@ void TranslationUnits::sendDocumentAnnotations(const TranslationUnit &translatio translationUnit.skippedSourceRanges().toSourceRangeContainers()); sendDocumentAnnotationsCallback(std::move(diagnosticsMessage), - std::move(highlightingsMessage)); + std::move(highlightingsMessage)); } } diff --git a/tests/unit/echoserver/echoserver.pro b/tests/unit/echoserver/echoserver.pro index 39a280db112..ccafe5521b8 100644 --- a/tests/unit/echoserver/echoserver.pro +++ b/tests/unit/echoserver/echoserver.pro @@ -15,6 +15,8 @@ osx:QMAKE_CXXFLAGS = -stdlib=libc++ include(../../../src/libs/clangbackendipc/clangbackendipc-lib.pri) include(../../../src/libs/sqlite/sqlite-lib.pri) +INCLUDEPATH += ../../../src/libs + SOURCES += \ echoipcserver.cpp \ echoserverprocessmain.cpp diff --git a/tests/unit/mockup/texteditor/semantichighlighter.h b/tests/unit/mockup/texteditor/semantichighlighter.h index b3bbfb2973d..dcb792e5f0f 100644 --- a/tests/unit/mockup/texteditor/semantichighlighter.h +++ b/tests/unit/mockup/texteditor/semantichighlighter.h @@ -26,6 +26,8 @@ #ifndef TEXTEDITOR_SEMANTICHIGHLIGHTER_H #define TEXTEDITOR_SEMANTICHIGHLIGHTER_H +#include + namespace TextEditor { class HighlightingResult { @@ -33,7 +35,11 @@ public: unsigned line; unsigned column; unsigned length; - int kind; + union { + TextStyles textStyles; + int kind; + }; + bool useTextSyles; bool isValid() const { return line != 0; } @@ -46,7 +52,11 @@ public: {} HighlightingResult(unsigned line, unsigned column, unsigned length, int kind) - : line(line), column(column), length(length), kind(kind) + : line(line), column(column), length(length), kind(kind), useTextSyles(false) + {} + + HighlightingResult(unsigned line, unsigned column, unsigned length, TextStyles textStyles) + : line(line), column(column), length(length), textStyles(textStyles), useTextSyles(true) {} bool operator==(const HighlightingResult& other) const diff --git a/tests/unit/unittest/clangipcservertest.cpp b/tests/unit/unittest/clangipcservertest.cpp index df8d615c3a5..28206c35ea8 100644 --- a/tests/unit/unittest/clangipcservertest.cpp +++ b/tests/unit/unittest/clangipcservertest.cpp @@ -81,6 +81,7 @@ using ClangBackEnd::UpdateVisibleTranslationUnitsMessage; using ClangBackEnd::RequestHighlightingMessage; using ClangBackEnd::HighlightingChangedMessage; using ClangBackEnd::HighlightingMarkContainer; +using ClangBackEnd::HighlightingTypes; MATCHER_P5(HasDirtyTranslationUnit, filePath, @@ -174,8 +175,10 @@ TEST_F(ClangIpcServer, GetCodeCompletion) TEST_F(ClangIpcServer, RequestHighlighting) { RequestHighlightingMessage requestHighlightingMessage({variableTestFilePath, projectPartId}); - - HighlightingMarkContainer highlightingMarkContainer(1, 6, 8, ClangBackEnd::HighlightingType::Function); + HighlightingTypes types; + types.mainHighlightingType = ClangBackEnd::HighlightingType::Function; + types.mixinHighlightingTypes.push_back(ClangBackEnd::HighlightingType::Declaration); + HighlightingMarkContainer highlightingMarkContainer(1, 6, 8, types); EXPECT_CALL(mockIpcClient, highlightingChanged(Property(&HighlightingChangedMessage::highlightingMarks, Contains(highlightingMarkContainer)))) .Times(1); diff --git a/tests/unit/unittest/highlightingmarkstest.cpp b/tests/unit/unittest/highlightingmarkstest.cpp index efbbdb680b1..e46e6e1f03d 100644 --- a/tests/unit/unittest/highlightingmarkstest.cpp +++ b/tests/unit/unittest/highlightingmarkstest.cpp @@ -42,6 +42,7 @@ #include "gtest-qt-printing.h" using ClangBackEnd::Cursor; +using ClangBackEnd::HighlightingTypes; using ClangBackEnd::HighlightingMark; using ClangBackEnd::HighlightingMarks; using ClangBackEnd::HighlightingType; @@ -75,12 +76,22 @@ MATCHER_P4(IsHighlightingMark, line, column, length, type, return arg == expected; } -MATCHER_P(HasType, type, +MATCHER_P(HasOnlyType, type, std::string(negation ? "isn't " : "is ") + PrintToString(type) ) { - return arg.hasType(type); + return arg.hasOnlyType(type); +} + +MATCHER_P2(HasTwoTypes, firstType, secondType, + std::string(negation ? "isn't " : "is ") + + PrintToString(firstType) + + " and " + + PrintToString(secondType) + ) +{ + return arg.hasMainType(firstType) && arg.hasMixinType(secondType); } struct Data { @@ -209,28 +220,28 @@ TEST_F(HighlightingMarks, FunctionDefinition) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(45, 20)); - ASSERT_THAT(infos[1], IsHighlightingMark(45u, 5u, 8u, HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, MemberFunctionDefinition) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(52, 29)); - ASSERT_THAT(infos[1], IsHighlightingMark(52u, 10u, 14u, HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, FunctionDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(55, 32)); - ASSERT_THAT(infos[1], IsHighlightingMark(55u, 5u, 19u, HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, MemberFunctionDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(59, 27)); - ASSERT_THAT(infos[1], IsHighlightingMark(59u, 10u, 14u, HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, MemberFunctionReference) @@ -244,7 +255,7 @@ TEST_F(HighlightingMarks, FunctionCall) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(64, 16)); - ASSERT_THAT(infos[0], IsHighlightingMark(64u, 5u, 8u, HighlightingType::Function)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TypeConversionFunction) @@ -321,399 +332,399 @@ TEST_F(HighlightingMarks, StaticMethodDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(110, 25)); - ASSERT_THAT(infos[1], IsHighlightingMark(110u, 10u, 12u, HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, StaticMethodReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(114, 30)); - ASSERT_THAT(infos[2], IsHighlightingMark(114u, 15u, 12u, HighlightingType::Function)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, Enumeration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(118, 17)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, Enumerator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(120, 15)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Enumeration)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Enumeration)); } TEST_F(HighlightingMarks, EnumerationReferenceDeclarationType) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, EnumerationReferenceDeclarationVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); - ASSERT_THAT(infos[1], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, EnumerationReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); - ASSERT_THAT(infos[0], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, EnumeratorReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Enumeration)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Enumeration)); } TEST_F(HighlightingMarks, ClassForwardDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(130, 12)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ConstructorDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(134, 13)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, DestructorDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(135, 15)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, ClassForwardDeclarationReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(138, 23)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ClassTypeReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ConstructorReferenceVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); - ASSERT_THAT(infos[1], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, UnionDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(145, 12)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, UnionDeclarationReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, GlobalVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); - ASSERT_THAT(infos[1], HasType(HighlightingType::GlobalVariable)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::GlobalVariable)); } TEST_F(HighlightingMarks, StructDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(50, 11)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpace) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(160, 22)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpaceAlias) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(164, 38)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, UsingStructInNameSpace) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(165, 36)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpaceReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, StructInNameSpaceReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } -TEST_F(HighlightingMarks, VirtualFunction) +TEST_F(HighlightingMarks, VirtualFunctionDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(170, 35)); - ASSERT_THAT(infos[2], HasType(HighlightingType::VirtualFunction)); + ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, DISABLED_NonVirtualFunctionCall) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(177, 46)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, DISABLED_NonVirtualFunctionCallPointer) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(180, 54)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, VirtualFunctionCallPointer) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(192, 51)); - ASSERT_THAT(infos[2], HasType(HighlightingType::VirtualFunction)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); } TEST_F(HighlightingMarks, FinalVirtualFunctionCallPointer) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(202, 61)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, NonFinalVirtualFunctionCallPointer) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(207, 61)); - ASSERT_THAT(infos[2], HasType(HighlightingType::VirtualFunction)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); } TEST_F(HighlightingMarks, PlusOperator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(224, 49)); - ASSERT_THAT(infos[6], HasType(HighlightingType::Operator)); + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Operator)); } TEST_F(HighlightingMarks, PlusAssignOperator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(226, 24)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Operator)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Operator)); } TEST_F(HighlightingMarks, Comment) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(229, 14)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Comment)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Comment)); } TEST_F(HighlightingMarks, PreprocessingDirective) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Preprocessor)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); } TEST_F(HighlightingMarks, PreprocessorMacroDefinition) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); - ASSERT_THAT(infos[2], HasType(HighlightingType::PreprocessorDefinition)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); } TEST_F(HighlightingMarks, PreprocessorFunctionMacroDefinition) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(232, 47)); - ASSERT_THAT(infos[2], HasType(HighlightingType::PreprocessorDefinition)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); } TEST_F(HighlightingMarks, PreprocessorMacroExpansion) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); - ASSERT_THAT(infos[0], HasType(HighlightingType::PreprocessorExpansion)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion)); } TEST_F(HighlightingMarks, PreprocessorMacroExpansionArgument) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); - ASSERT_THAT(infos[2], HasType(HighlightingType::NumberLiteral)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral)); } TEST_F(HighlightingMarks, PreprocessorInclusionDirective) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(239, 18)); - ASSERT_THAT(infos[1], HasType(HighlightingType::StringLiteral)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::StringLiteral)); } TEST_F(HighlightingMarks, GotoLabelStatement) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(242, 12)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Label)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Label)); } TEST_F(HighlightingMarks, GotoLabelStatementReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(244, 21)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Label)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Label)); } TEST_F(HighlightingMarks, TemplateReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(254, 25)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplateTypeParameter) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateDefaultParameter) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[5], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NonTypeTemplateParameter) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[8], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterDefaultArgument) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[10], HasType(HighlightingType::NumberLiteral)); + ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::NumberLiteral)); } TEST_F(HighlightingMarks, TemplateTemplateParameter) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[17], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[17], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateParameterDefaultArgument) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - ASSERT_THAT(infos[19], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[19], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateFunctionDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(266, 63)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplateTypeParameterReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTypeParameterDeclarationReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); - ASSERT_THAT(infos[1], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); - ASSERT_THAT(infos[3], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterReferenceReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); - ASSERT_THAT(infos[1], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, TemplateTemplateParameterReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateContainerParameterReference) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateParameterReferenceVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - ASSERT_THAT(infos[4], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCallPointer) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(212, 61)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCall) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(277, 23)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, HasFunctionArguments) @@ -745,35 +756,35 @@ TEST_F(HighlightingMarks, PreprocessorInclusionDirectiveWithAngleBrackets ) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(289, 38)); - ASSERT_THAT(infos[3], HasType(HighlightingType::StringLiteral)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); } TEST_F(HighlightingMarks, ArgumentInMacroExpansionIsKeyword) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Keyword)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Keyword)); } TEST_F(HighlightingMarks, DISABLED_FirstArgumentInMacroExpansionIsLocalVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsLocalVariable) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - ASSERT_THAT(infos[5], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsField) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(310, 40)); - ASSERT_THAT(infos[5], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); } @@ -781,184 +792,184 @@ TEST_F(HighlightingMarks, DISABLED_EnumerationType) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(316, 30)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TypeInStaticCast) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - ASSERT_THAT(infos[4], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, StaticCastIsKeyword) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Keyword)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword)); } TEST_F(HighlightingMarks, StaticCastPunctationIsInvalid) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Invalid)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Invalid)); - ASSERT_THAT(infos[5], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, TypeInReinterpretCast) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(329, 69)); - ASSERT_THAT(infos[4], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerAliasDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(333, 41)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerAlias) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(341, 31)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, SecondIntegerAlias) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(342, 43)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerTypedef) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(343, 35)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, FunctionAlias) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(344, 16)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, FriendTypeDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(350, 28)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FriendArgumentTypeDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); - ASSERT_THAT(infos[6], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FriendArgumentDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); - ASSERT_THAT(infos[8], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FieldInitialization) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(358, 18)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Field)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Field)); } TEST_F(HighlightingMarks, TemplateFunctionCall) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(372, 29)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Function)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplatedType) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(377, 21)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplatedTypeDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(384, 49)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NoOperator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(389, 24)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, ScopeOperator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(400, 33)); - ASSERT_THAT(infos[1], HasType(HighlightingType::Invalid)); + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, TemplateClassNamespace) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClass) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClassParameter) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - ASSERT_THAT(infos[4], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClassDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - ASSERT_THAT(infos[6], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, TypeDefDeclaration) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(418, 36)); - ASSERT_THAT(infos[2], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TypeDefDeclarationUsage) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(419, 48)); - ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, DISABLED_EnumerationTypeDef) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(424, 41)); - ASSERT_THAT(infos[3], HasType(HighlightingType::Type)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } // QTCREATORBUG-15473 @@ -966,7 +977,7 @@ TEST_F(HighlightingMarks, DISABLED_ArgumentToUserDefinedIndexOperator) { const auto infos = translationUnit.highlightingMarksInRange(sourceRange(434, 19)); - ASSERT_THAT(infos[2], HasType(HighlightingType::LocalVariable)); + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); } Data *HighlightingMarks::d;