Add an API to ValueObject that iterates over the entire parent chain via a callback...
authorEnrico Granata <egranata@apple.com>
Thu, 22 Jan 2015 03:07:34 +0000 (03:07 +0000)
committerEnrico Granata <egranata@apple.com>
Thu, 22 Jan 2015 03:07:34 +0000 (03:07 +0000)
llvm-svn: 226771

lldb/include/lldb/Core/ValueObject.h
lldb/source/Core/ValueObject.cpp

index 402a0f8..b50adfb 100644 (file)
@@ -527,9 +527,14 @@ public:
     virtual lldb::ModuleSP
     GetModule();
     
-    virtual ValueObject*
+    ValueObject*
     GetRoot ();
     
+    // Given a ValueObject, loop over itself and its parent, and its parent's parent, ..
+    // until either the given callback returns false, or you end up at a null pointer
+    ValueObject*
+    FollowParentChain (std::function<bool(ValueObject*)>);
+    
     virtual bool
     GetDeclaration (Declaration &decl);
 
index 3b9a7ab..7231f01 100644 (file)
@@ -4130,16 +4130,22 @@ ValueObject::GetRoot ()
 {
     if (m_root)
         return m_root;
-    ValueObject* parent = m_parent;
-    if (!parent)
-        return (m_root = this);
-    while (parent->m_parent)
+    return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
+        return (vo->m_parent != nullptr);
+    }));
+}
+
+ValueObject*
+ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
+{
+    ValueObject* vo = this;
+    while (vo)
     {
-        if (parent->m_root)
-            return (m_root = parent->m_root);
-        parent = parent->m_parent;
+        if (f(vo) == false)
+            break;
+        vo = vo->m_parent;
     }
-    return (m_root = parent);
+    return vo;
 }
 
 AddressType