2015-10-01 12:45:06 +02:00
|
|
|
/****************************************************************************
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:14 +01:00
|
|
|
** 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.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** 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.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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"
|
2016-07-01 15:07:32 +02:00
|
|
|
#include "clangfilepath.h"
|
2015-08-31 12:40:14 +02:00
|
|
|
#include "clangstring.h"
|
2016-05-30 10:25:52 +02:00
|
|
|
#include "clangunsavedfilesshallowarguments.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"
|
2016-02-29 13:09:39 +01:00
|
|
|
#include "highlightingmarks.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"
|
2016-04-22 15:31:49 +02:00
|
|
|
#include "translationunitreparseerrorexception.h"
|
2016-06-05 19:59:23 +02:00
|
|
|
#include "clangtranslationunitcore.h"
|
2016-07-15 12:30:25 +02:00
|
|
|
#include "clangtranslationunitupdater.h"
|
2015-08-31 12:40:14 +02:00
|
|
|
#include "translationunits.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
#include "unsavedfiles.h"
|
2016-05-30 10:25:52 +02:00
|
|
|
#include "unsavedfile.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-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;
|
2016-04-22 15:31:49 +02:00
|
|
|
CXErrorCode parseErrorCode = CXError_Success;
|
|
|
|
|
int reparseErrorCode = 0;
|
2015-06-01 18:51:55 +02:00
|
|
|
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;
|
2016-02-29 13:09:39 +01:00
|
|
|
bool hasNewHighlightingMarks = 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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
void TranslationUnit::parse() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
const TranslationUnitUpdateInput updateInput = createUpdateInput();
|
|
|
|
|
TranslationUnitUpdateResult result = translationUnitCore().parse(updateInput);
|
|
|
|
|
|
|
|
|
|
incorporateUpdaterResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
void TranslationUnit::reparse() const
|
2015-07-21 19:44:08 +02:00
|
|
|
{
|
2016-06-05 19:59:23 +02:00
|
|
|
parse(); // TODO: Remove
|
2015-07-21 19:44:08 +02:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
const TranslationUnitUpdateInput updateInput = createUpdateInput();
|
|
|
|
|
TranslationUnitUpdateResult result = translationUnitCore().reparse(updateInput);
|
|
|
|
|
|
|
|
|
|
incorporateUpdaterResult(result);
|
2015-07-21 19:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-22 15:31:49 +02:00
|
|
|
bool TranslationUnit::parseWasSuccessful() const
|
|
|
|
|
{
|
|
|
|
|
return d->parseErrorCode == CXError_Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::reparseWasSuccessful() const
|
|
|
|
|
{
|
|
|
|
|
return d->reparseErrorCode == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
CXIndex &TranslationUnit::index() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->index;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
CXTranslationUnit &TranslationUnit::cxTranslationUnit() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
checkIfNull();
|
2015-10-12 12:10:58 +02:00
|
|
|
checkIfFileExists();
|
2016-07-15 12:30:25 +02:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
return d->translationUnit;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 10:25:52 +02:00
|
|
|
UnsavedFile TranslationUnit::unsavedFile() const
|
2016-01-28 18:31:05 +01:00
|
|
|
{
|
|
|
|
|
return unsavedFiles().unsavedFile(filePath());
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 10:25:52 +02:00
|
|
|
Utf8String TranslationUnit::filePath() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 10:25:52 +02:00
|
|
|
Utf8StringVector TranslationUnit::fileArguments() const
|
|
|
|
|
{
|
|
|
|
|
checkIfNull();
|
|
|
|
|
|
|
|
|
|
return d->fileArguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utf8String TranslationUnit::projectPartId() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 13:09:39 +01:00
|
|
|
bool TranslationUnit::hasNewHighlightingMarks() const
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2016-02-29 13:09:39 +01:00
|
|
|
return d->hasNewHighlightingMarks;
|
2015-11-18 17:07:44 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
DiagnosticSet TranslationUnit::diagnostics() const
|
|
|
|
|
{
|
2015-08-26 16:33:32 +02:00
|
|
|
d->hasNewDiagnostics = false;
|
|
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
return translationUnitCore().diagnostics();
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-18 17:01:32 +02:00
|
|
|
QVector<ClangBackEnd::DiagnosticContainer> TranslationUnit::mainFileDiagnostics() const
|
|
|
|
|
{
|
2016-06-05 19:59:23 +02:00
|
|
|
d->hasNewDiagnostics = false;
|
2015-09-18 17:01:32 +02:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
return translationUnitCore().mainFileDiagnostics();
|
2015-09-18 17:01:32 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
const QSet<Utf8String> &TranslationUnit::dependedFilePaths() const
|
|
|
|
|
{
|
2016-07-15 12:30:25 +02:00
|
|
|
cxTranslationUnit();
|
2015-08-31 12:40:14 +02:00
|
|
|
|
|
|
|
|
return d->dependedFilePaths;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 13:37:02 +01:00
|
|
|
void TranslationUnit::setDirtyIfProjectPartIsOutdated()
|
|
|
|
|
{
|
|
|
|
|
if (projectPartIsOutdated())
|
|
|
|
|
setDirty();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
void TranslationUnit::setDirtyIfDependencyIsMet(const Utf8String &filePath)
|
2015-08-31 12:40:14 +02:00
|
|
|
{
|
2015-12-07 13:37:02 +01:00
|
|
|
if (d->dependedFilePaths.contains(filePath) && isMainFileAndExistsOrIsOtherFile(filePath))
|
|
|
|
|
setDirty();
|
2015-08-31 12:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-29 13:09:39 +01:00
|
|
|
HighlightingMarks TranslationUnit::highlightingMarks() const
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2016-02-29 13:09:39 +01:00
|
|
|
d->hasNewHighlightingMarks = false;
|
2015-11-18 17:07:44 +01:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
return translationUnitCore().highlightingMarks();
|
2015-11-17 13:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
void TranslationUnit::checkIfNull() const
|
|
|
|
|
{
|
|
|
|
|
if (isNull())
|
|
|
|
|
throw TranslationUnitIsNullException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::checkIfFileExists() const
|
|
|
|
|
{
|
2016-04-22 15:31:49 +02:00
|
|
|
if (!fileExists())
|
2015-06-01 18:51:55 +02:00
|
|
|
throw TranslationUnitFileNotExitsException(d->filePath);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2015-12-07 13:37:02 +01:00
|
|
|
void TranslationUnit::setDirty()
|
|
|
|
|
{
|
|
|
|
|
d->needsToBeReparsed = true;
|
|
|
|
|
d->hasNewDiagnostics = true;
|
2016-02-29 13:09:39 +01:00
|
|
|
d->hasNewHighlightingMarks = true;
|
2015-12-07 13:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-04-22 15:31:49 +02:00
|
|
|
void TranslationUnit::checkParseErrorCode() const
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-04-22 15:31:49 +02:00
|
|
|
if (!parseWasSuccessful()) {
|
|
|
|
|
throw TranslationUnitParseErrorException(d->filePath,
|
|
|
|
|
d->projectPart.projectPartId(),
|
|
|
|
|
d->parseErrorCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
bool TranslationUnit::fileExists() const
|
2016-04-22 15:31:49 +02:00
|
|
|
{
|
2016-07-15 12:30:25 +02:00
|
|
|
return QFileInfo::exists(d->filePath.toString());
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
TranslationUnitUpdateInput TranslationUnit::createUpdateInput() const
|
2015-08-31 12:40:14 +02:00
|
|
|
{
|
2016-07-15 12:30:25 +02:00
|
|
|
TranslationUnitUpdateInput updateInput;
|
|
|
|
|
updateInput.reparseNeeded = isNeedingReparse();
|
|
|
|
|
updateInput.parseNeeded = projectPartIsOutdated();
|
|
|
|
|
updateInput.filePath = filePath();
|
|
|
|
|
updateInput.fileArguments = fileArguments();
|
|
|
|
|
updateInput.unsavedFiles = unsavedFiles();
|
|
|
|
|
updateInput.projectId = projectPart().projectPartId();
|
|
|
|
|
updateInput.projectArguments = projectPart().arguments();
|
2015-08-31 12:40:14 +02:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
return updateInput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TranslationUnitUpdater TranslationUnit::createUpdater() const
|
|
|
|
|
{
|
|
|
|
|
const TranslationUnitUpdateInput updateInput = createUpdateInput();
|
2016-07-15 12:30:25 +02:00
|
|
|
TranslationUnitUpdater updater(index(), d->translationUnit, updateInput);
|
2015-08-31 12:40:14 +02:00
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
return updater;
|
2015-08-31 12:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
void TranslationUnit::incorporateUpdaterResult(const TranslationUnitUpdateResult &result) const
|
2015-08-31 12:40:14 +02:00
|
|
|
{
|
2016-07-15 12:30:25 +02:00
|
|
|
if (result.parseTimePointIsSet)
|
|
|
|
|
d->lastProjectPartChangeTimePoint = result.parseTimePoint;
|
2015-09-01 10:23:45 +02:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
d->dependedFilePaths = result.dependedOnFilePaths;
|
2015-08-31 12:40:14 +02:00
|
|
|
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
2015-07-15 13:55:51 +02:00
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
if (result.reparsed)
|
|
|
|
|
d->needsToBeReparsed = false;
|
2016-04-22 15:31:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TranslationUnit::isIntact() const
|
|
|
|
|
{
|
|
|
|
|
return !isNull()
|
|
|
|
|
&& fileExists()
|
|
|
|
|
&& parseWasSuccessful()
|
|
|
|
|
&& reparseWasSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
CommandLineArguments TranslationUnit::commandLineArguments() const
|
|
|
|
|
{
|
2016-07-15 12:30:25 +02:00
|
|
|
return createUpdater().commandLineArguments();
|
2015-11-06 11:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
TranslationUnitCore TranslationUnit::translationUnitCore() const
|
2015-07-15 13:55:51 +02:00
|
|
|
{
|
2016-06-05 19:59:23 +02:00
|
|
|
return TranslationUnitCore(d->filePath, d->index, d->translationUnit);
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-15 12:30:25 +02:00
|
|
|
UnsavedFiles TranslationUnit::unsavedFiles() const
|
|
|
|
|
{
|
|
|
|
|
return d->translationUnits.unsavedFiles();
|
|
|
|
|
}
|
|
|
|
|
|
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
|