diff options
author | Enrico Granata <egranata@apple.com> | 2015-01-22 03:07:34 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2015-01-22 03:07:34 +0000 |
commit | de61ebafcfa3445869e223802bc2cd75b08aab60 (patch) | |
tree | 35c9aefc6bce29d56f7b7ba0bcf9d78509acf5b9 | |
parent | 2e4db3d00ce680801fa82ed19fc750e280cb372d (diff) | |
download | bcm5719-llvm-de61ebafcfa3445869e223802bc2cd75b08aab60.tar.gz bcm5719-llvm-de61ebafcfa3445869e223802bc2cd75b08aab60.zip |
Add an API to ValueObject that iterates over the entire parent chain via a callback, and rewrite GetRoot() in terms of this general iteration API. NFC
llvm-svn: 226771
-rw-r--r-- | lldb/include/lldb/Core/ValueObject.h | 7 | ||||
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 22 |
2 files changed, 20 insertions, 9 deletions
diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 402a0f8bad2..b50adfb6956 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -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); diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 3b9a7ab049d..7231f0187ee 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -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 |