Quellcode durchsuchen

misc: Added utility method to allow working with stacks

Justin Berger vor 8 Jahren
Ursprung
Commit
39c2feaf8c
2 geänderte Dateien mit 17 neuen und 0 gelöschten Zeilen
  1. 13 0
      Source/cmListFileCache.cxx
  2. 4 0
      Source/cmListFileCache.h

+ 13 - 0
Source/cmListFileCache.cxx

@@ -438,6 +438,19 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
   }
 }
 
+size_t cmListFileBacktrace::Depth() const
+{
+  size_t depth = 0;
+  if (this->Cur == nullptr) {
+    return 0;
+  }
+
+  for (Entry* i = this->Cur->Up; i; i = i->Up) {
+    depth++;
+  }
+  return depth;
+}
+
 std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
 {
   os << lfc.FilePath;

+ 4 - 0
Source/cmListFileCache.h

@@ -6,6 +6,7 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include <iosfwd>
+#include <stddef.h>
 #include <string>
 #include <vector>
 
@@ -138,6 +139,9 @@ public:
   // Print the call stack below the top of the backtrace.
   void PrintCallStack(std::ostream& out) const;
 
+  // Get the number of 'frames' in this backtrace
+  size_t Depth() const;
+
 private:
   struct Entry;