@@ -4300,18 +4300,73 @@ def merge_with(self, other: "Symbol", docnames: List[str],
4300
4300
Symbol .debug_indent += 1
4301
4301
Symbol .debug_print ("merge_with:" )
4302
4302
assert other is not None
4303
+
4304
+ def unconditionalAdd (self , otherChild ):
4305
+ # TODO: hmm, should we prune by docnames?
4306
+ self ._children .append (otherChild )
4307
+ otherChild .parent = self
4308
+ otherChild ._assert_invariants ()
4309
+
4310
+ if Symbol .debug_lookup :
4311
+ Symbol .debug_indent += 1
4303
4312
for otherChild in other ._children :
4304
- ourChild = self ._find_first_named_symbol (
4313
+ if Symbol .debug_lookup :
4314
+ Symbol .debug_print ("otherChild:\n " , otherChild .to_string (Symbol .debug_indent ))
4315
+ Symbol .debug_indent += 1
4316
+ if otherChild .isRedeclaration :
4317
+ unconditionalAdd (self , otherChild )
4318
+ if Symbol .debug_lookup :
4319
+ Symbol .debug_print ("isRedeclaration" )
4320
+ Symbol .debug_indent -= 1
4321
+ continue
4322
+ candiateIter = self ._find_named_symbols (
4305
4323
identOrOp = otherChild .identOrOp ,
4306
4324
templateParams = otherChild .templateParams ,
4307
4325
templateArgs = otherChild .templateArgs ,
4308
4326
templateShorthand = False , matchSelf = False ,
4309
- recurseInAnon = False , correctPrimaryTemplateArgs = False )
4327
+ recurseInAnon = False , correctPrimaryTemplateArgs = False ,
4328
+ searchInSiblings = False )
4329
+ candidates = list (candiateIter )
4330
+
4331
+ if Symbol .debug_lookup :
4332
+ Symbol .debug_print ("raw candidate symbols:" , len (candidates ))
4333
+ symbols = [s for s in candidates if not s .isRedeclaration ]
4334
+ if Symbol .debug_lookup :
4335
+ Symbol .debug_print ("non-duplicate candidate symbols:" , len (symbols ))
4336
+
4337
+ if len (symbols ) == 0 :
4338
+ unconditionalAdd (self , otherChild )
4339
+ if Symbol .debug_lookup :
4340
+ Symbol .debug_indent -= 1
4341
+ continue
4342
+
4343
+ ourChild = None
4344
+ if otherChild .declaration is None :
4345
+ if Symbol .debug_lookup :
4346
+ Symbol .debug_print ("no declaration in other child" )
4347
+ ourChild = symbols [0 ]
4348
+ else :
4349
+ queryId = otherChild .declaration .get_newest_id ()
4350
+ if Symbol .debug_lookup :
4351
+ Symbol .debug_print ("queryId: " , queryId )
4352
+ for symbol in symbols :
4353
+ if symbol .declaration is None :
4354
+ if Symbol .debug_lookup :
4355
+ Symbol .debug_print ("empty candidate" )
4356
+ # if in the end we have non matching, but have an empty one,
4357
+ # then just continue with that
4358
+ ourChild = symbol
4359
+ continue
4360
+ candId = symbol .declaration .get_newest_id ()
4361
+ if Symbol .debug_lookup :
4362
+ Symbol .debug_print ("candidate:" , candId )
4363
+ if candId == queryId :
4364
+ ourChild = symbol
4365
+ break
4366
+ if Symbol .debug_lookup :
4367
+ Symbol .debug_indent -= 1
4310
4368
if ourChild is None :
4311
- # TODO: hmm, should we prune by docnames?
4312
- self ._children .append (otherChild )
4313
- otherChild .parent = self
4314
- otherChild ._assert_invariants ()
4369
+ unconditionalAdd (self , otherChild )
4315
4370
continue
4316
4371
if otherChild .declaration and otherChild .docname in docnames :
4317
4372
if not ourChild .declaration :
@@ -4326,10 +4381,14 @@ def merge_with(self, other: "Symbol", docnames: List[str],
4326
4381
# Both have declarations, and in the same docname.
4327
4382
# This can apparently happen, it should be safe to
4328
4383
# just ignore it, right?
4329
- pass
4384
+ # Hmm, only on duplicate declarations, right?
4385
+ msg = "Internal C++ domain error during symbol merging.\n "
4386
+ msg += "ourChild:\n " + ourChild .to_string (1 )
4387
+ msg += "\n otherChild:\n " + otherChild .to_string (1 )
4388
+ logger .warning (msg , location = otherChild .docname )
4330
4389
ourChild .merge_with (otherChild , docnames , env )
4331
4390
if Symbol .debug_lookup :
4332
- Symbol .debug_indent -= 1
4391
+ Symbol .debug_indent -= 2
4333
4392
4334
4393
def add_name (self , nestedName : ASTNestedName ,
4335
4394
templatePrefix : ASTTemplateDeclarationPrefix = None ) -> "Symbol" :
@@ -7116,7 +7175,6 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
7116
7175
print ("\t other:" )
7117
7176
print (otherdata ['root_symbol' ].dump (1 ))
7118
7177
print ("\t other end" )
7119
- print ("merge_domaindata end" )
7120
7178
7121
7179
self .data ['root_symbol' ].merge_with (otherdata ['root_symbol' ],
7122
7180
docnames , self .env )
@@ -7130,6 +7188,11 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
7130
7188
logger .warning (msg , location = docname )
7131
7189
else :
7132
7190
ourNames [name ] = docname
7191
+ if Symbol .debug_show_tree :
7192
+ print ("\t result:" )
7193
+ print (self .data ['root_symbol' ].dump (1 ))
7194
+ print ("\t result end" )
7195
+ print ("merge_domaindata end" )
7133
7196
7134
7197
def _resolve_xref_inner (self , env : BuildEnvironment , fromdocname : str , builder : Builder ,
7135
7198
typ : str , target : str , node : pending_xref ,
0 commit comments