From 90f94363db0cbaef4841f46db70d4ad5480871c0 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Sun, 5 Jun 2016 19:59:23 +0200 Subject: [PATCH] Clang: Extract TranslationUnitCore and (re)parse explicitly Extract TranslationUnitCore, which is the API for the high-level operations we need. TranslationUnit does not call any clang_* functions anymore, except the one needed for disposing the CXTranslationUnit - for now, we keep TranslationUnit the owner of TranslationUnitCore. TranslationUnitCore will be passed on to the worker threads. With this, the current "TranslationUnit" looses its meaning. We will rename it to "Document" in a follow-up change. *** TranslationUnit::cxTranslationUnit does not implicitly creates/parses/reparses anymore. We use more verbose update operations now. The test ClangIpcServer.GetCodeCompletionDependingOnArgumets fails now because of this - CodeCompleter::completeHelper() does not recreate the translation unit anymore, thus working on the old data. This will be addressed in a follow-up change. Change-Id: I6213d6f1609cd3c9a54666c84cb8b623b2fefe1c Reviewed-by: Tim Jenssen --- .../ipcsource/clangbackendclangipc-source.pri | 6 +- .../ipcsource/clangcodemodelserver.cpp | 16 +- .../ipcsource/clangtranslationunit.cpp | 118 +++----- .../ipcsource/clangtranslationunit.h | 27 +- .../ipcsource/clangtranslationunitcore.cpp | 189 +++++++++++++ .../ipcsource/clangtranslationunitcore.h | 102 +++++++ .../clangbackend/ipcsource/codecompleter.cpp | 30 +- .../clangbackend/ipcsource/codecompleter.h | 9 +- .../clangbackend/ipcsource/diagnosticset.h | 2 +- .../clangbackend/ipcsource/sourcelocation.h | 2 +- .../ipcsource/translationunits.cpp | 2 +- .../unittest/clangcodecompleteresultstest.cpp | 15 +- .../unittest/codecompletionsextractortest.cpp | 18 +- tests/unit/unittest/codecompletiontest.cpp | 47 ++-- tests/unit/unittest/cursortest.cpp | 212 +++++++------- tests/unit/unittest/diagnosticsettest.cpp | 28 +- tests/unit/unittest/diagnostictest.cpp | 80 ++++-- tests/unit/unittest/fixittest.cpp | 55 +++- tests/unit/unittest/highlightingmarkstest.cpp | 261 +++++++++--------- .../unit/unittest/skippedsourcerangestest.cpp | 14 +- tests/unit/unittest/sourcelocationtest.cpp | 32 ++- tests/unit/unittest/sourcerangetest.cpp | 47 +++- tests/unit/unittest/translationunitstest.cpp | 19 +- tests/unit/unittest/translationunittest.cpp | 54 ++-- 24 files changed, 899 insertions(+), 486 deletions(-) create mode 100644 src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp create mode 100644 src/tools/clangbackend/ipcsource/clangtranslationunitcore.h diff --git a/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri index f528d1c58de..667ed1fb5d1 100644 --- a/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri +++ b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri @@ -37,7 +37,8 @@ HEADERS += $$PWD/clangcodemodelserver.h \ $$PWD/highlightingmarksiterator.h \ $$PWD/utf8positionfromlinecolumn.h \ $$PWD/clangfilepath.h \ - $$PWD/clangunsavedfilesshallowarguments.h + $$PWD/clangunsavedfilesshallowarguments.h \ + $$PWD/clangtranslationunitcore.h SOURCES += $$PWD/clangcodemodelserver.cpp \ $$PWD/codecompleter.cpp \ @@ -74,4 +75,5 @@ SOURCES += $$PWD/clangcodemodelserver.cpp \ $$PWD/highlightingmarks.cpp \ $$PWD/utf8positionfromlinecolumn.cpp \ $$PWD/clangfilepath.cpp \ - $$PWD/clangunsavedfilesshallowarguments.cpp + $$PWD/clangunsavedfilesshallowarguments.cpp \ + $$PWD/clangtranslationunitcore.cpp diff --git a/src/tools/clangbackend/ipcsource/clangcodemodelserver.cpp b/src/tools/clangbackend/ipcsource/clangcodemodelserver.cpp index 7f7c41dd592..5d48966986c 100644 --- a/src/tools/clangbackend/ipcsource/clangcodemodelserver.cpp +++ b/src/tools/clangbackend/ipcsource/clangcodemodelserver.cpp @@ -240,8 +240,10 @@ void ClangCodeModelServer::completeCode(const ClangBackEnd::CompleteCodeMessage TIME_SCOPE_DURATION("ClangCodeModelServer::completeCode"); try { - CodeCompleter codeCompleter(translationUnits.translationUnit(message.filePath(), message.projectPartId()), - unsavedFiles); + auto translationUnit = translationUnits.translationUnit(message.filePath(), message.projectPartId()); + auto translationUnitCore = translationUnit.translationUnitCore(); + + CodeCompleter codeCompleter(translationUnitCore, unsavedFiles); const auto codeCompletions = codeCompleter.complete(message.line(), message.column()); @@ -264,11 +266,13 @@ void ClangCodeModelServer::requestDocumentAnnotations(const RequestDocumentAnnot try { auto translationUnit = translationUnits.translationUnit(message.fileContainer().filePath(), message.fileContainer().projectPartId()); + auto translationUnitCore = translationUnit.translationUnitCore(); - client()->documentAnnotationsChanged(DocumentAnnotationsChangedMessage(translationUnit.fileContainer(), - translationUnit.mainFileDiagnostics(), - translationUnit.highlightingMarks().toHighlightingMarksContainers(), - translationUnit.skippedSourceRanges().toSourceRangeContainers())); + client()->documentAnnotationsChanged(DocumentAnnotationsChangedMessage( + translationUnit.fileContainer(), + translationUnitCore.mainFileDiagnostics(), + translationUnitCore.highlightingMarks().toHighlightingMarksContainers(), + translationUnitCore.skippedSourceRanges().toSourceRangeContainers())); } catch (const TranslationUnitDoesNotExistException &exception) { client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer())); } catch (const ProjectPartDoNotExistException &exception) { diff --git a/src/tools/clangbackend/ipcsource/clangtranslationunit.cpp b/src/tools/clangbackend/ipcsource/clangtranslationunit.cpp index 2d7784b63b4..f271401b363 100644 --- a/src/tools/clangbackend/ipcsource/clangtranslationunit.cpp +++ b/src/tools/clangbackend/ipcsource/clangtranslationunit.cpp @@ -42,6 +42,7 @@ #include "translationunitisnullexception.h" #include "translationunitparseerrorexception.h" #include "translationunitreparseerrorexception.h" +#include "clangtranslationunitcore.h" #include "clangtranslationunitupdater.h" #include "translationunits.h" #include "unsavedfiles.h" @@ -148,11 +149,24 @@ void TranslationUnit::reset() d.reset(); } +void TranslationUnit::parse() const +{ + checkIfNull(); + + const TranslationUnitUpdateInput updateInput = createUpdateInput(); + TranslationUnitUpdateResult result = translationUnitCore().parse(updateInput); + + incorporateUpdaterResult(result); +} + void TranslationUnit::reparse() const { - cxTranslationUnit(); + parse(); // TODO: Remove - updateSynchronously(TranslationUnitUpdater::UpdateMode::ForceReparse); + const TranslationUnitUpdateInput updateInput = createUpdateInput(); + TranslationUnitUpdateResult result = translationUnitCore().reparse(updateInput); + + incorporateUpdaterResult(result); } bool TranslationUnit::parseWasSuccessful() const @@ -172,23 +186,11 @@ CXIndex &TranslationUnit::index() const return d->index; } -CXTranslationUnit TranslationUnit::cxTranslationUnit() const +CXTranslationUnit &TranslationUnit::cxTranslationUnit() const { checkIfNull(); checkIfFileExists(); - updateSynchronously(TranslationUnitUpdater::UpdateMode::AsNeeded); - - return d->translationUnit; -} - -CXTranslationUnit TranslationUnit::cxTranslationUnitWithoutReparsing() const -{ - checkIfNull(); - checkIfFileExists(); - - updateSynchronously(TranslationUnitUpdater::UpdateMode::ParseIfNeeded); - return d->translationUnit; } @@ -270,17 +272,14 @@ DiagnosticSet TranslationUnit::diagnostics() const { d->hasNewDiagnostics = false; - return DiagnosticSet(clang_getDiagnosticSetFromTU(cxTranslationUnit())); + return translationUnitCore().diagnostics(); } QVector TranslationUnit::mainFileDiagnostics() const { - const auto mainFilePath = filePath(); - const auto isMainFileDiagnostic = [mainFilePath](const Diagnostic &diagnostic) { - return diagnostic.location().filePath() == mainFilePath; - }; + d->hasNewDiagnostics = false; - return diagnostics().toDiagnosticContainers(isMainFileDiagnostic); + return translationUnitCore().mainFileDiagnostics(); } const QSet &TranslationUnit::dependedFilePaths() const @@ -302,58 +301,11 @@ void TranslationUnit::setDirtyIfDependencyIsMet(const Utf8String &filePath) setDirty(); } -SourceLocation TranslationUnit::sourceLocationAt(uint line, uint column) const -{ - return SourceLocation(cxTranslationUnit(), filePath(), line, column); -} - -SourceLocation TranslationUnit::sourceLocationAt(const Utf8String &filePath, uint line, uint column) const -{ - return SourceLocation(cxTranslationUnit(), filePath, line, column); -} - -SourceRange TranslationUnit::sourceRange(uint fromLine, uint fromColumn, uint toLine, uint toColumn) const -{ - return SourceRange(sourceLocationAt(fromLine, fromColumn), - sourceLocationAt(toLine, toColumn)); -} - -Cursor TranslationUnit::cursorAt(uint line, uint column) const -{ - return clang_getCursor(cxTranslationUnit(), sourceLocationAt(line, column)); -} - -Cursor TranslationUnit::cursorAt(const Utf8String &filePath, uint line, uint column) const -{ - return clang_getCursor(cxTranslationUnit(), sourceLocationAt(filePath, line, column)); -} - -Cursor TranslationUnit::cursor() const -{ - return clang_getTranslationUnitCursor(cxTranslationUnit()); -} - HighlightingMarks TranslationUnit::highlightingMarks() const { d->hasNewHighlightingMarks = false; - return highlightingMarksInRange(cursor().sourceRange()); -} - -HighlightingMarks TranslationUnit::highlightingMarksInRange(const SourceRange &range) const -{ - CXToken *cxTokens = 0; - uint cxTokensCount = 0; - auto translationUnit = cxTranslationUnit(); - - clang_tokenize(translationUnit, range, &cxTokens, &cxTokensCount); - - return HighlightingMarks(translationUnit, cxTokens, cxTokensCount); -} - -SkippedSourceRanges TranslationUnit::skippedSourceRanges() const -{ - return SkippedSourceRanges(cxTranslationUnit(), d->filePath.constData()); + return translationUnitCore().highlightingMarks(); } void TranslationUnit::checkIfNull() const @@ -402,15 +354,7 @@ bool TranslationUnit::fileExists() const return QFileInfo::exists(d->filePath.toString()); } -void TranslationUnit::updateSynchronously(TranslationUnitUpdater::UpdateMode updateMode) const -{ - TranslationUnitUpdater updater = createUpdater(); - const TranslationUnitUpdateResult updateResult = updater.update(updateMode); - - incorporateUpdaterResult(updateResult); -} - -TranslationUnitUpdater TranslationUnit::createUpdater() const +TranslationUnitUpdateInput TranslationUnit::createUpdateInput() const { TranslationUnitUpdateInput updateInput; updateInput.reparseNeeded = isNeedingReparse(); @@ -421,6 +365,12 @@ TranslationUnitUpdater TranslationUnit::createUpdater() const updateInput.projectId = projectPart().projectPartId(); updateInput.projectArguments = projectPart().arguments(); + return updateInput; +} + +TranslationUnitUpdater TranslationUnit::createUpdater() const +{ + const TranslationUnitUpdateInput updateInput = createUpdateInput(); TranslationUnitUpdater updater(index(), d->translationUnit, updateInput); return updater; @@ -431,8 +381,7 @@ void TranslationUnit::incorporateUpdaterResult(const TranslationUnitUpdateResult if (result.parseTimePointIsSet) d->lastProjectPartChangeTimePoint = result.parseTimePoint; - if (!result.dependedOnFilePaths.isEmpty()) // TODO: Remove me - d->dependedFilePaths = result.dependedOnFilePaths; + d->dependedFilePaths = result.dependedOnFilePaths; d->translationUnits.addWatchedFiles(d->dependedFilePaths); if (result.reparsed) @@ -452,14 +401,9 @@ CommandLineArguments TranslationUnit::commandLineArguments() const return createUpdater().commandLineArguments(); } -SourceLocation TranslationUnit::sourceLocationAtWithoutReparsing(uint line, uint column) const +TranslationUnitCore TranslationUnit::translationUnitCore() const { - return SourceLocation(cxTranslationUnitWithoutReparsing(), filePath(), line, column); -} - -uint TranslationUnit::defaultParseOptions() -{ - return TranslationUnitUpdater::defaultParseOptions(); + return TranslationUnitCore(d->filePath, d->index, d->translationUnit); } uint TranslationUnit::unsavedFilesCount() const diff --git a/src/tools/clangbackend/ipcsource/clangtranslationunit.h b/src/tools/clangbackend/ipcsource/clangtranslationunit.h index 6d353852bc7..36e03fd4dda 100644 --- a/src/tools/clangbackend/ipcsource/clangtranslationunit.h +++ b/src/tools/clangbackend/ipcsource/clangtranslationunit.h @@ -27,6 +27,8 @@ #include "clangtranslationunitupdater.h" +#include "clangtranslationunitcore.h" + #include #include @@ -41,6 +43,7 @@ class Utf8String; namespace ClangBackEnd { +class TranslationUnitCore; class TranslationUnitData; class TranslationUnitUpdateResult; class CodeCompleter; @@ -91,14 +94,14 @@ public: bool isVisibleInEditor() const; void reset(); + void parse() const; void reparse() const; bool isIntact() const; CXIndex &index() const; - CXTranslationUnit cxTranslationUnit() const; - CXTranslationUnit cxTranslationUnitWithoutReparsing() const; + CXTranslationUnit &cxTranslationUnit() const; UnsavedFile unsavedFile() const; UnsavedFiles unsavedFiles() const; @@ -116,9 +119,12 @@ public: const time_point &lastProjectPartChangeTimePoint() const; bool isNeedingReparse() const; + + // TODO: Remove the following two bool hasNewDiagnostics() const; bool hasNewHighlightingMarks() const; + // TODO: Remove the following two DiagnosticSet diagnostics() const; QVector mainFileDiagnostics() const; @@ -129,23 +135,12 @@ public: CommandLineArguments commandLineArguments() const; - SourceLocation sourceLocationAtWithoutReparsing(uint line, uint column) const; - SourceLocation sourceLocationAt(uint line, uint column) const; - SourceLocation sourceLocationAt(const Utf8String &filePath, uint line, uint column) const; - - SourceRange sourceRange(uint fromLine, uint fromColumn, uint toLine, uint toColumn) const; - - Cursor cursorAt(uint line, uint column) const; - Cursor cursorAt(const Utf8String &filePath, uint line, uint column) const; - Cursor cursor() const; - + // TODO: Remove HighlightingMarks highlightingMarks() const; - HighlightingMarks highlightingMarksInRange(const SourceRange &range) const; - SkippedSourceRanges skippedSourceRanges() const; + TranslationUnitCore translationUnitCore() const; bool projectPartIsOutdated() const; - static uint defaultParseOptions(); private: void setDirty(); @@ -157,7 +152,7 @@ private: bool reparseWasSuccessful() const; bool fileExists() const; - void updateSynchronously(TranslationUnitUpdater::UpdateMode updateMode) const; + TranslationUnitUpdateInput createUpdateInput() const; TranslationUnitUpdater createUpdater() const; void incorporateUpdaterResult(const TranslationUnitUpdateResult &result) const; diff --git a/src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp b/src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp new file mode 100644 index 00000000000..82f0f7d10c3 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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 "clangtranslationunitcore.h" +#include "clangtranslationunitupdater.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ClangBackEnd { + +TranslationUnitCore::TranslationUnitCore(const Utf8String &filepath, + CXIndex &cxIndex, + CXTranslationUnit &cxTranslationUnit) + : m_filePath(filepath) + , m_cxIndex(cxIndex) + , m_cxTranslationUnit(cxTranslationUnit) +{ +} + +bool TranslationUnitCore::isNull() const +{ + return !m_cxTranslationUnit || !m_cxIndex || m_filePath.isEmpty(); +} + +Utf8String TranslationUnitCore::filePath() const +{ + return m_filePath; +} + +CXIndex &TranslationUnitCore::cxIndex() const +{ + return m_cxIndex; +} + +CXTranslationUnit &TranslationUnitCore::cxTranslationUnit() const +{ + return m_cxTranslationUnit; +} + +TranslationUnitUpdateResult TranslationUnitCore::update( + const TranslationUnitUpdateInput &parseInput) const +{ + TranslationUnitUpdater updater(cxIndex(), cxTranslationUnit(), parseInput); + + return updater.update(TranslationUnitUpdater::UpdateMode::AsNeeded); +} + +TranslationUnitUpdateResult TranslationUnitCore::parse( + const TranslationUnitUpdateInput &parseInput) const +{ + TranslationUnitUpdater updater(cxIndex(), cxTranslationUnit(), parseInput); + + return updater.update(TranslationUnitUpdater::UpdateMode::ParseIfNeeded); +} + +TranslationUnitUpdateResult TranslationUnitCore::reparse( + const TranslationUnitUpdateInput &parseInput) const +{ + TranslationUnitUpdater updater(cxIndex(), cxTranslationUnit(), parseInput); + + return updater.update(TranslationUnitUpdater::UpdateMode::ForceReparse); +} + +TranslationUnitCore::CodeCompletionResult TranslationUnitCore::complete( + UnsavedFiles &unsavedFiles, + uint line, + uint column) const +{ + CodeCompleter codeCompleter(*this, unsavedFiles); + + const CodeCompletions completions = codeCompleter.complete(line, column); + const CompletionCorrection correction = codeCompleter.neededCorrection(); + + return CodeCompletionResult{completions, correction}; +} + +void TranslationUnitCore::extractDocumentAnnotations( + QVector &diagnostics, + QVector &highlightingMarks, + QVector &skippedSourceRanges) const +{ + diagnostics = mainFileDiagnostics(); + highlightingMarks = this->highlightingMarks().toHighlightingMarksContainers(); + skippedSourceRanges = this->skippedSourceRanges().toSourceRangeContainers(); +} + +DiagnosticSet TranslationUnitCore::diagnostics() const +{ + return DiagnosticSet(clang_getDiagnosticSetFromTU(m_cxTranslationUnit)); +} + +QVector TranslationUnitCore::mainFileDiagnostics() const +{ + const auto isMainFileDiagnostic = [this](const Diagnostic &diagnostic) { + return diagnostic.location().filePath() == m_filePath; + }; + + return diagnostics().toDiagnosticContainers(isMainFileDiagnostic); +} + +SourceLocation TranslationUnitCore::sourceLocationAt(uint line,uint column) const +{ + return SourceLocation(m_cxTranslationUnit, m_filePath, line, column); +} + +SourceLocation TranslationUnitCore::sourceLocationAt(const Utf8String &filePath, + uint line, + uint column) const +{ + return SourceLocation(m_cxTranslationUnit, filePath, line, column); +} + +SourceRange TranslationUnitCore::sourceRange(uint fromLine, + uint fromColumn, + uint toLine, + uint toColumn) const +{ + return SourceRange(sourceLocationAt(fromLine, fromColumn), + sourceLocationAt(toLine, toColumn)); +} + +Cursor TranslationUnitCore::cursorAt(uint line, uint column) const +{ + return clang_getCursor(m_cxTranslationUnit, sourceLocationAt(line, column)); +} + +Cursor TranslationUnitCore::cursorAt(const Utf8String &filePath, + uint line, + uint column) const +{ + return clang_getCursor(m_cxTranslationUnit, sourceLocationAt(filePath, line, column)); +} + +Cursor TranslationUnitCore::cursor() const +{ + return clang_getTranslationUnitCursor(m_cxTranslationUnit); +} + +HighlightingMarks TranslationUnitCore::highlightingMarks() const +{ + return highlightingMarksInRange(cursor().sourceRange()); +} + +HighlightingMarks TranslationUnitCore::highlightingMarksInRange(const SourceRange &range) const +{ + CXToken *cxTokens = 0; + uint cxTokensCount = 0; + + clang_tokenize(m_cxTranslationUnit, range, &cxTokens, &cxTokensCount); + + return HighlightingMarks(m_cxTranslationUnit, cxTokens, cxTokensCount); +} + +SkippedSourceRanges TranslationUnitCore::skippedSourceRanges() const +{ + return SkippedSourceRanges(m_cxTranslationUnit, m_filePath.constData()); +} + +} // namespace ClangBackEnd diff --git a/src/tools/clangbackend/ipcsource/clangtranslationunitcore.h b/src/tools/clangbackend/ipcsource/clangtranslationunitcore.h new file mode 100644 index 00000000000..3d7018a17ac --- /dev/null +++ b/src/tools/clangbackend/ipcsource/clangtranslationunitcore.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +#include + +#include + +class Utf8String; + +namespace ClangBackEnd { + +class Cursor; +class DiagnosticContainer; +class DiagnosticSet; +class HighlightingMarkContainer; +class HighlightingMarks; +class SkippedSourceRanges; +class SourceLocation; +class SourceRange; +class SourceRangeContainer; +class TranslationUnitUpdateInput; +class TranslationUnitUpdateResult; +class UnsavedFiles; + +class TranslationUnitCore +{ +public: + struct CodeCompletionResult { + CodeCompletions completions; + CompletionCorrection correction; + }; + +public: + TranslationUnitCore(const Utf8String &filePath, + CXIndex &cxIndex, + CXTranslationUnit &cxTranslationUnit); + + bool isNull() const; + + Utf8String filePath() const; + CXIndex &cxIndex() const; + CXTranslationUnit &cxTranslationUnit() const; + + TranslationUnitUpdateResult update(const TranslationUnitUpdateInput &parseInput) const; + TranslationUnitUpdateResult parse(const TranslationUnitUpdateInput &parseInput) const; + TranslationUnitUpdateResult reparse(const TranslationUnitUpdateInput &parseInput) const; + + CodeCompletionResult complete(UnsavedFiles &unsavedFiles, uint line, uint column) const; + + void extractDocumentAnnotations(QVector &diagnostics, + QVector &highlightingMarks, + QVector &skippedSourceRanges) const; + + DiagnosticSet diagnostics() const; + QVector mainFileDiagnostics() const; + + SourceLocation sourceLocationAt(uint line, uint column) const; + SourceLocation sourceLocationAt(const Utf8String &filePath, uint line, uint column) const; + SourceRange sourceRange(uint fromLine, uint fromColumn, uint toLine, uint toColumn) const; + + Cursor cursorAt(uint line, uint column) const; + Cursor cursorAt(const Utf8String &filePath, uint line, uint column) const; + Cursor cursor() const; + + HighlightingMarks highlightingMarks() const; + HighlightingMarks highlightingMarksInRange(const SourceRange &range) const; + + SkippedSourceRanges skippedSourceRanges() const; + +private: + const Utf8String m_filePath; + CXIndex &m_cxIndex; + CXTranslationUnit &m_cxTranslationUnit; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangbackend/ipcsource/codecompleter.cpp b/src/tools/clangbackend/ipcsource/codecompleter.cpp index 9cab1493c61..db396ffab3b 100644 --- a/src/tools/clangbackend/ipcsource/codecompleter.cpp +++ b/src/tools/clangbackend/ipcsource/codecompleter.cpp @@ -37,6 +37,7 @@ #include "clangtranslationunit.h" #include "sourcerange.h" #include "clangunsavedfilesshallowarguments.h" +#include "clangtranslationunitupdater.h" #include @@ -57,9 +58,9 @@ CodeCompletions toCodeCompletions(const ClangCodeCompleteResults &results) } // anonymous namespace -CodeCompleter::CodeCompleter(TranslationUnit translationUnit, +CodeCompleter::CodeCompleter(const TranslationUnitCore &translationUnitCore, const UnsavedFiles &unsavedFiles) - : translationUnit(std::move(translationUnit)) + : translationUnitCore(translationUnitCore) , unsavedFiles(unsavedFiles) { } @@ -82,10 +83,10 @@ CompletionCorrection CodeCompleter::neededCorrection() const ClangCodeCompleteResults CodeCompleter::completeHelper(uint line, uint column) { - const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnitCore.filePath()); UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments(); - return clang_codeCompleteAt(translationUnit.cxTranslationUnitWithoutReparsing(), + return clang_codeCompleteAt(translationUnitCore.cxTranslationUnit(), nativeFilePath.constData(), line, column, @@ -99,7 +100,7 @@ uint CodeCompleter::defaultOptions() const uint options = CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns; - if (translationUnit.defaultParseOptions() + if (TranslationUnitUpdater::defaultParseOptions() & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion) { options |= CXCodeComplete_IncludeBriefComments; } @@ -109,7 +110,7 @@ uint CodeCompleter::defaultOptions() const UnsavedFile &CodeCompleter::unsavedFile() { - return unsavedFiles.unsavedFile(translationUnit.filePath()); + return unsavedFiles.unsavedFile(translationUnitCore.filePath()); } void CodeCompleter::tryDotArrowCorrectionIfNoResults(ClangCodeCompleteResults &results, @@ -117,10 +118,10 @@ void CodeCompleter::tryDotArrowCorrectionIfNoResults(ClangCodeCompleteResults &r uint column) { if (results.hasNoResultsForDotCompletion()) { - const UnsavedFile &unsavedFile = translationUnit.unsavedFile(); + const UnsavedFile &theUnsavedFile = unsavedFile(); bool positionIsOk = false; - const uint dotPosition = unsavedFile.toUtf8Position(line, column - 1, &positionIsOk); - if (positionIsOk && unsavedFile.hasCharacterAt(dotPosition, '.')) + const uint dotPosition = theUnsavedFile.toUtf8Position(line, column - 1, &positionIsOk); + if (positionIsOk && theUnsavedFile.hasCharacterAt(dotPosition, '.')) results = completeWithArrowInsteadOfDot(line, column, dotPosition); } } @@ -143,16 +144,5 @@ ClangCodeCompleteResults CodeCompleter::completeWithArrowInsteadOfDot(uint line, return results; } -Utf8String CodeCompleter::filePath() const -{ - return translationUnit.filePath(); -} - -void CodeCompleter::checkCodeCompleteResult(CXCodeCompleteResults *completeResults) -{ - if (!completeResults) - throw CodeCompleteFailedException(); -} - } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/ipcsource/codecompleter.h b/src/tools/clangbackend/ipcsource/codecompleter.h index 6744ddb3671..821f28142d5 100644 --- a/src/tools/clangbackend/ipcsource/codecompleter.h +++ b/src/tools/clangbackend/ipcsource/codecompleter.h @@ -25,7 +25,7 @@ #pragma once -#include "clangtranslationunit.h" +#include "clangtranslationunitcore.h" #include "unsavedfiles.h" #include @@ -40,7 +40,7 @@ class CodeCompleter { public: CodeCompleter() = default; - CodeCompleter(TranslationUnit translationUnit, + CodeCompleter(const TranslationUnitCore &translationUnitCore, const UnsavedFiles &unsavedFiles); CodeCompletions complete(uint line, uint column); @@ -60,11 +60,8 @@ private: uint column, uint dotPosition); - Utf8String filePath() const; - static void checkCodeCompleteResult(CXCodeCompleteResults *completeResults); - private: - TranslationUnit translationUnit; + TranslationUnitCore translationUnitCore; UnsavedFiles unsavedFiles; CompletionCorrection neededCorrection_ = CompletionCorrection::NoCorrection; }; diff --git a/src/tools/clangbackend/ipcsource/diagnosticset.h b/src/tools/clangbackend/ipcsource/diagnosticset.h index e715ad2627b..01304607358 100644 --- a/src/tools/clangbackend/ipcsource/diagnosticset.h +++ b/src/tools/clangbackend/ipcsource/diagnosticset.h @@ -40,7 +40,7 @@ class DiagnosticSetIterator; class DiagnosticSet { - friend class TranslationUnit; + friend class TranslationUnitCore; friend class Diagnostic; public: diff --git a/src/tools/clangbackend/ipcsource/sourcelocation.h b/src/tools/clangbackend/ipcsource/sourcelocation.h index 094be9875ec..7fc7205ba21 100644 --- a/src/tools/clangbackend/ipcsource/sourcelocation.h +++ b/src/tools/clangbackend/ipcsource/sourcelocation.h @@ -38,7 +38,7 @@ class SourceLocation { friend class Diagnostic; friend class SourceRange; - friend class TranslationUnit; + friend class TranslationUnitCore; friend class Cursor; friend bool operator==(const SourceLocation &first, const SourceLocation &second); diff --git a/src/tools/clangbackend/ipcsource/translationunits.cpp b/src/tools/clangbackend/ipcsource/translationunits.cpp index dee37c4d41c..2e90e0bf81e 100644 --- a/src/tools/clangbackend/ipcsource/translationunits.cpp +++ b/src/tools/clangbackend/ipcsource/translationunits.cpp @@ -373,7 +373,7 @@ void TranslationUnits::sendDocumentAnnotations(const TranslationUnit &translatio DocumentAnnotationsChangedMessage message(translationUnit.fileContainer(), translationUnit.mainFileDiagnostics(), translationUnit.highlightingMarks().toHighlightingMarksContainers(), - translationUnit.skippedSourceRanges().toSourceRangeContainers()); + translationUnit.translationUnitCore().skippedSourceRanges().toSourceRangeContainers()); sendDocumentAnnotationsCallback(std::move(message)); } diff --git a/tests/unit/unittest/clangcodecompleteresultstest.cpp b/tests/unit/unittest/clangcodecompleteresultstest.cpp index 4e266c01425..c24aa54e719 100644 --- a/tests/unit/unittest/clangcodecompleteresultstest.cpp +++ b/tests/unit/unittest/clangcodecompleteresultstest.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -47,10 +48,12 @@ using ClangBackEnd::TranslationUnit; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; -static unsigned completionOptions(const TranslationUnit &translationUnit) +static unsigned completionOptions() { - return translationUnit.defaultOptions() & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion - ? CXCodeComplete_IncludeBriefComments : 0; + return ClangBackEnd::TranslationUnitUpdater::defaultParseOptions() + & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion + ? CXCodeComplete_IncludeBriefComments + : 0; } TEST(ClangCodeCompleteResults, GetData) @@ -64,11 +67,12 @@ TEST(ClangCodeCompleteResults, GetData) Utf8StringVector(), translationUnits); Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + translationUnit.parse(); CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), nativeFilePath.constData(), 49, 1, 0, 0, - completionOptions(translationUnit)); + completionOptions()); ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); @@ -95,11 +99,12 @@ TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults) Utf8StringVector(), translationUnits); Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + translationUnit.parse(); CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), nativeFilePath.constData(), 49, 1, 0, 0, - completionOptions(translationUnit)); + completionOptions()); ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); diff --git a/tests/unit/unittest/codecompletionsextractortest.cpp b/tests/unit/unittest/codecompletionsextractortest.cpp index 2f37556ff78..265d2334f52 100644 --- a/tests/unit/unittest/codecompletionsextractortest.cpp +++ b/tests/unit/unittest/codecompletionsextractortest.cpp @@ -146,7 +146,8 @@ class CodeCompletionsExtractor : public ::testing::Test protected: ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint line, - uint column = 1); + uint column = 1, + bool needsReparse = false); protected: ClangBackEnd::ProjectPart project{Utf8StringLiteral("/path/to/projectfile")}; @@ -573,7 +574,6 @@ TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile) TEST_F(CodeCompletionsExtractor, ArgumentDefinition) { - variableTranslationUnit.cxTranslationUnit(); project.setArguments({Utf8StringLiteral("-DArgumentDefinition"), Utf8StringLiteral("-std=gnu++14")}); ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); @@ -586,7 +586,6 @@ TEST_F(CodeCompletionsExtractor, ArgumentDefinition) TEST_F(CodeCompletionsExtractor, NoArgumentDefinition) { - variableTranslationUnit.cxTranslationUnit(); project.setArguments({Utf8StringLiteral("-std=gnu++14")}); ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35)); @@ -672,16 +671,23 @@ TEST_F(CodeCompletionsExtractor, CompletionChunksClass) TEST_F(CodeCompletionsExtractor, BriefComment) { - briefCommentTranslationUnit.reparse(); - ClangCodeCompleteResults completeResults(getResults(briefCommentTranslationUnit, 10)); + ClangCodeCompleteResults completeResults(getResults(briefCommentTranslationUnit, 10, 1, + /*needsReparse=*/ true)); ::CodeCompletionsExtractor extractor(completeResults.data()); ASSERT_THAT(extractor, HasBriefComment(Utf8StringLiteral("BriefComment"), Utf8StringLiteral("A brief comment"))); } -ClangCodeCompleteResults CodeCompletionsExtractor::getResults(const TranslationUnit &translationUnit, uint line, uint column) +ClangCodeCompleteResults CodeCompletionsExtractor::getResults(const TranslationUnit &translationUnit, + uint line, + uint column, + bool needsReparse) { + translationUnit.parse(); + if (needsReparse) + translationUnit.reparse(); + const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments(); diff --git a/tests/unit/unittest/codecompletiontest.cpp b/tests/unit/unittest/codecompletiontest.cpp index e20db4061ce..aafb1fb85d1 100644 --- a/tests/unit/unittest/codecompletiontest.cpp +++ b/tests/unit/unittest/codecompletiontest.cpp @@ -90,7 +90,7 @@ protected: ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; ClangBackEnd::TranslationUnit translationUnit; - ClangBackEnd::CodeCompleter completer; + QScopedPointer completer; ClangBackEnd::FileContainer unsavedMainFileContainer{mainFileContainer.filePath(), projectPart.projectPartId(), readFileContent(QStringLiteral("/complete_completer_main_unsaved.cpp")), @@ -213,20 +213,20 @@ void CodeCompleter::SetUp() projects.createOrUpdate({projectPart}); translationUnits.create({mainFileContainer}); translationUnit = translationUnits.translationUnit(mainFileContainer); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + completer.reset(new ClangBackEnd::CodeCompleter(translationUnit.translationUnitCore(), + unsavedFiles)); copyTargetHeaderToTemporaryIncludeDirecory(); - - translationUnit.cxTranslationUnit(); // initialize translation unit so we check changes + translationUnit.parse(); } TEST_F(CodeCompleter, FunctionInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); translationUnits.update({unsavedMainFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), AllOf(Contains(IsCodeCompletion(Utf8StringLiteral("FunctionWithArguments"), CodeCompletion::FunctionCompletionKind)), Contains(IsCodeCompletion(Utf8StringLiteral("Function"), @@ -243,9 +243,9 @@ TEST_F(CodeCompleter, VariableInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); translationUnits.update({unsavedMainFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("VariableInUnsavedFile"), CodeCompletion::VariableCompletionKind))); } @@ -254,9 +254,9 @@ TEST_F(CodeCompleter, GlobalVariableInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); translationUnits.update({unsavedMainFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("GlobalVariableInUnsavedFile"), CodeCompletion::VariableCompletionKind))); } @@ -265,23 +265,23 @@ TEST_F(CodeCompleter, Macro) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); translationUnits.update({unsavedMainFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("Macro"), CodeCompletion::PreProcessorCompletionKind))); } TEST_F(CodeCompleter, Keyword) { - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(completer->complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("switch"), CodeCompletion::KeywordCompletionKind))); } TEST_F(CodeCompleter, FunctionInIncludedHeader) { - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(completer->complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeader"), CodeCompletion::FunctionCompletionKind))); } @@ -290,9 +290,9 @@ TEST_F(CodeCompleter, FunctionInUnsavedIncludedHeader) { unsavedFiles.createOrUpdate({unsavedTargetHeaderFileContainer}); translationUnits.create({unsavedTargetHeaderFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderUnsaved"), CodeCompletion::FunctionCompletionKind))); } @@ -301,7 +301,7 @@ TEST_F(CodeCompleter, DISABLED_FunctionInChangedIncludedHeader) { copyChangedTargetHeaderToTemporaryIncludeDirecory(); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(completer->complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"), CodeCompletion::FunctionCompletionKind))); } @@ -310,11 +310,11 @@ TEST_F(CodeCompleter, DISABLED_FunctionInChangedIncludedHeaderWithUnsavedContent { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); translationUnits.update({unsavedMainFileContainer}); - completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles); + ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles); copyChangedTargetHeaderToTemporaryIncludeDirecory(); - ASSERT_THAT(completer.complete(27, 1), + ASSERT_THAT(myCompleter.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"), CodeCompletion::FunctionCompletionKind))); } @@ -352,9 +352,9 @@ TEST_F(CodeCompleter, DotToArrowCompletionForPointerInOutdatedTranslationUnit) unsavedFiles.createOrUpdate({fileContainerBeforeTyping}); auto translationUnit = translationUnits.translationUnit(fileContainerBeforeTyping.filePath(), fileContainerBeforeTyping.projectPartId()); - translationUnit.cxTranslationUnit(); // Parse + translationUnit.parse(); unsavedFiles.createOrUpdate({dotArrowCorrectionForPointerFileContainerAfterTyping}); - ClangBackEnd::CodeCompleter myCompleter(translationUnits.translationUnit(dotArrowCorrectionForPointerFileContainerAfterTyping), + ClangBackEnd::CodeCompleter myCompleter(translationUnits.translationUnit(dotArrowCorrectionForPointerFileContainerAfterTyping).translationUnitCore(), unsavedFiles); const ClangBackEnd::CodeCompletions completions = myCompleter.complete(5, 9); @@ -445,8 +445,11 @@ ClangBackEnd::CodeCompleter CodeCompleter::setupCompleter( { translationUnits.create({fileContainer}); unsavedFiles.createOrUpdate({fileContainer}); + translationUnit = translationUnits.translationUnit(fileContainer); + translationUnit.parse(); - return ClangBackEnd::CodeCompleter(translationUnits.translationUnit(fileContainer), + ClangBackEnd::TranslationUnit translationUnit = translationUnits.translationUnit(fileContainer); + return ClangBackEnd::CodeCompleter(translationUnit.translationUnitCore(), unsavedFiles); } diff --git a/tests/unit/unittest/cursortest.cpp b/tests/unit/unittest/cursortest.cpp index f809335155c..3060b2feefd 100644 --- a/tests/unit/unittest/cursortest.cpp +++ b/tests/unit/unittest/cursortest.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ using ClangBackEnd::Cursor; using ClangBackEnd::TranslationUnit; +using ClangBackEnd::TranslationUnitCore; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; using ClangBackEnd::TranslationUnits; @@ -62,10 +64,14 @@ struct Data { ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; - TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/cursor.cpp"), + Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/cursor.cpp")}; + TranslationUnit translationUnit{filePath, ProjectPart(Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-std=c++11")}), {}, translationUnits}; + TranslationUnitCore translationUnitCore{filePath, + translationUnit.index(), + translationUnit.cxTranslationUnit()}; }; class Cursor : public ::testing::Test @@ -77,8 +83,7 @@ public: protected: static Data *d; const TranslationUnit &translationUnit = d->translationUnit; - - + const TranslationUnitCore &translationUnitCore = d->translationUnitCore; }; TEST_F(Cursor, CreateNullCursor) @@ -105,14 +110,14 @@ TEST_F(Cursor, IsNotValid) TEST_F(Cursor, IsValid) { - auto cursor = translationUnit.cursor(); + auto cursor = translationUnitCore.cursor(); ASSERT_TRUE(cursor.isValid()); } TEST_F(Cursor, IsTranslationUnit) { - auto cursor = translationUnit.cursor(); + auto cursor = translationUnitCore.cursor(); ASSERT_TRUE(cursor.isTranslationUnit()); } @@ -133,29 +138,29 @@ TEST_F(Cursor, UnifiedSymbolResolution) TEST_F(Cursor, GetCursorAtLocation) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); ASSERT_THAT(cursor.unifiedSymbolResolution(), Utf8StringLiteral("c:@F@function#I#")); } TEST_F(Cursor, GetCursoSourceLocation) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); - ASSERT_THAT(cursor.sourceLocation(), translationUnit.sourceLocationAt(3, 6)); + ASSERT_THAT(cursor.sourceLocation(), translationUnitCore.sourceLocationAt(3, 6)); } TEST_F(Cursor, GetCursoSourceRange) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); - ASSERT_THAT(cursor.sourceRange(), SourceRange(translationUnit.sourceLocationAt(3, 1), - translationUnit.sourceLocationAt(6, 2))); + ASSERT_THAT(cursor.sourceRange(), SourceRange(translationUnitCore.sourceLocationAt(3, 1), + translationUnitCore.sourceLocationAt(6, 2))); } TEST_F(Cursor, Mangling) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); ASSERT_THAT(cursor.mangling().isEmpty(), false); @@ -163,7 +168,7 @@ TEST_F(Cursor, Mangling) TEST_F(Cursor, Spelling) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); ASSERT_THAT(cursor.spelling().cString(), StrEq("function")); @@ -171,7 +176,7 @@ TEST_F(Cursor, Spelling) TEST_F(Cursor, DisplayName) { - auto cursor = translationUnit.cursorAt(3, 6); + auto cursor = translationUnitCore.cursorAt(3, 6); ASSERT_THAT(cursor.displayName(), Utf8StringLiteral("function(int)")); @@ -179,7 +184,7 @@ TEST_F(Cursor, DisplayName) TEST_F(Cursor, BriefComment) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_THAT(cursor.briefComment(), Utf8StringLiteral("A brief comment")); @@ -187,7 +192,7 @@ TEST_F(Cursor, BriefComment) TEST_F(Cursor, RawComment) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_THAT(cursor.rawComment(), Utf8StringLiteral("/**\n * A brief comment\n */")); @@ -195,118 +200,118 @@ TEST_F(Cursor, RawComment) TEST_F(Cursor, CommentRange) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_THAT(cursor.commentRange(), - SourceRange(translationUnit.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 7, 1), - translationUnit.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 9, 4))); + SourceRange(translationUnitCore.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 7, 1), + translationUnitCore.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 9, 4))); } TEST_F(Cursor, IsDefinition) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_TRUE(cursor.isDefinition()); } TEST_F(Cursor, ForwardDeclarationIsNotDefinition) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); ASSERT_FALSE(cursor.isDefinition()); } TEST_F(Cursor, GetDefinitionOfFowardDeclaration) { - auto forwardDeclarationcursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); - auto definitionCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto forwardDeclarationcursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); + auto definitionCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_THAT(forwardDeclarationcursor.definition(), definitionCursor); } TEST_F(Cursor, CallToMethodeIsNotDynamic) { - auto cursor = translationUnit.cursorAt(18, 5); + auto cursor = translationUnitCore.cursorAt(18, 5); ASSERT_FALSE(cursor.isDynamicCall()); } TEST_F(Cursor, CallToAbstractVirtualMethodeIsDynamic) { - auto cursor = translationUnit.cursorAt(19, 5); + auto cursor = translationUnitCore.cursorAt(19, 5); ASSERT_TRUE(cursor.isDynamicCall()); } TEST_F(Cursor, CanonicalCursor) { - auto forwardDeclarationcursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); - auto definitionCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto forwardDeclarationcursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7); + auto definitionCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_THAT(definitionCursor.canonical(), forwardDeclarationcursor); } TEST_F(Cursor, ReferencedCursor) { - auto functionCallCursor = translationUnit.cursorAt(18, 5); - auto functionCursor = translationUnit.cursorAt(16, 17); + auto functionCallCursor = translationUnitCore.cursorAt(18, 5); + auto functionCursor = translationUnitCore.cursorAt(16, 17); ASSERT_THAT(functionCallCursor.referenced(), functionCursor); } TEST_F(Cursor, IsVirtual) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); ASSERT_TRUE(cursor.isVirtualMethod()); } TEST_F(Cursor, IsNotPureVirtualOnlyVirtual) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); ASSERT_FALSE(cursor.isPureVirtualMethod()); } TEST_F(Cursor, IsPureVirtual) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 16, 17); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 16, 17); ASSERT_TRUE(cursor.isPureVirtualMethod()); } TEST_F(Cursor, ConstantMethod) { - auto cursor = translationUnit.cursorAt(31, 18); + auto cursor = translationUnitCore.cursorAt(31, 18); ASSERT_TRUE(cursor.isConstantMethod()); } TEST_F(Cursor, IsStaticMethod) { - auto cursor = translationUnit.cursorAt(36, 18); + auto cursor = translationUnitCore.cursorAt(36, 18); ASSERT_TRUE(cursor.isStaticMethod()); } TEST_F(Cursor, TypeSpelling) { - auto cursor = translationUnit.cursorAt(43, 5); + auto cursor = translationUnitCore.cursorAt(43, 5); ASSERT_THAT(cursor.type().utf8Spelling(), Utf8StringLiteral("lint")); } TEST_F(Cursor, CanonicalTypeSpelling) { - auto cursor = translationUnit.cursorAt(43, 5); + auto cursor = translationUnitCore.cursorAt(43, 5); ASSERT_THAT(cursor.type().canonical().utf8Spelling(), Utf8StringLiteral("long long")); } TEST_F(Cursor, CanonicalTypeCStringSpelling) { - auto cursor = translationUnit.cursorAt(43, 5); + auto cursor = translationUnitCore.cursorAt(43, 5); auto spelling = cursor.type().canonical().spelling(); @@ -315,58 +320,58 @@ TEST_F(Cursor, CanonicalTypeCStringSpelling) TEST_F(Cursor, CanonicalTypeIsNotType) { - auto cursor = translationUnit.cursorAt(43, 5); + auto cursor = translationUnitCore.cursorAt(43, 5); ASSERT_THAT(cursor.type().canonical(), Not(cursor.type())); } TEST_F(Cursor, TypeDeclartionIsAlias) { - auto declarationCursor = translationUnit.cursorAt(41, 5); - auto lintCursor = translationUnit.cursorAt(39, 11); + auto declarationCursor = translationUnitCore.cursorAt(41, 5); + auto lintCursor = translationUnitCore.cursorAt(39, 11); ASSERT_THAT(declarationCursor.type().declaration().type(), lintCursor.type()); } TEST_F(Cursor, TypeIsConstantWithoutAliasLookup) { - auto cursor = translationUnit.cursorAt(45, 16); + auto cursor = translationUnitCore.cursorAt(45, 16); ASSERT_TRUE(cursor.type().isConstant()); } TEST_F(Cursor, ClassIsCompoundType) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7); ASSERT_TRUE(cursor.isCompoundType()); } TEST_F(Cursor, StructIsCompoundType) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); ASSERT_TRUE(cursor.isCompoundType()); } TEST_F(Cursor, UnionIsCompoundType) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 33, 7); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 33, 7); ASSERT_TRUE(cursor.isCompoundType()); } TEST_F(Cursor, IsDeclaration) { - auto cursor = translationUnit.cursorAt(41, 10); + auto cursor = translationUnitCore.cursorAt(41, 10); ASSERT_TRUE(cursor.isDeclaration()); } TEST_F(Cursor, SemanticParent) { - auto cursor = translationUnit.cursorAt(43, 6); - auto expectedSemanticParent = translationUnit.cursorAt(36, 18); + auto cursor = translationUnitCore.cursorAt(43, 6); + auto expectedSemanticParent = translationUnitCore.cursorAt(36, 18); auto semanticParent = cursor.semanticParent(); @@ -375,117 +380,117 @@ TEST_F(Cursor, SemanticParent) TEST_F(Cursor, IsLocalVariableInMethod) { - auto cursor = translationUnit.cursorAt(20, 9); + auto cursor = translationUnitCore.cursorAt(20, 9); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInStaticFunction) { - auto cursor = translationUnit.cursorAt(43, 5); + auto cursor = translationUnitCore.cursorAt(43, 5); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInTemplateFunction) { - auto cursor = translationUnit.cursorAt(52, 7); + auto cursor = translationUnitCore.cursorAt(52, 7); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInConversionOperator) { - auto cursor = translationUnit.cursorAt(57, 9); + auto cursor = translationUnitCore.cursorAt(57, 9); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInOperator) { - auto cursor = translationUnit.cursorAt(62, 9); + auto cursor = translationUnitCore.cursorAt(62, 9); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInConstructor) { - auto cursor = translationUnit.cursorAt(13, 9); + auto cursor = translationUnitCore.cursorAt(13, 9); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, IsLocalVariableInDestructor) { - auto cursor = translationUnit.cursorAt(69, 9); + auto cursor = translationUnitCore.cursorAt(69, 9); ASSERT_TRUE(cursor.isLocalVariable()); } TEST_F(Cursor, FindFunctionCaller) { - auto functionCursor = translationUnit.cursorAt(92, 24); - auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); + auto functionCursor = translationUnitCore.cursorAt(92, 24); + auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor); } TEST_F(Cursor, FindFunctionCallerPointer) { - auto functionCursor = translationUnit.cursorAt(79, 25); - auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); + auto functionCursor = translationUnitCore.cursorAt(79, 25); + auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor); } TEST_F(Cursor, FindFunctionCallerThis) { - auto functionCursor = translationUnit.cursorAt(106, 5); - auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8); + auto functionCursor = translationUnitCore.cursorAt(106, 5); + auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8); ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor); } TEST_F(Cursor, NonPointerTypeForValue) { - auto variableCursor = translationUnit.cursorAt(101, 10); - auto variablePointerCursor = translationUnit.cursorAt(100, 11); + auto variableCursor = translationUnitCore.cursorAt(101, 10); + auto variablePointerCursor = translationUnitCore.cursorAt(100, 11); ASSERT_THAT(variableCursor.nonPointerTupe(), variablePointerCursor.nonPointerTupe()); } TEST_F(Cursor, HasFinalAttributeInFunction) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 30, 18); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 30, 18); ASSERT_TRUE(cursor.hasFinalFunctionAttribute()); } TEST_F(Cursor, HasNotFinalAttributeInFunction) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 15, 17); ASSERT_FALSE(cursor.hasFinalFunctionAttribute()); } TEST_F(Cursor, HasFinalAttributeInClass) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8); ASSERT_TRUE(cursor.hasFinalClassAttribute()); } TEST_F(Cursor, HasNotFinaAttributeInClass) { - auto cursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8); + auto cursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8); ASSERT_FALSE(cursor.hasFinalClassAttribute()); } TEST_F(Cursor, HasOutputValues) { - auto callExpressionCursor = translationUnit.cursorAt(117, 19); - auto outputArgumentExpectedCursor = translationUnit.cursorAt(117, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(117, 19); + auto outputArgumentExpectedCursor = translationUnitCore.cursorAt(117, 20); auto outputArguments = callExpressionCursor.outputArguments(); @@ -495,7 +500,7 @@ TEST_F(Cursor, HasOutputValues) TEST_F(Cursor, HasOnlyInputValues) { - auto callExpressionCursor = translationUnit.cursorAt(118, 18); + auto callExpressionCursor = translationUnitCore.cursorAt(118, 18); auto outputArguments = callExpressionCursor.outputArguments(); @@ -504,7 +509,7 @@ TEST_F(Cursor, HasOnlyInputValues) TEST_F(Cursor, ArgumentCountIsZero) { - auto cursor = translationUnit.cursorAt(121, 23); + auto cursor = translationUnitCore.cursorAt(121, 23); auto count = cursor.type().argumentCount(); @@ -513,7 +518,7 @@ TEST_F(Cursor, ArgumentCountIsZero) TEST_F(Cursor, ArgumentCountIsTwo) { - auto cursor = translationUnit.cursorAt(122, 22); + auto cursor = translationUnitCore.cursorAt(122, 22); auto count = cursor.type().argumentCount(); @@ -522,7 +527,7 @@ TEST_F(Cursor, ArgumentCountIsTwo) TEST_F(Cursor, ArgumentOneIsValue) { - auto callExpressionCursor = translationUnit.cursorAt(122, 22); + auto callExpressionCursor = translationUnitCore.cursorAt(122, 22); auto argument = callExpressionCursor.type().argument(0); @@ -532,7 +537,7 @@ TEST_F(Cursor, ArgumentOneIsValue) TEST_F(Cursor, ArgumentTwoIsLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(122, 22); + auto callExpressionCursor = translationUnitCore.cursorAt(122, 22); auto argument = callExpressionCursor.type().argument(1); @@ -541,7 +546,7 @@ TEST_F(Cursor, ArgumentTwoIsLValueReference) TEST_F(Cursor, ArgumentTwoIsConstantReference) { - auto callExpressionCursor = translationUnit.cursorAt(122, 22); + auto callExpressionCursor = translationUnitCore.cursorAt(122, 22); auto argumentPointee = callExpressionCursor.type().argument(1); @@ -550,7 +555,7 @@ TEST_F(Cursor, ArgumentTwoIsConstantReference) TEST_F(Cursor, CursorArgumentCount) { - auto cursor = translationUnit.cursorAt(117, 19); + auto cursor = translationUnitCore.cursorAt(117, 19); ASSERT_THAT(cursor.kind(), CXCursor_CallExpr); ASSERT_THAT(cursor.argumentCount(), 4); @@ -558,15 +563,15 @@ TEST_F(Cursor, CursorArgumentCount) TEST_F(Cursor, CursorArgumentInputValue) { - auto callExpressionCursor = translationUnit.cursorAt(117, 19); - auto declarationReferenceExpressionCursor = translationUnit.cursorAt(117, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(117, 19); + auto declarationReferenceExpressionCursor = translationUnitCore.cursorAt(117, 20); ASSERT_THAT(callExpressionCursor.argument(0), declarationReferenceExpressionCursor); } TEST_F(Cursor, IsConstantLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -575,7 +580,7 @@ TEST_F(Cursor, IsConstantLValueReference) TEST_F(Cursor, LValueReferenceIsNotConstantLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(124, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(124, 21); auto argument = callExpressionCursor.type().argument(0); @@ -584,7 +589,7 @@ TEST_F(Cursor, LValueReferenceIsNotConstantLValueReference) TEST_F(Cursor, ValueIsNotConstantLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(123, 18); + auto callExpressionCursor = translationUnitCore.cursorAt(123, 18); auto argument = callExpressionCursor.type().argument(0); @@ -593,7 +598,7 @@ TEST_F(Cursor, ValueIsNotConstantLValueReference) TEST_F(Cursor, PointerToConstantNotConstantLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -602,7 +607,7 @@ TEST_F(Cursor, PointerToConstantNotConstantLValueReference) TEST_F(Cursor, IsLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(124, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(124, 21); auto argument = callExpressionCursor.type().argument(0); @@ -611,7 +616,7 @@ TEST_F(Cursor, IsLValueReference) TEST_F(Cursor, ConstantLValueReferenceIsLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -620,7 +625,7 @@ TEST_F(Cursor, ConstantLValueReferenceIsLValueReference) TEST_F(Cursor, ValueIsNotLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(123, 18); + auto callExpressionCursor = translationUnitCore.cursorAt(123, 18); auto argument = callExpressionCursor.type().argument(0); @@ -629,7 +634,7 @@ TEST_F(Cursor, ValueIsNotLValueReference) TEST_F(Cursor, PointerIsNotLValueReference) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -638,7 +643,7 @@ TEST_F(Cursor, PointerIsNotLValueReference) TEST_F(Cursor, PointerToConstant) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -647,7 +652,7 @@ TEST_F(Cursor, PointerToConstant) TEST_F(Cursor, ValueIsNotPointerToConstant) { - auto callExpressionCursor = translationUnit.cursorAt(123, 18); + auto callExpressionCursor = translationUnitCore.cursorAt(123, 18); auto argument = callExpressionCursor.type().argument(0); @@ -656,7 +661,7 @@ TEST_F(Cursor, ValueIsNotPointerToConstant) TEST_F(Cursor, PointerNotPointerToConstant) { - auto callExpressionCursor = translationUnit.cursorAt(127, 13); + auto callExpressionCursor = translationUnitCore.cursorAt(127, 13); auto argument = callExpressionCursor.type().argument(0); @@ -665,7 +670,7 @@ TEST_F(Cursor, PointerNotPointerToConstant) TEST_F(Cursor, ConstantLValueReferenceIsNotPointerToConstant) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -674,7 +679,7 @@ TEST_F(Cursor, ConstantLValueReferenceIsNotPointerToConstant) TEST_F(Cursor, IsConstantPointer) { - auto callExpressionCursor = translationUnit.cursorAt(128, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(128, 21); auto argument = callExpressionCursor.type().argument(0); @@ -683,7 +688,7 @@ TEST_F(Cursor, IsConstantPointer) TEST_F(Cursor, PointerToConstantIsNotConstantPointer) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -692,7 +697,7 @@ TEST_F(Cursor, PointerToConstantIsNotConstantPointer) TEST_F(Cursor, ConstValueIsNotConstantPointer) { - auto callExpressionCursor = translationUnit.cursorAt(129, 23); + auto callExpressionCursor = translationUnitCore.cursorAt(129, 23); auto argument = callExpressionCursor.type().argument(0); @@ -701,7 +706,7 @@ TEST_F(Cursor, ConstValueIsNotConstantPointer) TEST_F(Cursor, PointerToConstantIsReferencingConstant) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -710,7 +715,7 @@ TEST_F(Cursor, PointerToConstantIsReferencingConstant) TEST_F(Cursor, ConstantReferenceIsReferencingConstant) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -719,7 +724,7 @@ TEST_F(Cursor, ConstantReferenceIsReferencingConstant) TEST_F(Cursor, LValueReferenceIsNotReferencingConstant) { - auto callExpressionCursor = translationUnit.cursorAt(124, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(124, 21); auto argument = callExpressionCursor.type().argument(0); @@ -728,7 +733,7 @@ TEST_F(Cursor, LValueReferenceIsNotReferencingConstant) TEST_F(Cursor, ValueIsNotReferencingConstant) { - auto callExpressionCursor = translationUnit.cursorAt(123, 18); + auto callExpressionCursor = translationUnitCore.cursorAt(123, 18); auto argument = callExpressionCursor.type().argument(0); @@ -737,7 +742,7 @@ TEST_F(Cursor, ValueIsNotReferencingConstant) TEST_F(Cursor, PointerIsNotRefencingConstant) { - auto callExpressionCursor = translationUnit.cursorAt(127, 13); + auto callExpressionCursor = translationUnitCore.cursorAt(127, 13); auto argument = callExpressionCursor.type().argument(0); @@ -746,7 +751,7 @@ TEST_F(Cursor, PointerIsNotRefencingConstant) TEST_F(Cursor, PointerIsOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(127, 13); + auto callExpressionCursor = translationUnitCore.cursorAt(127, 13); auto argument = callExpressionCursor.type().argument(0); @@ -755,7 +760,7 @@ TEST_F(Cursor, PointerIsOutputParameter) TEST_F(Cursor, ConstantReferenceIsNotOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -764,7 +769,7 @@ TEST_F(Cursor, ConstantReferenceIsNotOutputParameter) TEST_F(Cursor, PointerToConstantIsNotOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(126, 20); + auto callExpressionCursor = translationUnitCore.cursorAt(126, 20); auto argument = callExpressionCursor.type().argument(0); @@ -773,7 +778,7 @@ TEST_F(Cursor, PointerToConstantIsNotOutputParameter) TEST_F(Cursor, ConstantPointerIsNotOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(128, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(128, 21); auto argument = callExpressionCursor.type().argument(0); @@ -782,7 +787,7 @@ TEST_F(Cursor, ConstantPointerIsNotOutputParameter) TEST_F(Cursor, ReferenceIsOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(124, 21); + auto callExpressionCursor = translationUnitCore.cursorAt(124, 21); auto argument = callExpressionCursor.type().argument(0); @@ -791,7 +796,7 @@ TEST_F(Cursor, ReferenceIsOutputParameter) TEST_F(Cursor, ConstReferenceIsNotOutputParameter) { - auto callExpressionCursor = translationUnit.cursorAt(125, 26); + auto callExpressionCursor = translationUnitCore.cursorAt(125, 26); auto argument = callExpressionCursor.type().argument(0); @@ -803,6 +808,7 @@ Data *Cursor::d; void Cursor::SetUpTestCase() { d = new Data; + d->translationUnit.parse(); } void Cursor::TearDownTestCase() diff --git a/tests/unit/unittest/diagnosticsettest.cpp b/tests/unit/unittest/diagnosticsettest.cpp index b6dd1fa818e..946eb8b63ba 100644 --- a/tests/unit/unittest/diagnosticsettest.cpp +++ b/tests/unit/unittest/diagnosticsettest.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -77,7 +78,6 @@ protected: projectPart, Utf8StringVector(), translationUnits}; - ::DiagnosticSet diagnosticSetWithChildren{translationUnitMainFile.diagnostics()}; protected: enum ChildMode { WithChild, WithoutChild }; @@ -86,14 +86,16 @@ protected: TEST_F(DiagnosticSet, SetHasContent) { - const auto set = translationUnit.diagnostics(); + translationUnit.parse(); + const auto set = translationUnit.translationUnitCore().diagnostics(); ASSERT_THAT(set.size(), 1); } TEST_F(DiagnosticSet, MoveConstructor) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); const auto set2 = std::move(set); @@ -103,7 +105,8 @@ TEST_F(DiagnosticSet, MoveConstructor) TEST_F(DiagnosticSet, MoveAssigment) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); auto set2 = std::move(set); set = std::move(set2); @@ -114,7 +117,8 @@ TEST_F(DiagnosticSet, MoveAssigment) TEST_F(DiagnosticSet, MoveSelfAssigment) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); set = std::move(set); @@ -123,21 +127,24 @@ TEST_F(DiagnosticSet, MoveSelfAssigment) TEST_F(DiagnosticSet, FirstElementEqualBegin) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); ASSERT_TRUE(set.front() == *set.begin()); } TEST_F(DiagnosticSet, BeginIsUnequalEnd) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); ASSERT_TRUE(set.begin() != set.end()); } TEST_F(DiagnosticSet, BeginPlusOneIsEqualEnd) { - auto set = translationUnit.diagnostics(); + translationUnit.parse(); + auto set = translationUnit.translationUnitCore().diagnostics(); ASSERT_TRUE(++set.begin() == set.end()); } @@ -145,14 +152,17 @@ TEST_F(DiagnosticSet, BeginPlusOneIsEqualEnd) TEST_F(DiagnosticSet, ToDiagnosticContainersLetThroughByDefault) { const auto diagnosticContainerWithoutChild = expectedDiagnostic(WithChild); + translationUnitMainFile.parse(); - const auto diagnostics = translationUnitMainFile.diagnostics().toDiagnosticContainers(); + const auto diagnostics = translationUnitMainFile.translationUnitCore().diagnostics().toDiagnosticContainers(); ASSERT_THAT(diagnostics, Contains(IsDiagnosticContainer(diagnosticContainerWithoutChild))); } TEST_F(DiagnosticSet, ToDiagnosticContainersFiltersOutTopLevelItem) { + translationUnitMainFile.parse(); + const ::DiagnosticSet diagnosticSetWithChildren{translationUnitMainFile.translationUnitCore().diagnostics()}; const auto acceptNoDiagnostics = [](const Diagnostic &) { return false; }; const auto diagnostics = diagnosticSetWithChildren.toDiagnosticContainers(acceptNoDiagnostics); diff --git a/tests/unit/unittest/diagnostictest.cpp b/tests/unit/unittest/diagnostictest.cpp index 314c76c9336..885ad498634 100644 --- a/tests/unit/unittest/diagnostictest.cpp +++ b/tests/unit/unittest/diagnostictest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -79,9 +80,24 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset, return true; } -class Diagnostic : public ::testing::Test -{ -protected: +struct DiagnosticData { + DiagnosticData(TranslationUnit &translationUnit) + : diagnosticSet{translationUnit.translationUnitCore().diagnostics()} + , diagnostic{diagnosticSet.front()} + { + } + + DiagnosticSet diagnosticSet; + ::Diagnostic diagnostic; +}; + +struct Data { + Data() + { + translationUnit.parse(); + d.reset(new DiagnosticData(translationUnit)); + } + ProjectPart projectPart{Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-std=c++11")}}; ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; @@ -90,8 +106,17 @@ protected: projectPart, Utf8StringVector(), translationUnits}; - DiagnosticSet diagnosticSet{translationUnit.diagnostics()}; - ::Diagnostic diagnostic{diagnosticSet.front()}; + std::unique_ptr d; +}; + +class Diagnostic : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + +protected: + Data *d; protected: enum ChildMode { WithChild, WithoutChild }; @@ -100,63 +125,63 @@ protected: TEST_F(Diagnostic, MoveContructor) { - const auto diagnostic2 = std::move(diagnostic); + const auto diagnostic2 = std::move(d->d->diagnostic); - ASSERT_TRUE(diagnostic.isNull()); + ASSERT_TRUE(d->d->diagnostic.isNull()); ASSERT_FALSE(diagnostic2.isNull()); } TEST_F(Diagnostic, MoveAssigment) { - auto diagnostic2 = std::move(diagnostic); - diagnostic = std::move(diagnostic2); + auto diagnostic2 = std::move(d->d->diagnostic); + d->d->diagnostic = std::move(diagnostic2); ASSERT_TRUE(diagnostic2.isNull()); - ASSERT_FALSE(diagnostic.isNull()); + ASSERT_FALSE(d->d->diagnostic.isNull()); } TEST_F(Diagnostic, MoveSelfAssigment) { - diagnostic = std::move(diagnostic); + d->d->diagnostic = std::move(d->d->diagnostic); - ASSERT_FALSE(diagnostic.isNull()); + ASSERT_FALSE(d->d->diagnostic.isNull()); } TEST_F(Diagnostic, Text) { - ASSERT_THAT(diagnostic.text(), Utf8StringLiteral("warning: control reaches end of non-void function")); + ASSERT_THAT(d->d->diagnostic.text(), Utf8StringLiteral("warning: control reaches end of non-void function")); } TEST_F(Diagnostic, Category) { - ASSERT_THAT(diagnostic.category(), Utf8StringLiteral("Semantic Issue")); + ASSERT_THAT(d->d->diagnostic.category(), Utf8StringLiteral("Semantic Issue")); } TEST_F(Diagnostic, EnableOption) { - ASSERT_THAT(diagnostic.options().first, Utf8StringLiteral("-Wreturn-type")); + ASSERT_THAT(d->d->diagnostic.options().first, Utf8StringLiteral("-Wreturn-type")); } TEST_F(Diagnostic, DisableOption) { - ASSERT_THAT(diagnostic.options().second, Utf8StringLiteral("-Wno-return-type")); + ASSERT_THAT(d->d->diagnostic.options().second, Utf8StringLiteral("-Wno-return-type")); } TEST_F(Diagnostic, Severity) { - ASSERT_THAT(diagnostic.severity(), DiagnosticSeverity::Warning); + ASSERT_THAT(d->d->diagnostic.severity(), DiagnosticSeverity::Warning); } TEST_F(Diagnostic, ChildDiagnosticsSize) { - auto diagnostic = diagnosticSet.back(); + auto diagnostic = d->d->diagnosticSet.back(); ASSERT_THAT(diagnostic.childDiagnostics().size(), 1); } TEST_F(Diagnostic, ChildDiagnosticsText) { - auto childDiagnostic = diagnosticSet.back().childDiagnostics().front(); + auto childDiagnostic = d->d->diagnosticSet.back().childDiagnostics().front(); ASSERT_THAT(childDiagnostic.text(), Utf8StringLiteral("note: candidate function not viable: requires 1 argument, but 0 were provided")); } @@ -165,11 +190,22 @@ TEST_F(Diagnostic, toDiagnosticContainerLetChildrenThroughByDefault) { const auto diagnosticWithChild = expectedDiagnostic(WithChild); - const auto diagnostic = diagnosticSet.back().toDiagnosticContainer(); + const auto diagnostic = d->d->diagnosticSet.back().toDiagnosticContainer(); ASSERT_THAT(diagnostic, IsDiagnosticContainer(diagnosticWithChild)); } +void Diagnostic::SetUp() +{ + d = new Data; +} + +void Diagnostic::TearDown() +{ + delete d; + d = nullptr; +} + DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMode) const { QVector children; @@ -179,7 +215,7 @@ DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMo Utf8StringLiteral("Semantic Issue"), {Utf8String(), Utf8String()}, ClangBackEnd::DiagnosticSeverity::Note, - SourceLocationContainer(translationUnit.filePath(), 5, 6), + SourceLocationContainer(d->translationUnit.filePath(), 5, 6), {}, {}, {} @@ -193,7 +229,7 @@ DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMo Utf8StringLiteral("Semantic Issue"), {Utf8String(), Utf8String()}, ClangBackEnd::DiagnosticSeverity::Error, - SourceLocationContainer(translationUnit.filePath(), 7, 5), + SourceLocationContainer(d->translationUnit.filePath(), 7, 5), {}, {}, children diff --git a/tests/unit/unittest/fixittest.cpp b/tests/unit/unittest/fixittest.cpp index 072ac37cf7e..1d5bf35a14a 100644 --- a/tests/unit/unittest/fixittest.cpp +++ b/tests/unit/unittest/fixittest.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ using ClangBackEnd::DiagnosticSet; using ClangBackEnd::TranslationUnit; +using ClangBackEnd::TranslationUnitCore; using ClangBackEnd::ProjectPart; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::Diagnostic; @@ -68,9 +70,28 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset, return true; } -class FixIt : public ::testing::Test +struct FixItData { -protected: + FixItData(TranslationUnitCore &translationUnitCore) + : diagnosticSet{translationUnitCore.diagnostics()} + , diagnostic{diagnosticSet.front()} + , fixIt{diagnostic.fixIts().front()} + { + } + + DiagnosticSet diagnosticSet; + Diagnostic diagnostic; + ::FixIt fixIt; +}; + +struct Data +{ + Data() + { + translationUnit.parse(); + d.reset(new FixItData(translationUnitCore)); + } + ProjectPart projectPart{Utf8StringLiteral("projectPartId")}; ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; @@ -79,9 +100,20 @@ protected: projectPart, Utf8StringVector(), translationUnits}; - DiagnosticSet diagnosticSet{translationUnit.diagnostics()}; - Diagnostic diagnostic{diagnosticSet.front()}; - ::FixIt fixIt{diagnostic.fixIts().front()}; + TranslationUnitCore translationUnitCore{translationUnit.translationUnitCore()}; + std::unique_ptr d; +}; + +class FixIt : public ::testing::Test +{ +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + +protected: + static Data *d; + ::Diagnostic &diagnostic = d->d->diagnostic; + ::FixIt &fixIt = d->d->fixIt; }; TEST_F(FixIt, Size) @@ -111,4 +143,17 @@ TEST_F(FixIt, End) 29u)); } +Data *FixIt::d; + +void FixIt::SetUpTestCase() +{ + d = new Data; } + +void FixIt::TearDownTestCase() +{ + delete d; + d = nullptr; +} + +} // anonymous diff --git a/tests/unit/unittest/highlightingmarkstest.cpp b/tests/unit/unittest/highlightingmarkstest.cpp index ebb388d3bb8..d79131e265a 100644 --- a/tests/unit/unittest/highlightingmarkstest.cpp +++ b/tests/unit/unittest/highlightingmarkstest.cpp @@ -23,6 +23,8 @@ ** ****************************************************************************/ +#include +#include #include #include #include @@ -32,10 +34,11 @@ #include #include #include -#include #include #include +#include + #include #include #include @@ -47,6 +50,7 @@ using ClangBackEnd::HighlightingMark; using ClangBackEnd::HighlightingMarks; using ClangBackEnd::HighlightingType; using ClangBackEnd::TranslationUnit; +using ClangBackEnd::TranslationUnitCore; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; using ClangBackEnd::TranslationUnits; @@ -95,13 +99,22 @@ MATCHER_P2(HasTwoTypes, firstType, secondType, } struct Data { + Data() + { + translationUnit.parse(); + } + ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; - TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp"), + Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp")}; + TranslationUnit translationUnit{filePath, ProjectPart(Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-std=c++14")}), {}, translationUnits}; + TranslationUnitCore translationUnitCore{filePath, + translationUnit.index(), + translationUnit.cxTranslationUnit()}; }; class HighlightingMarks : public ::testing::Test @@ -114,7 +127,7 @@ public: protected: static Data *d; - const TranslationUnit &translationUnit = d->translationUnit; + const TranslationUnitCore &translationUnitCore = d->translationUnitCore; }; TEST_F(HighlightingMarks, CreateNullInformations) @@ -133,17 +146,17 @@ TEST_F(HighlightingMarks, NullInformationsAreEmpty) TEST_F(HighlightingMarks, IsNotNull) { - const auto aRange = translationUnit.sourceRange(3, 1, 5, 1); + const auto aRange = translationUnitCore.sourceRange(3, 1, 5, 1); - const auto infos = translationUnit.highlightingMarksInRange(aRange); + const auto infos = translationUnitCore.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 aRange = translationUnitCore.sourceRange(3, 1, 5, 1); + const auto infos = translationUnitCore.highlightingMarksInRange(aRange); const auto endIterator = std::next(infos.begin(), infos.size()); @@ -152,7 +165,7 @@ TEST_F(HighlightingMarks, IteratorBeginEnd) TEST_F(HighlightingMarks, ForFullTranslationUnitRange) { - const auto infos = translationUnit.highlightingMarks(); + const auto infos = translationUnitCore.highlightingMarks(); ASSERT_THAT(infos, AllOf(Contains(IsHighlightingMark(1u, 1u, 4u, HighlightingType::Keyword)), Contains(IsHighlightingMark(277u, 5u, 15u, HighlightingType::Function)))); @@ -160,611 +173,611 @@ TEST_F(HighlightingMarks, ForFullTranslationUnitRange) TEST_F(HighlightingMarks, Size) { - const auto range = translationUnit.sourceRange(5, 5, 5, 10); + const auto range = translationUnitCore.sourceRange(5, 5, 5, 10); - const auto infos = translationUnit.highlightingMarksInRange(range); + const auto infos = translationUnitCore.highlightingMarksInRange(range); ASSERT_THAT(infos.size(), 1); } TEST_F(HighlightingMarks, DISABLED_Keyword) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(5, 12)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(45, 20)); ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, MemberFunctionDefinition) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(52, 29)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(52, 29)); ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Function, HighlightingType::Declaration)); } TEST_F(HighlightingMarks, FunctionDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(55, 32)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(64, 16)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TypeConversionFunction) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(68, 20)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(69, 20)); ASSERT_THAT(infos[1], IsHighlightingMark(69u, 14u, 3u, HighlightingType::Keyword)); } TEST_F(HighlightingMarks, TypeReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(74, 13)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(114, 30)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, Enumeration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(118, 17)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(118, 17)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, Enumerator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(120, 15)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(120, 15)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Enumeration)); } TEST_F(HighlightingMarks, EnumerationReferenceDeclarationType) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(125, 28)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, EnumerationReferenceDeclarationVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(125, 28)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(125, 28)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, EnumerationReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(127, 30)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, EnumeratorReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(127, 30)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(127, 30)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Enumeration)); } TEST_F(HighlightingMarks, ClassForwardDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(130, 12)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(130, 12)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ConstructorDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(134, 13)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(138, 23)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ClassTypeReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(140, 32)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, ConstructorReferenceVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(140, 32)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(140, 32)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, UnionDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(145, 12)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(145, 12)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, UnionDeclarationReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(150, 33)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, GlobalVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(150, 33)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(150, 33)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::GlobalVariable)); } TEST_F(HighlightingMarks, StructDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(50, 11)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(50, 11)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpace) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(160, 22)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(160, 22)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpaceAlias) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(164, 38)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(164, 38)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, UsingStructInNameSpace) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(165, 36)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(165, 36)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NameSpaceReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(166, 35)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, StructInNameSpaceReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(166, 35)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(166, 35)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, VirtualFunctionDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(170, 35)); + const auto infos = translationUnitCore.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)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(177, 46)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, DISABLED_NonVirtualFunctionCallPointer) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(180, 54)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(180, 54)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, VirtualFunctionCallPointer) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(192, 51)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(192, 51)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); } TEST_F(HighlightingMarks, FinalVirtualFunctionCallPointer) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(202, 61)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(202, 61)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, NonFinalVirtualFunctionCallPointer) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(207, 61)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(207, 61)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::VirtualFunction)); } TEST_F(HighlightingMarks, PlusOperator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(224, 49)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(224, 49)); ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Operator)); } TEST_F(HighlightingMarks, PlusAssignOperator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(226, 24)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(226, 24)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Operator)); } TEST_F(HighlightingMarks, Comment) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(229, 14)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(229, 14)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Comment)); } TEST_F(HighlightingMarks, PreprocessingDirective) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(231, 37)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor)); } TEST_F(HighlightingMarks, PreprocessorMacroDefinition) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(231, 37)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(231, 37)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); } TEST_F(HighlightingMarks, PreprocessorFunctionMacroDefinition) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(232, 47)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(232, 47)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::PreprocessorDefinition)); } TEST_F(HighlightingMarks, PreprocessorMacroExpansion) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(236, 27)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::PreprocessorExpansion)); } TEST_F(HighlightingMarks, PreprocessorMacroExpansionArgument) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(236, 27)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(236, 27)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::NumberLiteral)); } TEST_F(HighlightingMarks, PreprocessorInclusionDirective) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(239, 18)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(239, 18)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::StringLiteral)); } TEST_F(HighlightingMarks, GotoLabelStatement) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(242, 12)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(242, 12)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Label)); } TEST_F(HighlightingMarks, GotoLabelStatementReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(244, 21)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(244, 21)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Label)); } TEST_F(HighlightingMarks, TemplateReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(254, 25)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(254, 25)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplateTypeParameter) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateDefaultParameter) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NonTypeTemplateParameter) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterDefaultArgument) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[10], HasOnlyType(HighlightingType::NumberLiteral)); } TEST_F(HighlightingMarks, TemplateTemplateParameter) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[17], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateParameterDefaultArgument) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(265, 135)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(265, 135)); ASSERT_THAT(infos[19], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateFunctionDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(266, 63)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(266, 63)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplateTypeParameterReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(268, 58)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTypeParameterDeclarationReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(268, 58)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(268, 58)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(269, 71)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonTypeTemplateParameterReferenceReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(269, 71)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(269, 71)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, TemplateTemplateParameterReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(270, 89)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateContainerParameterReference) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(270, 89)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateTemplateParameterReferenceVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(270, 89)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(270, 89)); ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCallPointer) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(212, 61)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(212, 61)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, ClassFinalVirtualFunctionCall) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(277, 23)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(277, 23)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, HasFunctionArguments) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(286, 29)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(286, 29)); ASSERT_TRUE(infos[1].hasFunctionArguments()); } TEST_F(HighlightingMarks, PreprocessorInclusionDirectiveWithAngleBrackets ) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(289, 38)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(289, 38)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral)); } TEST_F(HighlightingMarks, ArgumentInMacroExpansionIsKeyword) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(302, 36)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Keyword)); } TEST_F(HighlightingMarks, DISABLED_FirstArgumentInMacroExpansionIsLocalVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(302, 36)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsLocalVariable) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(302, 36)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(302, 36)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsField) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(310, 40)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(310, 40)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Invalid)); } @@ -772,28 +785,28 @@ TEST_F(HighlightingMarks, DISABLED_SecondArgumentInMacroExpansionIsField) TEST_F(HighlightingMarks, DISABLED_EnumerationType) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(316, 30)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(316, 30)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TypeInStaticCast) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(328, 64)); ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, StaticCastIsKeyword) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(328, 64)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Keyword)); } TEST_F(HighlightingMarks, StaticCastPunctationIsInvalid) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(328, 64)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(328, 64)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Invalid)); @@ -802,154 +815,154 @@ TEST_F(HighlightingMarks, StaticCastPunctationIsInvalid) TEST_F(HighlightingMarks, TypeInReinterpretCast) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(329, 69)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(329, 69)); ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerAliasDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(333, 41)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(333, 41)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerAlias) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(341, 31)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(341, 31)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, SecondIntegerAlias) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(342, 43)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(342, 43)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, IntegerTypedef) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(343, 35)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(343, 35)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, FunctionAlias) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(344, 16)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(344, 16)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, FriendTypeDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(350, 28)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(350, 28)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FriendArgumentTypeDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(351, 65)); ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FriendArgumentDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(351, 65)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(351, 65)); ASSERT_THAT(infos[8], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, FieldInitialization) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(358, 18)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(358, 18)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Field)); } TEST_F(HighlightingMarks, TemplateFunctionCall) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(372, 29)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(372, 29)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Function)); } TEST_F(HighlightingMarks, TemplatedType) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(377, 21)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(377, 21)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplatedTypeDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(384, 49)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(384, 49)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, NoOperator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(389, 24)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(389, 24)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, ScopeOperator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(400, 33)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(400, 33)); ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); } TEST_F(HighlightingMarks, TemplateClassNamespace) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(413, 78)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClass) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(413, 78)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClassParameter) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(413, 78)); ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TemplateClassDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(413, 78)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(413, 78)); ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, TypeDefDeclaration) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(418, 36)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(418, 36)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, TypeDefDeclarationUsage) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(419, 48)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(419, 48)); ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Type)); } TEST_F(HighlightingMarks, DISABLED_EnumerationTypeDef) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(424, 41)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(424, 41)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Type)); } @@ -957,7 +970,7 @@ TEST_F(HighlightingMarks, DISABLED_EnumerationTypeDef) // QTCREATORBUG-15473 TEST_F(HighlightingMarks, DISABLED_ArgumentToUserDefinedIndexOperator) { - const auto infos = translationUnit.highlightingMarksInRange(sourceRange(434, 19)); + const auto infos = translationUnitCore.highlightingMarksInRange(sourceRange(434, 19)); ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::LocalVariable)); } @@ -977,7 +990,7 @@ void HighlightingMarks::TearDownTestCase() ClangBackEnd::SourceRange HighlightingMarks::sourceRange(uint line, uint columnEnd) const { - return translationUnit.sourceRange(line, 1, line, columnEnd); + return translationUnitCore.sourceRange(line, 1, line, columnEnd); } } diff --git a/tests/unit/unittest/skippedsourcerangestest.cpp b/tests/unit/unittest/skippedsourcerangestest.cpp index e6d61161f94..c75eaa89848 100644 --- a/tests/unit/unittest/skippedsourcerangestest.cpp +++ b/tests/unit/unittest/skippedsourcerangestest.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ using ClangBackEnd::Cursor; using ClangBackEnd::TranslationUnit; +using ClangBackEnd::TranslationUnitCore; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; using ClangBackEnd::TranslationUnits; @@ -84,6 +86,11 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset, } struct Data { + Data() + { + translationUnit.parse(); + } + ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; @@ -93,6 +100,9 @@ struct Data { {Utf8StringLiteral("-std=c++11"),Utf8StringLiteral("-DBLAH")}), {}, translationUnits}; + TranslationUnitCore translationUnitCore{filePath, + translationUnit.index(), + translationUnit.cxTranslationUnit()}; }; class SkippedSourceRanges : public ::testing::Test @@ -103,9 +113,9 @@ public: protected: static Data *d; - const TranslationUnit &translationUnit = d->translationUnit; + const TranslationUnitCore &translationUnitCore = d->translationUnitCore; const Utf8String &filePath = d->filePath; - const ::SkippedSourceRanges skippedSourceRanges{d->translationUnit.skippedSourceRanges()}; + const ::SkippedSourceRanges skippedSourceRanges{d->translationUnitCore.skippedSourceRanges()}; }; Data *SkippedSourceRanges::d; diff --git a/tests/unit/unittest/sourcelocationtest.cpp b/tests/unit/unittest/sourcelocationtest.cpp index ecda5f08d58..584d9540893 100644 --- a/tests/unit/unittest/sourcelocationtest.cpp +++ b/tests/unit/unittest/sourcelocationtest.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,26 @@ using testing::Not; namespace { +struct SourceLocationData { + SourceLocationData(TranslationUnit &translationUnit) + : diagnosticSet{translationUnit.translationUnitCore().diagnostics()} + , diagnostic{diagnosticSet.front()} + , sourceLocation{diagnostic.location()} + { + } + + DiagnosticSet diagnosticSet; + Diagnostic diagnostic; + ::SourceLocation sourceLocation; +}; + struct Data { + Data() + { + translationUnit.parse(); + d.reset(new SourceLocationData(translationUnit)); + } + ProjectPart projectPart{Utf8StringLiteral("projectPartId")}; ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; @@ -60,9 +80,7 @@ struct Data { projectPart, Utf8StringVector(), translationUnits}; - DiagnosticSet diagnosticSet{translationUnit.diagnostics()}; - Diagnostic diagnostic{diagnosticSet.front()}; - ::SourceLocation sourceLocation{diagnostic.location()}; + std::unique_ptr d; }; class SourceLocation : public ::testing::Test @@ -73,8 +91,8 @@ public: protected: static Data *d; - const ::SourceLocation &sourceLocation = d->sourceLocation; - const TranslationUnit &translationUnit = d->translationUnit; + TranslationUnit &translationUnit = d->translationUnit; + ::SourceLocation &sourceLocation = d->d->sourceLocation; }; TEST_F(SourceLocation, FilePath) @@ -99,12 +117,12 @@ TEST_F(SourceLocation, Offset) TEST_F(SourceLocation, Create) { - ASSERT_THAT(translationUnit.sourceLocationAt(4, 1), sourceLocation); + ASSERT_THAT(translationUnit.translationUnitCore().sourceLocationAt(4, 1), sourceLocation); } TEST_F(SourceLocation, NotEqual) { - ASSERT_THAT(translationUnit.sourceLocationAt(3, 1), Not(sourceLocation)); + ASSERT_THAT(translationUnit.translationUnitCore().sourceLocationAt(3, 1), Not(sourceLocation)); } Data *SourceLocation::d; diff --git a/tests/unit/unittest/sourcerangetest.cpp b/tests/unit/unittest/sourcerangetest.cpp index 6bd6eefa4ea..6299e5fb47d 100644 --- a/tests/unit/unittest/sourcerangetest.cpp +++ b/tests/unit/unittest/sourcerangetest.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include #include #include #include @@ -34,6 +35,8 @@ #include +#include + #include #include #include @@ -41,6 +44,7 @@ using ClangBackEnd::DiagnosticSet; using ClangBackEnd::TranslationUnit; +using ClangBackEnd::TranslationUnitCore; using ClangBackEnd::ProjectPart; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::Diagnostic; @@ -70,19 +74,42 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset, return true; } +struct SourceRangeData { + SourceRangeData(TranslationUnit &translationUnit) + : diagnosticSet{translationUnit.translationUnitCore().diagnostics()} + , diagnostic{diagnosticSet.front()} + , diagnosticWithFilteredOutInvalidRange{diagnosticSet.at(1)} + , sourceRange{diagnostic.ranges().front()} + { + } + + DiagnosticSet diagnosticSet; + Diagnostic diagnostic; + Diagnostic diagnosticWithFilteredOutInvalidRange; + ::SourceRange sourceRange; +}; + struct Data { + Data() + { + translationUnit.parse(); + d.reset(new SourceRangeData(translationUnit)); + } + ProjectPart projectPart{Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-pedantic")}}; ClangBackEnd::ProjectParts projects; ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; - TranslationUnit translationUnit{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_source_range.cpp"), + Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_source_range.cpp")}; + TranslationUnit translationUnit{filePath, projectPart, Utf8StringVector(), translationUnits}; - DiagnosticSet diagnosticSet{translationUnit.diagnostics()}; - Diagnostic diagnostic{diagnosticSet.front()}; - Diagnostic diagnosticWithFilteredOutInvalidRange{diagnosticSet.at(1)}; - ::SourceRange sourceRange{diagnostic.ranges().front()}; + TranslationUnitCore translationUnitCore{filePath, + translationUnit.index(), + translationUnit.cxTranslationUnit()}; + + std::unique_ptr d; }; class SourceRange : public ::testing::Test @@ -93,10 +120,10 @@ public: protected: static Data *d; - const ::SourceRange &sourceRange = d->sourceRange; - const Diagnostic &diagnostic = d->diagnostic; - const Diagnostic &diagnosticWithFilteredOutInvalidRange = d->diagnosticWithFilteredOutInvalidRange; - const TranslationUnit &translationUnit = d->translationUnit; + const ::SourceRange &sourceRange = d->d->sourceRange; + const Diagnostic &diagnostic = d->d->diagnostic; + const Diagnostic &diagnosticWithFilteredOutInvalidRange = d->d->diagnosticWithFilteredOutInvalidRange; + const TranslationUnitCore &translationUnitCore = d->translationUnitCore; }; TEST_F(SourceRange, IsNull) @@ -141,7 +168,7 @@ TEST_F(SourceRange, Create) TEST_F(SourceRange, SourceRangeFromTranslationUnit) { - auto sourceRangeFromTranslationUnit = translationUnit.sourceRange(8u, 5u, 8u, 6u); + auto sourceRangeFromTranslationUnit = translationUnitCore.sourceRange(8u, 5u, 8u, 6u); ASSERT_THAT(sourceRangeFromTranslationUnit, sourceRange); } diff --git a/tests/unit/unittest/translationunitstest.cpp b/tests/unit/unittest/translationunitstest.cpp index 75a8aa2cb6a..9f691842331 100644 --- a/tests/unit/unittest/translationunitstest.cpp +++ b/tests/unit/unittest/translationunitstest.cpp @@ -211,7 +211,8 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse) ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); translationUnits.create({fileContainer, headerContainer}); - translationUnits.translationUnit(filePath, projectPartId).cxTranslationUnit(); + TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId); + translationUnit.parse(); translationUnits.update({headerContainerWithUnsavedContent}); @@ -224,7 +225,9 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics) ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); translationUnits.create({fileContainer, headerContainer}); - translationUnits.translationUnit(filePath, projectPartId).diagnostics(); + TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId); + translationUnit.parse(); + translationUnit.diagnostics(); translationUnits.update({headerContainerWithUnsavedContent}); @@ -237,7 +240,9 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics) ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); translationUnits.create({fileContainer, headerContainer}); - translationUnits.translationUnit(filePath, projectPartId).diagnostics(); + TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId); + translationUnit.parse(); + translationUnit.diagnostics(); translationUnits.remove({headerContainerWithUnsavedContent}); @@ -250,7 +255,9 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForHighlightingMarks) ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); translationUnits.create({fileContainer, headerContainer}); - translationUnits.translationUnit(filePath, projectPartId).highlightingMarks(); + TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId); + translationUnit.parse(); + translationUnit.highlightingMarks(); translationUnits.update({headerContainerWithUnsavedContent}); @@ -263,7 +270,9 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForHighlightingMarks) ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); translationUnits.create({fileContainer, headerContainer}); - translationUnits.translationUnit(filePath, projectPartId).highlightingMarks(); + TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId); + translationUnit.parse(); + translationUnit.highlightingMarks(); translationUnits.remove({headerContainerWithUnsavedContent}); diff --git a/tests/unit/unittest/translationunittest.cpp b/tests/unit/unittest/translationunittest.cpp index 714ed595753..31b3a6ee33c 100644 --- a/tests/unit/unittest/translationunittest.cpp +++ b/tests/unit/unittest/translationunittest.cpp @@ -132,8 +132,10 @@ TEST_F(TranslationUnit, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit) ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitIsNullException); } -TEST_F(TranslationUnit, CxTranslationUnitGetterIsNonNullForValidUnit) +TEST_F(TranslationUnit, CxTranslationUnitGetterIsNonNullForParsedUnit) { + translationUnit.parse(); + ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull()); } @@ -164,7 +166,7 @@ TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslation auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint(); std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); - translationUnit.cxTranslationUnit(); + translationUnit.parse(); ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint)); } @@ -172,12 +174,12 @@ TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslation TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared) { ProjectPart projectPart = translationUnit.projectPart(); - translationUnit.cxTranslationUnit(); + translationUnit.parse(); auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint(); std::this_thread::sleep_for(std::chrono::steady_clock::duration(1)); projectPart.clear(); - translationUnit.cxTranslationUnit(); + translationUnit.parse(); ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint)); } @@ -191,6 +193,8 @@ TEST_F(TranslationUnit, DocumentRevisionInFileContainerGetter) TEST_F(TranslationUnit, DependedFilePaths) { + translationUnit.parse(); + ASSERT_THAT(translationUnit.dependedFilePaths(), AllOf(Contains(translationUnitFilePath), Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")))); @@ -207,14 +211,12 @@ TEST_F(TranslationUnit, DeletedFileShouldNotNeedReparsing) TEST_F(TranslationUnit, NeedsNoReparseAfterCreation) { - translationUnit.cxTranslationUnit(); - ASSERT_FALSE(translationUnit.isNeedingReparse()); } TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath); @@ -223,7 +225,7 @@ TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile) TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); @@ -232,7 +234,7 @@ TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile) TEST_F(TranslationUnit, NeedsReparsingForDependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); @@ -241,17 +243,17 @@ TEST_F(TranslationUnit, NeedsReparsingForDependendFile) TEST_F(TranslationUnit, NeedsNoReparsingAfterReparsing) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); - translationUnit.cxTranslationUnit(); + translationUnit.reparse(); ASSERT_FALSE(translationUnit.isNeedingReparse()); } -TEST_F(TranslationUnit, IsIntactAfterCreation) +TEST_F(TranslationUnit, IsIntactAfterParsing) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); ASSERT_TRUE(translationUnit.isIntact()); } @@ -263,16 +265,16 @@ TEST_F(TranslationUnit, IsNotIntactForDeletedFile) ASSERT_FALSE(translationUnit.isIntact()); } -TEST_F(TranslationUnit, HasNewDiagnosticsAfterCreation) +TEST_F(TranslationUnit, HasNewDiagnosticsAfterParse) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); ASSERT_TRUE(translationUnit.hasNewDiagnostics()); } TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath); @@ -281,7 +283,7 @@ TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile) TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.diagnostics(); // Reset hasNewDiagnostics translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); @@ -291,7 +293,7 @@ TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile) TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); @@ -300,7 +302,7 @@ TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile) TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath); translationUnit.diagnostics(); // Reset hasNewDiagnostics @@ -310,14 +312,14 @@ TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics) TEST_F(TranslationUnit, HasNewHighlightingMarksAfterCreation) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); ASSERT_TRUE(translationUnit.hasNewHighlightingMarks()); } TEST_F(TranslationUnit, HasNewHighlightingMarksForMainFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath); @@ -326,7 +328,7 @@ TEST_F(TranslationUnit, HasNewHighlightingMarksForMainFile) TEST_F(TranslationUnit, HasNoNewHighlightingMarksForIndependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.highlightingMarks(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); @@ -336,7 +338,7 @@ TEST_F(TranslationUnit, HasNoNewHighlightingMarksForIndependendFile) TEST_F(TranslationUnit, HasNewHighlightingMarksForDependendFile) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); @@ -345,7 +347,7 @@ TEST_F(TranslationUnit, HasNewHighlightingMarksForDependendFile) TEST_F(TranslationUnit, HasNoNewHighlightingMarksAfterGettingHighlightingMarks) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath); translationUnit.highlightingMarks(); @@ -356,7 +358,7 @@ TEST_F(TranslationUnit, HasNoNewHighlightingMarksAfterGettingHighlightingMarks) TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated) { projects.createOrUpdate({ProjectPartContainer(projectPartId)}); - translationUnit.cxTranslationUnit(); + translationUnit.parse(); projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})}); translationUnit.setDirtyIfProjectPartIsOutdated(); @@ -366,7 +368,7 @@ TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated) TEST_F(TranslationUnit, SetNotDirtyIfProjectPartIsNotOutdated) { - translationUnit.cxTranslationUnit(); + translationUnit.parse(); translationUnit.setDirtyIfProjectPartIsOutdated();