Skip to content

Commit 76bf57c

Browse files
committed
Look for element_type typedef in base classes (#85)
For the yes1 variable from the test_smart_pointer test, we get - with llvm/clang on mac: <Variable id="_1012" name="yes1" type="_1554" init="new int{6}" context="_1" location="f118:11" file="f118" line="11" mangled="_Z4yes1"/> <Class id="_1554" name="shared_ptr&lt;int&gt;" context="_7" location="f46:3868" file="f46" line="3868" members="_7239 _7240 _7241 _7242 _7243 _7244 _7245 _7246 _7247 _7248 _7249 _7250 _7251 _7252 _7253 _7254 _7255 _7256 _7257 _7258 _7259" befriending="" size="128" align="64"/> <Typedef id="_7239" name="element_type" type="_2541" context="_1554" access="public" location="f46:3871" file="f46" line="3871"/> - with gcc on Linux: <Variable id="_977" name="yes1" type="_1024" init="new int{6}" context="_1" location="f44:11" file="f44" line="11" mangled="_Z4yes1"/> <Class id="_1024" name="shared_ptr&lt;int&gt;" context="_7" location="f51:93" file="f51" line="93" members="_3644 _3645 _3646 _3647 _3648 _3649 _3650" bases="_1039" befriending="_1025" size="128" align="64"> <Base type="_1039" access="public" virtual="0" offset="0"/> </Class> <Class id="_1039" name="__shared_ptr&lt;int, __gnu_cxx::_Lock_policy::_S_atomic&gt;" context="_7" location="f42:867" file="f42" line="867" members="_3711 _3712 _3713 _3714 _3715 _3716 _3717 _3718 _3719 _3720 _3721 _3722 _3723 _3724 _3725 _3726 _3727 _3728 _3729 _3730 _3731" befriending="_1040" size="128" align="64"/> <Typedef id="_3711" name="element_type" type="_3121" context="_1039" access="public" location="f42:874" file="f42" line="874"/> In the second case, we need to loop over the base class and check the members of that class. The member _3711 is the one we are looking for. Without this change the value_type methods were not able to find the typedef.
1 parent 6a0bf82 commit 76bf57c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pygccxml/declarations/smart_pointer_traits.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from . import class_declaration_traits
1010
from . import class_traits
1111
from . import traits_impl_details
12+
from . import runtime_errors
1213

1314

1415
class internal_type_traits(object):
@@ -72,7 +73,10 @@ def value_type(type_):
7273
'Type "%s" is not an instantiation of \
7374
boost::shared_ptr or std::shared_ptr' %
7475
type_.decl_string)
75-
return internal_type_traits.get_by_name(type_, "element_type")
76+
try:
77+
return internal_type_traits.get_by_name(type_, "element_type")
78+
except runtime_errors.declaration_not_found_t:
79+
return _search_in_bases(type_)
7680

7781

7882
class auto_ptr_traits(object):
@@ -103,4 +107,23 @@ def value_type(type_):
103107
raise TypeError(
104108
'Type "%s" is not instantiation of std::auto_ptr' %
105109
type_.decl_string)
106-
return internal_type_traits.get_by_name(type_, "element_type")
110+
try:
111+
return internal_type_traits.get_by_name(type_, "element_type")
112+
except runtime_errors.declaration_not_found_t:
113+
return _search_in_bases(type_)
114+
115+
116+
def _search_in_bases(type_):
117+
"""Implementation detail."""
118+
found = False
119+
for base_type in type_.declaration.bases:
120+
try:
121+
found = internal_type_traits.get_by_name(
122+
base_type.related_class, "element_type")
123+
except runtime_errors.declaration_not_found_t:
124+
pass
125+
if found:
126+
return found
127+
raise RuntimeError(
128+
("Unable to find 'element_type' declaration '%s'"
129+
"in type '%s'.") % type_.decl_string)

0 commit comments

Comments
 (0)