diff options
-rw-r--r-- | lldb/include/lldb/Symbol/Block.h | 17 | ||||
-rw-r--r-- | lldb/source/Symbol/Block.cpp | 72 |
2 files changed, 55 insertions, 34 deletions
diff --git a/lldb/include/lldb/Symbol/Block.h b/lldb/include/lldb/Symbol/Block.h index c5f7911ec62..8fabf954073 100644 --- a/lldb/include/lldb/Symbol/Block.h +++ b/lldb/include/lldb/Symbol/Block.h @@ -247,10 +247,7 @@ public: /// sibling. //------------------------------------------------------------------ Block * - GetSibling () const - { - return m_sibling; - } + GetSibling () const; //------------------------------------------------------------------ /// Get the first child block. @@ -398,12 +395,6 @@ public: m_parent_scope = parent_scope; } - void - SetSibling (Block *block) - { - m_sibling = block; - } - //------------------------------------------------------------------ /// Set accessor for the variable list. /// @@ -466,7 +457,6 @@ protected: // Member variables. //------------------------------------------------------------------ SymbolContextScope *m_parent_scope; - Block *m_sibling; collection m_children; VMRange::collection m_ranges; ///< A list of address offset ranges relative to the function's section/offset address. lldb::InlineFunctionInfoSP m_inlineInfoSP; ///< Inlined function information. @@ -475,6 +465,11 @@ protected: m_parsed_block_variables:1, m_parsed_child_blocks:1; + // A parent of child blocks can be asked to find a sibling block given + // one of its child blocks + Block * + GetSiblingForChild (const Block *child_block) const; + private: DISALLOW_COPY_AND_ASSIGN (Block); }; diff --git a/lldb/source/Symbol/Block.cpp b/lldb/source/Symbol/Block.cpp index 6676279dabf..ed7772178f0 100644 --- a/lldb/source/Symbol/Block.cpp +++ b/lldb/source/Symbol/Block.cpp @@ -21,7 +21,6 @@ using namespace lldb_private; Block::Block(lldb::user_id_t uid) : UserID(uid), m_parent_scope (NULL), - m_sibling (NULL), m_children (), m_ranges (), m_inlineInfoSP (), @@ -117,10 +116,9 @@ Block::Dump(Stream *s, addr_t base_addr, int32_t depth, bool show_context) const m_variable_list_sp->Dump(s, show_context); } - for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) - { - child_block->Dump(s, base_addr, depth - 1, show_context); - } + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) + (*pos)->Dump(s, base_addr, depth - 1, show_context); s->IndentLess(); } @@ -135,9 +133,10 @@ Block::FindBlockByID (user_id_t block_id) return this; Block *matching_block = NULL; - for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) { - matching_block = child_block->FindBlockByID (block_id); + matching_block = (*pos)->FindBlockByID (block_id); if (matching_block) break; } @@ -458,16 +457,8 @@ Block::AddChild(const BlockSP &child_block_sp) { if (child_block_sp) { - Block *block_needs_sibling = NULL; - - if (!m_children.empty()) - block_needs_sibling = m_children.back().get(); - child_block_sp->SetParentScope (this); m_children.push_back (child_block_sp); - - if (block_needs_sibling) - block_needs_sibling->SetSibling (child_block_sp.get()); } } @@ -512,10 +503,10 @@ Block::AppendBlockVariables (bool can_create, if (get_child_block_variables) { - for (Block *child_block = GetFirstChild(); - child_block != NULL; - child_block = child_block->GetSibling()) - { + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) + { + Block *child_block = pos->get(); if (stop_if_child_block_is_inlined_function == false || child_block->GetInlinedFunctionInfo() == NULL) { @@ -590,8 +581,9 @@ Block::SetBlockInfoHasBeenParsed (bool b, bool set_children) if (set_children) { m_parsed_child_blocks = true; - for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) - child_block->SetBlockInfoHasBeenParsed (b, true); + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) + (*pos)->SetBlockInfoHasBeenParsed (b, true); } } @@ -601,8 +593,42 @@ Block::SetDidParseVariables (bool b, bool set_children) m_parsed_block_variables = b; if (set_children) { - for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) - child_block->SetDidParseVariables (b, true); + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) + (*pos)->SetDidParseVariables (b, true); + } +} + + +Block * +Block::GetSibling() const +{ + if (m_parent_scope) + { + Block *parent_block = m_parent_scope->CalculateSymbolContextBlock(); + if (parent_block) + return parent_block->GetSiblingForChild (this); } + return NULL; +} +// A parent of child blocks can be asked to find a sibling block given +// one of its child blocks +Block * +Block::GetSiblingForChild (const Block *child_block) const +{ + if (!m_children.empty()) + { + collection::const_iterator pos, end = m_children.end(); + for (pos = m_children.begin(); pos != end; ++pos) + { + if (pos->get() == child_block) + { + if (++pos != end) + return pos->get(); + break; + } + } + } + return NULL; } |