1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

183986: extract a Comparator from PDOMBinding

This commit is contained in:
Andrew Ferguson 2007-04-26 16:41:39 +00:00
parent 417e9c0d70
commit 6741a8d019
22 changed files with 373 additions and 133 deletions

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
/**
* Binding comparator suitable for C/C++ across index implementations. This will not be used
* unless we ever have non-PDOM implementations of IIndexFragment, and in that case we may find
* this implementation is too slow.
*/
public class DefaultFragmentBindingComparator implements IIndexFragmentBindingComparator {
public int compare(IIndexFragmentBinding a, IIndexFragmentBinding b) {
int cmp= compareQualifiedNames(a.getQualifiedName(),b.getQualifiedName());
if(cmp==0) {
int ac= a.getBindingConstant(), bc= b.getBindingConstant();
cmp= ac<bc ? -1 : (ac>bc ? 1 : 0);
if(cmp==0) {
cmp= IndexCPPSignatureUtil.compareSignatures(a, b);
}
}
return cmp;
}
private int compareQualifiedNames(String[] afqn, String[] bfqn) {
if(afqn.length < bfqn.length)
return -1;
if(afqn.length > bfqn.length)
return 1;
for(int i=0; i<afqn.length; i++) {
int cmp= afqn[i].compareTo(bfqn[i]);
if(cmp!=0)
return cmp;
}
return 0;
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
/**
* Constants used by IIndexFragment implementations for identifying persisted binding types
*/
public interface IIndexBindingConstants {
int POINTER_TYPE= 1;
int ARRAY_TYPE= 2;
int QUALIFIER_TYPE= 3;
int FILE_LOCAL_SCOPE_TYPE= 4;
int LAST_CONSTANT= FILE_LOCAL_SCOPE_TYPE;
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
/**
* Constants used by IIndexFragment implementations for identifying persisted binding types
*/
public interface IIndexCBindingConstants {
int CVARIABLE = IIndexBindingConstants.LAST_CONSTANT + 1;
int CFUNCTION = IIndexBindingConstants.LAST_CONSTANT + 2;
int CSTRUCTURE = IIndexBindingConstants.LAST_CONSTANT + 3;
int CFIELD = IIndexBindingConstants.LAST_CONSTANT + 4;
int CENUMERATION = IIndexBindingConstants.LAST_CONSTANT + 5;
int CENUMERATOR = IIndexBindingConstants.LAST_CONSTANT + 6;
int CTYPEDEF = IIndexBindingConstants.LAST_CONSTANT + 7;
int CPARAMETER = IIndexBindingConstants.LAST_CONSTANT + 8;
int CBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 9;
int CFUNCTIONTYPE = IIndexBindingConstants.LAST_CONSTANT + 10;
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
/**
* Constants used by IIndexFragment implementations for identifying persisted binding types
*/
public interface IIndexCPPBindingConstants {
int CPPVARIABLE = IIndexBindingConstants.LAST_CONSTANT + 1;
int CPPFUNCTION = IIndexBindingConstants.LAST_CONSTANT + 2;
int CPPCLASSTYPE = IIndexBindingConstants.LAST_CONSTANT + 3;
int CPPFIELD = IIndexBindingConstants.LAST_CONSTANT + 4;
int CPPMETHOD = IIndexBindingConstants.LAST_CONSTANT + 5;
int CPPNAMESPACE = IIndexBindingConstants.LAST_CONSTANT + 6;
int CPPNAMESPACEALIAS = IIndexBindingConstants.LAST_CONSTANT + 7;
int CPPBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 8;
int CPPPARAMETER = IIndexBindingConstants.LAST_CONSTANT + 9;
int CPPENUMERATION = IIndexBindingConstants.LAST_CONSTANT + 10;
int CPPENUMERATOR = IIndexBindingConstants.LAST_CONSTANT + 11;
int CPPTYPEDEF = IIndexBindingConstants.LAST_CONSTANT + 12;
int CPP_POINTER_TO_MEMBER_TYPE= IIndexBindingConstants.LAST_CONSTANT + 13;
int CPP_CONSTRUCTOR= IIndexBindingConstants.LAST_CONSTANT + 14;
int CPP_REFERENCE_TYPE= IIndexBindingConstants.LAST_CONSTANT + 15;
int CPP_FUNCTION_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 16;
int CPP_METHOD_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 17;
int CPP_CONSTRUCTOR_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 18;
int CPP_CLASS_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 19;
int CPP_CLASS_TEMPLATE_PARTIAL_SPEC= IIndexBindingConstants.LAST_CONSTANT + 20;
int CPP_FUNCTION_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 21;
int CPP_METHOD_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 22;
int CPP_CONSTRUCTOR_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 23;
int CPP_DEFERRED_FUNCTION_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 24;
int CPP_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 25;
int CPP_DEFERRED_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 26;
int CPP_PARAMETER_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 27;
int CPP_FIELD_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 28;
int CPP_FUNCTION_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 29;
int CPP_METHOD_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 30;
int CPP_CONSTRUCTOR_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 31;
int CPP_CLASS_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 32;
int CPP_FUNCTION_TEMPLATE_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 33;
int CPP_METHOD_TEMPLATE_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 34;
int CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 35;
int CPP_CLASS_TEMPLATE_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 36;
int CPP_TYPEDEF_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 37;
int CPP_TEMPLATE_TYPE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 38;
int CPP_FUNCTION_TYPE= IIndexBindingConstants.LAST_CONSTANT + 39;
}

View file

@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.core.runtime.CoreException;
public interface IIndexFragmentBinding extends Comparable, IIndexBinding {
public interface IIndexFragmentBinding extends IIndexBinding {
IIndexFragmentBinding[] EMPTY_INDEX_BINDING_ARRAY= new IIndexFragmentBinding[0];
/**
@ -40,4 +40,9 @@ public interface IIndexFragmentBinding extends Comparable, IIndexBinding {
* it in its associated fragment.
*/
boolean hasDeclaration() throws CoreException;
/**
* Returns the constant identifying the type of binding stored in the index
*/
int getBindingConstant();
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
public interface IIndexFragmentBindingComparator {
/**
* Compares to index fragment bindings, or returns {@link Integer.MIN_VALUE} if the comparator is
* not capable of comparing the two objects because of their run-time type.
* <p>
* Compares two index fragment bindings using the following scheme:
* <ul>
* <li>Compares the fully qualfied names, by pair-wise lexicographic comparison
* of individual name components, starting with the innermost scoped name. If
* all pair-wise comparisons are equal, then the comparison routine continues, otherwise returning
* <ul>
* <li> -1 if the first differing component name of <em>a</em> was &lt the pairwise equivalent from <em>b</em>
* <li> 1 if the first differing component name of <em>a</em> was &gt the pairwise equivalent from <em>b</em>
* </ul> In case binding <em>a</em> has fewer component names than binding <em>b</em> then
* -1 is returned, otherwise 1 is returned.
* <li>Compares a course-grained binding type dependent on language. For C/C++ the
* type comparison is performed by comparing the bindings associated constant as defined in
* IIndexCNodeConstants or IIndexCPPNodeConstants. If these are equal comparison continues
* <li>Compares fine grained binding information dependent on the binding language. For C++ the
* type comparison is relevant for binding types that are further differentiated by type signatures via
* {@link IndexCPPSignatureUtil}
* </ul>
* @param a a non null {@link IIndexFragmentBinding}
* @param b a non null {@link IIndexFragmentBinding}
* @return -1, 0, 1 or Integer.MIN_VALUE if this comparator cannot compare the two
*/
public int compare(IIndexFragmentBinding a, IIndexFragmentBinding b);
}

View file

@ -8,7 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
@ -29,9 +29,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.index.IIndexInternalTemplateParameter;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
@ -40,7 +37,7 @@ import org.eclipse.core.runtime.CoreException;
*
* @author Bryan Wilkinson
*/
class PDOMCPPOverloaderUtil {
public class IndexCPPSignatureUtil {
/**
* Returns the signature for the binding. Returns an empty string if a
@ -172,19 +169,23 @@ class PDOMCPPOverloaderUtil {
String sig= getFunctionParameterString(type);
return sig.length() == 0 ? null : new Integer(sig.hashCode());
}
public static int compare(IPDOMOverloader a, Object b) {
if(b instanceof IPDOMOverloader) {
IPDOMOverloader bb= (IPDOMOverloader) b;
try {
int mySM = a.getSignatureMemento();
int otherSM = bb.getSignatureMemento();
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
} else {
throw new PDOMNotImplementedError(b.getClass().toString());
/**
* Compares two bindings for signature information. Signature information covers
* function signatures, or template specialization/instance arguments.
* @param a
* @param b
* @return
*/
public static int compareSignatures(IBinding a, IBinding b) {
try {
int siga= getSignature(a).hashCode();
int sigb= getSignature(b).hashCode();
return siga<sigb ? -1 : (siga>sigb ? 1 : 0);
} catch(CoreException ce) {
CCorePlugin.log(ce);
} catch(DOMException de) {
CCorePlugin.log(de);
}
return 0;
}

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import java.util.Comparator;
import java.util.TreeSet;
import org.eclipse.cdt.core.CCorePlugin;
@ -17,7 +18,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.CIndex;
import org.eclipse.cdt.internal.core.index.DefaultFragmentBindingComparator;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFragmentBindingComparator;
import org.eclipse.core.runtime.CoreException;
/**
@ -25,9 +29,16 @@ import org.eclipse.core.runtime.CoreException;
*/
public abstract class AbstractCompositeFactory implements ICompositesFactory {
protected IIndex index;
private Comparator fragmentComparator;
public AbstractCompositeFactory(IIndex index) {
this.index = index;
this.index= index;
this.fragmentComparator= new FragmentBindingComparator(
new IIndexFragmentBindingComparator[] {
new PDOMFragmentBindingComparator(),
new DefaultFragmentBindingComparator()
}
);
}
/*
@ -54,14 +65,14 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
* @param fragmentBindings
* @return an array of unique bindings
*/
protected static IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) {
TreeSet ts = new TreeSet();
protected IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) {
TreeSet ts = new TreeSet(fragmentComparator);
for(int i=0; i<fragmentBindings.length; i++)
for(int j=0; j<fragmentBindings[i].length; j++)
ts.add(fragmentBindings[i][j]);
return (IIndexFragmentBinding[]) ts.toArray(new IIndexFragmentBinding[ts.size()]);
}
/**
* Convenience method for finding a binding with a definition in the specified index
* context, which is equivalent to the specified binding
@ -85,4 +96,27 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
}
throw new CompositingNotImplementedError();
}
private static class FragmentBindingComparator implements Comparator {
private IIndexFragmentBindingComparator[] comparators;
FragmentBindingComparator(IIndexFragmentBindingComparator[] comparators) {
this.comparators= comparators;
}
public int compare(Object o1, Object o2) {
if(o1 instanceof IIndexFragmentBinding && o2 instanceof IIndexFragmentBinding) {
IIndexFragmentBinding f1= (IIndexFragmentBinding) o1;
IIndexFragmentBinding f2= (IIndexFragmentBinding) o2;
for(int i=0; i<comparators.length; i++) {
int cmp= comparators[i].compare(f1, f2);
if(cmp!=Integer.MIN_VALUE) {
return cmp;
}
}
}
throw new IllegalArgumentException();
}
}
}

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -246,6 +247,21 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return getFirstDefinition()!=null;
}
/**
* Compares two binding fully qualified names. If b0 has
* less segments than b1 then -1 is returned, if b0 has
* more segments than b1 then 1 is returned. If the segment
* lengths are equal then comparison is lexographical on each
* component name, beginning with the most nested name and working
* outward. The first non-zero comparison is returned as the result.
* @param b0
* @param b1
* @return<ul><li> -1 if b0 &lt; b1
* <li> 0 if b0 == b1
* <li> 1 if b0 &gt; b1
* </ul>
* @throws CoreException
*/
private static int comparePDOMBindingQNs(PDOMBinding b0, PDOMBinding b1) {
try {
int cmp = 0;
@ -267,40 +283,31 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
}
}
public int compareTo(Object other) {
if(other==null)
return 1;
if(other instanceof IBinding) {
if(!(other instanceof PDOMBinding)) {
try {
other= getLinkageImpl().adaptBinding((IBinding)other);
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
}
if(other instanceof PDOMBinding) {
PDOMBinding otherBinding = (PDOMBinding) other;
int cmp = comparePDOMBindingQNs(this, otherBinding);
if(cmp==0) {
int t1 = getNodeType();
int t2 = otherBinding.getNodeType();
return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
}
return cmp;
}
if(other==null)
return 1;
throw new PDOMNotImplementedError(""+other); //$NON-NLS-1$
/**
* Compares two PDOMBinding objects in accordance with
* {@link IIndexFragmentBindingComparator#compare(IIndexFragmentBinding, IIndexFragmentBinding)}
* @param other
* @return
*/
public int pdomCompareTo(PDOMBinding other) {
PDOMBinding otherBinding = (PDOMBinding) other;
int cmp = comparePDOMBindingQNs(this, otherBinding);
if(cmp==0) {
int t1 = getNodeType();
int t2 = otherBinding.getNodeType();
return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
}
return -1;
return cmp;
}
public boolean equals(Object o) {
if (o instanceof PDOMNode) {
PDOMNode node= (PDOMNode) o;
return pdom==node.pdom && record == node.record;
}
return compareTo(o)==0;
/**
* Returns whether pdomCompareTo returns zero
*/
public final boolean pdomEquals(PDOMBinding other) {
return pdomCompareTo(other)==0;
}
}
public final int getBindingConstant() {
return getNodeType();
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
/**
* {@link IIndexFragmentBindingComparator} suitable for comparing two PDOMBindings
*
*/
public class PDOMFragmentBindingComparator implements IIndexFragmentBindingComparator {
public int compare(IIndexFragmentBinding a, IIndexFragmentBinding b) {
if(a instanceof PDOMBinding && b instanceof PDOMBinding) {
return ((PDOMBinding) a).pdomCompareTo((PDOMBinding) b);
}
return Integer.MIN_VALUE;
}
}

View file

@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -57,7 +58,7 @@ import org.eclipse.core.runtime.CoreException;
* This class represents a collection of symbols that can be linked together at
* link time. These are generally global symbols specific to a given language.
*/
public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage {
public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage, IIndexBindingConstants {
// record offsets
private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0;
@ -68,12 +69,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
// node types
protected static final int LINKAGE= 0; // special one for myself
static final int POINTER_TYPE= 1;
static final int ARRAY_TYPE= 2;
static final int QUALIFIER_TYPE= 3;
static final int FILE_LOCAL_SCOPE_TYPE= 4;
protected static final int LAST_NODE_TYPE = FILE_LOCAL_SCOPE_TYPE;
public PDOMLinkage(PDOM pdom, int record) {
super(pdom, record);

View file

@ -67,7 +67,7 @@ public abstract class PDOMNode implements IPDOMNode {
return record;
}
public boolean equals(Object obj) {
public final boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof PDOMNode) {
@ -78,7 +78,7 @@ public abstract class PDOMNode implements IPDOMNode {
return super.equals(obj);
}
public int hashCode() {
public final int hashCode() {
return System.identityHashCode(pdom) + 41*record;
}

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
@ -43,7 +44,7 @@ import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*/
class PDOMCLinkage extends PDOMLinkage {
class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
public PDOMCLinkage(PDOM pdom, int record) {
super(pdom, record);
@ -60,17 +61,6 @@ class PDOMCLinkage extends PDOMLinkage {
public String getID() {
return C_LINKAGE_ID;
}
public static final int CVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1;
public static final int CFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2;
public static final int CSTRUCTURE = PDOMLinkage.LAST_NODE_TYPE + 3;
public static final int CFIELD = PDOMLinkage.LAST_NODE_TYPE + 4;
public static final int CENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 5;
public static final int CENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 6;
public static final int CTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 7;
public static final int CPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 8;
public static final int CBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 9;
public static final int CFUNCTIONTYPE = PDOMLinkage.LAST_NODE_TYPE + 10;
public PDOMBinding addBinding(IBinding binding) throws CoreException {
PDOMBinding pdomBinding = adaptBinding(binding);

View file

@ -173,4 +173,8 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
public boolean isGloballyQualified() throws DOMException {
throw new PDOMNotImplementedError();
}
public int getBindingConstant() {
return getNodeType();
}
}

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
@ -107,7 +108,7 @@ public class CPPFindBinding extends FindBinding {
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding) throws CoreException {
Integer memento = null;
try {
memento = PDOMCPPOverloaderUtil.getSignatureMemento(binding);
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {
@ -119,7 +120,7 @@ public class CPPFindBinding extends FindBinding {
public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding) throws CoreException {
Integer memento = null;
try {
memento = PDOMCPPOverloaderUtil.getSignatureMemento(binding);
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {

View file

@ -28,9 +28,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
@ -59,7 +61,7 @@ class PDOMCPPClassTemplatePartialSpecialization extends
primary.addPartial(this);
try {
Integer memento = PDOMCPPOverloaderUtil.getSignatureMemento(partial);
Integer memento = IndexCPPSignatureUtil.getSignatureMemento(partial);
pdom.getDB().putInt(record + SIGNATURE_MEMENTO, memento != null ? memento.intValue() : 0);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
@ -140,8 +142,8 @@ class PDOMCPPClassTemplatePartialSpecialization extends
}
}
public int compareTo(Object other) {
int cmp = super.compareTo(other);
public int pdomCompareTo(PDOMBinding other) {
int cmp = super.pdomCompareTo(other);
if(cmp==0) {
if(other instanceof PDOMCPPClassTemplatePartialSpecialization) {
try {

View file

@ -23,9 +23,11 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
@ -75,7 +77,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
super(pdom, parent, function.getNameCharArray());
Database db = pdom.getDB();
try {
Integer memento = PDOMCPPOverloaderUtil.getSignatureMemento(function);
Integer memento = IndexCPPSignatureUtil.getSignatureMemento(function);
pdom.getDB().putInt(record + SIGNATURE_MEMENTO, memento != null ? memento.intValue() : 0);
if(setTypes) {
@ -200,9 +202,9 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
throw new PDOMNotImplementedError();
}
public int compareTo(Object other) {
int cmp= super.compareTo(other);
return cmp==0 ? PDOMCPPOverloaderUtil.compare(this, other) : cmp;
public int pdomCompareTo(PDOMBinding other) {
int cmp= super.pdomCompareTo(other);
return cmp==0 ? compareSignatures(this, other) : cmp;
}
public String toString() {
@ -214,4 +216,20 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
}
return result.toString();
}
protected static int compareSignatures(IPDOMOverloader a, Object b) {
if(b instanceof IPDOMOverloader) {
IPDOMOverloader bb= (IPDOMOverloader) b;
try {
int mySM = a.getSignatureMemento();
int otherSM = bb.getSignatureMemento();
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
} else {
throw new PDOMNotImplementedError(b.getClass().toString());
}
return 0;
}
}

View file

@ -182,8 +182,8 @@ class PDOMCPPFunctionInstance extends PDOMCPPInstance implements ICPPFunction {
return false;
}
public int compareTo(Object other) {
int cmp= super.compareTo(other);
return cmp==0 ? PDOMCPPOverloaderUtil.compare(this, other) : cmp;
public int pdomCompareTo(PDOMBinding other) {
int cmp= super.pdomCompareTo(other);
return cmp==0 ? PDOMCPPFunction.compareSignatures(this, other) : cmp;
}
}

View file

@ -195,8 +195,8 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
return false;
}
public int compareTo(Object other) {
int cmp= super.compareTo(other);
return cmp==0 ? PDOMCPPOverloaderUtil.compare(this, other) : cmp;
public int pdomCompareTo(PDOMBinding other) {
int cmp= super.pdomCompareTo(other);
return cmp==0 ? PDOMCPPFunction.compareSignatures(this, other) : cmp;
}
}

View file

@ -56,6 +56,7 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
@ -70,7 +71,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer
*
*/
class PDOMCPPLinkage extends PDOMLinkage {
class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
public PDOMCPPLinkage(PDOM pdom, int record) {
super(pdom, record);
}
@ -92,45 +93,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
}
// Binding types
public static final int CPPVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1;
public static final int CPPFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2;
public static final int CPPCLASSTYPE = PDOMLinkage.LAST_NODE_TYPE + 3;
public static final int CPPFIELD = PDOMLinkage.LAST_NODE_TYPE + 4;
public static final int CPPMETHOD = PDOMLinkage.LAST_NODE_TYPE + 5;
public static final int CPPNAMESPACE = PDOMLinkage.LAST_NODE_TYPE + 6;
public static final int CPPNAMESPACEALIAS = PDOMLinkage.LAST_NODE_TYPE + 7;
public static final int CPPBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 8;
public static final int CPPPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 9;
public static final int CPPENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 10;
public static final int CPPENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 11;
public static final int CPPTYPEDEF = PDOMLinkage.LAST_NODE_TYPE + 12;
public static final int CPP_POINTER_TO_MEMBER_TYPE= PDOMLinkage.LAST_NODE_TYPE + 13;
public static final int CPP_CONSTRUCTOR= PDOMLinkage.LAST_NODE_TYPE + 14;
public static final int CPP_REFERENCE_TYPE= PDOMLinkage.LAST_NODE_TYPE + 15;
public static final int CPP_FUNCTION_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 16;
public static final int CPP_METHOD_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 17;
public static final int CPP_CONSTRUCTOR_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 18;
public static final int CPP_CLASS_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 19;
public static final int CPP_CLASS_TEMPLATE_PARTIAL_SPEC= PDOMLinkage.LAST_NODE_TYPE + 20;
public static final int CPP_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 21;
public static final int CPP_METHOD_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 22;
public static final int CPP_CONSTRUCTOR_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 23;
public static final int CPP_DEFERRED_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 24;
public static final int CPP_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 25;
public static final int CPP_DEFERRED_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 26;
public static final int CPP_PARAMETER_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 27;
public static final int CPP_FIELD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 28;
public static final int CPP_FUNCTION_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 29;
public static final int CPP_METHOD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 30;
public static final int CPP_CONSTRUCTOR_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 31;
public static final int CPP_CLASS_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 32;
public static final int CPP_FUNCTION_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 33;
public static final int CPP_METHOD_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 34;
public static final int CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 35;
public static final int CPP_CLASS_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 36;
public static final int CPP_TYPEDEF_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 37;
public static final int CPP_TEMPLATE_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 38;
public static final int CPP_FUNCTION_TYPE= PDOMLinkage.LAST_NODE_TYPE + 39;
private class ConfigureTemplate implements Runnable {
ICPPTemplateDefinition template;

View file

@ -229,4 +229,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IIndexFra
public boolean isFileLocal() throws CoreException {
return true;
}
public int getBindingConstant() {
return getNodeType();
}
}

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
@ -73,7 +74,7 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements
}
}
try {
Integer memento = PDOMCPPOverloaderUtil.getSignatureMemento(spec);
Integer memento = IndexCPPSignatureUtil.getSignatureMemento(spec);
pdom.getDB().putInt(record + SIGNATURE_MEMENTO, memento != null ? memento.intValue() : 0);
} catch (DOMException e) {
}