summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-01-26 18:23:42 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-01-31 14:27:06 (GMT)
commit65c0a64dc5bc7cb0e13721500bdd754b6630e8ea (patch)
tree327a4dc86d33fb406ebeea660c61ec7bc863907d /Source
parent50abdaab936e6b1a7e40d17affae03f89ac00da6 (diff)
downloadCMake-65c0a64dc5bc7cb0e13721500bdd754b6630e8ea.zip
CMake-65c0a64dc5bc7cb0e13721500bdd754b6630e8ea.tar.gz
CMake-65c0a64dc5bc7cb0e13721500bdd754b6630e8ea.tar.bz2
cmComputeComponentGraph: use a name for "invalid component"
This is to prepare for making the graph use `size_t`.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmComputeComponentGraph.cxx8
-rw-r--r--Source/cmComputeComponentGraph.h2
-rw-r--r--Source/cmComputeLinkDepends.cxx27
-rw-r--r--Source/cmComputeLinkDepends.h5
-rw-r--r--Source/cmComputeTargetDepends.cxx4
5 files changed, 29 insertions, 17 deletions
diff --git a/Source/cmComputeComponentGraph.cxx b/Source/cmComputeComponentGraph.cxx
index 6591fb1..6826f23 100644
--- a/Source/cmComputeComponentGraph.cxx
+++ b/Source/cmComputeComponentGraph.cxx
@@ -5,6 +5,8 @@
#include <algorithm>
#include <cassert>
+const int cmComputeComponentGraph::INVALID_COMPONENT = -1;
+
cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
: InputGraph(input)
{
@@ -30,7 +32,7 @@ void cmComputeComponentGraph::Tarjan()
this->TarjanEntries.resize(0);
this->TarjanEntries.resize(n, entry);
this->TarjanComponents.resize(0);
- this->TarjanComponents.resize(n, -1);
+ this->TarjanComponents.resize(n, INVALID_COMPONENT);
this->TarjanWalkId = 0;
this->TarjanVisited.resize(0);
this->TarjanVisited.resize(n, 0);
@@ -52,7 +54,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
// Initialize the entry.
this->TarjanEntries[i].Root = i;
- this->TarjanComponents[i] = -1;
+ this->TarjanComponents[i] = INVALID_COMPONENT;
this->TarjanEntries[i].VisitIndex = ++this->TarjanIndex;
this->TarjanStack.push(i);
@@ -77,7 +79,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
// If the destination has not yet been assigned to a component,
// check if it has a better root for the current object.
- if (this->TarjanComponents[j] < 0) {
+ if (this->TarjanComponents[j] == INVALID_COMPONENT) {
if (this->TarjanEntries[this->TarjanEntries[j].Root].VisitIndex <
this->TarjanEntries[this->TarjanEntries[i].Root].VisitIndex) {
this->TarjanEntries[i].Root = this->TarjanEntries[j].Root;
diff --git a/Source/cmComputeComponentGraph.h b/Source/cmComputeComponentGraph.h
index 1d1d134..76879c7 100644
--- a/Source/cmComputeComponentGraph.h
+++ b/Source/cmComputeComponentGraph.h
@@ -53,6 +53,8 @@ public:
return this->TarjanComponents;
}
+ static const int INVALID_COMPONENT;
+
private:
void TransferEdges();
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 8e05fac..d72a1fe 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -518,7 +518,10 @@ void cmComputeLinkDepends::AddLinkObject(cmLinkItem const& item)
void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe)
{
// Get this entry representation.
- int depender_index = qe.GroupIndex == -1 ? qe.Index : qe.GroupIndex;
+ int depender_index =
+ qe.GroupIndex == cmComputeComponentGraph::INVALID_COMPONENT
+ ? qe.Index
+ : qe.GroupIndex;
LinkEntry const& entry = this->EntryList[qe.Index];
// Follow the item's dependencies.
@@ -679,13 +682,15 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
// Add direct link dependencies in this configuration.
cmLinkImplementation const* impl = this->Target->GetLinkImplementation(
this->Config, cmGeneratorTarget::LinkInterfaceFor::Link);
- this->AddLinkEntries(-1, impl->Libraries);
+ this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT,
+ impl->Libraries);
this->AddLinkObjects(impl->Objects);
for (auto const& language : impl->Languages) {
auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
- this->AddLinkEntries(-1, runtimeEntries->second);
+ this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT,
+ runtimeEntries->second);
}
}
for (cmLinkItem const& wi : impl->WrongConfigLibraries) {
@@ -702,7 +707,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
std::string feature = LinkEntry::DEFAULT;
bool inGroup = false;
- std::pair<int, bool> groupIndex{ -1, false };
+ std::pair<int, bool> groupIndex{ cmComputeComponentGraph::INVALID_COMPONENT,
+ false };
std::vector<int> groupItems;
// Loop over the libraries linked directly by the depender.
@@ -719,7 +725,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
feature = ExtractFeature(item.AsStr());
// emit a warning if an undefined feature is used as part of
// an imported target
- if (depender_index >= 0) {
+ if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
const auto& depender = this->EntryList[depender_index];
if (depender.Target != nullptr && depender.Target->IsImported() &&
!IsFeatureSupported(this->Makefile, this->LinkLanguage, feature)) {
@@ -752,7 +758,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
entry.Feature = ExtractGroupFeature(item.AsStr());
}
inGroup = true;
- if (depender_index >= 0) {
+ if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
this->EntryConstraintGraph[depender_index].emplace_back(
groupIndex.first, false, false, cmListFileBacktrace());
} else {
@@ -775,7 +781,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
continue;
}
- if (depender_index >= 0 && inGroup) {
+ if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT &&
+ inGroup) {
const auto& depender = this->EntryList[depender_index];
const auto& groupFeature = this->EntryList[groupIndex.first].Feature;
if (depender.Target != nullptr && depender.Target->IsImported() &&
@@ -913,7 +920,7 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
for (auto index : indexes) {
// The dependee must come after the depender.
- if (depender_index >= 0) {
+ if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
this->EntryConstraintGraph[depender_index].emplace_back(
index, false, false, cmListFileBacktrace());
} else {
@@ -962,7 +969,7 @@ cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index,
{
// Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target;
- if (depender_index >= 0) {
+ if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) {
if (cmGeneratorTarget const* depender =
this->EntryList[depender_index].Target) {
from = depender;
@@ -1140,7 +1147,7 @@ void cmComputeLinkDepends::OrderLinkEntries()
this->ComponentOrderId = n;
// Run in reverse order so the topological order will preserve the
// original order where there are no constraints.
- for (int c = n - 1; c >= 0; --c) {
+ for (int c = n - 1; c != cmComputeComponentGraph::INVALID_COMPONENT; --c) {
this->VisitComponent(c);
}
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index 8cc916a..1bf0ff1 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -93,8 +93,9 @@ private:
std::pair<std::map<cmLinkItem, int>::iterator, bool> AllocateLinkEntry(
cmLinkItem const& item);
- std::pair<int, bool> AddLinkEntry(cmLinkItem const& item,
- int groupIndex = -1);
+ std::pair<int, bool> AddLinkEntry(
+ cmLinkItem const& item,
+ int groupIndex = cmComputeComponentGraph::INVALID_COMPONENT);
void AddLinkObject(cmLinkItem const& item);
void AddVarLinkEntries(int depender_index, const char* value);
void AddDirectLinkEntries();
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index 3ff16a4..337bafb 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -693,7 +693,7 @@ bool cmComputeTargetDepends::IntraComponent(std::vector<int> const& cmap,
}
// Prepend to a linear linked-list of intra-component edges.
- if (*head >= 0) {
+ if (*head != cmComputeComponentGraph::INVALID_COMPONENT) {
this->FinalGraph[i].emplace_back(*head, false, false,
cmListFileBacktrace());
} else {
@@ -721,7 +721,7 @@ bool cmComputeTargetDepends::ComputeFinalDepends(
this->ComponentTail.resize(components.size());
int nc = static_cast<int>(components.size());
for (int c = 0; c < nc; ++c) {
- int head = -1;
+ int head = cmComputeComponentGraph::INVALID_COMPONENT;
std::set<int> emitted;
NodeList const& nl = components[c];
for (int ni : cmReverseRange(nl)) {