2015-10-01 12:45:06 +02:00
|
|
|
/****************************************************************************
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-11-24 11:17:18 +01:00
|
|
|
#include "clangtranslationunit.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-11-17 13:33:31 +01:00
|
|
|
#include "cursor.h"
|
2015-08-31 12:40:14 +02:00
|
|
|
#include "clangstring.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
#include "codecompleter.h"
|
2015-11-05 13:57:57 +01:00
|
|
|
#include "commandlinearguments.h"
|
2015-09-18 17:01:32 +02:00
|
|
|
#include "diagnosticcontainer.h"
|
2015-08-31 16:28:26 +02:00
|
|
|
#include "diagnosticset.h"
|
2015-06-16 12:38:04 +02:00
|
|
|
#include "projectpart.h"
|
2015-11-17 13:33:31 +01:00
|
|
|
#include "skippedsourceranges.h"
|
2015-09-18 17:01:32 +02:00
|
|
|
#include "sourcelocation.h"
|
2015-11-17 13:33:31 +01:00
|
|
|
#include "sourcerange.h"
|
|
|
|
|
#include "highlightinginformations.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
#include "translationunitfilenotexitexception.h"
|
2015-06-16 12:38:04 +02:00
|
|
|
#include "translationunitisnullexception.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
#include "translationunitparseerrorexception.h"
|
2015-08-31 12:40:14 +02:00
|
|
|
#include "translationunits.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
#include "unsavedfiles.h"
|
2015-06-16 12:38:04 +02:00
|
|
|
|
|
|
|
|
#include <utf8string.h>
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
#include <QDebug>
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <QFileInfo>
|
2015-07-28 16:44:39 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
#include <ostream>
|
|
|
|
|
|
2015-07-28 16:44:39 +02:00
|
|
|
static Q_LOGGING_CATEGORY(verboseLibLog, "qtc.clangbackend.verboselib");
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-11-05 13:57:57 +01:00
|
|
|
static bool isVerboseModeEnabled()
|
|
|
|
|
{
|
|
|
|
|
return verboseLibLog().isDebugEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
namespace ClangBackEnd {
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
class TranslationUnitData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TranslationUnitData(const Utf8String &filePath,
|
2015-08-31 12:40:14 +02:00
|
|
|
const ProjectPart &projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
const Utf8StringVector &fileArguments,
|
2015-08-31 12:40:14 +02:00
|
|
|
TranslationUnits &translationUnits);
|
2015-06-01 18:51:55 +02:00
|
|
|
~TranslationUnitData();
|
|
|
|
|
|
|
|
|
|
public:
|
2015-08-31 12:40:14 +02:00
|
|
|
TranslationUnits &translationUnits;
|
|
|
|
|
time_point lastProjectPartChangeTimePoint;
|
|
|
|
|
QSet<Utf8String> dependedFilePaths;
|
2015-06-01 18:51:55 +02:00
|
|
|
ProjectPart projectPart;
|
2015-11-05 13:57:57 +01:00
|
|
|
Utf8StringVector fileArguments;
|
2015-06-01 18:51:55 +02:00
|
|
|
Utf8String filePath;
|
|
|
|
|
CXTranslationUnit translationUnit = nullptr;
|
|
|
|
|
CXIndex index = nullptr;
|
2015-08-31 12:40:14 +02:00
|
|
|
uint documentRevision = 0;
|
2015-11-23 13:31:46 +01:00
|
|
|
bool needsToBeReparsed = false;
|
|
|
|
|
bool hasNewDiagnostics = true;
|
2015-11-25 15:21:24 +01:00
|
|
|
bool isUsedByCurrentEditor = false;
|
|
|
|
|
bool isVisibleInEditor = false;
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TranslationUnitData::TranslationUnitData(const Utf8String &filePath,
|
2015-08-31 12:40:14 +02:00
|
|
|
const ProjectPart &projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
const Utf8StringVector &fileArguments,
|
2015-08-31 12:40:14 +02:00
|
|
|
TranslationUnits &translationUnits)
|
|
|
|
|
: translationUnits(translationUnits),
|
|
|
|
|
lastProjectPartChangeTimePoint(std::chrono::steady_clock::now()),
|
2015-06-01 18:51:55 +02:00
|
|
|
projectPart(projectPart),
|
2015-11-05 13:57:57 +01:00
|
|
|
fileArguments(fileArguments),
|
2015-08-31 12:40:14 +02:00
|
|
|
filePath(filePath)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
dependedFilePaths.insert(filePath);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TranslationUnitData::~TranslationUnitData()
|
|
|
|
|
{
|
|
|
|
|
clang_disposeTranslationUnit(translationUnit);
|
|
|
|
|
clang_disposeIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TranslationUnit::TranslationUnit(const Utf8String &filePath,
|
2015-08-31 12:40:14 +02:00
|
|
|
const ProjectPart &projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
const Utf8StringVector &fileArguments,
|
2015-08-31 12:40:14 +02:00
|
|
|
TranslationUnits &translationUnits,
|
2015-06-01 18:51:55 +02:00
|
|
|
FileExistsCheck fileExistsCheck)
|
2015-11-05 13:57:57 +01:00
|
|
|
: d(std::make_shared<TranslationUnitData>(filePath,
|
|
|
|
|
projectPart,
|
|
|
|
|
fileArguments,
|
|
|
|
|
translationUnits))
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
if (fileExistsCheck == CheckIfFileExists)
|
|
|
|
|
checkIfFileExists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::isNull() const
|
|
|
|
|
{
|
|
|
|
|
return !d;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 15:21:24 +01:00
|
|
|
void TranslationUnit::setIsUsedByCurrentEditor(bool isUsedByCurrentEditor)
|
|
|
|
|
{
|
|
|
|
|
d->isUsedByCurrentEditor = isUsedByCurrentEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::isUsedByCurrentEditor() const
|
|
|
|
|
{
|
|
|
|
|
return d->isUsedByCurrentEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::setIsVisibleInEditor(bool isVisibleInEditor)
|
|
|
|
|
{
|
|
|
|
|
d->isVisibleInEditor = isVisibleInEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::isVisibleInEditor() const
|
|
|
|
|
{
|
|
|
|
|
return d->isVisibleInEditor;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
void TranslationUnit::reset()
|
|
|
|
|
{
|
|
|
|
|
d.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
void TranslationUnit::reparse() const
|
2015-07-21 19:44:08 +02:00
|
|
|
{
|
|
|
|
|
cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
reparseTranslationUnit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
CXIndex TranslationUnit::index() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
2015-07-28 16:44:39 +02:00
|
|
|
if (!d->index) {
|
2015-11-05 13:57:57 +01:00
|
|
|
const bool displayDiagnostics = isVerboseModeEnabled();
|
2015-07-28 16:44:39 +02:00
|
|
|
d->index = clang_createIndex(1, displayDiagnostics);
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
return d->index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CXTranslationUnit TranslationUnit::cxTranslationUnit() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
2015-10-12 12:10:58 +02:00
|
|
|
checkIfFileExists();
|
2015-08-31 12:40:14 +02:00
|
|
|
removeTranslationUnitIfProjectPartWasChanged();
|
2015-06-01 18:51:55 +02:00
|
|
|
createTranslationUnitIfNeeded();
|
2015-08-31 12:40:14 +02:00
|
|
|
reparseTranslationUnitIfFilesAreChanged();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
return d->translationUnit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Utf8String &TranslationUnit::filePath() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Utf8String &TranslationUnit::projectPartId() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->projectPart.projectPartId();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
FileContainer TranslationUnit::fileContainer() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
return FileContainer(d->filePath,
|
|
|
|
|
d->projectPart.projectPartId(),
|
|
|
|
|
Utf8String(),
|
|
|
|
|
false,
|
|
|
|
|
d->documentRevision);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ProjectPart &TranslationUnit::projectPart() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->projectPart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::setDocumentRevision(uint revision)
|
|
|
|
|
{
|
|
|
|
|
d->documentRevision = revision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint TranslationUnit::documentRevision() const
|
|
|
|
|
{
|
|
|
|
|
return d->documentRevision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const time_point &TranslationUnit::lastProjectPartChangeTimePoint() const
|
|
|
|
|
{
|
|
|
|
|
return d->lastProjectPartChangeTimePoint;
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
bool TranslationUnit::isNeedingReparse() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
return d->needsToBeReparsed;
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
bool TranslationUnit::hasNewDiagnostics() const
|
|
|
|
|
{
|
|
|
|
|
return d->hasNewDiagnostics;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
DiagnosticSet TranslationUnit::diagnostics() const
|
|
|
|
|
{
|
2015-08-26 16:33:32 +02:00
|
|
|
d->hasNewDiagnostics = false;
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
return DiagnosticSet(clang_getDiagnosticSetFromTU(cxTranslationUnit()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 17:01:32 +02:00
|
|
|
QVector<ClangBackEnd::DiagnosticContainer> TranslationUnit::mainFileDiagnostics() const
|
|
|
|
|
{
|
|
|
|
|
const auto mainFilePath = filePath();
|
|
|
|
|
const auto isMainFileDiagnostic = [mainFilePath](const Diagnostic &diagnostic) {
|
|
|
|
|
return diagnostic.location().filePath() == mainFilePath;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return diagnostics().toDiagnosticContainers(isMainFileDiagnostic);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
const QSet<Utf8String> &TranslationUnit::dependedFilePaths() const
|
|
|
|
|
{
|
|
|
|
|
createTranslationUnitIfNeeded();
|
|
|
|
|
|
|
|
|
|
return d->dependedFilePaths;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
void TranslationUnit::setDirtyIfDependencyIsMet(const Utf8String &filePath)
|
2015-08-31 12:40:14 +02:00
|
|
|
{
|
2015-10-12 17:36:18 +02:00
|
|
|
if (d->dependedFilePaths.contains(filePath) && isMainFileAndExistsOrIsOtherFile(filePath)) {
|
2015-08-31 12:40:14 +02:00
|
|
|
d->needsToBeReparsed = true;
|
2015-08-26 16:33:32 +02:00
|
|
|
d->hasNewDiagnostics = true;
|
|
|
|
|
}
|
2015-08-31 12:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-17 13:33:31 +01:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HighlightingInformations TranslationUnit::highlightingInformationsInRange(const SourceRange &range) const
|
|
|
|
|
{
|
|
|
|
|
CXToken *cxTokens = 0;
|
|
|
|
|
uint cxTokensCount = 0;
|
|
|
|
|
auto translationUnit = cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
clang_tokenize(translationUnit, range, &cxTokens, &cxTokensCount);
|
|
|
|
|
|
|
|
|
|
return HighlightingInformations(translationUnit, cxTokens, cxTokensCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SkippedSourceRanges TranslationUnit::skippedSourceRanges() const
|
|
|
|
|
{
|
|
|
|
|
return SkippedSourceRanges(cxTranslationUnit(), d->filePath.constData());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
void TranslationUnit::checkIfNull() const
|
|
|
|
|
{
|
|
|
|
|
if (isNull())
|
|
|
|
|
throw TranslationUnitIsNullException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::checkIfFileExists() const
|
|
|
|
|
{
|
|
|
|
|
if (!QFileInfo::exists(d->filePath.toString()))
|
|
|
|
|
throw TranslationUnitFileNotExitsException(d->filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
void TranslationUnit::updateLastProjectPartChangeTimePoint() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
d->lastProjectPartChangeTimePoint = std::chrono::steady_clock::now();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
void TranslationUnit::removeTranslationUnitIfProjectPartWasChanged() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
if (projectPartIsOutdated()) {
|
2015-06-01 18:51:55 +02:00
|
|
|
clang_disposeTranslationUnit(d->translationUnit);
|
|
|
|
|
d->translationUnit = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
bool TranslationUnit::projectPartIsOutdated() const
|
|
|
|
|
{
|
|
|
|
|
return d->projectPart.lastChangeTimePoint() >= d->lastProjectPartChangeTimePoint;
|
2015-10-12 17:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::isMainFileAndExistsOrIsOtherFile(const Utf8String &filePath) const
|
|
|
|
|
{
|
|
|
|
|
if (filePath == d->filePath)
|
|
|
|
|
return QFileInfo::exists(d->filePath);
|
|
|
|
|
|
|
|
|
|
return true;
|
2015-08-31 12:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
void TranslationUnit::createTranslationUnitIfNeeded() const
|
|
|
|
|
{
|
|
|
|
|
if (!d->translationUnit) {
|
|
|
|
|
d->translationUnit = CXTranslationUnit();
|
2015-11-05 13:57:57 +01:00
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
const auto args = commandLineArguments();
|
|
|
|
|
if (isVerboseModeEnabled())
|
|
|
|
|
args.print();
|
2015-11-05 13:57:57 +01:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
|
2015-11-06 11:16:53 +01:00
|
|
|
NULL,
|
2015-11-05 13:57:57 +01:00
|
|
|
args.data(),
|
|
|
|
|
args.count(),
|
2015-08-31 12:40:14 +02:00
|
|
|
unsavedFiles().cxUnsavedFiles(),
|
|
|
|
|
unsavedFiles().count(),
|
2015-07-15 13:55:51 +02:00
|
|
|
defaultOptions(),
|
2015-06-01 18:51:55 +02:00
|
|
|
&d->translationUnit);
|
|
|
|
|
|
|
|
|
|
checkTranslationUnitErrorCode(errorCode);
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
updateIncludeFilePaths();
|
|
|
|
|
|
|
|
|
|
updateLastProjectPartChangeTimePoint();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::checkTranslationUnitErrorCode(CXErrorCode errorCode) const
|
|
|
|
|
{
|
|
|
|
|
switch (errorCode) {
|
|
|
|
|
case CXError_Success: break;
|
|
|
|
|
default: throw TranslationUnitParseErrorException(d->filePath, d->projectPart.projectPartId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 13:55:51 +02:00
|
|
|
void TranslationUnit::reparseTranslationUnit() const
|
|
|
|
|
{
|
|
|
|
|
clang_reparseTranslationUnit(d->translationUnit,
|
2015-08-31 12:40:14 +02:00
|
|
|
unsavedFiles().count(),
|
|
|
|
|
unsavedFiles().cxUnsavedFiles(),
|
2015-07-15 13:55:51 +02:00
|
|
|
clang_defaultReparseOptions(d->translationUnit));
|
2015-08-31 12:40:14 +02:00
|
|
|
|
2015-09-01 10:09:17 +02:00
|
|
|
updateIncludeFilePaths();
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
d->needsToBeReparsed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::reparseTranslationUnitIfFilesAreChanged() const
|
|
|
|
|
{
|
|
|
|
|
if (isNeedingReparse())
|
|
|
|
|
reparseTranslationUnit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::includeCallback(CXFile included_file,
|
2015-09-01 09:14:34 +02:00
|
|
|
CXSourceLocation * /*inclusion_stack*/,
|
2015-08-31 12:40:14 +02:00
|
|
|
unsigned /*include_len*/,
|
|
|
|
|
CXClientData clientData)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ClangString includeFilePath(clang_getFileName(included_file));
|
|
|
|
|
|
|
|
|
|
TranslationUnit *translationUnit = static_cast<TranslationUnit*>(clientData);
|
|
|
|
|
|
|
|
|
|
translationUnit->d->dependedFilePaths.insert(includeFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnsavedFiles &TranslationUnit::unsavedFiles() const
|
|
|
|
|
{
|
|
|
|
|
return d->translationUnits.unsavedFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::updateIncludeFilePaths() const
|
|
|
|
|
{
|
2015-09-01 10:23:45 +02:00
|
|
|
auto oldDependedFilePaths = d->dependedFilePaths;
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
d->dependedFilePaths.clear();
|
|
|
|
|
d->dependedFilePaths.insert(filePath());
|
|
|
|
|
|
|
|
|
|
clang_getInclusions(d->translationUnit, includeCallback, const_cast<TranslationUnit*>(this));
|
|
|
|
|
|
2015-09-01 10:23:45 +02:00
|
|
|
if (d->dependedFilePaths.size() == 1)
|
|
|
|
|
d->dependedFilePaths = oldDependedFilePaths;
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
2015-07-15 13:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
CommandLineArguments TranslationUnit::commandLineArguments() const
|
|
|
|
|
{
|
|
|
|
|
return CommandLineArguments(d->filePath.constData(),
|
|
|
|
|
d->projectPart.arguments(),
|
|
|
|
|
d->fileArguments,
|
|
|
|
|
isVerboseModeEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 12:00:21 +02:00
|
|
|
uint TranslationUnit::defaultOptions()
|
2015-07-15 13:55:51 +02:00
|
|
|
{
|
|
|
|
|
return CXTranslationUnit_CacheCompletionResults
|
2015-08-25 16:19:19 +02:00
|
|
|
| CXTranslationUnit_PrecompiledPreamble
|
2015-11-17 13:33:31 +01:00
|
|
|
| CXTranslationUnit_IncludeBriefCommentsInCodeCompletion
|
|
|
|
|
| CXTranslationUnit_DetailedPreprocessingRecord;
|
2015-07-15 13:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
uint TranslationUnit::unsavedFilesCount() const
|
|
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
return unsavedFiles().count();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CXUnsavedFile *TranslationUnit::cxUnsavedFiles() const
|
|
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
return unsavedFiles().cxUnsavedFiles();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TranslationUnit::~TranslationUnit() = default;
|
|
|
|
|
|
|
|
|
|
TranslationUnit::TranslationUnit(const TranslationUnit &) = default;
|
2015-06-10 13:52:45 +02:00
|
|
|
TranslationUnit &TranslationUnit::operator=(const TranslationUnit &) = default;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
TranslationUnit::TranslationUnit(TranslationUnit &&other)
|
|
|
|
|
: d(std::move(other.d))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 13:52:45 +02:00
|
|
|
TranslationUnit &TranslationUnit::operator=(TranslationUnit &&other)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
d = std::move(other.d);
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 13:52:45 +02:00
|
|
|
bool operator==(const TranslationUnit &first, const TranslationUnit &second)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
return first.filePath() == second.filePath() && first.projectPartId() == second.projectPartId();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
void PrintTo(const TranslationUnit &translationUnit, ::std::ostream *os)
|
|
|
|
|
{
|
|
|
|
|
*os << "TranslationUnit("
|
|
|
|
|
<< translationUnit.filePath().constData() << ", "
|
|
|
|
|
<< translationUnit.projectPartId().constData() << ", "
|
|
|
|
|
<< translationUnit.documentRevision() << ")";
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
} // namespace ClangBackEnd
|