forked from qt-creator/qt-creator
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 <tim.jenssen@qt.io>
This commit is contained in:
@@ -37,7 +37,8 @@ HEADERS += $$PWD/clangcodemodelserver.h \
|
|||||||
$$PWD/highlightingmarksiterator.h \
|
$$PWD/highlightingmarksiterator.h \
|
||||||
$$PWD/utf8positionfromlinecolumn.h \
|
$$PWD/utf8positionfromlinecolumn.h \
|
||||||
$$PWD/clangfilepath.h \
|
$$PWD/clangfilepath.h \
|
||||||
$$PWD/clangunsavedfilesshallowarguments.h
|
$$PWD/clangunsavedfilesshallowarguments.h \
|
||||||
|
$$PWD/clangtranslationunitcore.h
|
||||||
|
|
||||||
SOURCES += $$PWD/clangcodemodelserver.cpp \
|
SOURCES += $$PWD/clangcodemodelserver.cpp \
|
||||||
$$PWD/codecompleter.cpp \
|
$$PWD/codecompleter.cpp \
|
||||||
@@ -74,4 +75,5 @@ SOURCES += $$PWD/clangcodemodelserver.cpp \
|
|||||||
$$PWD/highlightingmarks.cpp \
|
$$PWD/highlightingmarks.cpp \
|
||||||
$$PWD/utf8positionfromlinecolumn.cpp \
|
$$PWD/utf8positionfromlinecolumn.cpp \
|
||||||
$$PWD/clangfilepath.cpp \
|
$$PWD/clangfilepath.cpp \
|
||||||
$$PWD/clangunsavedfilesshallowarguments.cpp
|
$$PWD/clangunsavedfilesshallowarguments.cpp \
|
||||||
|
$$PWD/clangtranslationunitcore.cpp
|
||||||
|
|||||||
@@ -240,8 +240,10 @@ void ClangCodeModelServer::completeCode(const ClangBackEnd::CompleteCodeMessage
|
|||||||
TIME_SCOPE_DURATION("ClangCodeModelServer::completeCode");
|
TIME_SCOPE_DURATION("ClangCodeModelServer::completeCode");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CodeCompleter codeCompleter(translationUnits.translationUnit(message.filePath(), message.projectPartId()),
|
auto translationUnit = translationUnits.translationUnit(message.filePath(), message.projectPartId());
|
||||||
unsavedFiles);
|
auto translationUnitCore = translationUnit.translationUnitCore();
|
||||||
|
|
||||||
|
CodeCompleter codeCompleter(translationUnitCore, unsavedFiles);
|
||||||
|
|
||||||
const auto codeCompletions = codeCompleter.complete(message.line(), message.column());
|
const auto codeCompletions = codeCompleter.complete(message.line(), message.column());
|
||||||
|
|
||||||
@@ -264,11 +266,13 @@ void ClangCodeModelServer::requestDocumentAnnotations(const RequestDocumentAnnot
|
|||||||
try {
|
try {
|
||||||
auto translationUnit = translationUnits.translationUnit(message.fileContainer().filePath(),
|
auto translationUnit = translationUnits.translationUnit(message.fileContainer().filePath(),
|
||||||
message.fileContainer().projectPartId());
|
message.fileContainer().projectPartId());
|
||||||
|
auto translationUnitCore = translationUnit.translationUnitCore();
|
||||||
|
|
||||||
client()->documentAnnotationsChanged(DocumentAnnotationsChangedMessage(translationUnit.fileContainer(),
|
client()->documentAnnotationsChanged(DocumentAnnotationsChangedMessage(
|
||||||
translationUnit.mainFileDiagnostics(),
|
translationUnit.fileContainer(),
|
||||||
translationUnit.highlightingMarks().toHighlightingMarksContainers(),
|
translationUnitCore.mainFileDiagnostics(),
|
||||||
translationUnit.skippedSourceRanges().toSourceRangeContainers()));
|
translationUnitCore.highlightingMarks().toHighlightingMarksContainers(),
|
||||||
|
translationUnitCore.skippedSourceRanges().toSourceRangeContainers()));
|
||||||
} catch (const TranslationUnitDoesNotExistException &exception) {
|
} catch (const TranslationUnitDoesNotExistException &exception) {
|
||||||
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer()));
|
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer()));
|
||||||
} catch (const ProjectPartDoNotExistException &exception) {
|
} catch (const ProjectPartDoNotExistException &exception) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "translationunitisnullexception.h"
|
#include "translationunitisnullexception.h"
|
||||||
#include "translationunitparseerrorexception.h"
|
#include "translationunitparseerrorexception.h"
|
||||||
#include "translationunitreparseerrorexception.h"
|
#include "translationunitreparseerrorexception.h"
|
||||||
|
#include "clangtranslationunitcore.h"
|
||||||
#include "clangtranslationunitupdater.h"
|
#include "clangtranslationunitupdater.h"
|
||||||
#include "translationunits.h"
|
#include "translationunits.h"
|
||||||
#include "unsavedfiles.h"
|
#include "unsavedfiles.h"
|
||||||
@@ -148,11 +149,24 @@ void TranslationUnit::reset()
|
|||||||
d.reset();
|
d.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TranslationUnit::parse() const
|
||||||
|
{
|
||||||
|
checkIfNull();
|
||||||
|
|
||||||
|
const TranslationUnitUpdateInput updateInput = createUpdateInput();
|
||||||
|
TranslationUnitUpdateResult result = translationUnitCore().parse(updateInput);
|
||||||
|
|
||||||
|
incorporateUpdaterResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
void TranslationUnit::reparse() const
|
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
|
bool TranslationUnit::parseWasSuccessful() const
|
||||||
@@ -172,23 +186,11 @@ CXIndex &TranslationUnit::index() const
|
|||||||
return d->index;
|
return d->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
CXTranslationUnit TranslationUnit::cxTranslationUnit() const
|
CXTranslationUnit &TranslationUnit::cxTranslationUnit() const
|
||||||
{
|
{
|
||||||
checkIfNull();
|
checkIfNull();
|
||||||
checkIfFileExists();
|
checkIfFileExists();
|
||||||
|
|
||||||
updateSynchronously(TranslationUnitUpdater::UpdateMode::AsNeeded);
|
|
||||||
|
|
||||||
return d->translationUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
CXTranslationUnit TranslationUnit::cxTranslationUnitWithoutReparsing() const
|
|
||||||
{
|
|
||||||
checkIfNull();
|
|
||||||
checkIfFileExists();
|
|
||||||
|
|
||||||
updateSynchronously(TranslationUnitUpdater::UpdateMode::ParseIfNeeded);
|
|
||||||
|
|
||||||
return d->translationUnit;
|
return d->translationUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,17 +272,14 @@ DiagnosticSet TranslationUnit::diagnostics() const
|
|||||||
{
|
{
|
||||||
d->hasNewDiagnostics = false;
|
d->hasNewDiagnostics = false;
|
||||||
|
|
||||||
return DiagnosticSet(clang_getDiagnosticSetFromTU(cxTranslationUnit()));
|
return translationUnitCore().diagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<ClangBackEnd::DiagnosticContainer> TranslationUnit::mainFileDiagnostics() const
|
QVector<ClangBackEnd::DiagnosticContainer> TranslationUnit::mainFileDiagnostics() const
|
||||||
{
|
{
|
||||||
const auto mainFilePath = filePath();
|
d->hasNewDiagnostics = false;
|
||||||
const auto isMainFileDiagnostic = [mainFilePath](const Diagnostic &diagnostic) {
|
|
||||||
return diagnostic.location().filePath() == mainFilePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
return diagnostics().toDiagnosticContainers(isMainFileDiagnostic);
|
return translationUnitCore().mainFileDiagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QSet<Utf8String> &TranslationUnit::dependedFilePaths() const
|
const QSet<Utf8String> &TranslationUnit::dependedFilePaths() const
|
||||||
@@ -302,58 +301,11 @@ void TranslationUnit::setDirtyIfDependencyIsMet(const Utf8String &filePath)
|
|||||||
setDirty();
|
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
|
HighlightingMarks TranslationUnit::highlightingMarks() const
|
||||||
{
|
{
|
||||||
d->hasNewHighlightingMarks = false;
|
d->hasNewHighlightingMarks = false;
|
||||||
|
|
||||||
return highlightingMarksInRange(cursor().sourceRange());
|
return translationUnitCore().highlightingMarks();
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationUnit::checkIfNull() const
|
void TranslationUnit::checkIfNull() const
|
||||||
@@ -402,15 +354,7 @@ bool TranslationUnit::fileExists() const
|
|||||||
return QFileInfo::exists(d->filePath.toString());
|
return QFileInfo::exists(d->filePath.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationUnit::updateSynchronously(TranslationUnitUpdater::UpdateMode updateMode) const
|
TranslationUnitUpdateInput TranslationUnit::createUpdateInput() const
|
||||||
{
|
|
||||||
TranslationUnitUpdater updater = createUpdater();
|
|
||||||
const TranslationUnitUpdateResult updateResult = updater.update(updateMode);
|
|
||||||
|
|
||||||
incorporateUpdaterResult(updateResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
TranslationUnitUpdater TranslationUnit::createUpdater() const
|
|
||||||
{
|
{
|
||||||
TranslationUnitUpdateInput updateInput;
|
TranslationUnitUpdateInput updateInput;
|
||||||
updateInput.reparseNeeded = isNeedingReparse();
|
updateInput.reparseNeeded = isNeedingReparse();
|
||||||
@@ -421,6 +365,12 @@ TranslationUnitUpdater TranslationUnit::createUpdater() const
|
|||||||
updateInput.projectId = projectPart().projectPartId();
|
updateInput.projectId = projectPart().projectPartId();
|
||||||
updateInput.projectArguments = projectPart().arguments();
|
updateInput.projectArguments = projectPart().arguments();
|
||||||
|
|
||||||
|
return updateInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
TranslationUnitUpdater TranslationUnit::createUpdater() const
|
||||||
|
{
|
||||||
|
const TranslationUnitUpdateInput updateInput = createUpdateInput();
|
||||||
TranslationUnitUpdater updater(index(), d->translationUnit, updateInput);
|
TranslationUnitUpdater updater(index(), d->translationUnit, updateInput);
|
||||||
|
|
||||||
return updater;
|
return updater;
|
||||||
@@ -431,8 +381,7 @@ void TranslationUnit::incorporateUpdaterResult(const TranslationUnitUpdateResult
|
|||||||
if (result.parseTimePointIsSet)
|
if (result.parseTimePointIsSet)
|
||||||
d->lastProjectPartChangeTimePoint = result.parseTimePoint;
|
d->lastProjectPartChangeTimePoint = result.parseTimePoint;
|
||||||
|
|
||||||
if (!result.dependedOnFilePaths.isEmpty()) // TODO: Remove me
|
d->dependedFilePaths = result.dependedOnFilePaths;
|
||||||
d->dependedFilePaths = result.dependedOnFilePaths;
|
|
||||||
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
||||||
|
|
||||||
if (result.reparsed)
|
if (result.reparsed)
|
||||||
@@ -452,14 +401,9 @@ CommandLineArguments TranslationUnit::commandLineArguments() const
|
|||||||
return createUpdater().commandLineArguments();
|
return createUpdater().commandLineArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceLocation TranslationUnit::sourceLocationAtWithoutReparsing(uint line, uint column) const
|
TranslationUnitCore TranslationUnit::translationUnitCore() const
|
||||||
{
|
{
|
||||||
return SourceLocation(cxTranslationUnitWithoutReparsing(), filePath(), line, column);
|
return TranslationUnitCore(d->filePath, d->index, d->translationUnit);
|
||||||
}
|
|
||||||
|
|
||||||
uint TranslationUnit::defaultParseOptions()
|
|
||||||
{
|
|
||||||
return TranslationUnitUpdater::defaultParseOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint TranslationUnit::unsavedFilesCount() const
|
uint TranslationUnit::unsavedFilesCount() const
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "clangtranslationunitupdater.h"
|
#include "clangtranslationunitupdater.h"
|
||||||
|
|
||||||
|
#include "clangtranslationunitcore.h"
|
||||||
|
|
||||||
#include <utf8stringvector.h>
|
#include <utf8stringvector.h>
|
||||||
|
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
@@ -41,6 +43,7 @@ class Utf8String;
|
|||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class TranslationUnitCore;
|
||||||
class TranslationUnitData;
|
class TranslationUnitData;
|
||||||
class TranslationUnitUpdateResult;
|
class TranslationUnitUpdateResult;
|
||||||
class CodeCompleter;
|
class CodeCompleter;
|
||||||
@@ -91,14 +94,14 @@ public:
|
|||||||
bool isVisibleInEditor() const;
|
bool isVisibleInEditor() const;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
void parse() const;
|
||||||
void reparse() const;
|
void reparse() const;
|
||||||
|
|
||||||
bool isIntact() const;
|
bool isIntact() const;
|
||||||
|
|
||||||
CXIndex &index() const;
|
CXIndex &index() const;
|
||||||
|
|
||||||
CXTranslationUnit cxTranslationUnit() const;
|
CXTranslationUnit &cxTranslationUnit() const;
|
||||||
CXTranslationUnit cxTranslationUnitWithoutReparsing() const;
|
|
||||||
|
|
||||||
UnsavedFile unsavedFile() const;
|
UnsavedFile unsavedFile() const;
|
||||||
UnsavedFiles unsavedFiles() const;
|
UnsavedFiles unsavedFiles() const;
|
||||||
@@ -116,9 +119,12 @@ public:
|
|||||||
const time_point &lastProjectPartChangeTimePoint() const;
|
const time_point &lastProjectPartChangeTimePoint() const;
|
||||||
|
|
||||||
bool isNeedingReparse() const;
|
bool isNeedingReparse() const;
|
||||||
|
|
||||||
|
// TODO: Remove the following two
|
||||||
bool hasNewDiagnostics() const;
|
bool hasNewDiagnostics() const;
|
||||||
bool hasNewHighlightingMarks() const;
|
bool hasNewHighlightingMarks() const;
|
||||||
|
|
||||||
|
// TODO: Remove the following two
|
||||||
DiagnosticSet diagnostics() const;
|
DiagnosticSet diagnostics() const;
|
||||||
QVector<DiagnosticContainer> mainFileDiagnostics() const;
|
QVector<DiagnosticContainer> mainFileDiagnostics() const;
|
||||||
|
|
||||||
@@ -129,23 +135,12 @@ public:
|
|||||||
|
|
||||||
CommandLineArguments commandLineArguments() const;
|
CommandLineArguments commandLineArguments() const;
|
||||||
|
|
||||||
SourceLocation sourceLocationAtWithoutReparsing(uint line, uint column) const;
|
// TODO: Remove
|
||||||
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 highlightingMarks() const;
|
||||||
HighlightingMarks highlightingMarksInRange(const SourceRange &range) const;
|
|
||||||
|
|
||||||
SkippedSourceRanges skippedSourceRanges() const;
|
TranslationUnitCore translationUnitCore() const;
|
||||||
|
|
||||||
bool projectPartIsOutdated() const;
|
bool projectPartIsOutdated() const;
|
||||||
static uint defaultParseOptions();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDirty();
|
void setDirty();
|
||||||
@@ -157,7 +152,7 @@ private:
|
|||||||
bool reparseWasSuccessful() const;
|
bool reparseWasSuccessful() const;
|
||||||
bool fileExists() const;
|
bool fileExists() const;
|
||||||
|
|
||||||
void updateSynchronously(TranslationUnitUpdater::UpdateMode updateMode) const;
|
TranslationUnitUpdateInput createUpdateInput() const;
|
||||||
TranslationUnitUpdater createUpdater() const;
|
TranslationUnitUpdater createUpdater() const;
|
||||||
void incorporateUpdaterResult(const TranslationUnitUpdateResult &result) const;
|
void incorporateUpdaterResult(const TranslationUnitUpdateResult &result) const;
|
||||||
|
|
||||||
|
|||||||
189
src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp
Normal file
189
src/tools/clangbackend/ipcsource/clangtranslationunitcore.cpp
Normal file
@@ -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 <codecompleter.h>
|
||||||
|
#include <cursor.h>
|
||||||
|
#include <diagnosticcontainer.h>
|
||||||
|
#include <diagnosticset.h>
|
||||||
|
#include <highlightingmark.h>
|
||||||
|
#include <highlightingmarks.h>
|
||||||
|
#include <skippedsourceranges.h>
|
||||||
|
#include <sourcelocation.h>
|
||||||
|
#include <sourcerange.h>
|
||||||
|
|
||||||
|
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<DiagnosticContainer> &diagnostics,
|
||||||
|
QVector<HighlightingMarkContainer> &highlightingMarks,
|
||||||
|
QVector<SourceRangeContainer> &skippedSourceRanges) const
|
||||||
|
{
|
||||||
|
diagnostics = mainFileDiagnostics();
|
||||||
|
highlightingMarks = this->highlightingMarks().toHighlightingMarksContainers();
|
||||||
|
skippedSourceRanges = this->skippedSourceRanges().toSourceRangeContainers();
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagnosticSet TranslationUnitCore::diagnostics() const
|
||||||
|
{
|
||||||
|
return DiagnosticSet(clang_getDiagnosticSetFromTU(m_cxTranslationUnit));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<DiagnosticContainer> 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
|
||||||
102
src/tools/clangbackend/ipcsource/clangtranslationunitcore.h
Normal file
102
src/tools/clangbackend/ipcsource/clangtranslationunitcore.h
Normal file
@@ -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 <clangbackendipc/codecompletion.h>
|
||||||
|
|
||||||
|
#include <utf8string.h>
|
||||||
|
|
||||||
|
#include <clang-c/Index.h>
|
||||||
|
|
||||||
|
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<DiagnosticContainer> &diagnostics,
|
||||||
|
QVector<HighlightingMarkContainer> &highlightingMarks,
|
||||||
|
QVector<SourceRangeContainer> &skippedSourceRanges) const;
|
||||||
|
|
||||||
|
DiagnosticSet diagnostics() const;
|
||||||
|
QVector<DiagnosticContainer> 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
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "clangtranslationunit.h"
|
#include "clangtranslationunit.h"
|
||||||
#include "sourcerange.h"
|
#include "sourcerange.h"
|
||||||
#include "clangunsavedfilesshallowarguments.h"
|
#include "clangunsavedfilesshallowarguments.h"
|
||||||
|
#include "clangtranslationunitupdater.h"
|
||||||
|
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
|
|
||||||
@@ -57,9 +58,9 @@ CodeCompletions toCodeCompletions(const ClangCodeCompleteResults &results)
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
CodeCompleter::CodeCompleter(TranslationUnit translationUnit,
|
CodeCompleter::CodeCompleter(const TranslationUnitCore &translationUnitCore,
|
||||||
const UnsavedFiles &unsavedFiles)
|
const UnsavedFiles &unsavedFiles)
|
||||||
: translationUnit(std::move(translationUnit))
|
: translationUnitCore(translationUnitCore)
|
||||||
, unsavedFiles(unsavedFiles)
|
, unsavedFiles(unsavedFiles)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -82,10 +83,10 @@ CompletionCorrection CodeCompleter::neededCorrection() const
|
|||||||
|
|
||||||
ClangCodeCompleteResults CodeCompleter::completeHelper(uint line, uint column)
|
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();
|
UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments();
|
||||||
|
|
||||||
return clang_codeCompleteAt(translationUnit.cxTranslationUnitWithoutReparsing(),
|
return clang_codeCompleteAt(translationUnitCore.cxTranslationUnit(),
|
||||||
nativeFilePath.constData(),
|
nativeFilePath.constData(),
|
||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
@@ -99,7 +100,7 @@ uint CodeCompleter::defaultOptions() const
|
|||||||
uint options = CXCodeComplete_IncludeMacros
|
uint options = CXCodeComplete_IncludeMacros
|
||||||
| CXCodeComplete_IncludeCodePatterns;
|
| CXCodeComplete_IncludeCodePatterns;
|
||||||
|
|
||||||
if (translationUnit.defaultParseOptions()
|
if (TranslationUnitUpdater::defaultParseOptions()
|
||||||
& CXTranslationUnit_IncludeBriefCommentsInCodeCompletion) {
|
& CXTranslationUnit_IncludeBriefCommentsInCodeCompletion) {
|
||||||
options |= CXCodeComplete_IncludeBriefComments;
|
options |= CXCodeComplete_IncludeBriefComments;
|
||||||
}
|
}
|
||||||
@@ -109,7 +110,7 @@ uint CodeCompleter::defaultOptions() const
|
|||||||
|
|
||||||
UnsavedFile &CodeCompleter::unsavedFile()
|
UnsavedFile &CodeCompleter::unsavedFile()
|
||||||
{
|
{
|
||||||
return unsavedFiles.unsavedFile(translationUnit.filePath());
|
return unsavedFiles.unsavedFile(translationUnitCore.filePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCompleter::tryDotArrowCorrectionIfNoResults(ClangCodeCompleteResults &results,
|
void CodeCompleter::tryDotArrowCorrectionIfNoResults(ClangCodeCompleteResults &results,
|
||||||
@@ -117,10 +118,10 @@ void CodeCompleter::tryDotArrowCorrectionIfNoResults(ClangCodeCompleteResults &r
|
|||||||
uint column)
|
uint column)
|
||||||
{
|
{
|
||||||
if (results.hasNoResultsForDotCompletion()) {
|
if (results.hasNoResultsForDotCompletion()) {
|
||||||
const UnsavedFile &unsavedFile = translationUnit.unsavedFile();
|
const UnsavedFile &theUnsavedFile = unsavedFile();
|
||||||
bool positionIsOk = false;
|
bool positionIsOk = false;
|
||||||
const uint dotPosition = unsavedFile.toUtf8Position(line, column - 1, &positionIsOk);
|
const uint dotPosition = theUnsavedFile.toUtf8Position(line, column - 1, &positionIsOk);
|
||||||
if (positionIsOk && unsavedFile.hasCharacterAt(dotPosition, '.'))
|
if (positionIsOk && theUnsavedFile.hasCharacterAt(dotPosition, '.'))
|
||||||
results = completeWithArrowInsteadOfDot(line, column, dotPosition);
|
results = completeWithArrowInsteadOfDot(line, column, dotPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,16 +144,5 @@ ClangCodeCompleteResults CodeCompleter::completeWithArrowInsteadOfDot(uint line,
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utf8String CodeCompleter::filePath() const
|
|
||||||
{
|
|
||||||
return translationUnit.filePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CodeCompleter::checkCodeCompleteResult(CXCodeCompleteResults *completeResults)
|
|
||||||
{
|
|
||||||
if (!completeResults)
|
|
||||||
throw CodeCompleteFailedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "clangtranslationunit.h"
|
#include "clangtranslationunitcore.h"
|
||||||
#include "unsavedfiles.h"
|
#include "unsavedfiles.h"
|
||||||
|
|
||||||
#include <codecompletion.h>
|
#include <codecompletion.h>
|
||||||
@@ -40,7 +40,7 @@ class CodeCompleter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CodeCompleter() = default;
|
CodeCompleter() = default;
|
||||||
CodeCompleter(TranslationUnit translationUnit,
|
CodeCompleter(const TranslationUnitCore &translationUnitCore,
|
||||||
const UnsavedFiles &unsavedFiles);
|
const UnsavedFiles &unsavedFiles);
|
||||||
|
|
||||||
CodeCompletions complete(uint line, uint column);
|
CodeCompletions complete(uint line, uint column);
|
||||||
@@ -60,11 +60,8 @@ private:
|
|||||||
uint column,
|
uint column,
|
||||||
uint dotPosition);
|
uint dotPosition);
|
||||||
|
|
||||||
Utf8String filePath() const;
|
|
||||||
static void checkCodeCompleteResult(CXCodeCompleteResults *completeResults);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TranslationUnit translationUnit;
|
TranslationUnitCore translationUnitCore;
|
||||||
UnsavedFiles unsavedFiles;
|
UnsavedFiles unsavedFiles;
|
||||||
CompletionCorrection neededCorrection_ = CompletionCorrection::NoCorrection;
|
CompletionCorrection neededCorrection_ = CompletionCorrection::NoCorrection;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class DiagnosticSetIterator;
|
|||||||
|
|
||||||
class DiagnosticSet
|
class DiagnosticSet
|
||||||
{
|
{
|
||||||
friend class TranslationUnit;
|
friend class TranslationUnitCore;
|
||||||
friend class Diagnostic;
|
friend class Diagnostic;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class SourceLocation
|
|||||||
{
|
{
|
||||||
friend class Diagnostic;
|
friend class Diagnostic;
|
||||||
friend class SourceRange;
|
friend class SourceRange;
|
||||||
friend class TranslationUnit;
|
friend class TranslationUnitCore;
|
||||||
friend class Cursor;
|
friend class Cursor;
|
||||||
friend bool operator==(const SourceLocation &first, const SourceLocation &second);
|
friend bool operator==(const SourceLocation &first, const SourceLocation &second);
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ void TranslationUnits::sendDocumentAnnotations(const TranslationUnit &translatio
|
|||||||
DocumentAnnotationsChangedMessage message(translationUnit.fileContainer(),
|
DocumentAnnotationsChangedMessage message(translationUnit.fileContainer(),
|
||||||
translationUnit.mainFileDiagnostics(),
|
translationUnit.mainFileDiagnostics(),
|
||||||
translationUnit.highlightingMarks().toHighlightingMarksContainers(),
|
translationUnit.highlightingMarks().toHighlightingMarksContainers(),
|
||||||
translationUnit.skippedSourceRanges().toSourceRangeContainers());
|
translationUnit.translationUnitCore().skippedSourceRanges().toSourceRangeContainers());
|
||||||
|
|
||||||
sendDocumentAnnotationsCallback(std::move(message));
|
sendDocumentAnnotationsCallback(std::move(message));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <clangcodecompleteresults.h>
|
#include <clangcodecompleteresults.h>
|
||||||
#include <clangfilepath.h>
|
#include <clangfilepath.h>
|
||||||
|
#include <clangtranslationunitupdater.h>
|
||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
#include <projects.h>
|
#include <projects.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
@@ -47,10 +48,12 @@ using ClangBackEnd::TranslationUnit;
|
|||||||
using ClangBackEnd::UnsavedFiles;
|
using ClangBackEnd::UnsavedFiles;
|
||||||
using ClangBackEnd::ProjectPart;
|
using ClangBackEnd::ProjectPart;
|
||||||
|
|
||||||
static unsigned completionOptions(const TranslationUnit &translationUnit)
|
static unsigned completionOptions()
|
||||||
{
|
{
|
||||||
return translationUnit.defaultOptions() & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion
|
return ClangBackEnd::TranslationUnitUpdater::defaultParseOptions()
|
||||||
? CXCodeComplete_IncludeBriefComments : 0;
|
& CXTranslationUnit_IncludeBriefCommentsInCodeCompletion
|
||||||
|
? CXCodeComplete_IncludeBriefComments
|
||||||
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ClangCodeCompleteResults, GetData)
|
TEST(ClangCodeCompleteResults, GetData)
|
||||||
@@ -64,11 +67,12 @@ TEST(ClangCodeCompleteResults, GetData)
|
|||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits);
|
translationUnits);
|
||||||
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
||||||
|
translationUnit.parse();
|
||||||
CXCodeCompleteResults *cxCodeCompleteResults =
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
||||||
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
||||||
nativeFilePath.constData(),
|
nativeFilePath.constData(),
|
||||||
49, 1, 0, 0,
|
49, 1, 0, 0,
|
||||||
completionOptions(translationUnit));
|
completionOptions());
|
||||||
|
|
||||||
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
||||||
|
|
||||||
@@ -95,11 +99,12 @@ TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults)
|
|||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits);
|
translationUnits);
|
||||||
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
||||||
|
translationUnit.parse();
|
||||||
CXCodeCompleteResults *cxCodeCompleteResults =
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
||||||
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
||||||
nativeFilePath.constData(),
|
nativeFilePath.constData(),
|
||||||
49, 1, 0, 0,
|
49, 1, 0, 0,
|
||||||
completionOptions(translationUnit));
|
completionOptions());
|
||||||
|
|
||||||
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,8 @@ class CodeCompletionsExtractor : public ::testing::Test
|
|||||||
protected:
|
protected:
|
||||||
ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit,
|
ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit,
|
||||||
uint line,
|
uint line,
|
||||||
uint column = 1);
|
uint column = 1,
|
||||||
|
bool needsReparse = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ClangBackEnd::ProjectPart project{Utf8StringLiteral("/path/to/projectfile")};
|
ClangBackEnd::ProjectPart project{Utf8StringLiteral("/path/to/projectfile")};
|
||||||
@@ -573,7 +574,6 @@ TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile)
|
|||||||
|
|
||||||
TEST_F(CodeCompletionsExtractor, ArgumentDefinition)
|
TEST_F(CodeCompletionsExtractor, ArgumentDefinition)
|
||||||
{
|
{
|
||||||
variableTranslationUnit.cxTranslationUnit();
|
|
||||||
project.setArguments({Utf8StringLiteral("-DArgumentDefinition"), Utf8StringLiteral("-std=gnu++14")});
|
project.setArguments({Utf8StringLiteral("-DArgumentDefinition"), Utf8StringLiteral("-std=gnu++14")});
|
||||||
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
||||||
|
|
||||||
@@ -586,7 +586,6 @@ TEST_F(CodeCompletionsExtractor, ArgumentDefinition)
|
|||||||
|
|
||||||
TEST_F(CodeCompletionsExtractor, NoArgumentDefinition)
|
TEST_F(CodeCompletionsExtractor, NoArgumentDefinition)
|
||||||
{
|
{
|
||||||
variableTranslationUnit.cxTranslationUnit();
|
|
||||||
project.setArguments({Utf8StringLiteral("-std=gnu++14")});
|
project.setArguments({Utf8StringLiteral("-std=gnu++14")});
|
||||||
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
||||||
|
|
||||||
@@ -672,16 +671,23 @@ TEST_F(CodeCompletionsExtractor, CompletionChunksClass)
|
|||||||
|
|
||||||
TEST_F(CodeCompletionsExtractor, BriefComment)
|
TEST_F(CodeCompletionsExtractor, BriefComment)
|
||||||
{
|
{
|
||||||
briefCommentTranslationUnit.reparse();
|
ClangCodeCompleteResults completeResults(getResults(briefCommentTranslationUnit, 10, 1,
|
||||||
ClangCodeCompleteResults completeResults(getResults(briefCommentTranslationUnit, 10));
|
/*needsReparse=*/ true));
|
||||||
|
|
||||||
::CodeCompletionsExtractor extractor(completeResults.data());
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
||||||
|
|
||||||
ASSERT_THAT(extractor, HasBriefComment(Utf8StringLiteral("BriefComment"), Utf8StringLiteral("A brief comment")));
|
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());
|
const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
||||||
UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments();
|
UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments();
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ protected:
|
|||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
||||||
ClangBackEnd::TranslationUnit translationUnit;
|
ClangBackEnd::TranslationUnit translationUnit;
|
||||||
ClangBackEnd::CodeCompleter completer;
|
QScopedPointer<ClangBackEnd::CodeCompleter> completer;
|
||||||
ClangBackEnd::FileContainer unsavedMainFileContainer{mainFileContainer.filePath(),
|
ClangBackEnd::FileContainer unsavedMainFileContainer{mainFileContainer.filePath(),
|
||||||
projectPart.projectPartId(),
|
projectPart.projectPartId(),
|
||||||
readFileContent(QStringLiteral("/complete_completer_main_unsaved.cpp")),
|
readFileContent(QStringLiteral("/complete_completer_main_unsaved.cpp")),
|
||||||
@@ -213,20 +213,20 @@ void CodeCompleter::SetUp()
|
|||||||
projects.createOrUpdate({projectPart});
|
projects.createOrUpdate({projectPart});
|
||||||
translationUnits.create({mainFileContainer});
|
translationUnits.create({mainFileContainer});
|
||||||
translationUnit = translationUnits.translationUnit(mainFileContainer);
|
translationUnit = translationUnits.translationUnit(mainFileContainer);
|
||||||
completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles);
|
completer.reset(new ClangBackEnd::CodeCompleter(translationUnit.translationUnitCore(),
|
||||||
|
unsavedFiles));
|
||||||
|
|
||||||
copyTargetHeaderToTemporaryIncludeDirecory();
|
copyTargetHeaderToTemporaryIncludeDirecory();
|
||||||
|
translationUnit.parse();
|
||||||
translationUnit.cxTranslationUnit(); // initialize translation unit so we check changes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CodeCompleter, FunctionInUnsavedFile)
|
TEST_F(CodeCompleter, FunctionInUnsavedFile)
|
||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
||||||
translationUnits.update({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"),
|
AllOf(Contains(IsCodeCompletion(Utf8StringLiteral("FunctionWithArguments"),
|
||||||
CodeCompletion::FunctionCompletionKind)),
|
CodeCompletion::FunctionCompletionKind)),
|
||||||
Contains(IsCodeCompletion(Utf8StringLiteral("Function"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("Function"),
|
||||||
@@ -243,9 +243,9 @@ TEST_F(CodeCompleter, VariableInUnsavedFile)
|
|||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
||||||
translationUnits.update({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"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("VariableInUnsavedFile"),
|
||||||
CodeCompletion::VariableCompletionKind)));
|
CodeCompletion::VariableCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -254,9 +254,9 @@ TEST_F(CodeCompleter, GlobalVariableInUnsavedFile)
|
|||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
||||||
translationUnits.update({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"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("GlobalVariableInUnsavedFile"),
|
||||||
CodeCompletion::VariableCompletionKind)));
|
CodeCompletion::VariableCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -265,23 +265,23 @@ TEST_F(CodeCompleter, Macro)
|
|||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
||||||
translationUnits.update({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"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("Macro"),
|
||||||
CodeCompletion::PreProcessorCompletionKind)));
|
CodeCompletion::PreProcessorCompletionKind)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CodeCompleter, Keyword)
|
TEST_F(CodeCompleter, Keyword)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(completer.complete(27, 1),
|
ASSERT_THAT(completer->complete(27, 1),
|
||||||
Contains(IsCodeCompletion(Utf8StringLiteral("switch"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("switch"),
|
||||||
CodeCompletion::KeywordCompletionKind)));
|
CodeCompletion::KeywordCompletionKind)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CodeCompleter, FunctionInIncludedHeader)
|
TEST_F(CodeCompleter, FunctionInIncludedHeader)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(completer.complete(27, 1),
|
ASSERT_THAT(completer->complete(27, 1),
|
||||||
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeader"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeader"),
|
||||||
CodeCompletion::FunctionCompletionKind)));
|
CodeCompletion::FunctionCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -290,9 +290,9 @@ TEST_F(CodeCompleter, FunctionInUnsavedIncludedHeader)
|
|||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedTargetHeaderFileContainer});
|
unsavedFiles.createOrUpdate({unsavedTargetHeaderFileContainer});
|
||||||
translationUnits.create({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"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderUnsaved"),
|
||||||
CodeCompletion::FunctionCompletionKind)));
|
CodeCompletion::FunctionCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ TEST_F(CodeCompleter, DISABLED_FunctionInChangedIncludedHeader)
|
|||||||
{
|
{
|
||||||
copyChangedTargetHeaderToTemporaryIncludeDirecory();
|
copyChangedTargetHeaderToTemporaryIncludeDirecory();
|
||||||
|
|
||||||
ASSERT_THAT(completer.complete(27, 1),
|
ASSERT_THAT(completer->complete(27, 1),
|
||||||
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"),
|
||||||
CodeCompletion::FunctionCompletionKind)));
|
CodeCompletion::FunctionCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -310,11 +310,11 @@ TEST_F(CodeCompleter, DISABLED_FunctionInChangedIncludedHeaderWithUnsavedContent
|
|||||||
{
|
{
|
||||||
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
unsavedFiles.createOrUpdate({unsavedMainFileContainer});
|
||||||
translationUnits.update({unsavedMainFileContainer});
|
translationUnits.update({unsavedMainFileContainer});
|
||||||
completer = ClangBackEnd::CodeCompleter(translationUnit, unsavedFiles);
|
ClangBackEnd::CodeCompleter myCompleter(translationUnit.translationUnitCore(), unsavedFiles);
|
||||||
|
|
||||||
copyChangedTargetHeaderToTemporaryIncludeDirecory();
|
copyChangedTargetHeaderToTemporaryIncludeDirecory();
|
||||||
|
|
||||||
ASSERT_THAT(completer.complete(27, 1),
|
ASSERT_THAT(myCompleter.complete(27, 1),
|
||||||
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"),
|
Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderChanged"),
|
||||||
CodeCompletion::FunctionCompletionKind)));
|
CodeCompletion::FunctionCompletionKind)));
|
||||||
}
|
}
|
||||||
@@ -352,9 +352,9 @@ TEST_F(CodeCompleter, DotToArrowCompletionForPointerInOutdatedTranslationUnit)
|
|||||||
unsavedFiles.createOrUpdate({fileContainerBeforeTyping});
|
unsavedFiles.createOrUpdate({fileContainerBeforeTyping});
|
||||||
auto translationUnit = translationUnits.translationUnit(fileContainerBeforeTyping.filePath(),
|
auto translationUnit = translationUnits.translationUnit(fileContainerBeforeTyping.filePath(),
|
||||||
fileContainerBeforeTyping.projectPartId());
|
fileContainerBeforeTyping.projectPartId());
|
||||||
translationUnit.cxTranslationUnit(); // Parse
|
translationUnit.parse();
|
||||||
unsavedFiles.createOrUpdate({dotArrowCorrectionForPointerFileContainerAfterTyping});
|
unsavedFiles.createOrUpdate({dotArrowCorrectionForPointerFileContainerAfterTyping});
|
||||||
ClangBackEnd::CodeCompleter myCompleter(translationUnits.translationUnit(dotArrowCorrectionForPointerFileContainerAfterTyping),
|
ClangBackEnd::CodeCompleter myCompleter(translationUnits.translationUnit(dotArrowCorrectionForPointerFileContainerAfterTyping).translationUnitCore(),
|
||||||
unsavedFiles);
|
unsavedFiles);
|
||||||
|
|
||||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(5, 9);
|
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(5, 9);
|
||||||
@@ -445,8 +445,11 @@ ClangBackEnd::CodeCompleter CodeCompleter::setupCompleter(
|
|||||||
{
|
{
|
||||||
translationUnits.create({fileContainer});
|
translationUnits.create({fileContainer});
|
||||||
unsavedFiles.createOrUpdate({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);
|
unsavedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <sourcelocation.h>
|
#include <sourcelocation.h>
|
||||||
#include <sourcerange.h>
|
#include <sourcerange.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <translationunits.h>
|
#include <translationunits.h>
|
||||||
#include <unsavedfiles.h>
|
#include <unsavedfiles.h>
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
|
|
||||||
using ClangBackEnd::Cursor;
|
using ClangBackEnd::Cursor;
|
||||||
using ClangBackEnd::TranslationUnit;
|
using ClangBackEnd::TranslationUnit;
|
||||||
|
using ClangBackEnd::TranslationUnitCore;
|
||||||
using ClangBackEnd::UnsavedFiles;
|
using ClangBackEnd::UnsavedFiles;
|
||||||
using ClangBackEnd::ProjectPart;
|
using ClangBackEnd::ProjectPart;
|
||||||
using ClangBackEnd::TranslationUnits;
|
using ClangBackEnd::TranslationUnits;
|
||||||
@@ -62,10 +64,14 @@ struct Data {
|
|||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
ClangBackEnd::TranslationUnits translationUnits{projects, 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")}),
|
ProjectPart(Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-std=c++11")}),
|
||||||
{},
|
{},
|
||||||
translationUnits};
|
translationUnits};
|
||||||
|
TranslationUnitCore translationUnitCore{filePath,
|
||||||
|
translationUnit.index(),
|
||||||
|
translationUnit.cxTranslationUnit()};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Cursor : public ::testing::Test
|
class Cursor : public ::testing::Test
|
||||||
@@ -77,8 +83,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
static Data *d;
|
static Data *d;
|
||||||
const TranslationUnit &translationUnit = d->translationUnit;
|
const TranslationUnit &translationUnit = d->translationUnit;
|
||||||
|
const TranslationUnitCore &translationUnitCore = d->translationUnitCore;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(Cursor, CreateNullCursor)
|
TEST_F(Cursor, CreateNullCursor)
|
||||||
@@ -105,14 +110,14 @@ TEST_F(Cursor, IsNotValid)
|
|||||||
|
|
||||||
TEST_F(Cursor, IsValid)
|
TEST_F(Cursor, IsValid)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursor();
|
auto cursor = translationUnitCore.cursor();
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isValid());
|
ASSERT_TRUE(cursor.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsTranslationUnit)
|
TEST_F(Cursor, IsTranslationUnit)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursor();
|
auto cursor = translationUnitCore.cursor();
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isTranslationUnit());
|
ASSERT_TRUE(cursor.isTranslationUnit());
|
||||||
}
|
}
|
||||||
@@ -133,29 +138,29 @@ TEST_F(Cursor, UnifiedSymbolResolution)
|
|||||||
|
|
||||||
TEST_F(Cursor, GetCursorAtLocation)
|
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#"));
|
ASSERT_THAT(cursor.unifiedSymbolResolution(), Utf8StringLiteral("c:@F@function#I#"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, GetCursoSourceLocation)
|
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)
|
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),
|
ASSERT_THAT(cursor.sourceRange(), SourceRange(translationUnitCore.sourceLocationAt(3, 1),
|
||||||
translationUnit.sourceLocationAt(6, 2)));
|
translationUnitCore.sourceLocationAt(6, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, Mangling)
|
TEST_F(Cursor, Mangling)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(3, 6);
|
auto cursor = translationUnitCore.cursorAt(3, 6);
|
||||||
|
|
||||||
|
|
||||||
ASSERT_THAT(cursor.mangling().isEmpty(), false);
|
ASSERT_THAT(cursor.mangling().isEmpty(), false);
|
||||||
@@ -163,7 +168,7 @@ TEST_F(Cursor, Mangling)
|
|||||||
|
|
||||||
TEST_F(Cursor, Spelling)
|
TEST_F(Cursor, Spelling)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(3, 6);
|
auto cursor = translationUnitCore.cursorAt(3, 6);
|
||||||
|
|
||||||
|
|
||||||
ASSERT_THAT(cursor.spelling().cString(), StrEq("function"));
|
ASSERT_THAT(cursor.spelling().cString(), StrEq("function"));
|
||||||
@@ -171,7 +176,7 @@ TEST_F(Cursor, Spelling)
|
|||||||
|
|
||||||
TEST_F(Cursor, DisplayName)
|
TEST_F(Cursor, DisplayName)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(3, 6);
|
auto cursor = translationUnitCore.cursorAt(3, 6);
|
||||||
|
|
||||||
|
|
||||||
ASSERT_THAT(cursor.displayName(), Utf8StringLiteral("function(int)"));
|
ASSERT_THAT(cursor.displayName(), Utf8StringLiteral("function(int)"));
|
||||||
@@ -179,7 +184,7 @@ TEST_F(Cursor, DisplayName)
|
|||||||
|
|
||||||
TEST_F(Cursor, BriefComment)
|
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"));
|
ASSERT_THAT(cursor.briefComment(), Utf8StringLiteral("A brief comment"));
|
||||||
@@ -187,7 +192,7 @@ TEST_F(Cursor, BriefComment)
|
|||||||
|
|
||||||
TEST_F(Cursor, RawComment)
|
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 */"));
|
ASSERT_THAT(cursor.rawComment(), Utf8StringLiteral("/**\n * A brief comment\n */"));
|
||||||
@@ -195,118 +200,118 @@ TEST_F(Cursor, RawComment)
|
|||||||
|
|
||||||
TEST_F(Cursor, CommentRange)
|
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(),
|
ASSERT_THAT(cursor.commentRange(),
|
||||||
SourceRange(translationUnit.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 7, 1),
|
SourceRange(translationUnitCore.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 7, 1),
|
||||||
translationUnit.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 9, 4)));
|
translationUnitCore.sourceLocationAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 9, 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsDefinition)
|
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());
|
ASSERT_TRUE(cursor.isDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, ForwardDeclarationIsNotDefinition)
|
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());
|
ASSERT_FALSE(cursor.isDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, GetDefinitionOfFowardDeclaration)
|
TEST_F(Cursor, GetDefinitionOfFowardDeclaration)
|
||||||
{
|
{
|
||||||
auto forwardDeclarationcursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7);
|
auto forwardDeclarationcursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7);
|
||||||
auto definitionCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7);
|
auto definitionCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7);
|
||||||
|
|
||||||
ASSERT_THAT(forwardDeclarationcursor.definition(), definitionCursor);
|
ASSERT_THAT(forwardDeclarationcursor.definition(), definitionCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, CallToMethodeIsNotDynamic)
|
TEST_F(Cursor, CallToMethodeIsNotDynamic)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(18, 5);
|
auto cursor = translationUnitCore.cursorAt(18, 5);
|
||||||
|
|
||||||
ASSERT_FALSE(cursor.isDynamicCall());
|
ASSERT_FALSE(cursor.isDynamicCall());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, CallToAbstractVirtualMethodeIsDynamic)
|
TEST_F(Cursor, CallToAbstractVirtualMethodeIsDynamic)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(19, 5);
|
auto cursor = translationUnitCore.cursorAt(19, 5);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isDynamicCall());
|
ASSERT_TRUE(cursor.isDynamicCall());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, CanonicalCursor)
|
TEST_F(Cursor, CanonicalCursor)
|
||||||
{
|
{
|
||||||
auto forwardDeclarationcursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7);
|
auto forwardDeclarationcursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 6, 7);
|
||||||
auto definitionCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7);
|
auto definitionCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 10, 7);
|
||||||
|
|
||||||
ASSERT_THAT(definitionCursor.canonical(), forwardDeclarationcursor);
|
ASSERT_THAT(definitionCursor.canonical(), forwardDeclarationcursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, ReferencedCursor)
|
TEST_F(Cursor, ReferencedCursor)
|
||||||
{
|
{
|
||||||
auto functionCallCursor = translationUnit.cursorAt(18, 5);
|
auto functionCallCursor = translationUnitCore.cursorAt(18, 5);
|
||||||
auto functionCursor = translationUnit.cursorAt(16, 17);
|
auto functionCursor = translationUnitCore.cursorAt(16, 17);
|
||||||
|
|
||||||
ASSERT_THAT(functionCallCursor.referenced(), functionCursor);
|
ASSERT_THAT(functionCallCursor.referenced(), functionCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsVirtual)
|
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());
|
ASSERT_TRUE(cursor.isVirtualMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsNotPureVirtualOnlyVirtual)
|
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());
|
ASSERT_FALSE(cursor.isPureVirtualMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsPureVirtual)
|
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());
|
ASSERT_TRUE(cursor.isPureVirtualMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, ConstantMethod)
|
TEST_F(Cursor, ConstantMethod)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(31, 18);
|
auto cursor = translationUnitCore.cursorAt(31, 18);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isConstantMethod());
|
ASSERT_TRUE(cursor.isConstantMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsStaticMethod)
|
TEST_F(Cursor, IsStaticMethod)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(36, 18);
|
auto cursor = translationUnitCore.cursorAt(36, 18);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isStaticMethod());
|
ASSERT_TRUE(cursor.isStaticMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, TypeSpelling)
|
TEST_F(Cursor, TypeSpelling)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(43, 5);
|
auto cursor = translationUnitCore.cursorAt(43, 5);
|
||||||
|
|
||||||
ASSERT_THAT(cursor.type().utf8Spelling(), Utf8StringLiteral("lint"));
|
ASSERT_THAT(cursor.type().utf8Spelling(), Utf8StringLiteral("lint"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, CanonicalTypeSpelling)
|
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"));
|
ASSERT_THAT(cursor.type().canonical().utf8Spelling(), Utf8StringLiteral("long long"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, CanonicalTypeCStringSpelling)
|
TEST_F(Cursor, CanonicalTypeCStringSpelling)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(43, 5);
|
auto cursor = translationUnitCore.cursorAt(43, 5);
|
||||||
|
|
||||||
auto spelling = cursor.type().canonical().spelling();
|
auto spelling = cursor.type().canonical().spelling();
|
||||||
|
|
||||||
@@ -315,58 +320,58 @@ TEST_F(Cursor, CanonicalTypeCStringSpelling)
|
|||||||
|
|
||||||
TEST_F(Cursor, CanonicalTypeIsNotType)
|
TEST_F(Cursor, CanonicalTypeIsNotType)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(43, 5);
|
auto cursor = translationUnitCore.cursorAt(43, 5);
|
||||||
|
|
||||||
ASSERT_THAT(cursor.type().canonical(), Not(cursor.type()));
|
ASSERT_THAT(cursor.type().canonical(), Not(cursor.type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, TypeDeclartionIsAlias)
|
TEST_F(Cursor, TypeDeclartionIsAlias)
|
||||||
{
|
{
|
||||||
auto declarationCursor = translationUnit.cursorAt(41, 5);
|
auto declarationCursor = translationUnitCore.cursorAt(41, 5);
|
||||||
auto lintCursor = translationUnit.cursorAt(39, 11);
|
auto lintCursor = translationUnitCore.cursorAt(39, 11);
|
||||||
|
|
||||||
ASSERT_THAT(declarationCursor.type().declaration().type(), lintCursor.type());
|
ASSERT_THAT(declarationCursor.type().declaration().type(), lintCursor.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, TypeIsConstantWithoutAliasLookup)
|
TEST_F(Cursor, TypeIsConstantWithoutAliasLookup)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(45, 16);
|
auto cursor = translationUnitCore.cursorAt(45, 16);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.type().isConstant());
|
ASSERT_TRUE(cursor.type().isConstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, ClassIsCompoundType)
|
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());
|
ASSERT_TRUE(cursor.isCompoundType());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, StructIsCompoundType)
|
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());
|
ASSERT_TRUE(cursor.isCompoundType());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, UnionIsCompoundType)
|
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());
|
ASSERT_TRUE(cursor.isCompoundType());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsDeclaration)
|
TEST_F(Cursor, IsDeclaration)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(41, 10);
|
auto cursor = translationUnitCore.cursorAt(41, 10);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isDeclaration());
|
ASSERT_TRUE(cursor.isDeclaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, SemanticParent)
|
TEST_F(Cursor, SemanticParent)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(43, 6);
|
auto cursor = translationUnitCore.cursorAt(43, 6);
|
||||||
auto expectedSemanticParent = translationUnit.cursorAt(36, 18);
|
auto expectedSemanticParent = translationUnitCore.cursorAt(36, 18);
|
||||||
|
|
||||||
auto semanticParent = cursor.semanticParent();
|
auto semanticParent = cursor.semanticParent();
|
||||||
|
|
||||||
@@ -375,117 +380,117 @@ TEST_F(Cursor, SemanticParent)
|
|||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInMethod)
|
TEST_F(Cursor, IsLocalVariableInMethod)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(20, 9);
|
auto cursor = translationUnitCore.cursorAt(20, 9);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInStaticFunction)
|
TEST_F(Cursor, IsLocalVariableInStaticFunction)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(43, 5);
|
auto cursor = translationUnitCore.cursorAt(43, 5);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInTemplateFunction)
|
TEST_F(Cursor, IsLocalVariableInTemplateFunction)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(52, 7);
|
auto cursor = translationUnitCore.cursorAt(52, 7);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInConversionOperator)
|
TEST_F(Cursor, IsLocalVariableInConversionOperator)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(57, 9);
|
auto cursor = translationUnitCore.cursorAt(57, 9);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInOperator)
|
TEST_F(Cursor, IsLocalVariableInOperator)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(62, 9);
|
auto cursor = translationUnitCore.cursorAt(62, 9);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInConstructor)
|
TEST_F(Cursor, IsLocalVariableInConstructor)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(13, 9);
|
auto cursor = translationUnitCore.cursorAt(13, 9);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsLocalVariableInDestructor)
|
TEST_F(Cursor, IsLocalVariableInDestructor)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(69, 9);
|
auto cursor = translationUnitCore.cursorAt(69, 9);
|
||||||
|
|
||||||
ASSERT_TRUE(cursor.isLocalVariable());
|
ASSERT_TRUE(cursor.isLocalVariable());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, FindFunctionCaller)
|
TEST_F(Cursor, FindFunctionCaller)
|
||||||
{
|
{
|
||||||
auto functionCursor = translationUnit.cursorAt(92, 24);
|
auto functionCursor = translationUnitCore.cursorAt(92, 24);
|
||||||
auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8);
|
auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8);
|
||||||
|
|
||||||
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, FindFunctionCallerPointer)
|
TEST_F(Cursor, FindFunctionCallerPointer)
|
||||||
{
|
{
|
||||||
auto functionCursor = translationUnit.cursorAt(79, 25);
|
auto functionCursor = translationUnitCore.cursorAt(79, 25);
|
||||||
auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8);
|
auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 28, 8);
|
||||||
|
|
||||||
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, FindFunctionCallerThis)
|
TEST_F(Cursor, FindFunctionCallerThis)
|
||||||
{
|
{
|
||||||
auto functionCursor = translationUnit.cursorAt(106, 5);
|
auto functionCursor = translationUnitCore.cursorAt(106, 5);
|
||||||
auto structCursor = translationUnit.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8);
|
auto structCursor = translationUnitCore.cursorAt(Utf8StringLiteral(TESTDATA_DIR"/cursor.h"), 38, 8);
|
||||||
|
|
||||||
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
ASSERT_THAT(functionCursor.functionBaseDeclaration(), structCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, NonPointerTypeForValue)
|
TEST_F(Cursor, NonPointerTypeForValue)
|
||||||
{
|
{
|
||||||
auto variableCursor = translationUnit.cursorAt(101, 10);
|
auto variableCursor = translationUnitCore.cursorAt(101, 10);
|
||||||
auto variablePointerCursor = translationUnit.cursorAt(100, 11);
|
auto variablePointerCursor = translationUnitCore.cursorAt(100, 11);
|
||||||
|
|
||||||
ASSERT_THAT(variableCursor.nonPointerTupe(), variablePointerCursor.nonPointerTupe());
|
ASSERT_THAT(variableCursor.nonPointerTupe(), variablePointerCursor.nonPointerTupe());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, HasFinalAttributeInFunction)
|
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());
|
ASSERT_TRUE(cursor.hasFinalFunctionAttribute());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, HasNotFinalAttributeInFunction)
|
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());
|
ASSERT_FALSE(cursor.hasFinalFunctionAttribute());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, HasFinalAttributeInClass)
|
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());
|
ASSERT_TRUE(cursor.hasFinalClassAttribute());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, HasNotFinaAttributeInClass)
|
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());
|
ASSERT_FALSE(cursor.hasFinalClassAttribute());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, HasOutputValues)
|
TEST_F(Cursor, HasOutputValues)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(117, 19);
|
auto callExpressionCursor = translationUnitCore.cursorAt(117, 19);
|
||||||
auto outputArgumentExpectedCursor = translationUnit.cursorAt(117, 20);
|
auto outputArgumentExpectedCursor = translationUnitCore.cursorAt(117, 20);
|
||||||
|
|
||||||
auto outputArguments = callExpressionCursor.outputArguments();
|
auto outputArguments = callExpressionCursor.outputArguments();
|
||||||
|
|
||||||
@@ -495,7 +500,7 @@ TEST_F(Cursor, HasOutputValues)
|
|||||||
|
|
||||||
TEST_F(Cursor, HasOnlyInputValues)
|
TEST_F(Cursor, HasOnlyInputValues)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(118, 18);
|
auto callExpressionCursor = translationUnitCore.cursorAt(118, 18);
|
||||||
|
|
||||||
auto outputArguments = callExpressionCursor.outputArguments();
|
auto outputArguments = callExpressionCursor.outputArguments();
|
||||||
|
|
||||||
@@ -504,7 +509,7 @@ TEST_F(Cursor, HasOnlyInputValues)
|
|||||||
|
|
||||||
TEST_F(Cursor, ArgumentCountIsZero)
|
TEST_F(Cursor, ArgumentCountIsZero)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(121, 23);
|
auto cursor = translationUnitCore.cursorAt(121, 23);
|
||||||
|
|
||||||
auto count = cursor.type().argumentCount();
|
auto count = cursor.type().argumentCount();
|
||||||
|
|
||||||
@@ -513,7 +518,7 @@ TEST_F(Cursor, ArgumentCountIsZero)
|
|||||||
|
|
||||||
TEST_F(Cursor, ArgumentCountIsTwo)
|
TEST_F(Cursor, ArgumentCountIsTwo)
|
||||||
{
|
{
|
||||||
auto cursor = translationUnit.cursorAt(122, 22);
|
auto cursor = translationUnitCore.cursorAt(122, 22);
|
||||||
|
|
||||||
auto count = cursor.type().argumentCount();
|
auto count = cursor.type().argumentCount();
|
||||||
|
|
||||||
@@ -522,7 +527,7 @@ TEST_F(Cursor, ArgumentCountIsTwo)
|
|||||||
|
|
||||||
TEST_F(Cursor, ArgumentOneIsValue)
|
TEST_F(Cursor, ArgumentOneIsValue)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(122, 22);
|
auto callExpressionCursor = translationUnitCore.cursorAt(122, 22);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -532,7 +537,7 @@ TEST_F(Cursor, ArgumentOneIsValue)
|
|||||||
|
|
||||||
TEST_F(Cursor, ArgumentTwoIsLValueReference)
|
TEST_F(Cursor, ArgumentTwoIsLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(122, 22);
|
auto callExpressionCursor = translationUnitCore.cursorAt(122, 22);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(1);
|
auto argument = callExpressionCursor.type().argument(1);
|
||||||
|
|
||||||
@@ -541,7 +546,7 @@ TEST_F(Cursor, ArgumentTwoIsLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, ArgumentTwoIsConstantReference)
|
TEST_F(Cursor, ArgumentTwoIsConstantReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(122, 22);
|
auto callExpressionCursor = translationUnitCore.cursorAt(122, 22);
|
||||||
|
|
||||||
auto argumentPointee = callExpressionCursor.type().argument(1);
|
auto argumentPointee = callExpressionCursor.type().argument(1);
|
||||||
|
|
||||||
@@ -550,7 +555,7 @@ TEST_F(Cursor, ArgumentTwoIsConstantReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, CursorArgumentCount)
|
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.kind(), CXCursor_CallExpr);
|
||||||
ASSERT_THAT(cursor.argumentCount(), 4);
|
ASSERT_THAT(cursor.argumentCount(), 4);
|
||||||
@@ -558,15 +563,15 @@ TEST_F(Cursor, CursorArgumentCount)
|
|||||||
|
|
||||||
TEST_F(Cursor, CursorArgumentInputValue)
|
TEST_F(Cursor, CursorArgumentInputValue)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(117, 19);
|
auto callExpressionCursor = translationUnitCore.cursorAt(117, 19);
|
||||||
auto declarationReferenceExpressionCursor = translationUnit.cursorAt(117, 20);
|
auto declarationReferenceExpressionCursor = translationUnitCore.cursorAt(117, 20);
|
||||||
|
|
||||||
ASSERT_THAT(callExpressionCursor.argument(0), declarationReferenceExpressionCursor);
|
ASSERT_THAT(callExpressionCursor.argument(0), declarationReferenceExpressionCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cursor, IsConstantLValueReference)
|
TEST_F(Cursor, IsConstantLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -575,7 +580,7 @@ TEST_F(Cursor, IsConstantLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, LValueReferenceIsNotConstantLValueReference)
|
TEST_F(Cursor, LValueReferenceIsNotConstantLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(124, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(124, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -584,7 +589,7 @@ TEST_F(Cursor, LValueReferenceIsNotConstantLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, ValueIsNotConstantLValueReference)
|
TEST_F(Cursor, ValueIsNotConstantLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(123, 18);
|
auto callExpressionCursor = translationUnitCore.cursorAt(123, 18);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -593,7 +598,7 @@ TEST_F(Cursor, ValueIsNotConstantLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerToConstantNotConstantLValueReference)
|
TEST_F(Cursor, PointerToConstantNotConstantLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -602,7 +607,7 @@ TEST_F(Cursor, PointerToConstantNotConstantLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, IsLValueReference)
|
TEST_F(Cursor, IsLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(124, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(124, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -611,7 +616,7 @@ TEST_F(Cursor, IsLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstantLValueReferenceIsLValueReference)
|
TEST_F(Cursor, ConstantLValueReferenceIsLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -620,7 +625,7 @@ TEST_F(Cursor, ConstantLValueReferenceIsLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, ValueIsNotLValueReference)
|
TEST_F(Cursor, ValueIsNotLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(123, 18);
|
auto callExpressionCursor = translationUnitCore.cursorAt(123, 18);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -629,7 +634,7 @@ TEST_F(Cursor, ValueIsNotLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerIsNotLValueReference)
|
TEST_F(Cursor, PointerIsNotLValueReference)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -638,7 +643,7 @@ TEST_F(Cursor, PointerIsNotLValueReference)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerToConstant)
|
TEST_F(Cursor, PointerToConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -647,7 +652,7 @@ TEST_F(Cursor, PointerToConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, ValueIsNotPointerToConstant)
|
TEST_F(Cursor, ValueIsNotPointerToConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(123, 18);
|
auto callExpressionCursor = translationUnitCore.cursorAt(123, 18);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -656,7 +661,7 @@ TEST_F(Cursor, ValueIsNotPointerToConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerNotPointerToConstant)
|
TEST_F(Cursor, PointerNotPointerToConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(127, 13);
|
auto callExpressionCursor = translationUnitCore.cursorAt(127, 13);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -665,7 +670,7 @@ TEST_F(Cursor, PointerNotPointerToConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstantLValueReferenceIsNotPointerToConstant)
|
TEST_F(Cursor, ConstantLValueReferenceIsNotPointerToConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -674,7 +679,7 @@ TEST_F(Cursor, ConstantLValueReferenceIsNotPointerToConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, IsConstantPointer)
|
TEST_F(Cursor, IsConstantPointer)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(128, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(128, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -683,7 +688,7 @@ TEST_F(Cursor, IsConstantPointer)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerToConstantIsNotConstantPointer)
|
TEST_F(Cursor, PointerToConstantIsNotConstantPointer)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -692,7 +697,7 @@ TEST_F(Cursor, PointerToConstantIsNotConstantPointer)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstValueIsNotConstantPointer)
|
TEST_F(Cursor, ConstValueIsNotConstantPointer)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(129, 23);
|
auto callExpressionCursor = translationUnitCore.cursorAt(129, 23);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -701,7 +706,7 @@ TEST_F(Cursor, ConstValueIsNotConstantPointer)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerToConstantIsReferencingConstant)
|
TEST_F(Cursor, PointerToConstantIsReferencingConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -710,7 +715,7 @@ TEST_F(Cursor, PointerToConstantIsReferencingConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstantReferenceIsReferencingConstant)
|
TEST_F(Cursor, ConstantReferenceIsReferencingConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -719,7 +724,7 @@ TEST_F(Cursor, ConstantReferenceIsReferencingConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, LValueReferenceIsNotReferencingConstant)
|
TEST_F(Cursor, LValueReferenceIsNotReferencingConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(124, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(124, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -728,7 +733,7 @@ TEST_F(Cursor, LValueReferenceIsNotReferencingConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, ValueIsNotReferencingConstant)
|
TEST_F(Cursor, ValueIsNotReferencingConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(123, 18);
|
auto callExpressionCursor = translationUnitCore.cursorAt(123, 18);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -737,7 +742,7 @@ TEST_F(Cursor, ValueIsNotReferencingConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerIsNotRefencingConstant)
|
TEST_F(Cursor, PointerIsNotRefencingConstant)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(127, 13);
|
auto callExpressionCursor = translationUnitCore.cursorAt(127, 13);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -746,7 +751,7 @@ TEST_F(Cursor, PointerIsNotRefencingConstant)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerIsOutputParameter)
|
TEST_F(Cursor, PointerIsOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(127, 13);
|
auto callExpressionCursor = translationUnitCore.cursorAt(127, 13);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -755,7 +760,7 @@ TEST_F(Cursor, PointerIsOutputParameter)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstantReferenceIsNotOutputParameter)
|
TEST_F(Cursor, ConstantReferenceIsNotOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -764,7 +769,7 @@ TEST_F(Cursor, ConstantReferenceIsNotOutputParameter)
|
|||||||
|
|
||||||
TEST_F(Cursor, PointerToConstantIsNotOutputParameter)
|
TEST_F(Cursor, PointerToConstantIsNotOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(126, 20);
|
auto callExpressionCursor = translationUnitCore.cursorAt(126, 20);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -773,7 +778,7 @@ TEST_F(Cursor, PointerToConstantIsNotOutputParameter)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstantPointerIsNotOutputParameter)
|
TEST_F(Cursor, ConstantPointerIsNotOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(128, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(128, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -782,7 +787,7 @@ TEST_F(Cursor, ConstantPointerIsNotOutputParameter)
|
|||||||
|
|
||||||
TEST_F(Cursor, ReferenceIsOutputParameter)
|
TEST_F(Cursor, ReferenceIsOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(124, 21);
|
auto callExpressionCursor = translationUnitCore.cursorAt(124, 21);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -791,7 +796,7 @@ TEST_F(Cursor, ReferenceIsOutputParameter)
|
|||||||
|
|
||||||
TEST_F(Cursor, ConstReferenceIsNotOutputParameter)
|
TEST_F(Cursor, ConstReferenceIsNotOutputParameter)
|
||||||
{
|
{
|
||||||
auto callExpressionCursor = translationUnit.cursorAt(125, 26);
|
auto callExpressionCursor = translationUnitCore.cursorAt(125, 26);
|
||||||
|
|
||||||
auto argument = callExpressionCursor.type().argument(0);
|
auto argument = callExpressionCursor.type().argument(0);
|
||||||
|
|
||||||
@@ -803,6 +808,7 @@ Data *Cursor::d;
|
|||||||
void Cursor::SetUpTestCase()
|
void Cursor::SetUpTestCase()
|
||||||
{
|
{
|
||||||
d = new Data;
|
d = new Data;
|
||||||
|
d->translationUnit.parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor::TearDownTestCase()
|
void Cursor::TearDownTestCase()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <sourcelocationcontainer.h>
|
#include <sourcelocationcontainer.h>
|
||||||
#include <sourcerangecontainer.h>
|
#include <sourcerangecontainer.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <translationunits.h>
|
#include <translationunits.h>
|
||||||
#include <unsavedfiles.h>
|
#include <unsavedfiles.h>
|
||||||
|
|
||||||
@@ -77,7 +78,6 @@ protected:
|
|||||||
projectPart,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits};
|
translationUnits};
|
||||||
::DiagnosticSet diagnosticSetWithChildren{translationUnitMainFile.diagnostics()};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum ChildMode { WithChild, WithoutChild };
|
enum ChildMode { WithChild, WithoutChild };
|
||||||
@@ -86,14 +86,16 @@ protected:
|
|||||||
|
|
||||||
TEST_F(DiagnosticSet, SetHasContent)
|
TEST_F(DiagnosticSet, SetHasContent)
|
||||||
{
|
{
|
||||||
const auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
const auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
ASSERT_THAT(set.size(), 1);
|
ASSERT_THAT(set.size(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiagnosticSet, MoveConstructor)
|
TEST_F(DiagnosticSet, MoveConstructor)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
const auto set2 = std::move(set);
|
const auto set2 = std::move(set);
|
||||||
|
|
||||||
@@ -103,7 +105,8 @@ TEST_F(DiagnosticSet, MoveConstructor)
|
|||||||
|
|
||||||
TEST_F(DiagnosticSet, MoveAssigment)
|
TEST_F(DiagnosticSet, MoveAssigment)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
auto set2 = std::move(set);
|
auto set2 = std::move(set);
|
||||||
set = std::move(set2);
|
set = std::move(set2);
|
||||||
@@ -114,7 +117,8 @@ TEST_F(DiagnosticSet, MoveAssigment)
|
|||||||
|
|
||||||
TEST_F(DiagnosticSet, MoveSelfAssigment)
|
TEST_F(DiagnosticSet, MoveSelfAssigment)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
set = std::move(set);
|
set = std::move(set);
|
||||||
|
|
||||||
@@ -123,21 +127,24 @@ TEST_F(DiagnosticSet, MoveSelfAssigment)
|
|||||||
|
|
||||||
TEST_F(DiagnosticSet, FirstElementEqualBegin)
|
TEST_F(DiagnosticSet, FirstElementEqualBegin)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
ASSERT_TRUE(set.front() == *set.begin());
|
ASSERT_TRUE(set.front() == *set.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiagnosticSet, BeginIsUnequalEnd)
|
TEST_F(DiagnosticSet, BeginIsUnequalEnd)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
ASSERT_TRUE(set.begin() != set.end());
|
ASSERT_TRUE(set.begin() != set.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiagnosticSet, BeginPlusOneIsEqualEnd)
|
TEST_F(DiagnosticSet, BeginPlusOneIsEqualEnd)
|
||||||
{
|
{
|
||||||
auto set = translationUnit.diagnostics();
|
translationUnit.parse();
|
||||||
|
auto set = translationUnit.translationUnitCore().diagnostics();
|
||||||
|
|
||||||
ASSERT_TRUE(++set.begin() == set.end());
|
ASSERT_TRUE(++set.begin() == set.end());
|
||||||
}
|
}
|
||||||
@@ -145,14 +152,17 @@ TEST_F(DiagnosticSet, BeginPlusOneIsEqualEnd)
|
|||||||
TEST_F(DiagnosticSet, ToDiagnosticContainersLetThroughByDefault)
|
TEST_F(DiagnosticSet, ToDiagnosticContainersLetThroughByDefault)
|
||||||
{
|
{
|
||||||
const auto diagnosticContainerWithoutChild = expectedDiagnostic(WithChild);
|
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)));
|
ASSERT_THAT(diagnostics, Contains(IsDiagnosticContainer(diagnosticContainerWithoutChild)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DiagnosticSet, ToDiagnosticContainersFiltersOutTopLevelItem)
|
TEST_F(DiagnosticSet, ToDiagnosticContainersFiltersOutTopLevelItem)
|
||||||
{
|
{
|
||||||
|
translationUnitMainFile.parse();
|
||||||
|
const ::DiagnosticSet diagnosticSetWithChildren{translationUnitMainFile.translationUnitCore().diagnostics()};
|
||||||
const auto acceptNoDiagnostics = [](const Diagnostic &) { return false; };
|
const auto acceptNoDiagnostics = [](const Diagnostic &) { return false; };
|
||||||
|
|
||||||
const auto diagnostics = diagnosticSetWithChildren.toDiagnosticContainers(acceptNoDiagnostics);
|
const auto diagnostics = diagnosticSetWithChildren.toDiagnosticContainers(acceptNoDiagnostics);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <fixitcontainer.h>
|
#include <fixitcontainer.h>
|
||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <translationunits.h>
|
#include <translationunits.h>
|
||||||
#include <projects.h>
|
#include <projects.h>
|
||||||
#include <unsavedfiles.h>
|
#include <unsavedfiles.h>
|
||||||
@@ -79,9 +80,24 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Diagnostic : public ::testing::Test
|
struct DiagnosticData {
|
||||||
{
|
DiagnosticData(TranslationUnit &translationUnit)
|
||||||
protected:
|
: 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")}};
|
ProjectPart projectPart{Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-std=c++11")}};
|
||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
@@ -90,8 +106,17 @@ protected:
|
|||||||
projectPart,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits};
|
translationUnits};
|
||||||
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
|
std::unique_ptr<DiagnosticData> d;
|
||||||
::Diagnostic diagnostic{diagnosticSet.front()};
|
};
|
||||||
|
|
||||||
|
class Diagnostic : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void SetUp() override;
|
||||||
|
void TearDown() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Data *d;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum ChildMode { WithChild, WithoutChild };
|
enum ChildMode { WithChild, WithoutChild };
|
||||||
@@ -100,63 +125,63 @@ protected:
|
|||||||
|
|
||||||
TEST_F(Diagnostic, MoveContructor)
|
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());
|
ASSERT_FALSE(diagnostic2.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Diagnostic, MoveAssigment)
|
TEST_F(Diagnostic, MoveAssigment)
|
||||||
{
|
{
|
||||||
auto diagnostic2 = std::move(diagnostic);
|
auto diagnostic2 = std::move(d->d->diagnostic);
|
||||||
diagnostic = std::move(diagnostic2);
|
d->d->diagnostic = std::move(diagnostic2);
|
||||||
|
|
||||||
ASSERT_TRUE(diagnostic2.isNull());
|
ASSERT_TRUE(diagnostic2.isNull());
|
||||||
ASSERT_FALSE(diagnostic.isNull());
|
ASSERT_FALSE(d->d->diagnostic.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Diagnostic, MoveSelfAssigment)
|
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)
|
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)
|
TEST_F(Diagnostic, Category)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(diagnostic.category(), Utf8StringLiteral("Semantic Issue"));
|
ASSERT_THAT(d->d->diagnostic.category(), Utf8StringLiteral("Semantic Issue"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Diagnostic, EnableOption)
|
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)
|
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)
|
TEST_F(Diagnostic, Severity)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(diagnostic.severity(), DiagnosticSeverity::Warning);
|
ASSERT_THAT(d->d->diagnostic.severity(), DiagnosticSeverity::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Diagnostic, ChildDiagnosticsSize)
|
TEST_F(Diagnostic, ChildDiagnosticsSize)
|
||||||
{
|
{
|
||||||
auto diagnostic = diagnosticSet.back();
|
auto diagnostic = d->d->diagnosticSet.back();
|
||||||
|
|
||||||
ASSERT_THAT(diagnostic.childDiagnostics().size(), 1);
|
ASSERT_THAT(diagnostic.childDiagnostics().size(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Diagnostic, ChildDiagnosticsText)
|
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"));
|
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 diagnosticWithChild = expectedDiagnostic(WithChild);
|
||||||
|
|
||||||
const auto diagnostic = diagnosticSet.back().toDiagnosticContainer();
|
const auto diagnostic = d->d->diagnosticSet.back().toDiagnosticContainer();
|
||||||
|
|
||||||
ASSERT_THAT(diagnostic, IsDiagnosticContainer(diagnosticWithChild));
|
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
|
DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMode) const
|
||||||
{
|
{
|
||||||
QVector<DiagnosticContainer> children;
|
QVector<DiagnosticContainer> children;
|
||||||
@@ -179,7 +215,7 @@ DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMo
|
|||||||
Utf8StringLiteral("Semantic Issue"),
|
Utf8StringLiteral("Semantic Issue"),
|
||||||
{Utf8String(), Utf8String()},
|
{Utf8String(), Utf8String()},
|
||||||
ClangBackEnd::DiagnosticSeverity::Note,
|
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"),
|
Utf8StringLiteral("Semantic Issue"),
|
||||||
{Utf8String(), Utf8String()},
|
{Utf8String(), Utf8String()},
|
||||||
ClangBackEnd::DiagnosticSeverity::Error,
|
ClangBackEnd::DiagnosticSeverity::Error,
|
||||||
SourceLocationContainer(translationUnit.filePath(), 7, 5),
|
SourceLocationContainer(d->translationUnit.filePath(), 7, 5),
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
children
|
children
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
#include <projects.h>
|
#include <projects.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <translationunits.h>
|
#include <translationunits.h>
|
||||||
#include <unsavedfiles.h>
|
#include <unsavedfiles.h>
|
||||||
#include <sourcelocation.h>
|
#include <sourcelocation.h>
|
||||||
@@ -43,6 +44,7 @@
|
|||||||
|
|
||||||
using ClangBackEnd::DiagnosticSet;
|
using ClangBackEnd::DiagnosticSet;
|
||||||
using ClangBackEnd::TranslationUnit;
|
using ClangBackEnd::TranslationUnit;
|
||||||
|
using ClangBackEnd::TranslationUnitCore;
|
||||||
using ClangBackEnd::ProjectPart;
|
using ClangBackEnd::ProjectPart;
|
||||||
using ClangBackEnd::UnsavedFiles;
|
using ClangBackEnd::UnsavedFiles;
|
||||||
using ClangBackEnd::Diagnostic;
|
using ClangBackEnd::Diagnostic;
|
||||||
@@ -68,9 +70,28 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
|
|||||||
return true;
|
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")};
|
ProjectPart projectPart{Utf8StringLiteral("projectPartId")};
|
||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
@@ -79,9 +100,20 @@ protected:
|
|||||||
projectPart,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits};
|
translationUnits};
|
||||||
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
|
TranslationUnitCore translationUnitCore{translationUnit.translationUnitCore()};
|
||||||
Diagnostic diagnostic{diagnosticSet.front()};
|
std::unique_ptr<FixItData> d;
|
||||||
::FixIt fixIt{diagnostic.fixIts().front()};
|
};
|
||||||
|
|
||||||
|
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)
|
TEST_F(FixIt, Size)
|
||||||
@@ -111,4 +143,17 @@ TEST_F(FixIt, End)
|
|||||||
29u));
|
29u));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Data *FixIt::d;
|
||||||
|
|
||||||
|
void FixIt::SetUpTestCase()
|
||||||
|
{
|
||||||
|
d = new Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FixIt::TearDownTestCase()
|
||||||
|
{
|
||||||
|
delete d;
|
||||||
|
d = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <cursor.h>
|
#include <cursor.h>
|
||||||
#include <clangstring.h>
|
#include <clangstring.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
#include <projects.h>
|
#include <projects.h>
|
||||||
#include <skippedsourceranges.h>
|
#include <skippedsourceranges.h>
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
|
|
||||||
using ClangBackEnd::Cursor;
|
using ClangBackEnd::Cursor;
|
||||||
using ClangBackEnd::TranslationUnit;
|
using ClangBackEnd::TranslationUnit;
|
||||||
|
using ClangBackEnd::TranslationUnitCore;
|
||||||
using ClangBackEnd::UnsavedFiles;
|
using ClangBackEnd::UnsavedFiles;
|
||||||
using ClangBackEnd::ProjectPart;
|
using ClangBackEnd::ProjectPart;
|
||||||
using ClangBackEnd::TranslationUnits;
|
using ClangBackEnd::TranslationUnits;
|
||||||
@@ -84,6 +86,11 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
|
Data()
|
||||||
|
{
|
||||||
|
translationUnit.parse();
|
||||||
|
}
|
||||||
|
|
||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
||||||
@@ -93,6 +100,9 @@ struct Data {
|
|||||||
{Utf8StringLiteral("-std=c++11"),Utf8StringLiteral("-DBLAH")}),
|
{Utf8StringLiteral("-std=c++11"),Utf8StringLiteral("-DBLAH")}),
|
||||||
{},
|
{},
|
||||||
translationUnits};
|
translationUnits};
|
||||||
|
TranslationUnitCore translationUnitCore{filePath,
|
||||||
|
translationUnit.index(),
|
||||||
|
translationUnit.cxTranslationUnit()};
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkippedSourceRanges : public ::testing::Test
|
class SkippedSourceRanges : public ::testing::Test
|
||||||
@@ -103,9 +113,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Data *d;
|
static Data *d;
|
||||||
const TranslationUnit &translationUnit = d->translationUnit;
|
const TranslationUnitCore &translationUnitCore = d->translationUnitCore;
|
||||||
const Utf8String &filePath = d->filePath;
|
const Utf8String &filePath = d->filePath;
|
||||||
const ::SkippedSourceRanges skippedSourceRanges{d->translationUnit.skippedSourceRanges()};
|
const ::SkippedSourceRanges skippedSourceRanges{d->translationUnitCore.skippedSourceRanges()};
|
||||||
};
|
};
|
||||||
|
|
||||||
Data *SkippedSourceRanges::d;
|
Data *SkippedSourceRanges::d;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
#include <projects.h>
|
#include <projects.h>
|
||||||
#include <clangtranslationunit.h>
|
#include <clangtranslationunit.h>
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <translationunits.h>
|
#include <translationunits.h>
|
||||||
#include <unsavedfiles.h>
|
#include <unsavedfiles.h>
|
||||||
#include <sourcelocation.h>
|
#include <sourcelocation.h>
|
||||||
@@ -51,7 +52,26 @@ using testing::Not;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct SourceLocationData {
|
||||||
|
SourceLocationData(TranslationUnit &translationUnit)
|
||||||
|
: diagnosticSet{translationUnit.translationUnitCore().diagnostics()}
|
||||||
|
, diagnostic{diagnosticSet.front()}
|
||||||
|
, sourceLocation{diagnostic.location()}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagnosticSet diagnosticSet;
|
||||||
|
Diagnostic diagnostic;
|
||||||
|
::SourceLocation sourceLocation;
|
||||||
|
};
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
|
Data()
|
||||||
|
{
|
||||||
|
translationUnit.parse();
|
||||||
|
d.reset(new SourceLocationData(translationUnit));
|
||||||
|
}
|
||||||
|
|
||||||
ProjectPart projectPart{Utf8StringLiteral("projectPartId")};
|
ProjectPart projectPart{Utf8StringLiteral("projectPartId")};
|
||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
@@ -60,9 +80,7 @@ struct Data {
|
|||||||
projectPart,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits};
|
translationUnits};
|
||||||
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
|
std::unique_ptr<SourceLocationData> d;
|
||||||
Diagnostic diagnostic{diagnosticSet.front()};
|
|
||||||
::SourceLocation sourceLocation{diagnostic.location()};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SourceLocation : public ::testing::Test
|
class SourceLocation : public ::testing::Test
|
||||||
@@ -73,8 +91,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Data *d;
|
static Data *d;
|
||||||
const ::SourceLocation &sourceLocation = d->sourceLocation;
|
TranslationUnit &translationUnit = d->translationUnit;
|
||||||
const TranslationUnit &translationUnit = d->translationUnit;
|
::SourceLocation &sourceLocation = d->d->sourceLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(SourceLocation, FilePath)
|
TEST_F(SourceLocation, FilePath)
|
||||||
@@ -99,12 +117,12 @@ TEST_F(SourceLocation, Offset)
|
|||||||
|
|
||||||
TEST_F(SourceLocation, Create)
|
TEST_F(SourceLocation, Create)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(translationUnit.sourceLocationAt(4, 1), sourceLocation);
|
ASSERT_THAT(translationUnit.translationUnitCore().sourceLocationAt(4, 1), sourceLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SourceLocation, NotEqual)
|
TEST_F(SourceLocation, NotEqual)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(translationUnit.sourceLocationAt(3, 1), Not(sourceLocation));
|
ASSERT_THAT(translationUnit.translationUnitCore().sourceLocationAt(3, 1), Not(sourceLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
Data *SourceLocation::d;
|
Data *SourceLocation::d;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <clangtranslationunitcore.h>
|
||||||
#include <diagnostic.h>
|
#include <diagnostic.h>
|
||||||
#include <diagnosticset.h>
|
#include <diagnosticset.h>
|
||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
@@ -34,6 +35,8 @@
|
|||||||
|
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gmock/gmock-matchers.h>
|
#include <gmock/gmock-matchers.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -41,6 +44,7 @@
|
|||||||
|
|
||||||
using ClangBackEnd::DiagnosticSet;
|
using ClangBackEnd::DiagnosticSet;
|
||||||
using ClangBackEnd::TranslationUnit;
|
using ClangBackEnd::TranslationUnit;
|
||||||
|
using ClangBackEnd::TranslationUnitCore;
|
||||||
using ClangBackEnd::ProjectPart;
|
using ClangBackEnd::ProjectPart;
|
||||||
using ClangBackEnd::UnsavedFiles;
|
using ClangBackEnd::UnsavedFiles;
|
||||||
using ClangBackEnd::Diagnostic;
|
using ClangBackEnd::Diagnostic;
|
||||||
@@ -70,19 +74,42 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
|
|||||||
return true;
|
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 {
|
struct Data {
|
||||||
|
Data()
|
||||||
|
{
|
||||||
|
translationUnit.parse();
|
||||||
|
d.reset(new SourceRangeData(translationUnit));
|
||||||
|
}
|
||||||
|
|
||||||
ProjectPart projectPart{Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-pedantic")}};
|
ProjectPart projectPart{Utf8StringLiteral("projectPartId"), {Utf8StringLiteral("-pedantic")}};
|
||||||
ClangBackEnd::ProjectParts projects;
|
ClangBackEnd::ProjectParts projects;
|
||||||
ClangBackEnd::UnsavedFiles unsavedFiles;
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
||||||
ClangBackEnd::TranslationUnits translationUnits{projects, 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,
|
projectPart,
|
||||||
Utf8StringVector(),
|
Utf8StringVector(),
|
||||||
translationUnits};
|
translationUnits};
|
||||||
DiagnosticSet diagnosticSet{translationUnit.diagnostics()};
|
TranslationUnitCore translationUnitCore{filePath,
|
||||||
Diagnostic diagnostic{diagnosticSet.front()};
|
translationUnit.index(),
|
||||||
Diagnostic diagnosticWithFilteredOutInvalidRange{diagnosticSet.at(1)};
|
translationUnit.cxTranslationUnit()};
|
||||||
::SourceRange sourceRange{diagnostic.ranges().front()};
|
|
||||||
|
std::unique_ptr<SourceRangeData> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SourceRange : public ::testing::Test
|
class SourceRange : public ::testing::Test
|
||||||
@@ -93,10 +120,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Data *d;
|
static Data *d;
|
||||||
const ::SourceRange &sourceRange = d->sourceRange;
|
const ::SourceRange &sourceRange = d->d->sourceRange;
|
||||||
const Diagnostic &diagnostic = d->diagnostic;
|
const Diagnostic &diagnostic = d->d->diagnostic;
|
||||||
const Diagnostic &diagnosticWithFilteredOutInvalidRange = d->diagnosticWithFilteredOutInvalidRange;
|
const Diagnostic &diagnosticWithFilteredOutInvalidRange = d->d->diagnosticWithFilteredOutInvalidRange;
|
||||||
const TranslationUnit &translationUnit = d->translationUnit;
|
const TranslationUnitCore &translationUnitCore = d->translationUnitCore;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(SourceRange, IsNull)
|
TEST_F(SourceRange, IsNull)
|
||||||
@@ -141,7 +168,7 @@ TEST_F(SourceRange, Create)
|
|||||||
|
|
||||||
TEST_F(SourceRange, SourceRangeFromTranslationUnit)
|
TEST_F(SourceRange, SourceRangeFromTranslationUnit)
|
||||||
{
|
{
|
||||||
auto sourceRangeFromTranslationUnit = translationUnit.sourceRange(8u, 5u, 8u, 6u);
|
auto sourceRangeFromTranslationUnit = translationUnitCore.sourceRange(8u, 5u, 8u, 6u);
|
||||||
|
|
||||||
ASSERT_THAT(sourceRangeFromTranslationUnit, sourceRange);
|
ASSERT_THAT(sourceRangeFromTranslationUnit, sourceRange);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,7 +211,8 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse)
|
|||||||
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
||||||
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
||||||
translationUnits.create({fileContainer, headerContainer});
|
translationUnits.create({fileContainer, headerContainer});
|
||||||
translationUnits.translationUnit(filePath, projectPartId).cxTranslationUnit();
|
TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
||||||
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnits.update({headerContainerWithUnsavedContent});
|
translationUnits.update({headerContainerWithUnsavedContent});
|
||||||
|
|
||||||
@@ -224,7 +225,9 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics)
|
|||||||
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
||||||
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
||||||
translationUnits.create({fileContainer, headerContainer});
|
translationUnits.create({fileContainer, headerContainer});
|
||||||
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
|
TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
||||||
|
translationUnit.parse();
|
||||||
|
translationUnit.diagnostics();
|
||||||
|
|
||||||
translationUnits.update({headerContainerWithUnsavedContent});
|
translationUnits.update({headerContainerWithUnsavedContent});
|
||||||
|
|
||||||
@@ -237,7 +240,9 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics)
|
|||||||
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
||||||
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
||||||
translationUnits.create({fileContainer, headerContainer});
|
translationUnits.create({fileContainer, headerContainer});
|
||||||
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
|
TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
||||||
|
translationUnit.parse();
|
||||||
|
translationUnit.diagnostics();
|
||||||
|
|
||||||
translationUnits.remove({headerContainerWithUnsavedContent});
|
translationUnits.remove({headerContainerWithUnsavedContent});
|
||||||
|
|
||||||
@@ -250,7 +255,9 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForHighlightingMarks)
|
|||||||
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
||||||
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
||||||
translationUnits.create({fileContainer, headerContainer});
|
translationUnits.create({fileContainer, headerContainer});
|
||||||
translationUnits.translationUnit(filePath, projectPartId).highlightingMarks();
|
TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
||||||
|
translationUnit.parse();
|
||||||
|
translationUnit.highlightingMarks();
|
||||||
|
|
||||||
translationUnits.update({headerContainerWithUnsavedContent});
|
translationUnits.update({headerContainerWithUnsavedContent});
|
||||||
|
|
||||||
@@ -263,7 +270,9 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForHighlightingMarks)
|
|||||||
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
|
||||||
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
|
||||||
translationUnits.create({fileContainer, headerContainer});
|
translationUnits.create({fileContainer, headerContainer});
|
||||||
translationUnits.translationUnit(filePath, projectPartId).highlightingMarks();
|
TranslationUnit translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
||||||
|
translationUnit.parse();
|
||||||
|
translationUnit.highlightingMarks();
|
||||||
|
|
||||||
translationUnits.remove({headerContainerWithUnsavedContent});
|
translationUnits.remove({headerContainerWithUnsavedContent});
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,10 @@ TEST_F(TranslationUnit, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit)
|
|||||||
ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitIsNullException);
|
ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitIsNullException);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, CxTranslationUnitGetterIsNonNullForValidUnit)
|
TEST_F(TranslationUnit, CxTranslationUnitGetterIsNonNullForParsedUnit)
|
||||||
{
|
{
|
||||||
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull());
|
ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +166,7 @@ TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslation
|
|||||||
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
||||||
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
||||||
|
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
||||||
}
|
}
|
||||||
@@ -172,12 +174,12 @@ TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslation
|
|||||||
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared)
|
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared)
|
||||||
{
|
{
|
||||||
ProjectPart projectPart = translationUnit.projectPart();
|
ProjectPart projectPart = translationUnit.projectPart();
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
||||||
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
||||||
|
|
||||||
projectPart.clear();
|
projectPart.clear();
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
||||||
}
|
}
|
||||||
@@ -191,6 +193,8 @@ TEST_F(TranslationUnit, DocumentRevisionInFileContainerGetter)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, DependedFilePaths)
|
TEST_F(TranslationUnit, DependedFilePaths)
|
||||||
{
|
{
|
||||||
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_THAT(translationUnit.dependedFilePaths(),
|
ASSERT_THAT(translationUnit.dependedFilePaths(),
|
||||||
AllOf(Contains(translationUnitFilePath),
|
AllOf(Contains(translationUnitFilePath),
|
||||||
Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"))));
|
Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"))));
|
||||||
@@ -207,14 +211,12 @@ TEST_F(TranslationUnit, DeletedFileShouldNotNeedReparsing)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, NeedsNoReparseAfterCreation)
|
TEST_F(TranslationUnit, NeedsNoReparseAfterCreation)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
|
||||||
|
|
||||||
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile)
|
TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
||||||
|
|
||||||
@@ -223,7 +225,7 @@ TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile)
|
TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
||||||
|
|
||||||
@@ -232,7 +234,7 @@ TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, NeedsReparsingForDependendFile)
|
TEST_F(TranslationUnit, NeedsReparsingForDependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
||||||
|
|
||||||
@@ -241,17 +243,17 @@ TEST_F(TranslationUnit, NeedsReparsingForDependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, NeedsNoReparsingAfterReparsing)
|
TEST_F(TranslationUnit, NeedsNoReparsingAfterReparsing)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
||||||
|
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.reparse();
|
||||||
|
|
||||||
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, IsIntactAfterCreation)
|
TEST_F(TranslationUnit, IsIntactAfterParsing)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_TRUE(translationUnit.isIntact());
|
ASSERT_TRUE(translationUnit.isIntact());
|
||||||
}
|
}
|
||||||
@@ -263,16 +265,16 @@ TEST_F(TranslationUnit, IsNotIntactForDeletedFile)
|
|||||||
ASSERT_FALSE(translationUnit.isIntact());
|
ASSERT_FALSE(translationUnit.isIntact());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewDiagnosticsAfterCreation)
|
TEST_F(TranslationUnit, HasNewDiagnosticsAfterParse)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
|
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile)
|
TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
||||||
|
|
||||||
@@ -281,7 +283,7 @@ TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile)
|
TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
||||||
@@ -291,7 +293,7 @@ TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile)
|
TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
||||||
|
|
||||||
@@ -300,7 +302,7 @@ TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics)
|
TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
||||||
|
|
||||||
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
||||||
@@ -310,14 +312,14 @@ TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewHighlightingMarksAfterCreation)
|
TEST_F(TranslationUnit, HasNewHighlightingMarksAfterCreation)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
ASSERT_TRUE(translationUnit.hasNewHighlightingMarks());
|
ASSERT_TRUE(translationUnit.hasNewHighlightingMarks());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewHighlightingMarksForMainFile)
|
TEST_F(TranslationUnit, HasNewHighlightingMarksForMainFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
||||||
|
|
||||||
@@ -326,7 +328,7 @@ TEST_F(TranslationUnit, HasNewHighlightingMarksForMainFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNoNewHighlightingMarksForIndependendFile)
|
TEST_F(TranslationUnit, HasNoNewHighlightingMarksForIndependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
translationUnit.highlightingMarks();
|
translationUnit.highlightingMarks();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
||||||
@@ -336,7 +338,7 @@ TEST_F(TranslationUnit, HasNoNewHighlightingMarksForIndependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNewHighlightingMarksForDependendFile)
|
TEST_F(TranslationUnit, HasNewHighlightingMarksForDependendFile)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
||||||
|
|
||||||
@@ -345,7 +347,7 @@ TEST_F(TranslationUnit, HasNewHighlightingMarksForDependendFile)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, HasNoNewHighlightingMarksAfterGettingHighlightingMarks)
|
TEST_F(TranslationUnit, HasNoNewHighlightingMarksAfterGettingHighlightingMarks)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
||||||
|
|
||||||
translationUnit.highlightingMarks();
|
translationUnit.highlightingMarks();
|
||||||
@@ -356,7 +358,7 @@ TEST_F(TranslationUnit, HasNoNewHighlightingMarksAfterGettingHighlightingMarks)
|
|||||||
TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated)
|
TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated)
|
||||||
{
|
{
|
||||||
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
|
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})});
|
projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})});
|
||||||
|
|
||||||
translationUnit.setDirtyIfProjectPartIsOutdated();
|
translationUnit.setDirtyIfProjectPartIsOutdated();
|
||||||
@@ -366,7 +368,7 @@ TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated)
|
|||||||
|
|
||||||
TEST_F(TranslationUnit, SetNotDirtyIfProjectPartIsNotOutdated)
|
TEST_F(TranslationUnit, SetNotDirtyIfProjectPartIsNotOutdated)
|
||||||
{
|
{
|
||||||
translationUnit.cxTranslationUnit();
|
translationUnit.parse();
|
||||||
|
|
||||||
translationUnit.setDirtyIfProjectPartIsOutdated();
|
translationUnit.setDirtyIfProjectPartIsOutdated();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user