diff --git a/src/libs/clangsupport/clangsupport-lib.pri b/src/libs/clangsupport/clangsupport-lib.pri index a4f3e38ba31..a32f78c1868 100644 --- a/src/libs/clangsupport/clangsupport-lib.pri +++ b/src/libs/clangsupport/clangsupport-lib.pri @@ -41,7 +41,6 @@ SOURCES += \ $$PWD/filepath.cpp \ $$PWD/fixitcontainer.cpp \ $$PWD/followsymbolmessage.cpp \ - $$PWD/highlightingmarkcontainer.cpp \ $$PWD/ipcclientinterface.cpp \ $$PWD/ipcinterface.cpp \ $$PWD/ipcserverinterface.cpp \ @@ -82,6 +81,7 @@ SOURCES += \ $$PWD/sourcerangescontainer.cpp \ $$PWD/sourcerangesforquerymessage.cpp \ $$PWD/sourcerangewithtextcontainer.cpp \ + $$PWD/tokeninfocontainer.cpp \ $$PWD/unregisterunsavedfilesforeditormessage.cpp \ $$PWD/updatepchprojectpartsmessage.cpp \ $$PWD/updatetranslationunitsforeditormessage.cpp \ @@ -131,7 +131,6 @@ HEADERS += \ $$PWD/filecontainerv2.h \ $$PWD/fixitcontainer.h \ $$PWD/followsymbolmessage.h \ - $$PWD/highlightingmarkcontainer.h \ $$PWD/idpaths.h \ $$PWD/ipcclientinterface.h \ $$PWD/ipcinterface.h \ @@ -176,6 +175,7 @@ HEADERS += \ $$PWD/sourcerangesforquerymessage.h \ $$PWD/sourcerangewithtextcontainer.h \ $$PWD/stringcache.h \ + $$PWD/tokeninfocontainer.h \ $$PWD/unregisterunsavedfilesforeditormessage.h \ $$PWD/updatepchprojectpartsmessage.h \ $$PWD/updatetranslationunitsforeditormessage.h \ diff --git a/src/libs/clangsupport/documentannotationschangedmessage.cpp b/src/libs/clangsupport/documentannotationschangedmessage.cpp index a9fef59e4ac..dbfe48fbdac 100644 --- a/src/libs/clangsupport/documentannotationschangedmessage.cpp +++ b/src/libs/clangsupport/documentannotationschangedmessage.cpp @@ -38,7 +38,7 @@ QDebug operator<<(QDebug debug, const DocumentAnnotationsChangedMessage &message << message.fileContainer() << ", " << message.diagnostics().size() << ", " << !message.firstHeaderErrorDiagnostic().text().isEmpty() - << ", " << message.highlightingMarks().size() + << ", " << message.tokenInfos().size() << ", " << message.skippedPreprocessorRanges().size() << ")"; @@ -51,7 +51,7 @@ std::ostream &operator<<(std::ostream &os, const DocumentAnnotationsChangedMessa << message.fileContainer() << "," << message.diagnostics().size() << "," << !message.firstHeaderErrorDiagnostic().text().isEmpty() - << "," << message.highlightingMarks().size() + << "," << message.tokenInfos().size() << "," << message.skippedPreprocessorRanges().size() << ")"; diff --git a/src/libs/clangsupport/documentannotationschangedmessage.h b/src/libs/clangsupport/documentannotationschangedmessage.h index 370fd4d66fb..48118589610 100644 --- a/src/libs/clangsupport/documentannotationschangedmessage.h +++ b/src/libs/clangsupport/documentannotationschangedmessage.h @@ -28,7 +28,7 @@ #include "clangsupport_global.h" #include "diagnosticcontainer.h" #include "filecontainer.h" -#include "highlightingmarkcontainer.h" +#include "tokeninfocontainer.h" #include "sourcerangecontainer.h" #include @@ -42,12 +42,12 @@ public: DocumentAnnotationsChangedMessage(const FileContainer &fileContainer, const QVector &diagnostics, const DiagnosticContainer &firstHeaderErrorDiagnostic, - const QVector &highlightingMarks, + const QVector &tokenInfos, const QVector &skippedPreprocessorRanges) : m_fileContainer(fileContainer), m_diagnostics(diagnostics), m_firstHeaderErrorDiagnostic(firstHeaderErrorDiagnostic), - m_highlightingMarks(highlightingMarks), + m_tokenInfos(tokenInfos), m_skippedPreprocessorRanges(skippedPreprocessorRanges) { } @@ -67,9 +67,9 @@ public: return m_firstHeaderErrorDiagnostic; } - const QVector &highlightingMarks() const + const QVector &tokenInfos() const { - return m_highlightingMarks; + return m_tokenInfos; } const QVector &skippedPreprocessorRanges() const @@ -82,7 +82,7 @@ public: out << message.m_fileContainer; out << message.m_diagnostics; out << message.m_firstHeaderErrorDiagnostic; - out << message.m_highlightingMarks; + out << message.m_tokenInfos; out << message.m_skippedPreprocessorRanges; return out; @@ -93,7 +93,7 @@ public: in >> message.m_fileContainer; in >> message.m_diagnostics; in >> message.m_firstHeaderErrorDiagnostic; - in >> message.m_highlightingMarks; + in >> message.m_tokenInfos; in >> message.m_skippedPreprocessorRanges; return in; @@ -105,7 +105,7 @@ public: return first.m_fileContainer == second.m_fileContainer && first.m_diagnostics == second.m_diagnostics && first.m_firstHeaderErrorDiagnostic == second.m_firstHeaderErrorDiagnostic - && first.m_highlightingMarks == second.m_highlightingMarks + && first.m_tokenInfos == second.m_tokenInfos && first.m_skippedPreprocessorRanges == second.m_skippedPreprocessorRanges; } @@ -113,7 +113,7 @@ private: FileContainer m_fileContainer; QVector m_diagnostics; DiagnosticContainer m_firstHeaderErrorDiagnostic; - QVector m_highlightingMarks; + QVector m_tokenInfos; QVector m_skippedPreprocessorRanges; }; diff --git a/src/libs/clangsupport/highlightingmarkcontainer.cpp b/src/libs/clangsupport/tokeninfocontainer.cpp similarity index 93% rename from src/libs/clangsupport/highlightingmarkcontainer.cpp rename to src/libs/clangsupport/tokeninfocontainer.cpp index 9e6bf2867c4..5ac4dcf6aeb 100644 --- a/src/libs/clangsupport/highlightingmarkcontainer.cpp +++ b/src/libs/clangsupport/tokeninfocontainer.cpp @@ -23,7 +23,7 @@ ** ****************************************************************************/ -#include "highlightingmarkcontainer.h" +#include "tokeninfocontainer.h" #include @@ -59,9 +59,9 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type) } #undef RETURN_TEXT_FOR_CASE -QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container) +QDebug operator<<(QDebug debug, const TokenInfoContainer &container) { - debug.nospace() << "HighlightingMarkContainer(" + debug.nospace() << "TokenInfosContainer(" << container.line() << ", " << container.column() << ", " << container.length() << ", " @@ -91,7 +91,7 @@ std::ostream &operator<<(std::ostream &os, HighlightingTypes types) return os; } -std::ostream &operator<<(std::ostream &os, const HighlightingMarkContainer &container) +std::ostream &operator<<(std::ostream &os, const TokenInfoContainer &container) { os << "(" << container.line() << ", " diff --git a/src/libs/clangsupport/highlightingmarkcontainer.h b/src/libs/clangsupport/tokeninfocontainer.h similarity index 88% rename from src/libs/clangsupport/highlightingmarkcontainer.h rename to src/libs/clangsupport/tokeninfocontainer.h index 07bd27ca8a9..c3041cb4379 100644 --- a/src/libs/clangsupport/highlightingmarkcontainer.h +++ b/src/libs/clangsupport/tokeninfocontainer.h @@ -40,11 +40,11 @@ inline QDataStream &operator>>(QDataStream &in, HighlightingTypes &highlightingT inline bool operator==(const MixinHighlightingTypes &first, const MixinHighlightingTypes &second); inline bool operator==(const HighlightingTypes &first, const HighlightingTypes &second); -class HighlightingMarkContainer +class TokenInfoContainer { public: - HighlightingMarkContainer() = default; - HighlightingMarkContainer(uint line, uint column, uint length, HighlightingTypes types, + TokenInfoContainer() = default; + TokenInfoContainer(uint line, uint column, uint length, HighlightingTypes types, bool isIdentifier = false, bool isIncludeDirectivePath = false) : line_(line), column_(column), @@ -55,7 +55,7 @@ public: { } - HighlightingMarkContainer(uint line, uint column, uint length, HighlightingType type) + TokenInfoContainer(uint line, uint column, uint length, HighlightingType type) : line_(line), column_(column), length_(length) @@ -98,7 +98,7 @@ public: return isIncludeDirectivePath_; } - friend QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container) + friend QDataStream &operator<<(QDataStream &out, const TokenInfoContainer &container) { out << container.line_; out << container.column_; @@ -110,7 +110,7 @@ public: return out; } - friend QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container) + friend QDataStream &operator>>(QDataStream &in, TokenInfoContainer &container) { in >> container.line_; in >> container.column_; @@ -122,7 +122,7 @@ public: return in; } - friend bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second) + friend bool operator==(const TokenInfoContainer &first, const TokenInfoContainer &second) { return first.line_ == second.line_ && first.column_ == second.column_ @@ -200,9 +200,9 @@ inline bool operator==(const HighlightingTypes &first, const HighlightingTypes & && first.mixinHighlightingTypes == second.mixinHighlightingTypes; } -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container); +CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const TokenInfoContainer &container); CLANGSUPPORT_EXPORT std::ostream &operator<<(std::ostream &os, HighlightingType highlightingType); CLANGSUPPORT_EXPORT std::ostream &operator<<(std::ostream &os, HighlightingTypes types); -std::ostream &operator<<(std::ostream &os, const HighlightingMarkContainer &container); +std::ostream &operator<<(std::ostream &os, const TokenInfoContainer &container); } // namespace ClangBackEnd diff --git a/src/plugins/clangcodemodel/clangbackendreceiver.cpp b/src/plugins/clangcodemodel/clangbackendreceiver.cpp index c9bea084258..69bea4fa008 100644 --- a/src/plugins/clangcodemodel/clangbackendreceiver.cpp +++ b/src/plugins/clangcodemodel/clangbackendreceiver.cpp @@ -181,7 +181,7 @@ void BackendReceiver::documentAnnotationsChanged(const DocumentAnnotationsChange { qCDebug(log) << "<<< DocumentAnnotationsChangedMessage with" << message.diagnostics().size() << "diagnostics" - << message.highlightingMarks().size() << "highlighting marks" + << message.tokenInfos().size() << "highlighting marks" << message.skippedPreprocessorRanges().size() << "skipped preprocessor ranges"; auto processor = ClangEditorDocumentProcessor::get(message.fileContainer().filePath()); @@ -195,7 +195,7 @@ void BackendReceiver::documentAnnotationsChanged(const DocumentAnnotationsChange processor->updateCodeWarnings(message.diagnostics(), message.firstHeaderErrorDiagnostic(), documentRevision); - processor->updateHighlighting(message.highlightingMarks(), + processor->updateHighlighting(message.tokenInfos(), message.skippedPreprocessorRanges(), documentRevision); } diff --git a/src/plugins/clangcodemodel/clangcodemodel.pro b/src/plugins/clangcodemodel/clangcodemodel.pro index bd10d49e207..9136db5db5c 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.pro +++ b/src/plugins/clangcodemodel/clangcodemodel.pro @@ -30,7 +30,7 @@ SOURCES += \ clangfixitoperationsextractor.cpp \ clangfollowsymbol.cpp \ clangfunctionhintmodel.cpp \ - clanghighlightingmarksreporter.cpp \ + clangtokeninfosreporter.cpp \ clangmodelmanagersupport.cpp \ clangpreprocessorassistproposalitem.cpp \ clangprojectsettings.cpp \ @@ -66,7 +66,6 @@ HEADERS += \ clangfixitoperationsextractor.h \ clangfollowsymbol.h \ clangfunctionhintmodel.h \ - clanghighlightingmarksreporter.h \ clangisdiagnosticrelatedtolocation.h \ clangmodelmanagersupport.h \ clangpreprocessorassistproposalitem.h \ @@ -75,7 +74,8 @@ HEADERS += \ clangrefactoringengine.h \ clangtextmark.h \ clanguiheaderondiskmanager.h \ - clangutils.h + clangutils.h \ + clangtokeninfosreporter.h FORMS += clangprojectsettingswidget.ui diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index 1733a26e60b..cc81025925f 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -80,8 +80,8 @@ QtcPlugin { "clangfollowsymbol.h", "clangfunctionhintmodel.cpp", "clangfunctionhintmodel.h", - "clanghighlightingmarksreporter.cpp", - "clanghighlightingmarksreporter.h", + "clangtokeninfosreporter.cpp", + "clangtokeninfosreporter.h", "clangisdiagnosticrelatedtolocation.h", "clangmodelmanagersupport.cpp", "clangmodelmanagersupport.h", diff --git a/src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri b/src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri index 165dc1cd7f4..50b9817fdfd 100644 --- a/src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri +++ b/src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri @@ -7,7 +7,7 @@ SOURCES += \ $$PWD/clangcompletioncontextanalyzer.cpp \ $$PWD/clangdiagnosticfilter.cpp \ $$PWD/clangfixitoperation.cpp \ - $$PWD/clanghighlightingmarksreporter.cpp + $$PWD/clangtokeninfosreporter.cpp HEADERS += \ $$PWD/clangactivationsequencecontextprocessor.h \ @@ -16,5 +16,5 @@ HEADERS += \ $$PWD/clangcompletioncontextanalyzer.h \ $$PWD/clangdiagnosticfilter.h \ $$PWD/clangfixitoperation.h \ - $$PWD/clanghighlightingmarksreporter.h \ + $$PWD/clangtokeninfosreporter.h \ $$PWD/clangisdiagnosticrelatedtolocation.h diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 813bd44583f..04bdccf893d 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -29,7 +29,7 @@ #include "clangdiagnostictooltipwidget.h" #include "clangfixitoperation.h" #include "clangfixitoperationsextractor.h" -#include "clanghighlightingmarksreporter.h" +#include "clangtokeninfosreporter.h" #include "clangprojectsettings.h" #include "clangutils.h" @@ -225,14 +225,14 @@ toTextEditorBlocks(QTextDocument *textDocument, } } -const QVector -&ClangEditorDocumentProcessor::highlightingMarks() const +const QVector +&ClangEditorDocumentProcessor::tokenInfos() const { - return m_highlightingMarks; + return m_tokenInfos; } void ClangEditorDocumentProcessor::updateHighlighting( - const QVector &highlightingMarks, + const QVector &tokenInfos, const QVector &skippedPreprocessorRanges, uint documentRevision) { @@ -240,10 +240,10 @@ void ClangEditorDocumentProcessor::updateHighlighting( const auto skippedPreprocessorBlocks = toTextEditorBlocks(textDocument(), skippedPreprocessorRanges); emit ifdefedOutBlocksUpdated(documentRevision, skippedPreprocessorBlocks); - m_highlightingMarks = highlightingMarks; + m_tokenInfos = tokenInfos; m_semanticHighlighter.setHighlightingRunner( - [highlightingMarks]() { - auto *reporter = new HighlightingMarksReporter(highlightingMarks); + [tokenInfos]() { + auto *reporter = new TokenInfosReporter(tokenInfos); return reporter->start(); }); m_semanticHighlighter.run(); diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.h b/src/plugins/clangcodemodel/clangeditordocumentprocessor.h index 328adb0143b..2bb7ca04633 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.h +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.h @@ -36,7 +36,7 @@ namespace ClangBackEnd { class DiagnosticContainer; -class HighlightingMarkContainer; +class TokenInfoContainer; class FileContainer; } @@ -70,7 +70,7 @@ public: void updateCodeWarnings(const QVector &diagnostics, const ClangBackEnd::DiagnosticContainer &firstHeaderErrorDiagnostic, uint documentRevision); - void updateHighlighting(const QVector &highlightingMarks, + void updateHighlighting(const QVector &tokenInfos, const QVector &skippedPreprocessorRanges, uint documentRevision); @@ -93,7 +93,7 @@ public: void clearDiagnosticsWithFixIts(); - const QVector &highlightingMarks() const; + const QVector &tokenInfos() const; public: static ClangEditorDocumentProcessor *get(const QString &filePath); @@ -123,7 +123,7 @@ private: QTimer m_updateTranslationUnitTimer; unsigned m_parserRevision; - QVector m_highlightingMarks; + QVector m_tokenInfos; CppTools::SemanticHighlighter m_semanticHighlighter; CppTools::BuiltinEditorDocumentProcessor m_builtinProcessor; }; diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.cpp b/src/plugins/clangcodemodel/clangfollowsymbol.cpp index 2062dccf455..e9a9e841d00 100644 --- a/src/plugins/clangcodemodel/clangfollowsymbol.cpp +++ b/src/plugins/clangcodemodel/clangfollowsymbol.cpp @@ -28,7 +28,7 @@ #include -#include +#include #include #include @@ -37,13 +37,13 @@ namespace ClangCodeModel { namespace Internal { // Returns invalid Mark if it is not found at (line, column) -static bool findMark(const QVector &marks, +static bool findMark(const QVector &marks, uint line, uint column, - ClangBackEnd::HighlightingMarkContainer &mark) + ClangBackEnd::TokenInfoContainer &mark) { mark = Utils::findOrDefault(marks, - [line, column](const ClangBackEnd::HighlightingMarkContainer &curMark) { + [line, column](const ClangBackEnd::TokenInfoContainer &curMark) { if (curMark.line() != line) return false; if (curMark.column() == column) @@ -57,7 +57,7 @@ static bool findMark(const QVector &mar return true; } -static int getMarkPos(QTextCursor cursor, const ClangBackEnd::HighlightingMarkContainer &mark) +static int getMarkPos(QTextCursor cursor, const ClangBackEnd::TokenInfoContainer &mark) { cursor.setPosition(0); cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, mark.line() - 1); @@ -70,9 +70,9 @@ static Utils::Link linkAtCursor(QTextCursor cursor, const QString &filePath, uin { using Link = Utils::Link; - const QVector &marks - = processor->highlightingMarks(); - ClangBackEnd::HighlightingMarkContainer mark; + const QVector &marks + = processor->tokenInfos(); + ClangBackEnd::TokenInfoContainer mark; if (!findMark(marks, line, column, mark)) return Link(); diff --git a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp b/src/plugins/clangcodemodel/clangtokeninfosreporter.cpp similarity index 81% rename from src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp rename to src/plugins/clangcodemodel/clangtokeninfosreporter.cpp index d63ed65ff61..913861c2677 100644 --- a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.cpp +++ b/src/plugins/clangcodemodel/clangtokeninfosreporter.cpp @@ -23,7 +23,7 @@ ** ****************************************************************************/ -#include "clanghighlightingmarksreporter.h" +#include "clangtokeninfosreporter.h" #include #include @@ -97,13 +97,13 @@ TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types) } TextEditor::HighlightingResult toHighlightingResult( - const ClangBackEnd::HighlightingMarkContainer &highlightingMark) + const ClangBackEnd::TokenInfoContainer &tokenInfo) { - const auto textStyles = toTextStyles(highlightingMark.types()); + const auto textStyles = toTextStyles(tokenInfo.types()); - return TextEditor::HighlightingResult(highlightingMark.line(), - highlightingMark.column(), - highlightingMark.length(), + return TextEditor::HighlightingResult(tokenInfo.line(), + tokenInfo.column(), + tokenInfo.length(), textStyles); } @@ -111,14 +111,14 @@ TextEditor::HighlightingResult toHighlightingResult( namespace ClangCodeModel { -HighlightingMarksReporter::HighlightingMarksReporter( - const QVector &highlightingMarks) - : m_highlightingMarks(highlightingMarks) +TokenInfosReporter::TokenInfosReporter( + const QVector &tokenInfos) + : m_tokenInfos(tokenInfos) { m_chunksToReport.reserve(m_chunkSize + 1); } -void HighlightingMarksReporter::reportChunkWise( +void TokenInfosReporter::reportChunkWise( const TextEditor::HighlightingResult &highlightingResult) { if (m_chunksToReport.size() >= m_chunkSize) { @@ -133,7 +133,7 @@ void HighlightingMarksReporter::reportChunkWise( m_chunksToReport.append(highlightingResult); } -void HighlightingMarksReporter::reportAndClearCurrentChunks() +void TokenInfosReporter::reportAndClearCurrentChunks() { m_flushRequested = false; m_flushLine = 0; @@ -144,30 +144,30 @@ void HighlightingMarksReporter::reportAndClearCurrentChunks() } } -void HighlightingMarksReporter::setChunkSize(int chunkSize) +void TokenInfosReporter::setChunkSize(int chunkSize) { m_chunkSize = chunkSize; } -void HighlightingMarksReporter::run() +void TokenInfosReporter::run() { run_internal(); reportFinished(); } -void HighlightingMarksReporter::run_internal() +void TokenInfosReporter::run_internal() { if (isCanceled()) return; using ClangBackEnd::HighlightingType; - for (const auto &highlightingMark : m_highlightingMarks) { - const HighlightingType mainType = highlightingMark.types().mainHighlightingType; + for (const auto &tokenInfo : m_tokenInfos) { + const HighlightingType mainType = tokenInfo.types().mainHighlightingType; if (mainType == HighlightingType::StringLiteral) continue; - reportChunkWise(toHighlightingResult(highlightingMark)); + reportChunkWise(toHighlightingResult(tokenInfo)); } if (isCanceled()) @@ -176,7 +176,7 @@ void HighlightingMarksReporter::run_internal() reportAndClearCurrentChunks(); } -QFuture HighlightingMarksReporter::start() +QFuture TokenInfosReporter::start() { this->setRunnable(this); this->reportStarted(); diff --git a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.h b/src/plugins/clangcodemodel/clangtokeninfosreporter.h similarity index 88% rename from src/plugins/clangcodemodel/clanghighlightingmarksreporter.h rename to src/plugins/clangcodemodel/clangtokeninfosreporter.h index 379e2c55f62..d525ebc5984 100644 --- a/src/plugins/clangcodemodel/clanghighlightingmarksreporter.h +++ b/src/plugins/clangcodemodel/clangtokeninfosreporter.h @@ -32,11 +32,11 @@ #include -#include +#include namespace ClangCodeModel { -class HighlightingMarksReporter: +class TokenInfosReporter: public QObject, public QRunnable, public QFutureInterface @@ -44,7 +44,7 @@ class HighlightingMarksReporter: Q_OBJECT public: - HighlightingMarksReporter(const QVector &highlightingMarks); + TokenInfosReporter(const QVector &tokenInfos); void setChunkSize(int chunkSize); @@ -58,7 +58,7 @@ private: void reportAndClearCurrentChunks(); private: - QVector m_highlightingMarks; + QVector m_tokenInfos; QVector m_chunksToReport; int m_chunkSize = 100; diff --git a/src/tools/clangbackend/source/clangbackendclangipc-source.pri b/src/tools/clangbackend/source/clangbackendclangipc-source.pri index 6919db68399..3460e9d297d 100644 --- a/src/tools/clangbackend/source/clangbackendclangipc-source.pri +++ b/src/tools/clangbackend/source/clangbackendclangipc-source.pri @@ -48,14 +48,14 @@ HEADERS += \ $$PWD/diagnosticset.h \ $$PWD/diagnosticsetiterator.h \ $$PWD/fixit.h \ - $$PWD/highlightingmark.h \ - $$PWD/highlightingmarks.h \ - $$PWD/highlightingmarksiterator.h \ $$PWD/projectpart.h \ $$PWD/projects.h \ $$PWD/skippedsourceranges.h \ $$PWD/sourcelocation.h \ $$PWD/sourcerange.h \ + $$PWD/tokeninfo.h \ + $$PWD/tokeninfos.h \ + $$PWD/tokeninfositerator.h \ $$PWD/unsavedfile.h \ $$PWD/unsavedfiles.h \ $$PWD/utf8positionfromlinecolumn.h @@ -102,13 +102,13 @@ SOURCES += \ $$PWD/diagnostic.cpp \ $$PWD/diagnosticset.cpp \ $$PWD/fixit.cpp \ - $$PWD/highlightingmark.cpp \ - $$PWD/highlightingmarks.cpp \ $$PWD/projectpart.cpp \ $$PWD/projects.cpp \ $$PWD/skippedsourceranges.cpp \ $$PWD/sourcelocation.cpp \ $$PWD/sourcerange.cpp \ + $$PWD/tokeninfo.cpp \ + $$PWD/tokeninfos.cpp \ $$PWD/unsavedfile.cpp \ $$PWD/unsavedfiles.cpp \ $$PWD/utf8positionfromlinecolumn.cpp diff --git a/src/tools/clangbackend/source/clangcodemodelserver.cpp b/src/tools/clangbackend/source/clangcodemodelserver.cpp index 8b9a03dfe51..df8f1381582 100644 --- a/src/tools/clangbackend/source/clangcodemodelserver.cpp +++ b/src/tools/clangbackend/source/clangcodemodelserver.cpp @@ -31,7 +31,7 @@ #include "clangtranslationunits.h" #include "codecompleter.h" #include "diagnosticset.h" -#include "highlightingmarks.h" +#include "tokeninfos.h" #include "clangexceptions.h" #include "skippedsourceranges.h" diff --git a/src/tools/clangbackend/source/clangdocuments.cpp b/src/tools/clangbackend/source/clangdocuments.cpp index 5fc8f294a78..95195d251b1 100644 --- a/src/tools/clangbackend/source/clangdocuments.cpp +++ b/src/tools/clangbackend/source/clangdocuments.cpp @@ -26,7 +26,7 @@ #include "clangdocuments.h" #include -#include +#include #include #include #include diff --git a/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.cpp b/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.cpp index 99ac98eec2a..3cb1479b766 100644 --- a/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.cpp +++ b/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.cpp @@ -47,7 +47,7 @@ IAsyncJob::AsyncPrepareResult RequestDocumentAnnotationsJob::prepareAsyncRun() RequestDocumentAnnotationsJob::AsyncResult asyncResult; translationUnit.extractDocumentAnnotations(asyncResult.firstHeaderErrorDiagnostic, asyncResult.diagnostics, - asyncResult.highlightingMarks, + asyncResult.tokenInfos, asyncResult.skippedSourceRanges); return asyncResult; }); @@ -63,7 +63,7 @@ void RequestDocumentAnnotationsJob::finalizeAsyncRun() DocumentAnnotationsChangedMessage(m_pinnedFileContainer, result.diagnostics, result.firstHeaderErrorDiagnostic, - result.highlightingMarks, + result.tokenInfos, result.skippedSourceRanges)); } } diff --git a/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.h b/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.h index 1c78621119e..fe8da149adf 100644 --- a/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.h +++ b/src/tools/clangbackend/source/clangrequestdocumentannotationsjob.h @@ -28,7 +28,7 @@ #include "clangdocumentjob.h" #include -#include +#include #include namespace ClangBackEnd { @@ -37,7 +37,7 @@ struct RequestDocumentAnnotationsJobResult { ClangBackEnd::DiagnosticContainer firstHeaderErrorDiagnostic; QVector diagnostics; - QVector highlightingMarks; + QVector tokenInfos; QVector skippedSourceRanges; }; diff --git a/src/tools/clangbackend/source/clangtranslationunit.cpp b/src/tools/clangbackend/source/clangtranslationunit.cpp index 7d3bcbbddd9..6f54deab461 100644 --- a/src/tools/clangbackend/source/clangtranslationunit.cpp +++ b/src/tools/clangbackend/source/clangtranslationunit.cpp @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -131,11 +131,11 @@ TranslationUnit::CodeCompletionResult TranslationUnit::complete( void TranslationUnit::extractDocumentAnnotations( DiagnosticContainer &firstHeaderErrorDiagnostic, QVector &mainFileDiagnostics, - QVector &highlightingMarks, + QVector &tokenInfos, QVector &skippedSourceRanges) const { extractDiagnostics(firstHeaderErrorDiagnostic, mainFileDiagnostics); - highlightingMarks = this->highlightingMarks().toHighlightingMarksContainers(); + tokenInfos = this->tokenInfos().toTokenInfoContainers(); skippedSourceRanges = this->skippedSourceRanges().toSourceRangeContainers(); } @@ -187,19 +187,19 @@ Cursor TranslationUnit::cursor() const return clang_getTranslationUnitCursor(m_cxTranslationUnit); } -HighlightingMarks TranslationUnit::highlightingMarks() const +TokenInfos TranslationUnit::tokenInfos() const { - return highlightingMarksInRange(cursor().sourceRange()); + return tokenInfosInRange(cursor().sourceRange()); } -HighlightingMarks TranslationUnit::highlightingMarksInRange(const SourceRange &range) const +TokenInfos TranslationUnit::tokenInfosInRange(const SourceRange &range) const { CXToken *cxTokens = 0; uint cxTokensCount = 0; clang_tokenize(m_cxTranslationUnit, range, &cxTokens, &cxTokensCount); - return HighlightingMarks(m_cxTranslationUnit, cxTokens, cxTokensCount); + return TokenInfos(m_cxTranslationUnit, cxTokens, cxTokensCount); } SkippedSourceRanges TranslationUnit::skippedSourceRanges() const diff --git a/src/tools/clangbackend/source/clangtranslationunit.h b/src/tools/clangbackend/source/clangtranslationunit.h index e42d67ea6da..9110d637d10 100644 --- a/src/tools/clangbackend/source/clangtranslationunit.h +++ b/src/tools/clangbackend/source/clangtranslationunit.h @@ -34,8 +34,8 @@ namespace ClangBackEnd { class Cursor; class DiagnosticContainer; class DiagnosticSet; -class HighlightingMarkContainer; -class HighlightingMarks; +class TokenInfoContainer; +class TokenInfos; class ReferencesResult; class SkippedSourceRanges; class SourceLocation; @@ -81,7 +81,7 @@ public: QVector &mainFileDiagnostics) const; void extractDocumentAnnotations(DiagnosticContainer &firstHeaderErrorDiagnostic, QVector &mainFileDiagnostics, - QVector &highlightingMarks, + QVector &tokenInfos, QVector &skippedSourceRanges) const; @@ -96,8 +96,8 @@ public: Cursor cursorAt(const Utf8String &filePath, uint line, uint column) const; Cursor cursor() const; - HighlightingMarks highlightingMarks() const; - HighlightingMarks highlightingMarksInRange(const SourceRange &range) const; + TokenInfos tokenInfos() const; + TokenInfos tokenInfosInRange(const SourceRange &range) const; SkippedSourceRanges skippedSourceRanges() const; SourceRangeContainer followSymbol(uint line, diff --git a/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.cpp b/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.cpp index 7333ca68787..7d68653c590 100644 --- a/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.cpp +++ b/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.cpp @@ -51,7 +51,7 @@ IAsyncJob::AsyncPrepareResult UpdateDocumentAnnotationsJob::prepareAsyncRun() // Collect translationUnit.extractDocumentAnnotations(asyncResult.firstHeaderErrorDiagnostic, asyncResult.diagnostics, - asyncResult.highlightingMarks, + asyncResult.tokenInfos, asyncResult.skippedSourceRanges); return asyncResult; @@ -70,7 +70,7 @@ void UpdateDocumentAnnotationsJob::finalizeAsyncRun() DocumentAnnotationsChangedMessage(m_pinnedFileContainer, result.diagnostics, result.firstHeaderErrorDiagnostic, - result.highlightingMarks, + result.tokenInfos, result.skippedSourceRanges)); } } diff --git a/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.h b/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.h index 141b3535a09..89ec61dc618 100644 --- a/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.h +++ b/src/tools/clangbackend/source/clangupdatedocumentannotationsjob.h @@ -28,7 +28,7 @@ #include "clangdocumentjob.h" #include -#include +#include #include namespace ClangBackEnd { @@ -39,7 +39,7 @@ struct UpdateDocumentAnnotationsJobResult ClangBackEnd::DiagnosticContainer firstHeaderErrorDiagnostic; QVector diagnostics; - QVector highlightingMarks; + QVector tokenInfos; QVector skippedSourceRanges; }; diff --git a/src/tools/clangbackend/source/highlightingmark.cpp b/src/tools/clangbackend/source/tokeninfo.cpp similarity index 86% rename from src/tools/clangbackend/source/highlightingmark.cpp rename to src/tools/clangbackend/source/tokeninfo.cpp index b4c1a19547d..63cfb9c679d 100644 --- a/src/tools/clangbackend/source/highlightingmark.cpp +++ b/src/tools/clangbackend/source/tokeninfo.cpp @@ -23,11 +23,11 @@ ** ****************************************************************************/ -#include +#include #include "clangstring.h" #include "cursor.h" -#include "highlightingmark.h" +#include "tokeninfo.h" #include "sourcelocation.h" #include "sourcerange.h" #include "sourcerangecontainer.h" @@ -39,7 +39,7 @@ namespace ClangBackEnd { -HighlightingMark::HighlightingMark(const CXCursor &cxCursor, +TokenInfo::TokenInfo(const CXCursor &cxCursor, CXToken *cxToken, CXTranslationUnit cxTranslationUnit, std::vector ¤tOutputArgumentRanges) @@ -57,7 +57,7 @@ HighlightingMark::HighlightingMark(const CXCursor &cxCursor, collectKinds(cxTranslationUnit, cxToken, m_originalCursor); } -HighlightingMark::HighlightingMark(uint line, uint column, uint length, HighlightingTypes types) +TokenInfo::TokenInfo(uint line, uint column, uint length, HighlightingTypes types) : m_line(line), m_column(column), m_length(length), @@ -65,7 +65,7 @@ HighlightingMark::HighlightingMark(uint line, uint column, uint length, Highligh { } -HighlightingMark::HighlightingMark(uint line, uint column, uint length, HighlightingType type) +TokenInfo::TokenInfo(uint line, uint column, uint length, HighlightingType type) : m_line(line), m_column(column), m_length(length), @@ -74,21 +74,21 @@ HighlightingMark::HighlightingMark(uint line, uint column, uint length, Highligh m_types.mainHighlightingType = type; } -bool HighlightingMark::hasInvalidMainType() const +bool TokenInfo::hasInvalidMainType() const { return m_types.mainHighlightingType == HighlightingType::Invalid; } -bool HighlightingMark::hasMainType(HighlightingType type) const +bool TokenInfo::hasMainType(HighlightingType type) const { return m_types.mainHighlightingType == type; } -unsigned HighlightingMark::mixinSize() const { +unsigned TokenInfo::mixinSize() const { return m_types.mixinHighlightingTypes.size(); } -bool HighlightingMark::hasMixinType(HighlightingType type) const +bool TokenInfo::hasMixinType(HighlightingType type) const { auto found = std::find(m_types.mixinHighlightingTypes.begin(), m_types.mixinHighlightingTypes.end(), @@ -97,25 +97,25 @@ bool HighlightingMark::hasMixinType(HighlightingType type) const return found != m_types.mixinHighlightingTypes.end(); } -bool HighlightingMark::hasMixinTypeAt(uint position, HighlightingType type) const +bool TokenInfo::hasMixinTypeAt(uint position, HighlightingType type) const { return m_types.mixinHighlightingTypes.size() > position && m_types.mixinHighlightingTypes.at(position) == type; } -bool HighlightingMark::hasOnlyType(HighlightingType type) const +bool TokenInfo::hasOnlyType(HighlightingType type) const { return m_types.mixinHighlightingTypes.size() == 0 && hasMainType(type); } -bool HighlightingMark::hasFunctionArguments() const +bool TokenInfo::hasFunctionArguments() const { return m_originalCursor.argumentCount() > 0; } -HighlightingMark::operator HighlightingMarkContainer() const +TokenInfo::operator TokenInfoContainer() const { - return HighlightingMarkContainer(m_line, m_column, m_length, m_types, m_isIdentifier, + return TokenInfoContainer(m_line, m_column, m_length, m_types, m_isIdentifier, m_isInclusion); } @@ -140,7 +140,7 @@ bool isFunctionInFinalClass(const Cursor &cursor) } } -void HighlightingMark::memberReferenceKind(const Cursor &cursor) +void TokenInfo::memberReferenceKind(const Cursor &cursor) { if (cursor.isDynamicCall()) { if (isFinalFunction(cursor) || isFunctionInFinalClass(cursor)) @@ -152,7 +152,7 @@ void HighlightingMark::memberReferenceKind(const Cursor &cursor) } } -void HighlightingMark::referencedTypeKind(const Cursor &cursor) +void TokenInfo::referencedTypeKind(const Cursor &cursor) { const Cursor referencedCursor = cursor.referenced(); @@ -168,7 +168,7 @@ void HighlightingMark::referencedTypeKind(const Cursor &cursor) } } -void HighlightingMark::overloadedDeclRefKind(const Cursor &cursor) +void TokenInfo::overloadedDeclRefKind(const Cursor &cursor) { m_types.mainHighlightingType = HighlightingType::Function; @@ -182,7 +182,7 @@ void HighlightingMark::overloadedDeclRefKind(const Cursor &cursor) } } -void HighlightingMark::variableKind(const Cursor &cursor) +void TokenInfo::variableKind(const Cursor &cursor) { if (cursor.isLocalVariable()) m_types.mainHighlightingType = HighlightingType::LocalVariable; @@ -193,7 +193,7 @@ void HighlightingMark::variableKind(const Cursor &cursor) m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument); } -void HighlightingMark::fieldKind(const Cursor &) +void TokenInfo::fieldKind(const Cursor &) { m_types.mainHighlightingType = HighlightingType::Field; @@ -201,12 +201,12 @@ void HighlightingMark::fieldKind(const Cursor &) m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument); } -bool HighlightingMark::isDefinition() const +bool TokenInfo::isDefinition() const { return m_originalCursor.isDefinition(); } -bool HighlightingMark::isVirtualMethodDeclarationOrDefinition(const Cursor &cursor) const +bool TokenInfo::isVirtualMethodDeclarationOrDefinition(const Cursor &cursor) const { return cursor.isVirtualMethod() && (m_originalCursor.isDeclaration() || m_originalCursor.isDefinition()); @@ -218,19 +218,19 @@ bool isNotFinalFunction(const Cursor &cursor) return !cursor.hasFinalFunctionAttribute(); } } -bool HighlightingMark::isRealDynamicCall(const Cursor &cursor) const +bool TokenInfo::isRealDynamicCall(const Cursor &cursor) const { return m_originalCursor.isDynamicCall() && isNotFinalFunction(cursor); } -void HighlightingMark::addExtraTypeIfFirstPass(HighlightingType type, +void TokenInfo::addExtraTypeIfFirstPass(HighlightingType type, Recursion recursion) { if (recursion == Recursion::FirstPass) m_types.mixinHighlightingTypes.push_back(type); } -bool HighlightingMark::isArgumentInCurrentOutputArgumentLocations() const +bool TokenInfo::isArgumentInCurrentOutputArgumentLocations() const { auto originalSourceLocation = m_originalCursor.cxSourceLocation(); @@ -248,7 +248,7 @@ bool HighlightingMark::isArgumentInCurrentOutputArgumentLocations() const return isOutputArgument; } -bool HighlightingMark::isOutputArgument() const +bool TokenInfo::isOutputArgument() const { if (m_currentOutputArgumentRanges->empty()) return false; @@ -256,7 +256,7 @@ bool HighlightingMark::isOutputArgument() const return isArgumentInCurrentOutputArgumentLocations(); } -void HighlightingMark::collectOutputArguments(const Cursor &cursor) +void TokenInfo::collectOutputArguments(const Cursor &cursor) { cursor.collectOutputArgumentRangesTo(*m_currentOutputArgumentRanges); filterOutPreviousOutputArguments(); @@ -276,7 +276,7 @@ uint getEnd(CXSourceRange cxSourceRange) } } -void HighlightingMark::filterOutPreviousOutputArguments() +void TokenInfo::filterOutPreviousOutputArguments() { auto isAfterLocation = [this] (CXSourceRange outputRange) { return getEnd(outputRange) > m_offset; @@ -289,7 +289,7 @@ void HighlightingMark::filterOutPreviousOutputArguments() m_currentOutputArgumentRanges->erase(precedingBegin, m_currentOutputArgumentRanges->end()); } -void HighlightingMark::functionKind(const Cursor &cursor, Recursion recursion) +void TokenInfo::functionKind(const Cursor &cursor, Recursion recursion) { if (isRealDynamicCall(cursor) || isVirtualMethodDeclarationOrDefinition(cursor)) m_types.mainHighlightingType = HighlightingType::VirtualFunction; @@ -305,7 +305,7 @@ void HighlightingMark::functionKind(const Cursor &cursor, Recursion recursion) addExtraTypeIfFirstPass(HighlightingType::FunctionDefinition, recursion); } -void HighlightingMark::identifierKind(const Cursor &cursor, Recursion recursion) +void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion) { m_isIdentifier = (cursor.kind() != CXCursor_PreprocessingDirective); @@ -398,7 +398,7 @@ HighlightingType operatorKind(const Cursor &cursor) } -HighlightingType HighlightingMark::punctuationKind(const Cursor &cursor) +HighlightingType TokenInfo::punctuationKind(const Cursor &cursor) { HighlightingType highlightingType = HighlightingType::Invalid; @@ -445,7 +445,7 @@ static HighlightingType highlightingTypeForKeyword(CXTranslationUnit cxTranslati return HighlightingType::Keyword; } -void HighlightingMark::collectKinds(CXTranslationUnit cxTranslationUnit, +void TokenInfo::collectKinds(CXTranslationUnit cxTranslationUnit, CXToken *cxToken, const Cursor &cursor) { auto cxTokenKind = clang_getTokenKind(*cxToken); @@ -463,12 +463,12 @@ void HighlightingMark::collectKinds(CXTranslationUnit cxTranslationUnit, m_isInclusion = (cursor.kind() == CXCursor_InclusionDirective); } -std::ostream &operator<<(std::ostream &os, const HighlightingMark& highlightingMark) +std::ostream &operator<<(std::ostream &os, const TokenInfo& tokenInfo) { - os << "(type: " << highlightingMark.m_types << ", " - << " line: " << highlightingMark.m_line << ", " - << " column: " << highlightingMark.m_column << ", " - << " length: " << highlightingMark.m_length + os << "(type: " << tokenInfo.m_types << ", " + << " line: " << tokenInfo.m_line << ", " + << " column: " << tokenInfo.m_column << ", " + << " length: " << tokenInfo.m_length << ")"; return os; diff --git a/src/tools/clangbackend/source/highlightingmark.h b/src/tools/clangbackend/source/tokeninfo.h similarity index 84% rename from src/tools/clangbackend/source/highlightingmark.h rename to src/tools/clangbackend/source/tokeninfo.h index 013ef55861a..951a6f99a6f 100644 --- a/src/tools/clangbackend/source/highlightingmark.h +++ b/src/tools/clangbackend/source/tokeninfo.h @@ -26,7 +26,7 @@ #pragma once #include -#include +#include #include "cursor.h" @@ -34,9 +34,9 @@ namespace ClangBackEnd { -class HighlightingMark +class TokenInfo { - friend bool operator==(const HighlightingMark &first, const HighlightingMark &second); + friend bool operator==(const TokenInfo &first, const TokenInfo &second); enum class Recursion { FirstPass, @@ -44,12 +44,12 @@ class HighlightingMark }; public: - HighlightingMark(const CXCursor &cxCursor, + TokenInfo(const CXCursor &cxCursor, CXToken *cxToken, CXTranslationUnit cxTranslationUnit, std::vector &m_currentOutputArgumentRanges); - HighlightingMark(uint m_line, uint m_column, uint m_length, HighlightingTypes m_types); - HighlightingMark(uint m_line, uint m_column, uint m_length, HighlightingType type); + TokenInfo(uint m_line, uint m_column, uint m_length, HighlightingTypes m_types); + TokenInfo(uint m_line, uint m_column, uint m_length, HighlightingType type); bool hasInvalidMainType() const; bool hasMainType(HighlightingType type) const; @@ -59,7 +59,7 @@ public: bool hasOnlyType(HighlightingType type) const; bool hasFunctionArguments() const; - operator HighlightingMarkContainer() const; + operator TokenInfoContainer() const; private: void identifierKind(const Cursor &cursor, Recursion recursion); @@ -80,7 +80,7 @@ private: void filterOutPreviousOutputArguments(); bool isArgumentInCurrentOutputArgumentLocations() const; - friend std::ostream &operator<<(std::ostream &os, const HighlightingMark& highlightingMark); + friend std::ostream &operator<<(std::ostream &os, const TokenInfo& tokenInfo); private: std::vector *m_currentOutputArgumentRanges = nullptr; @@ -95,7 +95,7 @@ private: }; -inline bool operator==(const HighlightingMark &first, const HighlightingMark &second) +inline bool operator==(const TokenInfo &first, const TokenInfo &second) { return first.m_line == second.m_line && first.m_column == second.m_column diff --git a/src/tools/clangbackend/source/highlightingmarks.cpp b/src/tools/clangbackend/source/tokeninfos.cpp similarity index 63% rename from src/tools/clangbackend/source/highlightingmarks.cpp rename to src/tools/clangbackend/source/tokeninfos.cpp index ed8ddfdd656..168601fb58d 100644 --- a/src/tools/clangbackend/source/highlightingmarks.cpp +++ b/src/tools/clangbackend/source/tokeninfos.cpp @@ -23,15 +23,15 @@ ** ****************************************************************************/ -#include "highlightingmarks.h" +#include "tokeninfos.h" -#include "highlightingmarkcontainer.h" +#include "tokeninfocontainer.h" #include namespace ClangBackEnd { -HighlightingMarks::HighlightingMarks(CXTranslationUnit cxTranslationUnit, CXToken *tokens, uint tokensCount) +TokenInfos::TokenInfos(CXTranslationUnit cxTranslationUnit, CXToken *tokens, uint tokensCount) : cxTranslationUnit(cxTranslationUnit), cxToken(tokens), cxTokenCount(tokensCount) @@ -40,12 +40,12 @@ HighlightingMarks::HighlightingMarks(CXTranslationUnit cxTranslationUnit, CXToke clang_annotateTokens(cxTranslationUnit, cxToken, cxTokenCount, cxCursor.data()); } -HighlightingMarks::~HighlightingMarks() +TokenInfos::~TokenInfos() { clang_disposeTokens(cxTranslationUnit, cxToken, cxTokenCount); } -HighlightingMarks::const_iterator HighlightingMarks::begin() const +TokenInfos::const_iterator TokenInfos::begin() const { return const_iterator(cxCursor.cbegin(), cxToken, @@ -53,7 +53,7 @@ HighlightingMarks::const_iterator HighlightingMarks::begin() const currentOutputArgumentRanges); } -HighlightingMarks::const_iterator HighlightingMarks::end() const +TokenInfos::const_iterator TokenInfos::end() const { return const_iterator(cxCursor.cend(), cxToken + cxTokenCount, @@ -61,56 +61,56 @@ HighlightingMarks::const_iterator HighlightingMarks::end() const currentOutputArgumentRanges); } -QVector HighlightingMarks::toHighlightingMarksContainers() const +QVector TokenInfos::toTokenInfoContainers() const { - QVector containers; + QVector containers; containers.reserve(size()); - const auto isValidHighlightMark = [] (const HighlightingMark &highlightMark) { - return !highlightMark.hasInvalidMainType() - && !highlightMark.hasMainType(HighlightingType::NumberLiteral) - && !highlightMark.hasMainType(HighlightingType::Comment); + const auto isValidTokenInfo = [] (const TokenInfo &tokenInfo) { + return !tokenInfo.hasInvalidMainType() + && !tokenInfo.hasMainType(HighlightingType::NumberLiteral) + && !tokenInfo.hasMainType(HighlightingType::Comment); }; - for (const HighlightingMark &highlightMark : *this) - if (isValidHighlightMark(highlightMark)) - containers.push_back(highlightMark); + for (const TokenInfo &tokenInfo : *this) + if (isValidTokenInfo(tokenInfo)) + containers.push_back(tokenInfo); return containers; } -bool HighlightingMarks::currentOutputArgumentRangesAreEmpty() const +bool TokenInfos::currentOutputArgumentRangesAreEmpty() const { return currentOutputArgumentRanges.empty(); } -bool HighlightingMarks::isEmpty() const +bool TokenInfos::isEmpty() const { return cxTokenCount == 0; } -bool ClangBackEnd::HighlightingMarks::isNull() const +bool ClangBackEnd::TokenInfos::isNull() const { return cxToken == nullptr; } -uint HighlightingMarks::size() const +uint TokenInfos::size() const { return cxTokenCount; } -HighlightingMark HighlightingMarks::operator[](size_t index) const +TokenInfo TokenInfos::operator[](size_t index) const { - return HighlightingMark(cxCursor[index], + return TokenInfo(cxCursor[index], cxToken + index, cxTranslationUnit, currentOutputArgumentRanges); } -std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks) +std::ostream &operator<<(std::ostream &out, const TokenInfos &marks) { out << "["; - for (const HighlightingMark entry : marks) + for (const TokenInfo entry : marks) out << entry; out << "]"; diff --git a/src/tools/clangbackend/source/highlightingmarks.h b/src/tools/clangbackend/source/tokeninfos.h similarity index 76% rename from src/tools/clangbackend/source/highlightingmarks.h rename to src/tools/clangbackend/source/tokeninfos.h index e573dc267e4..15e3ba50c25 100644 --- a/src/tools/clangbackend/source/highlightingmarks.h +++ b/src/tools/clangbackend/source/tokeninfos.h @@ -25,7 +25,7 @@ #pragma once -#include "highlightingmarksiterator.h" +#include "tokeninfositerator.h" #include @@ -34,29 +34,29 @@ namespace ClangBackEnd { using uint = unsigned int; -class HighlightingMarkContainer; +class TokenInfoContainer; -class HighlightingMarks +class TokenInfos { public: - using const_iterator = HighlightingMarksIterator; - using value_type = HighlightingMark; + using const_iterator = TokenInfosIterator; + using value_type = TokenInfo; public: - HighlightingMarks() = default; - HighlightingMarks(CXTranslationUnit cxTranslationUnit, CXToken *tokens, uint tokensCount); - ~HighlightingMarks(); + TokenInfos() = default; + TokenInfos(CXTranslationUnit cxTranslationUnit, CXToken *tokens, uint tokensCount); + ~TokenInfos(); bool isEmpty() const; bool isNull() const; uint size() const; - HighlightingMark operator[](size_t index) const; + TokenInfo operator[](size_t index) const; const_iterator begin() const; const_iterator end() const; - QVector toHighlightingMarksContainers() const; + QVector toTokenInfoContainers() const; bool currentOutputArgumentRangesAreEmpty() const; @@ -69,6 +69,6 @@ private: std::vector cxCursor; }; -std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks); +std::ostream &operator<<(std::ostream &out, const TokenInfos &marks); } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/highlightingmarksiterator.h b/src/tools/clangbackend/source/tokeninfositerator.h similarity index 81% rename from src/tools/clangbackend/source/highlightingmarksiterator.h rename to src/tools/clangbackend/source/tokeninfositerator.h index daeada47a76..6379ee846fe 100644 --- a/src/tools/clangbackend/source/highlightingmarksiterator.h +++ b/src/tools/clangbackend/source/tokeninfositerator.h @@ -25,7 +25,7 @@ #pragma once -#include "highlightingmark.h" +#include "tokeninfo.h" #include #include @@ -39,10 +39,10 @@ using uint = unsigned int; class DiagnosticSet; class Diagnostic; -class HighlightingMarksIterator : public std::iterator +class TokenInfosIterator : public std::iterator { public: - HighlightingMarksIterator(std::vector::const_iterator cxCursorIterator, + TokenInfosIterator(std::vector::const_iterator cxCursorIterator, CXToken *cxToken, CXTranslationUnit cxTranslationUnit, std::vector ¤tOutputArgumentRanges) @@ -52,7 +52,7 @@ public: currentOutputArgumentRanges(currentOutputArgumentRanges) {} - HighlightingMarksIterator& operator++() + TokenInfosIterator& operator++() { ++cxCursorIterator; ++cxToken; @@ -60,27 +60,27 @@ public: return *this; } - HighlightingMarksIterator operator++(int) + TokenInfosIterator operator++(int) { - return HighlightingMarksIterator(cxCursorIterator++, + return TokenInfosIterator(cxCursorIterator++, cxToken++, cxTranslationUnit, currentOutputArgumentRanges); } - bool operator==(HighlightingMarksIterator other) const + bool operator==(TokenInfosIterator other) const { return cxCursorIterator == other.cxCursorIterator; } - bool operator!=(HighlightingMarksIterator other) const + bool operator!=(TokenInfosIterator other) const { return cxCursorIterator != other.cxCursorIterator; } - HighlightingMark operator*() + TokenInfo operator*() { - return HighlightingMark(*cxCursorIterator, + return TokenInfo(*cxCursorIterator, cxToken, cxTranslationUnit, currentOutputArgumentRanges); diff --git a/tests/unit/unittest/clangcodemodelserver-test.cpp b/tests/unit/unittest/clangcodemodelserver-test.cpp index f580e8ab0e7..9a3b36d8550 100644 --- a/tests/unit/unittest/clangcodemodelserver-test.cpp +++ b/tests/unit/unittest/clangcodemodelserver-test.cpp @@ -29,7 +29,7 @@ #include "processevents-utilities.h" #include -#include +#include #include #include #include @@ -630,12 +630,12 @@ void ClangCodeModelServer::expectDocumentAnnotationsChangedForFileBWithSpecificH types.mainHighlightingType = ClangBackEnd::HighlightingType::Function; types.mixinHighlightingTypes.push_back(ClangBackEnd::HighlightingType::Declaration); types.mixinHighlightingTypes.push_back(ClangBackEnd::HighlightingType::FunctionDefinition); - const HighlightingMarkContainer highlightingMark(1, 6, 8, types, true); + const TokenInfoContainer tokenInfo(1, 6, 8, types, true); EXPECT_CALL(mockClangCodeModelClient, documentAnnotationsChanged( - Property(&DocumentAnnotationsChangedMessage::highlightingMarks, - Contains(highlightingMark)))) + Property(&DocumentAnnotationsChangedMessage::tokenInfos, + Contains(tokenInfo)))) .Times(1); } diff --git a/tests/unit/unittest/clangdocument-test.cpp b/tests/unit/unittest/clangdocument-test.cpp index c6e843efb99..a830dbbe1a6 100644 --- a/tests/unit/unittest/clangdocument-test.cpp +++ b/tests/unit/unittest/clangdocument-test.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/unittest/clientserverinprocess-test.cpp b/tests/unit/unittest/clientserverinprocess-test.cpp index f45677e4476..b02c519dad3 100644 --- a/tests/unit/unittest/clientserverinprocess-test.cpp +++ b/tests/unit/unittest/clientserverinprocess-test.cpp @@ -227,7 +227,7 @@ TEST_F(ClientServerInProcess, UpdateVisibleTranslationUnitsMessage) TEST_F(ClientServerInProcess, SendDocumentAnnotationsChangedMessage) { - ClangBackEnd::HighlightingMarkContainer highlightingMark(1, 1, 1, ClangBackEnd::HighlightingType::Keyword); + ClangBackEnd::TokenInfoContainer tokenInfo(1, 1, 1, ClangBackEnd::HighlightingType::Keyword); ClangBackEnd::DiagnosticContainer diagnostic(Utf8StringLiteral("don't do that"), Utf8StringLiteral("warning"), {Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")}, @@ -240,7 +240,7 @@ TEST_F(ClientServerInProcess, SendDocumentAnnotationsChangedMessage) ClangBackEnd::DocumentAnnotationsChangedMessage message(fileContainer, {diagnostic}, {}, - {highlightingMark}, + {tokenInfo}, QVector()); diff --git a/tests/unit/unittest/highlightingmarks-test.cpp b/tests/unit/unittest/highlightingmarks-test.cpp deleted file mode 100644 index 5e9fb77c285..00000000000 --- a/tests/unit/unittest/highlightingmarks-test.cpp +++ /dev/null @@ -1,1267 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "testenvironment.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using ClangBackEnd::Cursor; -using ClangBackEnd::HighlightingTypes; -using ClangBackEnd::HighlightingMark; -using ClangBackEnd::HighlightingMarks; -using ClangBackEnd::HighlightingType; -using ClangBackEnd::Document; -using ClangBackEnd::Documents; -using ClangBackEnd::TranslationUnit; -using ClangBackEnd::UnsavedFiles; -using ClangBackEnd::ProjectPart; -using ClangBackEnd::ClangString; -using ClangBackEnd::SourceRange; - -using testing::PrintToString; -using testing::IsNull; -using testing::NotNull; -using testing::Gt; -using testing::Contains; -using testing::ElementsAre; -using testing::_; -using testing::EndsWith; -using testing::AllOf; -using testing::Not; -using testing::IsEmpty; -using testing::SizeIs; - -namespace { - -MATCHER_P4(IsHighlightingMark, line, column, length, type, - std::string(negation ? "isn't " : "is ") - + PrintToString(HighlightingMark(line, column, length, type)) - ) -{ - const HighlightingMark expected(line, column, length, type); - - return arg == expected; -} - -MATCHER_P(HasOnlyType, type, - std::string(negation ? "isn't " : "is ") - + PrintToString(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.hasMixinTypeAt(0, secondType) && arg.mixinSize() == 1; -} - -MATCHER_P3(HasThreeTypes, firstType, secondType, thirdType, - std::string(negation ? "isn't " : "is ") - + PrintToString(firstType) - + ", " - + PrintToString(secondType) - + " and " - + PrintToString(thirdType) - ) -{ - return arg.hasMainType(firstType) && arg.hasMixinTypeAt(0, secondType) && arg.hasMixinTypeAt(1, thirdType) && arg.mixinSize() == 2; -} - -MATCHER_P(HasMixin, mixinType, - std::string(negation ? "isn't " : "is ") - + PrintToString(mixinType) - ) -{ - return arg.hasMixinType(mixinType); -} - -struct Data { - Data() - { - document.parse(); - } - - ClangBackEnd::ProjectParts projects; - ClangBackEnd::UnsavedFiles unsavedFiles; - ClangBackEnd::Documents documents{projects, unsavedFiles}; - Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp")}; - Document document{filePath, - ProjectPart(Utf8StringLiteral("projectPartId"), - TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14"), - Utf8StringLiteral("-I" TESTDATA_DIR)})), - {}, - documents}; - TranslationUnit translationUnit{filePath, - filePath, - document.translationUnit().cxIndex(), - document.translationUnit().cxTranslationUnit()}; -}; - -class HighlightingMarks : public ::testing::Test -{ -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - - SourceRange sourceRange(uint line, uint columnEnd) const; - -protected: - static Data *d; - const TranslationUnit &translationUnit = d->translationUnit; -}; - -TEST_F(HighlightingMarks, CreateNullInformations) -{ - ::HighlightingMarks infos; - - ASSERT_TRUE(infos.isNull()); -} - -TEST_F(HighlightingMarks, NullInformationsAreEmpty) -{ - ::HighlightingMarks infos; - - ASSERT_TRUE(infos.isEmpty()); -} - -TEST_F(HighlightingMarks, IsNotNull) -{ - const auto aRange = translationUnit.sourceRange(3, 1, 5, 1); - - const auto infos = translationUnit.highlightingMarksInRange(aRange); - - ASSERT_FALSE(infos.isNull()); -} - -TEST_F(HighlightingMarks, IteratorBeginEnd) -{ - const auto aRange = translationUnit.sourceRange(3, 1, 5, 1); - const auto infos = translationUnit.highlightingMarksInRange(aRange); - - const auto endIterator = std::next(infos.begin(), infos.size()); - - ASSERT_THAT(infos.end(), endIterator); -} - -TEST_F(HighlightingMarks, ForFullTranslationUnitRange) -{ - const auto infos = translationUnit.highlightingMarks(); - - ASSERT_THAT(infos, AllOf(Contains(IsHighlightingMark(1u, 1u, 4u, HighlightingType::Keyword)), - Contains(IsHighlightingMark(277u, 5u, 15u, HighlightingType::Function)))); -} - -TEST_F(HighlightingMarks, Size) -{ - const auto range = translationUnit.sourceRange(5, 5, 5, 10); - - const auto infos = translationUnit.highlightingMarksInRange(range); - - ASSERT_THAT(infos.size(), 1); -} - -TEST_F(HighlightingMarks, DISABLED_Keyword) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(5, 12)); - - ASSERT_THAT(infos[0], IsHighlightingMark(5u, 5u, 6u, HighlightingType::Keyword)); -} - -TEST_F(HighlightingMarks, StringLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(1, 29)); - - ASSERT_THAT(infos[4], IsHighlightingMark(1u, 24u, 10u, HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, Utf8StringLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(2, 33)); - - ASSERT_THAT(infos[4], IsHighlightingMark(2u, 24u, 12u, HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, RawStringLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(3, 34)); - - ASSERT_THAT(infos[4], IsHighlightingMark(3u, 24u, 13u, HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, CharacterLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(4, 28)); - - ASSERT_THAT(infos[3], IsHighlightingMark(4u, 24u, 3u, HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, IntegerLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(23, 26)); - - ASSERT_THAT(infos[3], IsHighlightingMark(23u, 24u, 1u, HighlightingType::NumberLiteral)); -} - -TEST_F(HighlightingMarks, FloatLiteral) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(24, 29)); - - ASSERT_THAT(infos[3], IsHighlightingMark(24u, 24u, 4u, HighlightingType::NumberLiteral)); -} - -TEST_F(HighlightingMarks, FunctionDefinition) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(45, 20)); - - ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Function, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); -} - -TEST_F(HighlightingMarks, MemberFunctionDefinition) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(52, 29)); - - ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Function, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); -} - -TEST_F(HighlightingMarks, VirtualMemberFunctionDefinitionOutsideOfClassBody) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(586, 37)); - - ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); -} - -TEST_F(HighlightingMarks, VirtualMemberFunctionDefinitionInsideOfClassBody) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(589, 47)); - - ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); -} - -TEST_F(HighlightingMarks, FunctionDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(55, 32)); - - 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], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); -} - -TEST_F(HighlightingMarks, MemberFunctionReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(104, 35)); - - ASSERT_THAT(infos[0], IsHighlightingMark(104u, 9u, 23u, HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, FunctionCall) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(64, 16)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, TypeConversionFunction) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(68, 20)); - - ASSERT_THAT(infos[1], IsHighlightingMark(68u, 14u, 3u, HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, InbuiltTypeConversionFunction) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(69, 20)); - - ASSERT_THAT(infos[1], IsHighlightingMark(69u, 14u, 3u, HighlightingType::PrimitiveType)); -} - -TEST_F(HighlightingMarks, TypeReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(74, 13)); - - ASSERT_THAT(infos[0], IsHighlightingMark(74u, 5u, 3u, HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, LocalVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(79, 13)); - - ASSERT_THAT(infos[1], IsHighlightingMark(79u, 9u, 3u, HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, LocalVariableDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(79, 13)); - - ASSERT_THAT(infos[1], IsHighlightingMark(79u, 9u, 3u, HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, LocalVariableReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(81, 26)); - - ASSERT_THAT(infos[0], IsHighlightingMark(81u, 5u, 3u, HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, LocalVariableFunctionArgumentDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(84, 45)); - - ASSERT_THAT(infos[5], IsHighlightingMark(84u, 41u, 3u, HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, LocalVariableFunctionArgumentReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(86, 26)); - - ASSERT_THAT(infos[0], IsHighlightingMark(86u, 5u, 3u, HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, ClassVariableDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(90, 21)); - - ASSERT_THAT(infos[1], IsHighlightingMark(90u, 9u, 11u, HighlightingType::Field)); -} - -TEST_F(HighlightingMarks, ClassVariableReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(94, 23)); - - ASSERT_THAT(infos[0], IsHighlightingMark(94u, 9u, 11u, HighlightingType::Field)); -} - -TEST_F(HighlightingMarks, StaticMethodDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(110, 25)); - - 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], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, Enumeration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(118, 17)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, Enumerator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(120, 15)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Enumeration)); -} - -TEST_F(HighlightingMarks, EnumerationReferenceDeclarationType) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, EnumerationReferenceDeclarationVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, EnumerationReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, EnumeratorReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Enumeration)); -} - -TEST_F(HighlightingMarks, ClassForwardDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(130, 12)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, ConstructorDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(134, 13)); - - 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], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); -} - -TEST_F(HighlightingMarks, ClassForwardDeclarationReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(138, 23)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, ClassTypeReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, ConstructorReferenceVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, UnionDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(145, 12)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, UnionDeclarationReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, GlobalVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::GlobalVariable)); -} - -TEST_F(HighlightingMarks, StructDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(50, 11)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NameSpace) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(160, 22)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NameSpaceAlias) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(164, 38)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, UsingStructInNameSpace) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(165, 36)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NameSpaceReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, StructInNameSpaceReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, VirtualFunctionDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(170, 35)); - - 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], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, DISABLED_NonVirtualFunctionCallPointer) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(180, 54)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, VirtualFunctionCallPointer) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(192, 51)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); -} - -TEST_F(HighlightingMarks, FinalVirtualFunctionCallPointer) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(202, 61)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, NonFinalVirtualFunctionCallPointer) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(207, 61)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); -} - -TEST_F(HighlightingMarks, PlusOperator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(224, 49)); - - ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Operator)); -} - -TEST_F(HighlightingMarks, PlusAssignOperator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(226, 24)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Operator)); -} - -TEST_F(HighlightingMarks, Comment) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(229, 14)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Comment)); -} - -TEST_F(HighlightingMarks, PreprocessingDirective) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); -} - -TEST_F(HighlightingMarks, PreprocessorMacroDefinition) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); -} - -TEST_F(HighlightingMarks, PreprocessorFunctionMacroDefinition) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(232, 47)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); -} - -TEST_F(HighlightingMarks, PreprocessorMacroExpansion) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion)); -} - -TEST_F(HighlightingMarks, PreprocessorMacroExpansionArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral)); -} - -TEST_F(HighlightingMarks, PreprocessorInclusionDirective) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(239, 18)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, GotoLabelStatement) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(242, 12)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Label)); -} - -TEST_F(HighlightingMarks, GotoLabelStatementReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(244, 21)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Label)); -} - -TEST_F(HighlightingMarks, TemplateReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(254, 25)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, TemplateTypeParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateDefaultParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NonTypeTemplateParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonTypeTemplateParameterDefaultArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::NumberLiteral)); -} - -TEST_F(HighlightingMarks, TemplateTemplateParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[17], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateTemplateParameterDefaultArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); - - ASSERT_THAT(infos[19], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateFunctionDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(266, 63)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, TemplateTypeParameterReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateTypeParameterDeclarationReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonTypeTemplateParameterReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonTypeTemplateParameterReferenceReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, TemplateTemplateParameterReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateTemplateContainerParameterReference) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateTemplateParameterReferenceVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); - - ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCallPointer) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(212, 61)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCall) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(277, 23)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, HasFunctionArguments) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(286, 29)); - - ASSERT_TRUE(infos[1].hasFunctionArguments()); -} - -TEST_F(HighlightingMarks, PreprocessorInclusionDirectiveWithAngleBrackets ) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(289, 38)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); -} - -TEST_F(HighlightingMarks, ArgumentInMacroExpansionIsKeyword) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PrimitiveType)); -} - -TEST_F(HighlightingMarks, DISABLED_FirstArgumentInMacroExpansionIsLocalVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); -} - -TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsLocalVariable) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); - - ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); -} - -TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsField) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(310, 40)); - - ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); -} - - -TEST_F(HighlightingMarks, EnumerationType) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(316, 30)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TypeInStaticCast) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - - ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, StaticCastIsKeyword) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword)); -} - -TEST_F(HighlightingMarks, StaticCastPunctationIsInvalid) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); - - 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], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, IntegerAliasDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(333, 41)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, IntegerAlias) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(341, 31)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, SecondIntegerAlias) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(342, 43)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, IntegerTypedef) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(343, 35)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, FunctionAlias) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(344, 16)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, FriendTypeDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(350, 28)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, FriendArgumentTypeDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); - - ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, FriendArgumentDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); - - ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, FieldInitialization) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(358, 18)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Field)); -} - -TEST_F(HighlightingMarks, TemplateFunctionCall) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(372, 29)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, TemplatedType) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(377, 21)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplatedTypeDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(384, 49)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NoOperator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(389, 24)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); -} - -TEST_F(HighlightingMarks, ScopeOperator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(400, 33)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); -} - -TEST_F(HighlightingMarks, TemplateClassNamespace) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateClass) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateClassParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - - ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TemplateClassDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); - - ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, TypeDefDeclaration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(418, 36)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, TypeDefDeclarationUsage) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(419, 48)); - - ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, NonConstReferenceArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(455, 35)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, ConstReferenceArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(464, 32)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, RValueReferenceArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(473, 52)); - - infos[1]; - - ASSERT_THAT(infos[8], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonConstPointerArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(482, 33)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, PointerToConstArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(490, 31)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, ConstPointerArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(491, 30)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonConstPointerGetterAsArgument) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(580, 42)); - - infos[1]; - - ASSERT_THAT(infos[2] ,HasMixin(HighlightingType::OutputArgument)); - ASSERT_THAT(infos[3], HasMixin(HighlightingType::OutputArgument)); - ASSERT_THAT(infos[4], HasMixin(HighlightingType::OutputArgument)); - ASSERT_THAT(infos[5], HasMixin(HighlightingType::OutputArgument)); - ASSERT_THAT(infos[6], HasMixin(HighlightingType::OutputArgument)); - ASSERT_THAT(infos[7], Not(HasMixin(HighlightingType::OutputArgument))); -} - -TEST_F(HighlightingMarks, NonConstReferenceArgumentCallInsideCall) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(501, 64)); - infos[1]; - - infos[3]; - - ASSERT_THAT(infos[7], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, OutputArgumentsAreEmptyAfterIteration) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(501, 63)); - - for (const auto &info : infos ) { Q_UNUSED(info) } - - ASSERT_TRUE(infos.currentOutputArgumentRangesAreEmpty()); -} - -TEST_F(HighlightingMarks, NonConstReferenceArgumentFromFunctionParameter) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(506, 42)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, NonConstPointerArgumentAsExpression) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(513, 33)); - - infos[1]; - - ASSERT_THAT(infos[3], - HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, NonConstPointerArgumentAsInstanceWithMember) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(525, 46)); - - infos[1]; - - ASSERT_THAT(infos[2], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, NonConstPointerArgumentAsMemberOfInstance) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(525, 46)); - - infos[1]; - infos[2]; - - ASSERT_THAT(infos[4], - HasTwoTypes(HighlightingType::Field, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, DISABLED_NonConstReferenceArgumentConstructor) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(540, 57)); - - infos[2]; - - ASSERT_THAT(infos[3], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, DISABLED_NonConstReferenceMemberInitialization) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(546, 19)); - - infos[2]; - - ASSERT_THAT(infos[3], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); -} - -TEST_F(HighlightingMarks, EnumerationTypeDef) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(424, 41)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); -} - -// QTCREATORBUG-15473 -TEST_F(HighlightingMarks, DISABLED_ArgumentToUserDefinedIndexOperator) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(434, 19)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, ClassTemplateParticalSpecialization) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(553, 33)); - - ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Type)); -} - -TEST_F(HighlightingMarks, UsingFunction) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(556, 27)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, PreprocessorIfDirective) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(558, 6)); - - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); -} - -TEST_F(HighlightingMarks, PreprocessorInclusionDirectiveWithKeyword) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(561, 15)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); -} - -// CLANG-UPGRADE-CHECK: Enable once https://bugs.llvm.org//show_bug.cgi?id=12972 is resolved. -TEST_F(HighlightingMarks, DISABLED_VariableInOperatorFunctionCall) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(566, 12)); - - ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); -} - -TEST_F(HighlightingMarks, UsingTemplateFunction) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(584, 17)); - - ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function)); -} - -TEST_F(HighlightingMarks, HeaderNameIsInclusion) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(239, 31)); - ClangBackEnd::HighlightingMarkContainer container(infos[2]); - ASSERT_THAT(container.isIncludeDirectivePath(), true); -} - -TEST_F(HighlightingMarks, HeaderNameIsInclusionWithAngleBrackets) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(289, 31)); - ClangBackEnd::HighlightingMarkContainer container(infos[2]); - ASSERT_THAT(container.isIncludeDirectivePath(), true); -} - - -TEST_F(HighlightingMarks, NotInclusion) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(241, 13)); - ClangBackEnd::HighlightingMarkContainer container(infos[1]); - ASSERT_THAT(container.isIncludeDirectivePath(), false); -} - -TEST_F(HighlightingMarks, MacroIsIdentifier) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(232, 30)); - ClangBackEnd::HighlightingMarkContainer container(infos[2]); - ASSERT_THAT(container.isIdentifier(), true); -} - -TEST_F(HighlightingMarks, DefineIsNotIdentifier) -{ - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(232, 30)); - ClangBackEnd::HighlightingMarkContainer container(infos[1]); - ASSERT_THAT(container.isIncludeDirectivePath(), false); -} - -Data *HighlightingMarks::d; - -void HighlightingMarks::SetUpTestCase() -{ - d = new Data; -} - -void HighlightingMarks::TearDownTestCase() -{ - delete d; - d = nullptr; -} - -ClangBackEnd::SourceRange HighlightingMarks::sourceRange(uint line, uint columnEnd) const -{ - return translationUnit.sourceRange(line, 1, line, columnEnd); -} - -} diff --git a/tests/unit/unittest/readandwritemessageblock-test.cpp b/tests/unit/unittest/readandwritemessageblock-test.cpp index 0c9e9db18d5..cf69837dc0b 100644 --- a/tests/unit/unittest/readandwritemessageblock-test.cpp +++ b/tests/unit/unittest/readandwritemessageblock-test.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -174,12 +174,12 @@ TEST_F(ReadAndWriteMessageBlock, CompareDocumentAnnotationsChangedMessage) {}, {}); - ClangBackEnd::HighlightingMarkContainer highlightingMark(1, 1, 1, ClangBackEnd::HighlightingType::Keyword); + ClangBackEnd::TokenInfoContainer tokenInfo(1, 1, 1, ClangBackEnd::HighlightingType::Keyword); CompareMessage(ClangBackEnd::DocumentAnnotationsChangedMessage(fileContainer, {diagnostic}, {}, - {highlightingMark}, + {tokenInfo}, QVector())); } diff --git a/tests/unit/unittest/tokeninfos-test.cpp b/tests/unit/unittest/tokeninfos-test.cpp new file mode 100644 index 00000000000..0d9b34f4b67 --- /dev/null +++ b/tests/unit/unittest/tokeninfos-test.cpp @@ -0,0 +1,1267 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include "googletest.h" +#include "testenvironment.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using ClangBackEnd::Cursor; +using ClangBackEnd::HighlightingTypes; +using ClangBackEnd::TokenInfo; +using ClangBackEnd::TokenInfos; +using ClangBackEnd::HighlightingType; +using ClangBackEnd::Document; +using ClangBackEnd::Documents; +using ClangBackEnd::TranslationUnit; +using ClangBackEnd::UnsavedFiles; +using ClangBackEnd::ProjectPart; +using ClangBackEnd::ClangString; +using ClangBackEnd::SourceRange; + +using testing::PrintToString; +using testing::IsNull; +using testing::NotNull; +using testing::Gt; +using testing::Contains; +using testing::ElementsAre; +using testing::_; +using testing::EndsWith; +using testing::AllOf; +using testing::Not; +using testing::IsEmpty; +using testing::SizeIs; + +namespace { + +MATCHER_P4(IsHighlightingMark, line, column, length, type, + std::string(negation ? "isn't " : "is ") + + PrintToString(TokenInfo(line, column, length, type)) + ) +{ + const TokenInfo expected(line, column, length, type); + + return arg == expected; +} + +MATCHER_P(HasOnlyType, type, + std::string(negation ? "isn't " : "is ") + + PrintToString(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.hasMixinTypeAt(0, secondType) && arg.mixinSize() == 1; +} + +MATCHER_P3(HasThreeTypes, firstType, secondType, thirdType, + std::string(negation ? "isn't " : "is ") + + PrintToString(firstType) + + ", " + + PrintToString(secondType) + + " and " + + PrintToString(thirdType) + ) +{ + return arg.hasMainType(firstType) && arg.hasMixinTypeAt(0, secondType) && arg.hasMixinTypeAt(1, thirdType) && arg.mixinSize() == 2; +} + +MATCHER_P(HasMixin, mixinType, + std::string(negation ? "isn't " : "is ") + + PrintToString(mixinType) + ) +{ + return arg.hasMixinType(mixinType); +} + +struct Data { + Data() + { + document.parse(); + } + + ClangBackEnd::ProjectParts projects; + ClangBackEnd::UnsavedFiles unsavedFiles; + ClangBackEnd::Documents documents{projects, unsavedFiles}; + Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp")}; + Document document{filePath, + ProjectPart(Utf8StringLiteral("projectPartId"), + TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14"), + Utf8StringLiteral("-I" TESTDATA_DIR)})), + {}, + documents}; + TranslationUnit translationUnit{filePath, + filePath, + document.translationUnit().cxIndex(), + document.translationUnit().cxTranslationUnit()}; +}; + +class TokenInfos : public ::testing::Test +{ +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + SourceRange sourceRange(uint line, uint columnEnd) const; + +protected: + static Data *d; + const TranslationUnit &translationUnit = d->translationUnit; +}; + +TEST_F(TokenInfos, CreateNullInformations) +{ + ::TokenInfos infos; + + ASSERT_TRUE(infos.isNull()); +} + +TEST_F(TokenInfos, NullInformationsAreEmpty) +{ + ::TokenInfos infos; + + ASSERT_TRUE(infos.isEmpty()); +} + +TEST_F(TokenInfos, IsNotNull) +{ + const auto aRange = translationUnit.sourceRange(3, 1, 5, 1); + + const auto infos = translationUnit.tokenInfosInRange(aRange); + + ASSERT_FALSE(infos.isNull()); +} + +TEST_F(TokenInfos, IteratorBeginEnd) +{ + const auto aRange = translationUnit.sourceRange(3, 1, 5, 1); + const auto infos = translationUnit.tokenInfosInRange(aRange); + + const auto endIterator = std::next(infos.begin(), infos.size()); + + ASSERT_THAT(infos.end(), endIterator); +} + +TEST_F(TokenInfos, ForFullTranslationUnitRange) +{ + const auto infos = translationUnit.tokenInfos(); + + ASSERT_THAT(infos, AllOf(Contains(IsHighlightingMark(1u, 1u, 4u, HighlightingType::Keyword)), + Contains(IsHighlightingMark(277u, 5u, 15u, HighlightingType::Function)))); +} + +TEST_F(TokenInfos, Size) +{ + const auto range = translationUnit.sourceRange(5, 5, 5, 10); + + const auto infos = translationUnit.tokenInfosInRange(range); + + ASSERT_THAT(infos.size(), 1); +} + +TEST_F(TokenInfos, DISABLED_Keyword) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(5, 12)); + + ASSERT_THAT(infos[0], IsHighlightingMark(5u, 5u, 6u, HighlightingType::Keyword)); +} + +TEST_F(TokenInfos, StringLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(1, 29)); + + ASSERT_THAT(infos[4], IsHighlightingMark(1u, 24u, 10u, HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, Utf8StringLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(2, 33)); + + ASSERT_THAT(infos[4], IsHighlightingMark(2u, 24u, 12u, HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, RawStringLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(3, 34)); + + ASSERT_THAT(infos[4], IsHighlightingMark(3u, 24u, 13u, HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, CharacterLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(4, 28)); + + ASSERT_THAT(infos[3], IsHighlightingMark(4u, 24u, 3u, HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, IntegerLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(23, 26)); + + ASSERT_THAT(infos[3], IsHighlightingMark(23u, 24u, 1u, HighlightingType::NumberLiteral)); +} + +TEST_F(TokenInfos, FloatLiteral) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(24, 29)); + + ASSERT_THAT(infos[3], IsHighlightingMark(24u, 24u, 4u, HighlightingType::NumberLiteral)); +} + +TEST_F(TokenInfos, FunctionDefinition) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(45, 20)); + + ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Function, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); +} + +TEST_F(TokenInfos, MemberFunctionDefinition) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(52, 29)); + + ASSERT_THAT(infos[1], HasThreeTypes(HighlightingType::Function, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); +} + +TEST_F(TokenInfos, VirtualMemberFunctionDefinitionOutsideOfClassBody) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(586, 37)); + + ASSERT_THAT(infos[3], HasThreeTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); +} + +TEST_F(TokenInfos, VirtualMemberFunctionDefinitionInsideOfClassBody) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(589, 47)); + + ASSERT_THAT(infos[2], HasThreeTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration, HighlightingType::FunctionDefinition)); +} + +TEST_F(TokenInfos, FunctionDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(55, 32)); + + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, MemberFunctionDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(59, 27)); + + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, MemberFunctionReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(104, 35)); + + ASSERT_THAT(infos[0], IsHighlightingMark(104u, 9u, 23u, HighlightingType::Function)); +} + +TEST_F(TokenInfos, FunctionCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(64, 16)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, TypeConversionFunction) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(68, 20)); + + ASSERT_THAT(infos[1], IsHighlightingMark(68u, 14u, 3u, HighlightingType::Type)); +} + +TEST_F(TokenInfos, InbuiltTypeConversionFunction) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(69, 20)); + + ASSERT_THAT(infos[1], IsHighlightingMark(69u, 14u, 3u, HighlightingType::PrimitiveType)); +} + +TEST_F(TokenInfos, TypeReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(74, 13)); + + ASSERT_THAT(infos[0], IsHighlightingMark(74u, 5u, 3u, HighlightingType::Type)); +} + +TEST_F(TokenInfos, LocalVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(79, 13)); + + ASSERT_THAT(infos[1], IsHighlightingMark(79u, 9u, 3u, HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, LocalVariableDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(79, 13)); + + ASSERT_THAT(infos[1], IsHighlightingMark(79u, 9u, 3u, HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, LocalVariableReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(81, 26)); + + ASSERT_THAT(infos[0], IsHighlightingMark(81u, 5u, 3u, HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, LocalVariableFunctionArgumentDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(84, 45)); + + ASSERT_THAT(infos[5], IsHighlightingMark(84u, 41u, 3u, HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, LocalVariableFunctionArgumentReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(86, 26)); + + ASSERT_THAT(infos[0], IsHighlightingMark(86u, 5u, 3u, HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, ClassVariableDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(90, 21)); + + ASSERT_THAT(infos[1], IsHighlightingMark(90u, 9u, 11u, HighlightingType::Field)); +} + +TEST_F(TokenInfos, ClassVariableReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(94, 23)); + + ASSERT_THAT(infos[0], IsHighlightingMark(94u, 9u, 11u, HighlightingType::Field)); +} + +TEST_F(TokenInfos, StaticMethodDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(110, 25)); + + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, StaticMethodReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(114, 30)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, Enumeration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(118, 17)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, Enumerator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(120, 15)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Enumeration)); +} + +TEST_F(TokenInfos, EnumerationReferenceDeclarationType) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(125, 28)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, EnumerationReferenceDeclarationVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(125, 28)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, EnumerationReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(127, 30)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, EnumeratorReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(127, 30)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Enumeration)); +} + +TEST_F(TokenInfos, ClassForwardDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(130, 12)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, ConstructorDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(134, 13)); + + ASSERT_THAT(infos[0], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, DestructorDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(135, 15)); + + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, ClassForwardDeclarationReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(138, 23)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, ClassTypeReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(140, 32)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, ConstructorReferenceVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(140, 32)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, UnionDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(145, 12)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, UnionDeclarationReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(150, 33)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, GlobalVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(150, 33)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::GlobalVariable)); +} + +TEST_F(TokenInfos, StructDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(50, 11)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NameSpace) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(160, 22)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NameSpaceAlias) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(164, 38)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, UsingStructInNameSpace) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(165, 36)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NameSpaceReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(166, 35)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, StructInNameSpaceReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(166, 35)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, VirtualFunctionDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(170, 35)); + + ASSERT_THAT(infos[2], HasTwoTypes(HighlightingType::VirtualFunction, HighlightingType::Declaration)); +} + +TEST_F(TokenInfos, DISABLED_NonVirtualFunctionCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(177, 46)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, DISABLED_NonVirtualFunctionCallPointer) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(180, 54)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, VirtualFunctionCallPointer) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(192, 51)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); +} + +TEST_F(TokenInfos, FinalVirtualFunctionCallPointer) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(202, 61)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, NonFinalVirtualFunctionCallPointer) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(207, 61)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); +} + +TEST_F(TokenInfos, PlusOperator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(224, 49)); + + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Operator)); +} + +TEST_F(TokenInfos, PlusAssignOperator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(226, 24)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Operator)); +} + +TEST_F(TokenInfos, Comment) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(229, 14)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Comment)); +} + +TEST_F(TokenInfos, PreprocessingDirective) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(231, 37)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); +} + +TEST_F(TokenInfos, PreprocessorMacroDefinition) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(231, 37)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); +} + +TEST_F(TokenInfos, PreprocessorFunctionMacroDefinition) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(232, 47)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); +} + +TEST_F(TokenInfos, PreprocessorMacroExpansion) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(236, 27)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion)); +} + +TEST_F(TokenInfos, PreprocessorMacroExpansionArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(236, 27)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral)); +} + +TEST_F(TokenInfos, PreprocessorInclusionDirective) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(239, 18)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, GotoLabelStatement) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(242, 12)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Label)); +} + +TEST_F(TokenInfos, GotoLabelStatementReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(244, 21)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Label)); +} + +TEST_F(TokenInfos, TemplateReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(254, 25)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, TemplateTypeParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateDefaultParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NonTypeTemplateParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonTypeTemplateParameterDefaultArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::NumberLiteral)); +} + +TEST_F(TokenInfos, TemplateTemplateParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[17], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateTemplateParameterDefaultArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(265, 135)); + + ASSERT_THAT(infos[19], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateFunctionDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(266, 63)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, TemplateTypeParameterReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(268, 58)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateTypeParameterDeclarationReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(268, 58)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonTypeTemplateParameterReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(269, 71)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonTypeTemplateParameterReferenceReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(269, 71)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, TemplateTemplateParameterReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(270, 89)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateTemplateContainerParameterReference) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(270, 89)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateTemplateParameterReferenceVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(270, 89)); + + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, ClassFinalVirtualFunctionCallPointer) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(212, 61)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, ClassFinalVirtualFunctionCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(277, 23)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, HasFunctionArguments) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(286, 29)); + + ASSERT_TRUE(infos[1].hasFunctionArguments()); +} + +TEST_F(TokenInfos, PreprocessorInclusionDirectiveWithAngleBrackets ) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(289, 38)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); +} + +TEST_F(TokenInfos, ArgumentInMacroExpansionIsKeyword) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(302, 36)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PrimitiveType)); +} + +TEST_F(TokenInfos, DISABLED_FirstArgumentInMacroExpansionIsLocalVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(302, 36)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, DISABLED_SecondArgumentInMacroExpansionIsLocalVariable) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(302, 36)); + + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, DISABLED_SecondArgumentInMacroExpansionIsField) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(310, 40)); + + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); +} + + +TEST_F(TokenInfos, EnumerationType) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(316, 30)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TypeInStaticCast) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64)); + + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, StaticCastIsKeyword) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword)); +} + +TEST_F(TokenInfos, StaticCastPunctationIsInvalid) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); + ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, TypeInReinterpretCast) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(329, 69)); + + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, IntegerAliasDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(333, 41)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, IntegerAlias) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(341, 31)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, SecondIntegerAlias) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(342, 43)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, IntegerTypedef) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(343, 35)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, FunctionAlias) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(344, 16)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, FriendTypeDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(350, 28)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, FriendArgumentTypeDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(351, 65)); + + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, FriendArgumentDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(351, 65)); + + ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, FieldInitialization) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(358, 18)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Field)); +} + +TEST_F(TokenInfos, TemplateFunctionCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(372, 29)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, TemplatedType) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(377, 21)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplatedTypeDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(384, 49)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NoOperator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(389, 24)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, ScopeOperator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(400, 33)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, TemplateClassNamespace) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(413, 78)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateClass) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(413, 78)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateClassParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(413, 78)); + + ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TemplateClassDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(413, 78)); + + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, TypeDefDeclaration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(418, 36)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, TypeDefDeclarationUsage) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(419, 48)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, NonConstReferenceArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(455, 35)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, ConstReferenceArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(464, 32)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, RValueReferenceArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(473, 52)); + + infos[1]; + + ASSERT_THAT(infos[8], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonConstPointerArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(482, 33)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, PointerToConstArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(490, 31)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, ConstPointerArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(491, 30)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonConstPointerGetterAsArgument) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(580, 42)); + + infos[1]; + + ASSERT_THAT(infos[2] ,HasMixin(HighlightingType::OutputArgument)); + ASSERT_THAT(infos[3], HasMixin(HighlightingType::OutputArgument)); + ASSERT_THAT(infos[4], HasMixin(HighlightingType::OutputArgument)); + ASSERT_THAT(infos[5], HasMixin(HighlightingType::OutputArgument)); + ASSERT_THAT(infos[6], HasMixin(HighlightingType::OutputArgument)); + ASSERT_THAT(infos[7], Not(HasMixin(HighlightingType::OutputArgument))); +} + +TEST_F(TokenInfos, NonConstReferenceArgumentCallInsideCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(501, 64)); + infos[1]; + + infos[3]; + + ASSERT_THAT(infos[7], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, OutputArgumentsAreEmptyAfterIteration) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(501, 63)); + + for (const auto &info : infos ) { Q_UNUSED(info) } + + ASSERT_TRUE(infos.currentOutputArgumentRangesAreEmpty()); +} + +TEST_F(TokenInfos, NonConstReferenceArgumentFromFunctionParameter) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(506, 42)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, NonConstPointerArgumentAsExpression) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(513, 33)); + + infos[1]; + + ASSERT_THAT(infos[3], + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, NonConstPointerArgumentAsInstanceWithMember) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(525, 46)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, NonConstPointerArgumentAsMemberOfInstance) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(525, 46)); + + infos[1]; + infos[2]; + + ASSERT_THAT(infos[4], + HasTwoTypes(HighlightingType::Field, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, DISABLED_NonConstReferenceArgumentConstructor) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(540, 57)); + + infos[2]; + + ASSERT_THAT(infos[3], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, DISABLED_NonConstReferenceMemberInitialization) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(546, 19)); + + infos[2]; + + ASSERT_THAT(infos[3], + HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); +} + +TEST_F(TokenInfos, EnumerationTypeDef) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(424, 41)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); +} + +// QTCREATORBUG-15473 +TEST_F(TokenInfos, DISABLED_ArgumentToUserDefinedIndexOperator) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(434, 19)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, ClassTemplateParticalSpecialization) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(553, 33)); + + ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Type)); +} + +TEST_F(TokenInfos, UsingFunction) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(556, 27)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, PreprocessorIfDirective) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(558, 6)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); +} + +TEST_F(TokenInfos, PreprocessorInclusionDirectiveWithKeyword) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(561, 15)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); +} + +// CLANG-UPGRADE-CHECK: Enable once https://bugs.llvm.org//show_bug.cgi?id=12972 is resolved. +TEST_F(TokenInfos, DISABLED_VariableInOperatorFunctionCall) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(566, 12)); + + ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(TokenInfos, UsingTemplateFunction) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(584, 17)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function)); +} + +TEST_F(TokenInfos, HeaderNameIsInclusion) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(239, 31)); + ClangBackEnd::TokenInfoContainer container(infos[2]); + ASSERT_THAT(container.isIncludeDirectivePath(), true); +} + +TEST_F(TokenInfos, HeaderNameIsInclusionWithAngleBrackets) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(289, 31)); + ClangBackEnd::TokenInfoContainer container(infos[2]); + ASSERT_THAT(container.isIncludeDirectivePath(), true); +} + + +TEST_F(TokenInfos, NotInclusion) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(241, 13)); + ClangBackEnd::TokenInfoContainer container(infos[1]); + ASSERT_THAT(container.isIncludeDirectivePath(), false); +} + +TEST_F(TokenInfos, MacroIsIdentifier) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(232, 30)); + ClangBackEnd::TokenInfoContainer container(infos[2]); + ASSERT_THAT(container.isIdentifier(), true); +} + +TEST_F(TokenInfos, DefineIsNotIdentifier) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(232, 30)); + ClangBackEnd::TokenInfoContainer container(infos[1]); + ASSERT_THAT(container.isIncludeDirectivePath(), false); +} + +Data *TokenInfos::d; + +void TokenInfos::SetUpTestCase() +{ + d = new Data; +} + +void TokenInfos::TearDownTestCase() +{ + delete d; + d = nullptr; +} + +ClangBackEnd::SourceRange TokenInfos::sourceRange(uint line, uint columnEnd) const +{ + return translationUnit.sourceRange(line, 1, line, columnEnd); +} + +} diff --git a/tests/unit/unittest/highlightingmarksreporter-test.cpp b/tests/unit/unittest/tokeninfosreporter-test.cpp similarity index 63% rename from tests/unit/unittest/highlightingmarksreporter-test.cpp rename to tests/unit/unittest/tokeninfosreporter-test.cpp index f153ba3472b..b6f4de0defc 100644 --- a/tests/unit/unittest/highlightingmarksreporter-test.cpp +++ b/tests/unit/unittest/tokeninfosreporter-test.cpp @@ -30,16 +30,16 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include using ClangBackEnd::Cursor; -using ClangBackEnd::HighlightingMarks; -using ClangBackEnd::HighlightingMarkContainer; +using ClangBackEnd::TokenInfos; +using ClangBackEnd::TokenInfoContainer; using ClangBackEnd::HighlightingType; using ClangBackEnd::Document; using ClangBackEnd::Documents; @@ -61,7 +61,7 @@ struct Data { documents}; }; -class HighlightingMarksReporter : public ::testing::Test +class TokenInfosReporter : public ::testing::Test { public: static void SetUpTestCase(); @@ -71,26 +71,26 @@ protected: static Data *d; }; -QVector noHighlightingMarks() +QVector noTokenInfos() { - return QVector(); + return QVector(); } -QVector generateHighlightingMarks(uint count) +QVector generateTokenInfos(uint count) { - auto container = QVector(); + auto container = QVector(); for (uint i = 0; i < count; ++i) { const uint line = i + 1; - container.append(HighlightingMarkContainer(line, 1, 1, HighlightingType::Type)); + container.append(TokenInfoContainer(line, 1, 1, HighlightingType::Type)); } return container; } -TEST_F(HighlightingMarksReporter, StartAndFinish) +TEST_F(TokenInfosReporter, StartAndFinish) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(noHighlightingMarks()); + auto reporter = new ClangCodeModel::TokenInfosReporter(noTokenInfos()); auto future = reporter->start(); @@ -98,9 +98,9 @@ TEST_F(HighlightingMarksReporter, StartAndFinish) ASSERT_THAT(future.isFinished(), true); } -TEST_F(HighlightingMarksReporter, ReportNothingIfNothingToReport) +TEST_F(TokenInfosReporter, ReportNothingIfNothingToReport) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(generateHighlightingMarks(0)); + auto reporter = new ClangCodeModel::TokenInfosReporter(generateTokenInfos(0)); auto future = reporter->start(); @@ -108,9 +108,9 @@ TEST_F(HighlightingMarksReporter, ReportNothingIfNothingToReport) ASSERT_THAT(monitor.resultsReadyCounter(), 0L); } -TEST_F(HighlightingMarksReporter, ReportSingleResultAsOneChunk) +TEST_F(TokenInfosReporter, ReportSingleResultAsOneChunk) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(generateHighlightingMarks(1)); + auto reporter = new ClangCodeModel::TokenInfosReporter(generateTokenInfos(1)); reporter->setChunkSize(1); auto future = reporter->start(); @@ -119,9 +119,9 @@ TEST_F(HighlightingMarksReporter, ReportSingleResultAsOneChunk) ASSERT_THAT(monitor.resultsReadyCounter(), 1L); } -TEST_F(HighlightingMarksReporter, ReportRestIfChunkSizeNotReached) +TEST_F(TokenInfosReporter, ReportRestIfChunkSizeNotReached) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(generateHighlightingMarks(1)); + auto reporter = new ClangCodeModel::TokenInfosReporter(generateTokenInfos(1)); const int notReachedChunkSize = 100; reporter->setChunkSize(notReachedChunkSize); @@ -131,9 +131,9 @@ TEST_F(HighlightingMarksReporter, ReportRestIfChunkSizeNotReached) ASSERT_THAT(monitor.resultsReadyCounter(), 1L); } -TEST_F(HighlightingMarksReporter, ReportChunksWithoutRest) +TEST_F(TokenInfosReporter, ReportChunksWithoutRest) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(generateHighlightingMarks(4)); + auto reporter = new ClangCodeModel::TokenInfosReporter(generateTokenInfos(4)); reporter->setChunkSize(1); auto future = reporter->start(); @@ -142,9 +142,9 @@ TEST_F(HighlightingMarksReporter, ReportChunksWithoutRest) ASSERT_THAT(monitor.resultsReadyCounter(), 2L); } -TEST_F(HighlightingMarksReporter, ReportSingleChunkAndRest) +TEST_F(TokenInfosReporter, ReportSingleChunkAndRest) { - auto reporter = new ClangCodeModel::HighlightingMarksReporter(generateHighlightingMarks(5)); + auto reporter = new ClangCodeModel::TokenInfosReporter(generateTokenInfos(5)); reporter->setChunkSize(2); auto future = reporter->start(); @@ -153,14 +153,14 @@ TEST_F(HighlightingMarksReporter, ReportSingleChunkAndRest) ASSERT_THAT(monitor.resultsReadyCounter(), 2L); } -TEST_F(HighlightingMarksReporter, ReportCompleteLines) +TEST_F(TokenInfosReporter, ReportCompleteLines) { - QVector highlightingMarks { - HighlightingMarkContainer(1, 1, 1, HighlightingType::Type), - HighlightingMarkContainer(1, 2, 1, HighlightingType::Type), - HighlightingMarkContainer(2, 1, 1, HighlightingType::Type), + QVector tokenInfos { + TokenInfoContainer(1, 1, 1, HighlightingType::Type), + TokenInfoContainer(1, 2, 1, HighlightingType::Type), + TokenInfoContainer(2, 1, 1, HighlightingType::Type), }; - auto reporter = new ClangCodeModel::HighlightingMarksReporter(highlightingMarks); + auto reporter = new ClangCodeModel::TokenInfosReporter(tokenInfos); reporter->setChunkSize(1); auto future = reporter->start(); @@ -169,14 +169,14 @@ TEST_F(HighlightingMarksReporter, ReportCompleteLines) ASSERT_THAT(monitor.resultsReadyCounter(), 2L); } -Data *HighlightingMarksReporter::d; +Data *TokenInfosReporter::d; -void HighlightingMarksReporter::SetUpTestCase() +void TokenInfosReporter::SetUpTestCase() { d = new Data; } -void HighlightingMarksReporter::TearDownTestCase() +void TokenInfosReporter::TearDownTestCase() { delete d; d = nullptr; diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index d9e1044cfee..41f5a6113c8 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -129,8 +129,6 @@ SOURCES += \ diagnosticset-test.cpp \ diagnostic-test.cpp \ fixit-test.cpp \ - highlightingmarksreporter-test.cpp \ - highlightingmarks-test.cpp \ projectpart-test.cpp \ senddocumenttracker-test.cpp \ skippedsourceranges-test.cpp \ @@ -142,6 +140,8 @@ SOURCES += \ sqlitestatement-test.cpp \ sqlitetable-test.cpp \ sqlstatementbuilder-test.cpp \ + tokeninfos-test.cpp \ + tokeninfosreporter-test.cpp \ translationunitupdater-test.cpp \ unsavedfiles-test.cpp \ unsavedfile-test.cpp \