aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2018-01-05 12:28:15 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2018-01-08 13:18:54 +0000
commite3b1259004a8616d045ce42e6cb5a5c5382bca4c (patch)
treef2721fc21c5c61e9781e96e48def639ffa64b4db
parent063b327097c8e45d12e22ab4ef22d04384c7b906 (diff)
Clang: Introduce DocumentParsed as job requirement
This is in prepration for a follow-up change, which introduces a state where the Document is not yet parsed (it was reset) but the queue has jobs. All jobs get this requirement except those that generate an AST. Change-Id: Ifcbb704e54108b40797180514c5ad3f3768ef10b Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
-rw-r--r--src/tools/clangbackend/source/clangjobqueue.cpp6
-rw-r--r--src/tools/clangbackend/source/clangjobrequest.cpp3
-rw-r--r--src/tools/clangbackend/source/clangjobrequest.h3
-rw-r--r--src/tools/clangbackend/source/clangtranslationunits.cpp7
-rw-r--r--src/tools/clangbackend/source/clangtranslationunits.h1
-rw-r--r--tests/unit/unittest/clangjobqueue-test.cpp12
6 files changed, 30 insertions, 2 deletions
diff --git a/src/tools/clangbackend/source/clangjobqueue.cpp b/src/tools/clangbackend/source/clangjobqueue.cpp
index 7f3b64c65e..f3e722ab97 100644
--- a/src/tools/clangbackend/source/clangjobqueue.cpp
+++ b/src/tools/clangbackend/source/clangjobqueue.cpp
@@ -247,6 +247,12 @@ bool JobQueue::areRunConditionsMet(const JobRequest &request, const Document &do
}
}
+ if (conditions.testFlag(Condition::DocumentParsed)
+ && !document.translationUnits().hasParsedTranslationUnit()) {
+ qCDebugJobs() << "Not choosing due to not yet parsed translation unit:" << request;
+ return false;
+ }
+
return true;
}
diff --git a/src/tools/clangbackend/source/clangjobrequest.cpp b/src/tools/clangbackend/source/clangjobrequest.cpp
index 9f8eb55f77..93017fc956 100644
--- a/src/tools/clangbackend/source/clangjobrequest.cpp
+++ b/src/tools/clangbackend/source/clangjobrequest.cpp
@@ -156,6 +156,9 @@ static JobRequest::RunConditions conditionsForType(JobRequest::Type type)
if (type == Type::RequestReferences)
conditions |= Condition::CurrentDocumentRevision;
+ if (type != Type::UpdateDocumentAnnotations && type != Type::ParseSupportiveTranslationUnit)
+ conditions |= Condition::DocumentParsed;
+
return conditions;
}
diff --git a/src/tools/clangbackend/source/clangjobrequest.h b/src/tools/clangbackend/source/clangjobrequest.h
index fb72491e4b..4b79f22792 100644
--- a/src/tools/clangbackend/source/clangjobrequest.h
+++ b/src/tools/clangbackend/source/clangjobrequest.h
@@ -70,7 +70,8 @@ public:
DocumentNotVisible = 1 << 2,
DocumentSuspended = 1 << 3,
DocumentUnsuspended = 1 << 4,
- CurrentDocumentRevision = 1 << 5,
+ DocumentParsed = 1 << 5,
+ CurrentDocumentRevision = 1 << 6,
};
Q_DECLARE_FLAGS(RunConditions, RunCondition)
diff --git a/src/tools/clangbackend/source/clangtranslationunits.cpp b/src/tools/clangbackend/source/clangtranslationunits.cpp
index 432da3d02c..f47513b6dc 100644
--- a/src/tools/clangbackend/source/clangtranslationunits.cpp
+++ b/src/tools/clangbackend/source/clangtranslationunits.cpp
@@ -111,6 +111,13 @@ bool TranslationUnits::areAllTranslationUnitsParsed() const
});
}
+bool TranslationUnits::hasParsedTranslationUnit() const
+{
+ return Utils::anyOf(m_units, [](const TranslationUnitDataPtr &unit) {
+ return unit->parseTimePoint != TimePoint();
+ });
+}
+
int TranslationUnits::size() const
{
return m_units.size();
diff --git a/src/tools/clangbackend/source/clangtranslationunits.h b/src/tools/clangbackend/source/clangtranslationunits.h
index e89d0ebd25..eed9b2d1ea 100644
--- a/src/tools/clangbackend/source/clangtranslationunits.h
+++ b/src/tools/clangbackend/source/clangtranslationunits.h
@@ -65,6 +65,7 @@ public:
void updateParseTimePoint(const Utf8String &translationUnitId, TimePoint timePoint);
bool areAllTranslationUnitsParsed() const;
+ bool hasParsedTranslationUnit() const;
public: // for tests
int size() const;
diff --git a/tests/unit/unittest/clangjobqueue-test.cpp b/tests/unit/unittest/clangjobqueue-test.cpp
index 202e9762ab..b9c336551f 100644
--- a/tests/unit/unittest/clangjobqueue-test.cpp
+++ b/tests/unit/unittest/clangjobqueue-test.cpp
@@ -66,6 +66,8 @@ protected:
PreferredTranslationUnit preferredTranslationUnit
= PreferredTranslationUnit::RecentlyParsed) const;
+ void pretendParsedTranslationUnit();
+
void updateDocumentRevision();
void updateUnsavedFiles();
void updateProject();
@@ -173,7 +175,7 @@ TEST_F(JobQueue, ProcessSingleJob)
TEST_F(JobQueue, ProcessUntilEmpty)
{
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::UpdateDocumentAnnotations));
- jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CreateInitialDocumentPreamble));
+ jobQueue.add(createJobRequest(filePath1, JobRequest::Type::ParseSupportiveTranslationUnit));
JobRequests jobsToRun;
ASSERT_THAT(jobQueue.size(), Eq(2));
@@ -421,6 +423,7 @@ TEST_F(JobQueue, RequestCompleteCodeOutdatableByDocumentClose)
TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByUnsavedFilesChange)
{
+ pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CompleteCode));
updateUnsavedFiles();
@@ -431,6 +434,7 @@ TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByUnsavedFilesChange)
TEST_F(JobQueue, RequestCompleteCodeNotOutdatableByDocumentRevisionChange)
{
+ pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::CompleteCode));
updateDocumentRevision();
@@ -461,6 +465,7 @@ TEST_F(JobQueue, RequestCompleteCodeOutdatableByDocumentRevisionChange)
TEST_F(JobQueue, RequestReferencesRunsForCurrentDocumentRevision)
{
+ pretendParsedTranslationUnit();
jobQueue.add(createJobRequest(filePath1, JobRequest::Type::RequestReferences));
const JobRequests jobsToStart = jobQueue.processQueue();
@@ -549,6 +554,11 @@ JobRequest JobQueue::createJobRequest(
return jobRequest;
}
+void JobQueue::pretendParsedTranslationUnit()
+{
+ document.translationUnits().updateParseTimePoint(document.translationUnit().id(), Clock::now());
+}
+
void JobQueue::updateDocumentRevision()
{
documents.update({FileContainer(filePath1, projectPartId, Utf8String(), true, 1)});