Skip to content

Commit 5032746

Browse files
committed
1 parent b02910c commit 5032746

15 files changed

+60
-20
lines changed

pygccxml/binary_parsers/parsers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__( self, global_ns, map_file_path ):
139139

140140
def load_symbols( self ):
141141
"""returns dictionary { decorated symbol : original declaration name }"""
142-
f = file( self.binary_file )
142+
f = open( self.binary_file )
143143
lines = []
144144
was_exports = False
145145
for line in f:
@@ -154,7 +154,7 @@ def load_symbols( self ):
154154
result = []
155155
while index < len( lines ):
156156
line = lines[index].rstrip()
157-
found = self.cpp_entry.match( line )
157+
found = self.cpp_entry.match( line.decode('ascii') )
158158
if found:
159159
result.append( ( found.group( 'decorated' ), found.group( 'undecorated' ) ) )
160160
elif index + 1 < len( lines ):

pygccxml/declarations/calldef.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from . import algorithm
2222
from . import templates
2323
from . import declaration
24-
# circular import
25-
#from . import type_traits
24+
#from . import type_traits # moved below to fix a cyclic dependency problem
25+
type_traits = None
2626
from . import dependencies
2727
from . import call_invocation
2828

@@ -104,6 +104,12 @@ def __eq__(self, other):
104104
and self.default_value == other.default_value \
105105
and self.type == other.type
106106

107+
def __hash__(self, other):
108+
return (hash(self.__class__) ^
109+
hash(self.name) ^
110+
hash(self.default_value) ^
111+
hash(self.type))
112+
107113
def __ne__( self, other):
108114
return not self.__eq__( other )
109115

@@ -155,6 +161,11 @@ def _set_attributes( self, attributes ):
155161
class calldef_t( declaration.declaration_t ):
156162
"""base class for all "callable" declarations"""
157163
def __init__( self, name='', arguments=None, exceptions=None, return_type=None, has_extern=False, does_throw=True ):
164+
# moved here to fix a cyclic dependency problem
165+
from . import type_traits as tt
166+
global type_traits
167+
type_traits = tt
168+
158169
declaration.declaration_t.__init__( self, name )
159170
if not arguments:
160171
arguments = []
@@ -195,6 +206,11 @@ def __eq__(self, other):
195206
and self._sorted_list( self.exceptions ) == other._sorted_list( other.exceptions ) \
196207
and self.demangled_name == other.demangled_name
197208

209+
def __hash__(self):
210+
return (super.__hash__(self) ^
211+
hash(self.return_type) ^
212+
hash(self.demangled_name))
213+
198214
def _get_arguments(self):
199215
return self._arguments
200216
def _set_arguments(self, arguments):
@@ -296,7 +312,6 @@ def __remove_parent_fname( self, demangled ):
296312
return demangled
297313

298314
def _get_demangled_name( self ):
299-
from . import type_traits
300315
if not self.demangled:
301316
self._demangled_name = ''
302317

@@ -424,6 +439,8 @@ def __eq__(self, other):
424439
and self.has_static == other.has_static \
425440
and self.has_const == other.has_const
426441

442+
def __hash__(self): return super.__hash__(self)
443+
427444
def get_virtuality(self):
428445
return self._virtuality
429446
def set_virtuality(self, virtuality):
@@ -576,7 +593,6 @@ def __str__(self):
576593
@property
577594
def is_copy_constructor(self):
578595
"""returns True if described declaration is copy constructor, otherwise False"""
579-
from . import type_traits
580596
args = self.arguments
581597
if 1 != len( args ):
582598
return False
@@ -618,9 +634,6 @@ class free_function_t( free_calldef_t ):
618634
def __init__( self, *args, **keywords ):
619635
free_calldef_t.__init__( self, *args, **keywords )
620636

621-
def __hash__(self):
622-
return hash(self.get_mangled_name())
623-
624637
def get_mangled_name( self ):
625638
if not self._mangled and not self._demangled \
626639
and not '<' in self.name and not self.overloads:
@@ -640,7 +653,6 @@ def __init__( self, *args, **keywords ):
640653
@property
641654
def class_types( self ):
642655
"""list of class/class declaration types, extracted from the operator arguments"""
643-
from . import type_traits
644656
if None is self.__class_types:
645657
self.__class_types = []
646658
for type_ in self.argument_types:

pygccxml/declarations/class_declaration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def __eq__(self, other):
6767
and self.access == other.access \
6868
and self.is_virtual == other.is_virtual
6969

70+
def __hash__(self):
71+
return hash(algorithm.declaration_path(self.related_class))
72+
7073
def __ne__( self, other):
7174
return not self.__eq__( other )
7275

@@ -224,6 +227,9 @@ def __eq__(self, other):
224227
and self._sorted_list( self.protected_members ) \
225228
== self._sorted_list( other.protected_members )
226229

230+
def __hash__(self):
231+
return hash(self.class_type)
232+
227233
def _get_class_type(self):
228234
return self._class_type
229235
def _set_class_type( self, new_class_type):

pygccxml/declarations/cpptypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __eq__(self, other):
3030
return False
3131
return self.decl_string == other.decl_string
3232

33+
def __hash__(self):
34+
return hash(self.decl_string)
35+
3336
def __ne__( self, other):
3437
return not self.__eq__( other )
3538

@@ -713,6 +716,8 @@ def __eq__(self, other):
713716
return self.has_static == other.has_static \
714717
and self.has_mutable == other.has_mutable
715718

719+
def __hash__(self): return super.__hash__(self)
720+
716721
def __ne__( self, other):
717722
return not self.__eq__( other )
718723

pygccxml/declarations/declaration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def __eq__(self, other):
2424
return self.line == other.line \
2525
and self.file_name == other.file_name
2626

27+
def __hash__(self):
28+
return hash(self.__class__) ^ hash(self.line) ^ hash(self.file_name)
29+
2730
def __ne__( self, other):
2831
return not self.__eq__( other )
2932

@@ -122,6 +125,11 @@ def __eq__(self, other):
122125
and algorithm.declaration_path( self.parent ) \
123126
== algorithm.declaration_path( other.parent )
124127

128+
def __hash__(self):
129+
return (hash(self.__class__) ^
130+
hash(self.name) ^
131+
hash(self.location))
132+
125133
def __ne__( self, other):
126134
"""return not self.__eq__( other )"""
127135
return not self.__eq__( other )

pygccxml/declarations/enumeration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def __eq__(self, other):
4545
return False
4646
return self.values == other.values
4747

48+
def __hash__(self): return super.__hash__(self)
49+
4850
def _get__cmp__items( self ):
4951
"""implementation details"""
5052
return [self.values]

pygccxml/declarations/scopedef.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def __eq__(self, other):
116116
#else:
117117
#return self_decls == other_decls
118118

119+
def __hash__(self):
120+
return super.__hash__(self)
121+
119122
def _get_declarations_impl(self):
120123
raise NotImplementedError()
121124

pygccxml/declarations/type_traits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from . import enumeration
3131
from . import class_declaration
3232
from pygccxml import utils
33-
import types as build_in_types
3433

3534
def __remove_alias(type_):
3635
"""implementation details"""
@@ -94,7 +93,7 @@ def base_type(type):
9493

9594
def does_match_definition(given, main, secondary ):
9695
"""implementation details"""
97-
#assert isinstance( secondary, build_in_types.tuple )
96+
assert isinstance( secondary, tuple )
9897
assert 2 == len( secondary ) #general solution could be provided
9998
types = decompose_type( given )
10099
if isinstance( types[0], main ):

pygccxml/declarations/typedef.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def __eq__(self, other):
2727
return False
2828
return self.type == other.type
2929

30+
def __hash__(self):
31+
return super.__hash__(self)
32+
3033
def _get_type(self):
3134
return self._type
3235
def _set_type(self, type):

pygccxml/declarations/variable.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __eq__(self, other):
3636
and self.value == other.value \
3737
and self.bits == other.bits
3838

39+
def __hash__(self): return super.__hash__(self)
40+
3941
def _get_type(self):
4042
return self._type
4143
def _set_type(self, type):

0 commit comments

Comments
 (0)