2121from . import algorithm
2222from . import templates
2323from . 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
2626from . import dependencies
2727from . 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 ):
155161class 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 :
0 commit comments