Commit 8d443b40 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Extract long clock/time_point references



Change-Id: If2790263e9a314f27762c57cf6bf4ef67f93a84b
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 1a426d9f
......@@ -45,7 +45,8 @@ HEADERS += $$PWD/clangcodemodelserver.h \
$$PWD/clangexceptions.h \
$$PWD/clangdocumentprocessor.h \
$$PWD/clangdocumentprocessors.h \
$$PWD/clangtranslationunits.h
$$PWD/clangtranslationunits.h \
$$PWD/clangclock.h \
SOURCES += $$PWD/clangcodemodelserver.cpp \
$$PWD/codecompleter.cpp \
......
/****************************************************************************
**
** 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 <chrono>
namespace ClangBackEnd {
using Clock = std::chrono::steady_clock;
using Duration = std::chrono::steady_clock::duration;
using TimePoint = std::chrono::steady_clock::time_point;
} // namespace ClangBackEnd
......@@ -63,14 +63,14 @@ public:
const Utf8StringVector fileArguments;
ProjectPart projectPart;
time_point lastProjectPartChangeTimePoint;
TimePoint lastProjectPartChangeTimePoint;
TranslationUnits translationUnits;
QSet<Utf8String> dependedFilePaths;
uint documentRevision = 0;
time_point needsToBeReparsedChangeTimePoint;
TimePoint needsToBeReparsedChangeTimePoint;
bool hasParseOrReparseFailed = false;
bool needsToBeReparsed = false;
bool isUsedByCurrentEditor = false;
......@@ -85,7 +85,7 @@ DocumentData::DocumentData(const Utf8String &filePath,
filePath(filePath),
fileArguments(fileArguments),
projectPart(projectPart),
lastProjectPartChangeTimePoint(std::chrono::steady_clock::now()),
lastProjectPartChangeTimePoint(Clock::now()),
translationUnits(filePath),
needsToBeReparsedChangeTimePoint(lastProjectPartChangeTimePoint)
{
......@@ -183,7 +183,7 @@ const ProjectPart &Document::projectPart() const
return d->projectPart;
}
const time_point Document::lastProjectPartChangeTimePoint() const
const TimePoint Document::lastProjectPartChangeTimePoint() const
{
checkIfNull();
......@@ -239,7 +239,7 @@ void Document::setIsVisibleInEditor(bool isVisibleInEditor)
d->isVisibleInEditor = isVisibleInEditor;
}
time_point Document::isNeededReparseChangeTimePoint() const
TimePoint Document::isNeededReparseChangeTimePoint() const
{
checkIfNull();
......@@ -312,7 +312,7 @@ void Document::incorporateUpdaterResult(const TranslationUnitUpdateResult &resul
if (result.hasParsed() || result.hasReparsed()) {
d->dependedFilePaths = result.dependedOnFilePaths;
const time_point timePoint = qMax(result.parseTimePoint, result.reparseTimePoint);
const TimePoint timePoint = qMax(result.parseTimePoint, result.reparseTimePoint);
d->translationUnits.updateParseTimePoint(result.translationUnitId, timePoint);
}
......@@ -366,7 +366,7 @@ const QSet<Utf8String> Document::dependedFilePaths() const
void Document::setDirty()
{
d->needsToBeReparsedChangeTimePoint = std::chrono::steady_clock::now();
d->needsToBeReparsedChangeTimePoint = Clock::now();
d->needsToBeReparsed = true;
}
......
......@@ -37,7 +37,6 @@
#include <QSet>
#include <QtGlobal>
#include <chrono>
#include <memory>
class Utf8String;
......@@ -52,8 +51,6 @@ class ProjectPart;
class FileContainer;
class Documents;
using time_point = std::chrono::steady_clock::time_point;
class Document
{
public:
......@@ -87,7 +84,7 @@ public:
Utf8String projectPartId() const;
const ProjectPart &projectPart() const;
const time_point lastProjectPartChangeTimePoint() const;
const TimePoint lastProjectPartChangeTimePoint() const;
bool isProjectPartOutdated() const;
uint documentRevision() const;
......@@ -116,7 +113,7 @@ public: // for tests
const QSet<Utf8String> dependedFilePaths() const;
TranslationUnitUpdater createUpdater() const;
void setHasParseOrReparseFailed(bool hasFailed);
time_point isNeededReparseChangeTimePoint() const;
TimePoint isNeededReparseChangeTimePoint() const;
private:
void setDirty();
......
......@@ -25,18 +25,16 @@
#pragma once
#include "clangclock.h"
#include <utf8string.h>
#include <QFlags>
#include <QDebug>
#include <QVector>
#include <chrono>
namespace ClangBackEnd {
using time_point = std::chrono::steady_clock::time_point;
class JobRequest
{
public:
......@@ -72,8 +70,8 @@ public:
// General
Utf8String filePath;
Utf8String projectPartId;
time_point unsavedFilesChangeTimePoint;
time_point projectChangeTimePoint;
TimePoint unsavedFilesChangeTimePoint;
TimePoint projectChangeTimePoint;
uint documentRevision = 0;
// For code completion
......
......@@ -77,11 +77,11 @@ TranslationUnit TranslationUnits::get(PreferredTranslationUnit type)
}
void TranslationUnits::updateParseTimePoint(const Utf8String &translationUnitId,
time_point timePoint)
TimePoint timePoint)
{
TranslationUnitData &unit = findUnit(translationUnitId);
QTC_CHECK(timePoint != time_point());
QTC_CHECK(timePoint != TimePoint());
unit.parseTimePoint = timePoint;
qCDebug(tuLog) << "Updated" << translationUnitId << "for" << QFileInfo(m_filePath).fileName()
......@@ -92,7 +92,7 @@ void TranslationUnits::updateParseTimePoint(const Utf8String &translationUnitId,
bool TranslationUnits::areAllTranslationUnitsParsed() const
{
return Utils::allOf(m_tuDatas, [](const TranslationUnitData &unit) {
return unit.parseTimePoint != time_point();
return unit.parseTimePoint != TimePoint();
});
}
......
......@@ -26,6 +26,7 @@
#pragma once
#include "clangbackend_global.h"
#include "clangclock.h"
#include <utf8string.h>
......@@ -33,12 +34,8 @@
#include <QList>
#include <chrono>
namespace ClangBackEnd {
using time_point = std::chrono::steady_clock::time_point;
class TranslationUnit;
class TranslationUnits
......@@ -55,7 +52,7 @@ public:
CXTranslationUnit cxTranslationUnit = nullptr;
CXIndex cxIndex = nullptr;
time_point parseTimePoint;
TimePoint parseTimePoint;
};
public:
......@@ -64,7 +61,7 @@ public:
TranslationUnit createAndAppend();
TranslationUnit get(PreferredTranslationUnit type = PreferredTranslationUnit::RecentlyParsed);
void updateParseTimePoint(const Utf8String &translationUnitId, time_point timePoint);
void updateParseTimePoint(const Utf8String &translationUnitId, TimePoint timePoint);
private:
bool areAllTranslationUnitsParsed() const;
......
......@@ -124,7 +124,7 @@ void TranslationUnitUpdater::createTranslationUnitIfNeeded()
if (parseWasSuccessful()) {
updateIncludeFilePaths();
m_out.parseTimePoint = std::chrono::steady_clock::now();
m_out.parseTimePoint = Clock::now();
} else {
qWarning() << "Parsing" << m_in.filePath << "failed:"
<< errorCodeToText(m_parseErrorCode);
......@@ -153,7 +153,7 @@ void TranslationUnitUpdater::reparse()
if (reparseWasSuccessful()) {
updateIncludeFilePaths();
m_out.reparseTimePoint = std::chrono::steady_clock::now();
m_out.reparseTimePoint = Clock::now();
m_out.needsToBeReparsedChangeTimePoint = m_in.needsToBeReparsedChangeTimePoint;
} else {
qWarning() << "Reparsing" << m_in.filePath << "failed:" << m_reparseErrorCode;
......
......@@ -25,6 +25,8 @@
#pragma once
#include "clangclock.h"
#include "commandlinearguments.h"
#include "unsavedfiles.h"
#include "utf8stringvector.h"
......@@ -33,18 +35,14 @@
#include <QSet>
#include <chrono>
namespace ClangBackEnd {
using time_point = std::chrono::steady_clock::time_point;
class TranslationUnitUpdateInput {
public:
bool parseNeeded = false;
bool reparseNeeded = false;
time_point needsToBeReparsedChangeTimePoint;
TimePoint needsToBeReparsedChangeTimePoint;
Utf8String filePath;
Utf8StringVector fileArguments;
......@@ -57,18 +55,18 @@ public:
class TranslationUnitUpdateResult {
public:
bool hasParsed() const
{ return parseTimePoint != time_point(); }
{ return parseTimePoint != TimePoint(); }
bool hasReparsed() const
{ return reparseTimePoint != time_point(); }
{ return reparseTimePoint != TimePoint(); }
public:
Utf8String translationUnitId;
bool hasParseOrReparseFailed = false;
time_point parseTimePoint;
time_point reparseTimePoint;
time_point needsToBeReparsedChangeTimePoint;
TimePoint parseTimePoint;
TimePoint reparseTimePoint;
TimePoint needsToBeReparsedChangeTimePoint;
QSet<Utf8String> dependedOnFilePaths;
};
......
......@@ -39,13 +39,13 @@ public:
~ProjectPartData();
public:
time_point lastChangeTimePoint;
TimePoint lastChangeTimePoint;
Utf8StringVector arguments;
Utf8String projectPartId;
};
ProjectPartData::ProjectPartData(const Utf8String &projectPartId)
: lastChangeTimePoint(std::chrono::steady_clock::now()),
: lastChangeTimePoint(Clock::now()),
projectPartId(projectPartId)
{
}
......@@ -111,14 +111,14 @@ const Utf8StringVector ProjectPart::arguments() const
return d->arguments;
}
const time_point &ProjectPart::lastChangeTimePoint() const
const TimePoint &ProjectPart::lastChangeTimePoint() const
{
return d->lastChangeTimePoint;
}
void ProjectPart::updateLastChangeTimePoint()
{
d->lastChangeTimePoint = std::chrono::steady_clock::now();
d->lastChangeTimePoint = Clock::now();
}
bool operator==(const ProjectPart &first, const ProjectPart &second)
......
......@@ -25,9 +25,10 @@
#pragma once
#include "clangclock.h"
#include <utf8string.h>
#include <chrono>
#include <memory>
class Utf8StringVector;
......@@ -37,8 +38,6 @@ namespace ClangBackEnd {
class ProjectPartContainer;
class ProjectPartData;
using time_point = std::chrono::steady_clock::time_point;
class ProjectPart
{
public:
......@@ -61,7 +60,7 @@ public:
void setArguments(const Utf8StringVector &arguments_);
const Utf8StringVector arguments() const;
const time_point &lastChangeTimePoint() const;
const TimePoint &lastChangeTimePoint() const;
private:
void updateLastChangeTimePoint();
......
......@@ -40,12 +40,12 @@ public:
UnsavedFilesData();
public:
time_point lastChangeTimePoint;
TimePoint lastChangeTimePoint;
QVector<UnsavedFile> unsavedFiles;
};
UnsavedFilesData::UnsavedFilesData()
: lastChangeTimePoint(std::chrono::steady_clock::now())
: lastChangeTimePoint(Clock::now())
{
}
......@@ -116,7 +116,7 @@ UnsavedFilesShallowArguments UnsavedFiles::shallowArguments() const
return UnsavedFilesShallowArguments(*this);
}
const time_point UnsavedFiles::lastChangeTimePoint() const
const TimePoint UnsavedFiles::lastChangeTimePoint() const
{
return d->lastChangeTimePoint;
}
......@@ -154,7 +154,7 @@ void UnsavedFiles::addOrUpdateUnsavedFile(const FileContainer &fileContainer)
void UnsavedFiles::updateLastChangeTimePoint()
{
d->lastChangeTimePoint = std::chrono::steady_clock::now();
d->lastChangeTimePoint = Clock::now();
}
} // namespace ClangBackEnd
......@@ -25,6 +25,8 @@
#pragma once
#include "clangclock.h"
#include <filecontainer.h>
#include <QSharedPointer>
......@@ -32,12 +34,8 @@
#include <clang-c/Index.h>
#include <chrono>
namespace ClangBackEnd {
using time_point = std::chrono::steady_clock::time_point;
class UnsavedFile;
class UnsavedFilesData;
class UnsavedFilesShallowArguments;
......@@ -61,7 +59,7 @@ public:
UnsavedFilesShallowArguments shallowArguments() const;
const time_point lastChangeTimePoint() const;
const TimePoint lastChangeTimePoint() const;
private:
void updateUnsavedFileWithFileContainer(const FileContainer &fileContainer);
......
......@@ -25,6 +25,7 @@
#include "googletest.h"
#include <clangclock.h>
#include <clangfilepath.h>
#include <clangtranslationunitupdater.h>
#include <clangtranslationunits.h>
......@@ -47,9 +48,10 @@
#include <QTemporaryFile>
#include <chrono>
#include <thread>
using ClangBackEnd::Clock;
using ClangBackEnd::Duration;
using ClangBackEnd::FileContainer;
using ClangBackEnd::FilePath;
using ClangBackEnd::Document;
......@@ -165,7 +167,7 @@ TEST_F(Document, LastCommandLineArgumentIsFilePath)
TEST_F(Document, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
{
auto lastChangeTimePoint = document.lastProjectPartChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
std::this_thread::sleep_for(Duration(1));
document.parse();
......@@ -177,7 +179,7 @@ TEST_F(Document, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared)
ProjectPart projectPart = document.projectPart();
document.parse();
auto lastChangeTimePoint = document.lastProjectPartChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
std::this_thread::sleep_for(Duration(1));
projectPart.clear();
document.parse();
......@@ -334,7 +336,7 @@ TEST_F(Document, IncorporateUpdaterResultResetsDirtyness)
{
document.setDirtyIfDependencyIsMet(document.filePath());
TranslationUnitUpdateResult result;
result.reparseTimePoint = std::chrono::steady_clock::now();
result.reparseTimePoint = Clock::now();
result.needsToBeReparsedChangeTimePoint = document.isNeededReparseChangeTimePoint();
result.translationUnitId = document.translationUnit().id();
......@@ -346,8 +348,8 @@ TEST_F(Document, IncorporateUpdaterResultResetsDirtyness)
TEST_F(Document, IncorporateUpdaterResultDoesNotResetDirtynessIfItWasChanged)
{
TranslationUnitUpdateResult result;
result.reparseTimePoint = std::chrono::steady_clock::now();
result.needsToBeReparsedChangeTimePoint = std::chrono::steady_clock::now();
result.reparseTimePoint = Clock::now();
result.needsToBeReparsedChangeTimePoint = Clock::now();
result.translationUnitId = document.translationUnit().id();
document.setDirtyIfDependencyIsMet(document.filePath());
......@@ -360,12 +362,12 @@ TEST_F(Document, IncorporateUpdaterResultUpdatesTranslationUnitsReparseTimePoint
{
TranslationUnits &translationUnits = document.translationUnits();
const TranslationUnit initialTranslationUnit = translationUnits.get();
translationUnits.updateParseTimePoint(initialTranslationUnit.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(initialTranslationUnit.id(), Clock::now());
const TranslationUnit alternativeTranslationUnit = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(alternativeTranslationUnit.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(alternativeTranslationUnit.id(), Clock::now());
TranslationUnitUpdateResult result;
result.reparseTimePoint = std::chrono::steady_clock::now();
result.needsToBeReparsedChangeTimePoint = std::chrono::steady_clock::now();
result.reparseTimePoint = Clock::now();
result.needsToBeReparsedChangeTimePoint = Clock::now();
result.translationUnitId = initialTranslationUnit.id();
document.setDirtyIfDependencyIsMet(document.filePath());
ASSERT_THAT(translationUnits.get().id(), Eq(alternativeTranslationUnit.id()));
......
......@@ -31,13 +31,12 @@
#include <clang-c/Index.h>
#include <chrono>
#include <gmock/gmock.h>
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
#include "gtest-qt-printing.h"
using ClangBackEnd::Clock;
using ClangBackEnd::TranslationUnit;
using ClangBackEnd::TranslationUnits;
using ClangBackEnd::TranslationUnitDoesNotExist;
......@@ -88,7 +87,7 @@ TEST_F(TranslationUnits, GetFirstForMultipleTranslationUnits)
TEST_F(TranslationUnits, GetFirstForMultipleTranslationUnitsAndOnlyFirstParsed)
{
const TranslationUnit created1 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created1.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created1.id(), Clock::now());
translationUnits.createAndAppend();
const TranslationUnit queried = translationUnits.get();
......@@ -100,7 +99,7 @@ TEST_F(TranslationUnits, GetFirstForMultipleTranslationUnitsAndOnlySecondParsed)
{
const TranslationUnit created1 = translationUnits.createAndAppend();
const TranslationUnit created2 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created2.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created2.id(), Clock::now());
const TranslationUnit queried = translationUnits.get();
......@@ -110,9 +109,9 @@ TEST_F(TranslationUnits, GetFirstForMultipleTranslationUnitsAndOnlySecondParsed)
TEST_F(TranslationUnits, GetRecentForMultipleTranslationUnits)
{
const TranslationUnit created1 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created1.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created1.id(), Clock::now());
const TranslationUnit created2 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created2.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created2.id(), Clock::now());
const TranslationUnit queried = translationUnits.get(PreferredTranslationUnit::RecentlyParsed);
......@@ -122,9 +121,9 @@ TEST_F(TranslationUnits, GetRecentForMultipleTranslationUnits)
TEST_F(TranslationUnits, GetPreviousForMultipleTranslationUnits)
{
const TranslationUnit created1 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created1.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created1.id(), Clock::now());
const TranslationUnit created2 = translationUnits.createAndAppend();
translationUnits.updateParseTimePoint(created2.id(), std::chrono::steady_clock::now());
translationUnits.updateParseTimePoint(created2.id(), Clock::now());
const TranslationUnit queried = translationUnits.get(PreferredTranslationUnit::PreviouslyParsed);
......@@ -136,7 +135,7 @@ TEST_F(TranslationUnits, UpdateThrowsForNotExisting)
ClangBackEnd::TranslationUnits otherTranslationUnits{someFilePath};
const TranslationUnit translationUnit = otherTranslationUnits.createAndAppend();
ASSERT_THROW(translationUnits.updateParseTimePoint(translationUnit.id(), std::chrono::steady_clock::now()),
ASSERT_THROW(translationUnits.updateParseTimePoint(translationUnit.id(), Clock::now()),
TranslationUnitDoesNotExist);
}
......
......@@ -97,7 +97,7 @@ TEST_F(UpdateDocumentAnnotationsJob, DontSendAnnotationsIfDocumentRevisionChange
TEST_F(UpdateDocumentAnnotationsJob, UpdatesTranslationUnit)
{
const time_point timePointBefore = document.lastProjectPartChangeTimePoint();
const TimePoint timePointBefore = document.lastProjectPartChangeTimePoint();
const QSet<Utf8String> dependendOnFilesBefore = document.dependedFilePaths();
job.setContext(jobContext);
job.prepareAsyncRun();
......
......@@ -25,12 +25,12 @@
#include "googletest.h"
#include <clangclock.h>
#include <projectpart.h>
#include <clangexceptions.h>
#include <projects.h>
#include <utf8stringvector.h>
#include <chrono>
#include <thread>
using testing::ElementsAre;
......@@ -82,7 +82,7 @@ TEST(ProjectPart, TimeStampIsUpdatedAsArgumentChanged)
{
ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro"));
auto lastChangeTimePoint = project.lastChangeTimePoint();
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
std::this_thread::sleep_for(ClangBackEnd::Duration(1));
project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")}));
......@@ -163,7 +163,7 @@ TEST(ProjectPart, ProjectPartIsClearedAfterRemove)