Selaa lähdekoodia

cmComputeComponentGraph: use a name for "invalid component"

This is to prepare for making the graph use `size_t`.
Ben Boeckel 2 vuotta sitten
vanhempi
sitoutus
65c0a64dc5

+ 5 - 3
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;

+ 2 - 0
Source/cmComputeComponentGraph.h

@@ -53,6 +53,8 @@ public:
     return this->TarjanComponents;
   }
 
+  static const int INVALID_COMPONENT;
+
 private:
   void TransferEdges();
 

+ 17 - 10
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);
   }
 

+ 3 - 2
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();

+ 2 - 2
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)) {