Skip to content

Commit ceecb7f

Browse files
committed
Always check overloader signature of name segment while comparing PDOMBinding fully qualified names
Signature checking was already implemented in pdomCompareTo for specific cases PDOMFunction and PDOMCPPFunctionSpecialization, but trying to compare two PDOM bindings where intermediate name seqments are a class template and related class template specialization fails because DBname is the same. Allow differentiating bindings in this case by always comparing signatures. Clean up special cases since base method now would always compare signatures. This fixes CppCallHierarcyTests.testTemplates() if base lookup in index is perfomed by just "m" and results in both class template CT::m and CT<char>::m which are now considered distinct PDOM bindings.
1 parent 182ebe8 commit ceecb7f

File tree

4 files changed

+20
-51
lines changed

4 files changed

+20
-51
lines changed

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ private static int comparePDOMBindingQNs(PDOMBinding b0, PDOMBinding b1) {
395395
do {
396396
IString s0 = b0.getDBName(), s1 = b1.getDBName();
397397
cmp = s0.compare(s1, true);
398+
if (cmp == 0) {
399+
cmp = compareSignatures(b0, b1);
400+
}
398401
if (cmp == 0) {
399402
long l1 = b0.getLocalToFileRec();
400403
long l2 = b1.getLocalToFileRec();
@@ -415,6 +418,23 @@ private static int comparePDOMBindingQNs(PDOMBinding b0, PDOMBinding b1) {
415418
}
416419
}
417420

421+
protected static int compareSignatures(PDOMBinding a, PDOMBinding b) {
422+
try {
423+
final IPDOMOverloader bo0 = a instanceof final IPDOMOverloader xa ? xa : null;
424+
final IPDOMOverloader bo1 = b instanceof final IPDOMOverloader xb ? xb : null;
425+
if (bo0 == null || bo1 == null) {
426+
return bo0 == bo1 ? 0 : (bo0 == null ? -1 : 1);
427+
} else {
428+
int mySM = bo0.getSignatureHash();
429+
int otherSM = bo1.getSignatureHash();
430+
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
431+
}
432+
} catch (CoreException e) {
433+
CCorePlugin.log(e);
434+
}
435+
return 0;
436+
}
437+
418438
/**
419439
* Compares two PDOMBinding objects in accordance with
420440
* {@link IIndexFragmentBindingComparator#compare(IIndexFragmentBinding, IIndexFragmentBinding)}

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
2929
import org.eclipse.cdt.internal.core.pdom.db.Database;
3030
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
31-
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
3231
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
3332
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
3433
import org.eclipse.core.runtime.CoreException;
@@ -126,27 +125,6 @@ public ICPPTemplateArgument[] getTemplateArguments() {
126125
}
127126
}
128127

129-
@Override
130-
public int pdomCompareTo(PDOMBinding other) {
131-
int cmp = super.pdomCompareTo(other);
132-
if (cmp == 0) {
133-
if (other instanceof PDOMCPPClassTemplatePartialSpecialization) {
134-
try {
135-
PDOMCPPClassTemplatePartialSpecialization otherSpec = (PDOMCPPClassTemplatePartialSpecialization) other;
136-
int mySM = getSignatureHash();
137-
int otherSM = otherSpec.getSignatureHash();
138-
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
139-
} catch (CoreException e) {
140-
CCorePlugin.log("Comparison failure for " + getName(), e); //$NON-NLS-1$
141-
}
142-
} else {
143-
assert false;
144-
CCorePlugin.log(new AssertionError("Assertion failure for " + getName())); //$NON-NLS-1$
145-
}
146-
}
147-
return cmp;
148-
}
149-
150128
@Override
151129
public boolean isSameType(IType type) {
152130
if (type instanceof ITypedef) {

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
3535
import org.eclipse.cdt.internal.core.pdom.db.Database;
3636
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
37-
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
3837
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
3938
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
4039
import org.eclipse.core.runtime.CoreException;
@@ -404,28 +403,6 @@ public Object clone() {
404403
throw new UnsupportedOperationException();
405404
}
406405

407-
@Override
408-
public int pdomCompareTo(PDOMBinding other) {
409-
int cmp = super.pdomCompareTo(other);
410-
return cmp == 0 ? compareSignatures(this, other) : cmp;
411-
}
412-
413-
protected static int compareSignatures(IPDOMOverloader a, Object b) {
414-
if (b instanceof IPDOMOverloader) {
415-
IPDOMOverloader bb = (IPDOMOverloader) b;
416-
try {
417-
int mySM = a.getSignatureHash();
418-
int otherSM = bb.getSignatureHash();
419-
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
420-
} catch (CoreException e) {
421-
CCorePlugin.log(e);
422-
}
423-
} else {
424-
assert false;
425-
}
426-
return 0;
427-
}
428-
429406
@Override
430407
public IType[] getExceptionSpecification() {
431408
try {

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,6 @@ public boolean isDeleted() {
309309
return PDOMCPPAnnotations.isDeletedFunction(getAnnotations());
310310
}
311311

312-
@Override
313-
public int pdomCompareTo(PDOMBinding other) {
314-
int cmp = super.pdomCompareTo(other);
315-
return cmp == 0 ? PDOMCPPFunction.compareSignatures(this, other) : cmp;
316-
}
317-
318312
@Override
319313
public IType[] getExceptionSpecification() {
320314
try {

0 commit comments

Comments
 (0)