1"""
2Summary and synthetic providers for LLDB-specific shared pointers
3
4part of The LLVM Compiler Infrastructure
5This file is distributed under the University of Illinois Open Source
6License. See LICENSE.TXT for details.
7"""
8
9class SharedPtr_SyntheticChildrenProvider:
10	def __init__(self,valobj,dict):
11		self.valobj = valobj
12		self.update()
13	def update(self):
14		pass
15	def num_children(self):
16		return 1
17	def get_child_index(self,name):
18		if name == "ptr":
19			return 0
20		if name == "count":
21			return 1
22		return None
23	def get_child_at_index(self,index):
24		if index == 0:
25			return self.valobj.GetChildMemberWithName('_M_ptr')
26		if index == 1:
27			return self.valobj.GetChildMemberWithName('_M_refcount').GetChildMemberWithName('_M_pi').GetChildMemberWithName('_M_use_count')
28		return None
29
30def SharedPtr_SummaryProvider (valobj,dict):
31	return 'use = ' + str(valobj.GetChildMemberWithName("count").GetValueAsUnsigned())
32
33class ValueObjectSP_SyntheticChildrenProvider:
34	def __init__(self,valobj,dict):
35		self.valobj = valobj
36		self.update()
37	def update(self):
38		pass
39	def num_children(self):
40		return 1
41	def get_child_index(self,name):
42		if name == "ptr":
43			return 0
44		if name == "count":
45			return 1
46		return None
47	def get_child_at_index(self,index):
48		if index == 0:
49			return self.valobj.GetChildMemberWithName('ptr_')
50		if index == 1:
51			return self.valobj.GetChildMemberWithName('cntrl_').GetChildMemberWithName('shared_owners_')
52		return None
53
54def ValueObjectSP_SummaryProvider (valobj,dict):
55	return 'use = ' + str(1 + valobj.GetChildMemberWithName("count").GetValueAsUnsigned())
56
57def __lldb_init_module(debugger, dict):
58	debugger.HandleCommand('type summary add -x ".*ValueObjectSP" --expand -F sp_cp.ValueObjectSP_SummaryProvider')
59	debugger.HandleCommand('type synthetic add -x ".*ValueObjectSP" -l sp_cp.ValueObjectSP_SyntheticChildrenProvider')
60	debugger.HandleCommand('type summary add -x ".*SP" --expand -F sp_cp.SharedPtr_SummaryProvider')
61	debugger.HandleCommand('type synthetic add -x ".*SP" -l sp_cp.SharedPtr_SyntheticChildrenProvider')
62