Skip to content

Commit 379278e

Browse files
author
roman_yakovenko
committed
fix project merge bug - in case there are class definition and class forward declaration, the second one should be replaced with the first one
1 parent 329a082 commit 379278e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

pygccxml/parser/project_reader.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,26 @@ def _join_namespaces( self, nsref ):
384384
assert 1 == len( joined_decls[ decl._name ] )
385385
if isinstance( decl, pygccxml.declarations.namespace_t ):
386386
joined_decls[ decl._name ][0].take_parenting( decl )
387+
388+
class_t = pygccxml.declarations.class_t
389+
class_declaration_t = pygccxml.declarations.class_declaration_t
390+
if class_t in ddhash and class_declaration_t in ddhash:
391+
#if there is a class and its forward declaration - get rid of the
392+
#second one.
393+
class_names = set()
394+
for name, same_name_classes in ddhash[ class_t ].iteritems():
395+
if not name:
396+
continue
397+
class_names.add( same_name_classes[0].mangled )
398+
399+
class_declarations = ddhash[ class_declaration_t ]
400+
for name, same_name_class_declarations in class_declarations.iteritems():
401+
if not name:
402+
continue
403+
for class_declaration in same_name_class_declarations :
404+
if class_declaration.mangled and class_declaration.mangled in class_names:
405+
decls.remove( class_declaration )
406+
387407
nsref.declarations = decls
388408

389409
def _join_class_hierarchy( self, namespaces ):
@@ -454,14 +474,20 @@ def _join_class_hierarchy( self, namespaces ):
454474
def _relink_declarated_types(self, leaved_classes, declarated_types):
455475
create_key = lambda decl:( decl.location.as_tuple()
456476
, tuple( pygccxml.declarations.declaration_path( decl ) ) )
477+
create_mangled_key = lambda decl:( decl.location.as_tuple(), decl.mangled )
478+
479+
mangled_leaved_classes = {}
480+
for cls in leaved_classes.itervalues():
481+
mangled_leaved_classes[ create_mangled_key( cls ) ] = cls
482+
457483
for decl_wrapper_type in declarated_types:
458484
#it is possible, that cache contains reference to dropped class
459485
#We need to clear it
460486
decl_wrapper_type.cache.reset()
461487
if isinstance( decl_wrapper_type.declaration, pygccxml.declarations.class_t ):
462488
key = create_key(decl_wrapper_type.declaration)
463489
if leaved_classes.has_key( key ):
464-
decl_wrapper_type.declaration = leaved_classes[ create_key(decl_wrapper_type.declaration) ]
490+
decl_wrapper_type.declaration = leaved_classes[ key ]
465491
else:
466492
if decl_wrapper_type.declaration._name.startswith( '__vmi_class_type_info_pseudo' ):
467493
continue
@@ -472,6 +498,10 @@ def _relink_declarated_types(self, leaved_classes, declarated_types):
472498
msg.append( " 1. There are different preprocessor definitions applied on same file during compilation" )
473499
msg.append( " 2. Bug in pygccxml." )
474500
self.logger.error( os.linesep.join(msg) )
501+
elif isinstance( decl_wrapper_type.declaration, pygccxml.declarations.class_declaration_t ):
502+
key = create_mangled_key(decl_wrapper_type.declaration)
503+
if mangled_leaved_classes.has_key( key ):
504+
decl_wrapper_type.declaration = mangled_leaved_classes[ key ]
475505

476506
def _join_declarations( self, declref ):
477507
self._join_namespaces( declref )

0 commit comments

Comments
 (0)