2010-06-08 16:52:24 +00:00
//===-- Block.cpp -----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
# include "lldb/Symbol/Block.h"
2011-09-29 23:41:34 +00:00
# include "lldb/lldb-private-log.h"
# include "lldb/Core/Log.h"
2010-06-08 16:52:24 +00:00
# include "lldb/Core/Module.h"
# include "lldb/Core/Section.h"
2011-09-29 23:41:34 +00:00
# include "lldb/Symbol/Function.h"
2011-08-05 23:43:37 +00:00
# include "lldb/Symbol/SymbolFile.h"
2010-06-08 16:52:24 +00:00
# include "lldb/Symbol/SymbolVendor.h"
# include "lldb/Symbol/VariableList.h"
using namespace lldb ;
using namespace lldb_private ;
2010-08-21 02:22:51 +00:00
Block : : Block ( lldb : : user_id_t uid ) :
2010-06-08 16:52:24 +00:00
UserID ( uid ) ,
2010-08-21 02:22:51 +00:00
m_parent_scope ( NULL ) ,
m_children ( ) ,
m_ranges ( ) ,
m_inlineInfoSP ( ) ,
2010-08-24 21:05:24 +00:00
m_variable_list_sp ( ) ,
2010-08-21 02:22:51 +00:00
m_parsed_block_info ( false ) ,
m_parsed_block_variables ( false ) ,
m_parsed_child_blocks ( false )
2010-06-08 16:52:24 +00:00
{
}
Block : : ~ Block ( )
{
}
2010-06-28 21:30:43 +00:00
void
2010-09-14 23:36:40 +00:00
Block : : GetDescription ( Stream * s , Function * function , lldb : : DescriptionLevel level , Target * target ) const
2010-06-28 21:30:43 +00:00
{
2010-09-10 01:30:46 +00:00
* s < < " id = " < < ( ( const UserID & ) * this ) ;
2011-10-08 00:49:15 +00:00
size_t num_ranges = m_ranges . GetSize ( ) ;
if ( num_ranges > 0 )
2010-06-28 21:30:43 +00:00
{
addr_t base_addr = LLDB_INVALID_ADDRESS ;
2010-09-14 23:36:40 +00:00
if ( target )
base_addr = function - > GetAddressRange ( ) . GetBaseAddress ( ) . GetLoadAddress ( target ) ;
2010-06-28 21:30:43 +00:00
if ( base_addr = = LLDB_INVALID_ADDRESS )
2010-08-21 02:22:51 +00:00
base_addr = function - > GetAddressRange ( ) . GetBaseAddress ( ) . GetFileAddress ( ) ;
2010-06-28 21:30:43 +00:00
2010-09-10 01:30:46 +00:00
s - > Printf ( " , range%s = " , num_ranges > 1 ? " s " : " " ) ;
2011-10-08 00:49:15 +00:00
for ( size_t i = 0 ; i < num_ranges ; + + i )
{
const Range & range = m_ranges . GetEntryRef ( i ) ;
s - > AddressRange ( base_addr + range . GetRangeBase ( ) , base_addr + range . GetRangeEnd ( ) , 4 ) ;
}
2010-06-28 21:30:43 +00:00
}
if ( m_inlineInfoSP . get ( ) ! = NULL )
2010-09-15 05:51:24 +00:00
{
bool show_fullpaths = ( level = = eDescriptionLevelVerbose ) ;
m_inlineInfoSP - > Dump ( s , show_fullpaths ) ;
}
2010-06-28 21:30:43 +00:00
}
2010-06-08 16:52:24 +00:00
void
Block : : Dump ( Stream * s , addr_t base_addr , int32_t depth , bool show_context ) const
{
if ( depth < 0 )
{
2010-08-21 02:22:51 +00:00
Block * parent = GetParent ( ) ;
if ( parent )
{
// We have a depth that is less than zero, print our parent blocks
// first
parent - > Dump ( s , base_addr , depth + 1 , show_context ) ;
}
2010-06-08 16:52:24 +00:00
}
2011-09-20 21:44:10 +00:00
s - > Printf ( " %p: " , this ) ;
2010-06-08 16:52:24 +00:00
s - > Indent ( ) ;
* s < < " Block " < < ( ( const UserID & ) * this ) ;
2010-06-28 21:30:43 +00:00
const Block * parent_block = GetParent ( ) ;
if ( parent_block )
2010-06-08 16:52:24 +00:00
{
2012-11-29 21:49:15 +00:00
s - > Printf ( " , parent = {0x%8.8 " PRIx64 " } " , parent_block - > GetID ( ) ) ;
2010-06-08 16:52:24 +00:00
}
if ( m_inlineInfoSP . get ( ) ! = NULL )
2010-09-15 05:51:24 +00:00
{
bool show_fullpaths = false ;
m_inlineInfoSP - > Dump ( s , show_fullpaths ) ;
}
2010-06-08 16:52:24 +00:00
2011-10-08 00:49:15 +00:00
if ( ! m_ranges . IsEmpty ( ) )
2010-06-08 16:52:24 +00:00
{
* s < < " , ranges = " ;
2011-10-08 00:49:15 +00:00
size_t num_ranges = m_ranges . GetSize ( ) ;
for ( size_t i = 0 ; i < num_ranges ; + + i )
2010-06-08 16:52:24 +00:00
{
2011-10-08 00:49:15 +00:00
const Range & range = m_ranges . GetEntryRef ( i ) ;
if ( parent_block ! = NULL & & parent_block - > Contains ( range ) = = false )
2010-06-08 16:52:24 +00:00
* s < < ' ! ' ;
else
* s < < ' ' ;
2011-10-08 00:49:15 +00:00
s - > AddressRange ( base_addr + range . GetRangeBase ( ) , base_addr + range . GetRangeEnd ( ) , 4 ) ;
2010-06-08 16:52:24 +00:00
}
}
s - > EOL ( ) ;
if ( depth > 0 )
{
s - > IndentMore ( ) ;
2010-08-24 21:05:24 +00:00
if ( m_variable_list_sp . get ( ) )
2010-06-08 16:52:24 +00:00
{
2010-08-24 21:05:24 +00:00
m_variable_list_sp - > Dump ( s , show_context ) ;
2010-06-08 16:52:24 +00:00
}
2011-09-29 21:19:25 +00:00
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 ) ;
2010-06-08 16:52:24 +00:00
s - > IndentLess ( ) ;
}
}
2010-08-21 02:22:51 +00:00
Block *
Block : : FindBlockByID ( user_id_t block_id )
{
if ( block_id = = GetID ( ) )
return this ;
Block * matching_block = NULL ;
2011-09-29 21:19:25 +00:00
collection : : const_iterator pos , end = m_children . end ( ) ;
for ( pos = m_children . begin ( ) ; pos ! = end ; + + pos )
2010-08-21 02:22:51 +00:00
{
2011-09-29 21:19:25 +00:00
matching_block = ( * pos ) - > FindBlockByID ( block_id ) ;
2010-08-21 02:22:51 +00:00
if ( matching_block )
break ;
}
return matching_block ;
}
2010-06-08 16:52:24 +00:00
void
2010-08-24 21:05:24 +00:00
Block : : CalculateSymbolContext ( SymbolContext * sc )
2010-06-08 16:52:24 +00:00
{
2010-08-21 02:22:51 +00:00
if ( m_parent_scope )
m_parent_scope - > CalculateSymbolContext ( sc ) ;
2010-06-08 16:52:24 +00:00
sc - > block = this ;
}
2012-02-24 01:59:29 +00:00
lldb : : ModuleSP
2011-08-12 21:40:01 +00:00
Block : : CalculateSymbolContextModule ( )
{
if ( m_parent_scope )
return m_parent_scope - > CalculateSymbolContextModule ( ) ;
2012-02-24 01:59:29 +00:00
return lldb : : ModuleSP ( ) ;
2011-08-12 21:40:01 +00:00
}
CompileUnit *
Block : : CalculateSymbolContextCompileUnit ( )
{
if ( m_parent_scope )
return m_parent_scope - > CalculateSymbolContextCompileUnit ( ) ;
return NULL ;
}
Function *
Block : : CalculateSymbolContextFunction ( )
{
if ( m_parent_scope )
return m_parent_scope - > CalculateSymbolContextFunction ( ) ;
return NULL ;
}
Block *
Block : : CalculateSymbolContextBlock ( )
{
return this ;
}
2010-06-08 16:52:24 +00:00
void
Block : : DumpSymbolContext ( Stream * s )
{
2011-08-12 21:40:01 +00:00
Function * function = CalculateSymbolContextFunction ( ) ;
if ( function )
function - > DumpSymbolContext ( s ) ;
2012-11-29 21:49:15 +00:00
s - > Printf ( " , Block{0x%8.8 " PRIx64 " } " , GetID ( ) ) ;
2010-06-08 16:52:24 +00:00
}
2010-09-20 05:20:02 +00:00
void
Block : : DumpAddressRanges ( Stream * s , lldb : : addr_t base_addr )
{
2011-10-08 00:49:15 +00:00
if ( ! m_ranges . IsEmpty ( ) )
2010-09-20 05:20:02 +00:00
{
2011-10-08 00:49:15 +00:00
size_t num_ranges = m_ranges . GetSize ( ) ;
for ( size_t i = 0 ; i < num_ranges ; + + i )
{
const Range & range = m_ranges . GetEntryRef ( i ) ;
s - > AddressRange ( base_addr + range . GetRangeBase ( ) , base_addr + range . GetRangeEnd ( ) , 4 ) ;
}
2010-09-20 05:20:02 +00:00
}
}
2010-06-08 16:52:24 +00:00
bool
Block : : Contains ( addr_t range_offset ) const
{
2011-10-08 00:49:15 +00:00
return m_ranges . FindEntryThatContains ( range_offset ) ! = NULL ;
2010-06-08 16:52:24 +00:00
}
2010-09-02 21:44:10 +00:00
bool
Block : : Contains ( const Block * block ) const
{
if ( this = = block )
2010-09-14 03:16:58 +00:00
return false ; // This block doesn't contain itself...
2010-09-02 21:44:10 +00:00
2010-09-14 03:16:58 +00:00
// Walk the parent chain for "block" and see if any if them match this block
2010-09-02 21:44:10 +00:00
const Block * block_parent ;
for ( block_parent = block - > GetParent ( ) ;
block_parent ! = NULL ;
block_parent = block_parent - > GetParent ( ) )
{
2010-09-14 03:16:58 +00:00
if ( this = = block_parent )
return true ; // One of the parents of "block" is this object!
2010-09-02 21:44:10 +00:00
}
return false ;
}
2010-06-08 16:52:24 +00:00
bool
2011-10-08 00:49:15 +00:00
Block : : Contains ( const Range & range ) const
2010-06-08 16:52:24 +00:00
{
2011-10-08 00:49:15 +00:00
return m_ranges . FindEntryThatContains ( range ) ! = NULL ;
2010-06-08 16:52:24 +00:00
}
2010-08-21 02:22:51 +00:00
Block *
Block : : GetParent ( ) const
2010-06-08 16:52:24 +00:00
{
2010-08-21 02:22:51 +00:00
if ( m_parent_scope )
2011-08-12 21:40:01 +00:00
return m_parent_scope - > CalculateSymbolContextBlock ( ) ;
2010-08-21 02:22:51 +00:00
return NULL ;
2010-06-08 16:52:24 +00:00
}
2010-08-24 00:45:41 +00:00
Block *
2010-08-24 21:05:24 +00:00
Block : : GetContainingInlinedBlock ( )
{
2010-09-07 04:20:48 +00:00
if ( GetInlinedFunctionInfo ( ) )
2010-08-24 21:05:24 +00:00
return this ;
return GetInlinedParent ( ) ;
}
Block *
Block : : GetInlinedParent ( )
2010-08-24 00:45:41 +00:00
{
Block * parent_block = GetParent ( ) ;
if ( parent_block )
{
2010-09-07 04:20:48 +00:00
if ( parent_block - > GetInlinedFunctionInfo ( ) )
2010-08-24 00:45:41 +00:00
return parent_block ;
else
return parent_block - > GetInlinedParent ( ) ;
}
return NULL ;
}
2010-08-24 21:05:24 +00:00
bool
2011-10-08 00:49:15 +00:00
Block : : GetRangeContainingOffset ( const addr_t offset , Range & range )
2010-08-24 21:05:24 +00:00
{
2011-10-08 00:49:15 +00:00
const Range * range_ptr = m_ranges . FindEntryThatContains ( offset ) ;
if ( range_ptr )
2010-08-24 21:05:24 +00:00
{
2011-10-08 00:49:15 +00:00
range = * range_ptr ;
2010-08-24 21:05:24 +00:00
return true ;
}
range . Clear ( ) ;
return false ;
}
2010-08-24 00:45:41 +00:00
bool
2011-10-08 00:49:15 +00:00
Block : : GetRangeContainingAddress ( const Address & addr , AddressRange & range )
2010-08-24 00:45:41 +00:00
{
2011-08-12 21:40:01 +00:00
Function * function = CalculateSymbolContextFunction ( ) ;
if ( function )
2010-08-24 00:45:41 +00:00
{
2011-08-12 21:40:01 +00:00
const AddressRange & func_range = function - > GetAddressRange ( ) ;
2010-08-24 00:45:41 +00:00
if ( addr . GetSection ( ) = = func_range . GetBaseAddress ( ) . GetSection ( ) )
{
const addr_t addr_offset = addr . GetOffset ( ) ;
const addr_t func_offset = func_range . GetBaseAddress ( ) . GetOffset ( ) ;
if ( addr_offset > = func_offset & & addr_offset < func_offset + func_range . GetByteSize ( ) )
{
addr_t offset = addr_offset - func_offset ;
2011-10-08 00:49:15 +00:00
const Range * range_ptr = m_ranges . FindEntryThatContains ( offset ) ;
if ( range_ptr )
2010-08-24 00:45:41 +00:00
{
range . GetBaseAddress ( ) = func_range . GetBaseAddress ( ) ;
2011-10-08 00:49:15 +00:00
range . GetBaseAddress ( ) . SetOffset ( func_offset + range_ptr - > GetRangeBase ( ) ) ;
range . SetByteSize ( range_ptr - > GetByteSize ( ) ) ;
2010-08-24 00:45:41 +00:00
return true ;
}
}
}
}
range . Clear ( ) ;
return false ;
}
2012-08-31 23:49:32 +00:00
bool
Block : : GetRangeContainingLoadAddress ( lldb : : addr_t load_addr , Target & target , AddressRange & range )
{
Address load_address ;
load_address . SetLoadAddress ( load_addr , & target ) ;
AddressRange containing_range ;
return GetRangeContainingAddress ( load_address , containing_range ) ;
}
2011-10-08 00:49:15 +00:00
uint32_t
Block : : GetRangeIndexContainingAddress ( const Address & addr )
{
Function * function = CalculateSymbolContextFunction ( ) ;
if ( function )
{
const AddressRange & func_range = function - > GetAddressRange ( ) ;
if ( addr . GetSection ( ) = = func_range . GetBaseAddress ( ) . GetSection ( ) )
{
const addr_t addr_offset = addr . GetOffset ( ) ;
const addr_t func_offset = func_range . GetBaseAddress ( ) . GetOffset ( ) ;
if ( addr_offset > = func_offset & & addr_offset < func_offset + func_range . GetByteSize ( ) )
{
addr_t offset = addr_offset - func_offset ;
return m_ranges . FindEntryIndexThatContains ( offset ) ;
}
}
}
return UINT32_MAX ;
}
2011-04-23 02:04:55 +00:00
bool
Block : : GetRangeAtIndex ( uint32_t range_idx , AddressRange & range )
{
2011-10-08 00:49:15 +00:00
if ( range_idx < m_ranges . GetSize ( ) )
2011-04-23 02:04:55 +00:00
{
2011-08-12 21:40:01 +00:00
Function * function = CalculateSymbolContextFunction ( ) ;
if ( function )
2011-04-23 02:04:55 +00:00
{
2011-10-08 00:49:15 +00:00
const Range & vm_range = m_ranges . GetEntryRef ( range_idx ) ;
2011-08-12 21:40:01 +00:00
range . GetBaseAddress ( ) = function - > GetAddressRange ( ) . GetBaseAddress ( ) ;
2011-10-08 00:49:15 +00:00
range . GetBaseAddress ( ) . Slide ( vm_range . GetRangeBase ( ) ) ;
range . SetByteSize ( vm_range . GetByteSize ( ) ) ;
2011-04-23 02:04:55 +00:00
return true ;
}
}
return false ;
}
2010-11-14 00:22:48 +00:00
bool
Block : : GetStartAddress ( Address & addr )
{
2011-10-08 00:49:15 +00:00
if ( m_ranges . IsEmpty ( ) )
2010-11-14 00:22:48 +00:00
return false ;
2011-08-12 21:40:01 +00:00
Function * function = CalculateSymbolContextFunction ( ) ;
if ( function )
2010-11-14 00:22:48 +00:00
{
2011-08-12 21:40:01 +00:00
addr = function - > GetAddressRange ( ) . GetBaseAddress ( ) ;
2011-10-08 00:49:15 +00:00
addr . Slide ( m_ranges . GetEntryRef ( 0 ) . GetRangeBase ( ) ) ;
2010-11-14 00:22:48 +00:00
return true ;
}
return false ;
}
2010-06-08 16:52:24 +00:00
void
2011-10-08 00:49:15 +00:00
Block : : FinalizeRanges ( )
{
m_ranges . Sort ( ) ;
m_ranges . CombineConsecutiveRanges ( ) ;
}
void
Block : : AddRange ( const Range & range )
2010-06-08 16:52:24 +00:00
{
2011-09-29 23:41:34 +00:00
Block * parent_block = GetParent ( ) ;
2011-10-08 00:49:15 +00:00
if ( parent_block & & ! parent_block - > Contains ( range ) )
2011-09-29 23:41:34 +00:00
{
2013-03-27 23:08:40 +00:00
Log * log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_SYMBOLS ) ) ;
2011-09-29 23:41:34 +00:00
if ( log )
{
2012-02-24 01:59:29 +00:00
ModuleSP module_sp ( m_parent_scope - > CalculateSymbolContextModule ( ) ) ;
2011-09-29 23:41:34 +00:00
Function * function = m_parent_scope - > CalculateSymbolContextFunction ( ) ;
const addr_t function_file_addr = function - > GetAddressRange ( ) . GetBaseAddress ( ) . GetFileAddress ( ) ;
2011-10-08 00:49:15 +00:00
const addr_t block_start_addr = function_file_addr + range . GetRangeBase ( ) ;
const addr_t block_end_addr = function_file_addr + range . GetRangeEnd ( ) ;
2011-09-29 23:41:34 +00:00
Type * func_type = function - > GetType ( ) ;
const Declaration & func_decl = func_type - > GetDeclaration ( ) ;
if ( func_decl . GetLine ( ) )
{
2013-04-29 17:25:54 +00:00
log - > Printf ( " warning: %s:%u block {0x%8.8 " PRIx64 " } has range[%u] [0x% " PRIx64 " - 0x% " PRIx64 " ) which is not contained in parent block {0x%8.8 " PRIx64 " } in function {0x%8.8 " PRIx64 " } from %s " ,
func_decl . GetFile ( ) . GetPath ( ) . c_str ( ) ,
2011-09-29 23:41:34 +00:00
func_decl . GetLine ( ) ,
GetID ( ) ,
2011-10-08 00:49:15 +00:00
( uint32_t ) m_ranges . GetSize ( ) ,
2011-09-29 23:41:34 +00:00
block_start_addr ,
block_end_addr ,
parent_block - > GetID ( ) ,
function - > GetID ( ) ,
2013-04-29 17:25:54 +00:00
module_sp - > GetFileSpec ( ) . GetPath ( ) . c_str ( ) ) ;
2011-09-29 23:41:34 +00:00
}
else
{
2013-04-29 17:25:54 +00:00
log - > Printf ( " warning: block {0x%8.8 " PRIx64 " } has range[%u] [0x% " PRIx64 " - 0x% " PRIx64 " ) which is not contained in parent block {0x%8.8 " PRIx64 " } in function {0x%8.8 " PRIx64 " } from %s " ,
2011-09-29 23:41:34 +00:00
GetID ( ) ,
2011-10-08 00:49:15 +00:00
( uint32_t ) m_ranges . GetSize ( ) ,
2011-09-29 23:41:34 +00:00
block_start_addr ,
block_end_addr ,
parent_block - > GetID ( ) ,
function - > GetID ( ) ,
2013-04-29 17:25:54 +00:00
module_sp - > GetFileSpec ( ) . GetPath ( ) . c_str ( ) ) ;
2011-09-29 23:41:34 +00:00
}
}
2011-10-08 00:49:15 +00:00
parent_block - > AddRange ( range ) ;
2011-09-29 23:41:34 +00:00
}
2011-10-08 00:49:15 +00:00
m_ranges . Append ( range ) ;
2010-06-08 16:52:24 +00:00
}
// Return the current number of bytes that this object occupies in memory
size_t
Block : : MemorySize ( ) const
{
2011-10-08 00:49:15 +00:00
size_t mem_size = sizeof ( Block ) + m_ranges . GetSize ( ) * sizeof ( Range ) ;
2010-06-08 16:52:24 +00:00
if ( m_inlineInfoSP . get ( ) )
mem_size + = m_inlineInfoSP - > MemorySize ( ) ;
2010-08-24 21:05:24 +00:00
if ( m_variable_list_sp . get ( ) )
mem_size + = m_variable_list_sp - > MemorySize ( ) ;
2010-06-08 16:52:24 +00:00
return mem_size ;
}
2010-08-21 02:22:51 +00:00
void
Block : : AddChild ( const BlockSP & child_block_sp )
2010-06-08 16:52:24 +00:00
{
2010-08-21 02:22:51 +00:00
if ( child_block_sp )
{
child_block_sp - > SetParentScope ( this ) ;
m_children . push_back ( child_block_sp ) ;
}
2010-06-08 16:52:24 +00:00
}
void
Block : : SetInlinedFunctionInfo ( const char * name , const char * mangled , const Declaration * decl_ptr , const Declaration * call_decl_ptr )
{
m_inlineInfoSP . reset ( new InlineFunctionInfo ( name , mangled , decl_ptr , call_decl_ptr ) ) ;
}
2010-08-18 19:29:16 +00:00
VariableListSP
2011-06-17 22:10:16 +00:00
Block : : GetBlockVariableList ( bool can_create )
2010-08-18 19:29:16 +00:00
{
2010-08-21 02:22:51 +00:00
if ( m_parsed_block_variables = = false )
2010-08-18 19:29:16 +00:00
{
2010-08-24 21:05:24 +00:00
if ( m_variable_list_sp . get ( ) = = NULL & & can_create )
2010-08-21 02:22:51 +00:00
{
m_parsed_block_variables = true ;
SymbolContext sc ;
CalculateSymbolContext ( & sc ) ;
assert ( sc . module_sp ) ;
sc . module_sp - > GetSymbolVendor ( ) - > ParseVariablesForContext ( sc ) ;
}
2010-08-18 19:29:16 +00:00
}
2011-06-17 22:10:16 +00:00
return m_variable_list_sp ;
}
2010-08-18 19:29:16 +00:00
2011-06-17 22:10:16 +00:00
uint32_t
Block : : AppendBlockVariables ( bool can_create ,
bool get_child_block_variables ,
bool stop_if_child_block_is_inlined_function ,
VariableList * variable_list )
{
uint32_t num_variables_added = 0 ;
VariableList * block_var_list = GetBlockVariableList ( can_create ) . get ( ) ;
if ( block_var_list )
2010-08-18 19:29:16 +00:00
{
2011-06-17 22:10:16 +00:00
num_variables_added + = block_var_list - > GetSize ( ) ;
variable_list - > AddVariables ( block_var_list ) ;
}
if ( get_child_block_variables )
{
2011-09-29 21:19:25 +00:00
collection : : const_iterator pos , end = m_children . end ( ) ;
for ( pos = m_children . begin ( ) ; pos ! = end ; + + pos )
{
Block * child_block = pos - > get ( ) ;
2011-06-17 22:10:16 +00:00
if ( stop_if_child_block_is_inlined_function = = false | |
child_block - > GetInlinedFunctionInfo ( ) = = NULL )
{
num_variables_added + = child_block - > AppendBlockVariables ( can_create ,
get_child_block_variables ,
stop_if_child_block_is_inlined_function ,
variable_list ) ;
2010-08-18 19:29:16 +00:00
}
}
}
2011-06-17 22:10:16 +00:00
return num_variables_added ;
2010-08-18 19:29:16 +00:00
}
uint32_t
2010-08-24 00:45:41 +00:00
Block : : AppendVariables
(
bool can_create ,
bool get_parent_variables ,
bool stop_if_block_is_inlined_function ,
VariableList * variable_list
)
2010-08-18 19:29:16 +00:00
{
uint32_t num_variables_added = 0 ;
2011-06-17 22:10:16 +00:00
VariableListSP variable_list_sp ( GetBlockVariableList ( can_create ) ) ;
2010-08-18 19:29:16 +00:00
2010-09-07 04:20:48 +00:00
bool is_inlined_function = GetInlinedFunctionInfo ( ) ! = NULL ;
2010-08-18 19:29:16 +00:00
if ( variable_list_sp . get ( ) )
{
num_variables_added = variable_list_sp - > GetSize ( ) ;
variable_list - > AddVariables ( variable_list_sp . get ( ) ) ;
}
2010-08-24 00:45:41 +00:00
2010-08-18 19:29:16 +00:00
if ( get_parent_variables )
{
2010-08-24 00:45:41 +00:00
if ( stop_if_block_is_inlined_function & & is_inlined_function )
return num_variables_added ;
2010-08-18 19:29:16 +00:00
Block * parent_block = GetParent ( ) ;
if ( parent_block )
2010-08-24 00:45:41 +00:00
num_variables_added + = parent_block - > AppendVariables ( can_create , get_parent_variables , stop_if_block_is_inlined_function , variable_list ) ;
2010-08-18 19:29:16 +00:00
}
return num_variables_added ;
}
2011-08-05 23:43:37 +00:00
clang : : DeclContext *
2012-07-14 00:53:55 +00:00
Block : : GetClangDeclContext ( )
2011-08-05 23:43:37 +00:00
{
SymbolContext sc ;
CalculateSymbolContext ( & sc ) ;
if ( ! sc . module_sp )
return NULL ;
SymbolVendor * sym_vendor = sc . module_sp - > GetSymbolVendor ( ) ;
if ( ! sym_vendor )
return NULL ;
SymbolFile * sym_file = sym_vendor - > GetSymbolFile ( ) ;
if ( ! sym_file )
return NULL ;
return sym_file - > GetClangDeclContextForTypeUID ( sc , m_uid ) ;
}
2010-06-08 16:52:24 +00:00
void
2010-08-21 02:22:51 +00:00
Block : : SetBlockInfoHasBeenParsed ( bool b , bool set_children )
2010-06-08 16:52:24 +00:00
{
2010-08-21 02:22:51 +00:00
m_parsed_block_info = b ;
if ( set_children )
2010-06-08 16:52:24 +00:00
{
2010-08-21 02:22:51 +00:00
m_parsed_child_blocks = true ;
2011-09-29 21:19:25 +00:00
collection : : const_iterator pos , end = m_children . end ( ) ;
for ( pos = m_children . begin ( ) ; pos ! = end ; + + pos )
( * pos ) - > SetBlockInfoHasBeenParsed ( b , true ) ;
2010-06-08 16:52:24 +00:00
}
}
2011-06-17 22:10:16 +00:00
void
Block : : SetDidParseVariables ( bool b , bool set_children )
{
m_parsed_block_variables = b ;
if ( set_children )
{
2011-09-29 21:19:25 +00:00
collection : : const_iterator pos , end = m_children . end ( ) ;
for ( pos = m_children . begin ( ) ; pos ! = end ; + + pos )
( * pos ) - > SetDidParseVariables ( b , true ) ;
2011-06-17 22:10:16 +00:00
}
}
2011-09-29 21:19:25 +00:00
Block *
Block : : GetSibling ( ) const
{
if ( m_parent_scope )
{
2011-09-29 23:41:34 +00:00
Block * parent_block = GetParent ( ) ;
2011-09-29 21:19:25 +00:00
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 ;
}