1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 91577. Do a IType.isSameType instead of IType.equals

This commit is contained in:
Andrew Niefer 2005-04-19 18:57:46 +00:00
parent 1da410d13a
commit 12c064978c
32 changed files with 248 additions and 67 deletions

View file

@ -472,7 +472,7 @@ public class CompleteParser2Tests extends TestCase {
assertSame( ((IQualifierType)rt.getType()).getType(), B ); assertSame( ((IQualifierType)rt.getType()).getType(), B );
IType pt = ftype.getParameterTypes()[0]; IType pt = ftype.getParameterTypes()[0];
assertEquals( p.getType(), pt ); assertTrue( p.getType().isSameType( pt ) );
assertTrue( pt instanceof IPointerType ); assertTrue( pt instanceof IPointerType );
assertSame( ((IPointerType) pt).getType(), A ); assertSame( ((IPointerType) pt).getType(), A );
} }

View file

@ -16,4 +16,10 @@ package org.eclipse.cdt.core.dom.ast;
public interface IType extends Cloneable { public interface IType extends Cloneable {
public Object clone(); public Object clone();
/**
* is the given type the same as this type?
* @param type
* @return
*/
public boolean isSameType( IType type );
} }

View file

@ -180,4 +180,11 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
public boolean isFullyCached() throws DOMException { public boolean isFullyCached() throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
return type == this;
}
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType; import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -29,7 +30,11 @@ public class CArrayType implements ICArrayType, ITypeContainer {
this.type = type; this.type = type;
} }
public boolean equals(Object obj) { public boolean isSameType(IType obj) {
if( obj == this )
return true;
if( obj instanceof ITypedef )
return obj.isSameType( this );
if( obj instanceof ICArrayType ){ if( obj instanceof ICArrayType ){
ICArrayType at = (ICArrayType) obj; ICArrayType at = (ICArrayType) obj;
try { try {
@ -39,7 +44,7 @@ public class CArrayType implements ICArrayType, ITypeContainer {
if( isVolatile() != at.isVolatile() ) return false; if( isVolatile() != at.isVolatile() ) return false;
if( isVariableLength() != at.isVariableLength() ) return false; if( isVariableLength() != at.isVariableLength() ) return false;
return at.getType().equals( type ); return at.getType().isSameType( type );
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
@ -69,10 +70,12 @@ public class CBasicType implements ICBasicType {
return sds.isLongLong(); return sds.isLongLong();
} }
/* (non-Javadoc) public boolean isSameType(IType obj) {
* @see java.lang.Object#equals(java.lang.Object) if( obj == this )
*/ return true;
public boolean equals(Object obj) { if( obj instanceof ITypedef )
return obj.isSameType( this );
if (!(obj instanceof CBasicType)) return false; if (!(obj instanceof CBasicType)) return false;
CBasicType cObj = (CBasicType)obj; CBasicType cObj = (CBasicType)obj;

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
@ -142,4 +143,16 @@ public class CEnumeration implements IEnumeration {
public void addDefinition( IASTName name ) { public void addDefinition( IASTName name ) {
definition = name; definition = name;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return type.isSameType( this );
return false;
}
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
/** /**
* @author dsteffle * @author dsteffle
@ -30,7 +31,11 @@ public class CFunctionType implements IFunctionType {
this.parameters = types; this.parameters = types;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( o == this )
return true;
if( o instanceof ITypedef )
return o.isSameType( this );
if( o instanceof IFunctionType ){ if( o instanceof IFunctionType ){
IFunctionType ft = (IFunctionType) o; IFunctionType ft = (IFunctionType) o;
IType [] fps; IType [] fps;
@ -42,13 +47,13 @@ public class CFunctionType implements IFunctionType {
if( fps.length != parameters.length ) if( fps.length != parameters.length )
return false; return false;
try { try {
if( ! returnType.equals( ft.getReturnType() ) ) if( ! returnType.isSameType( ft.getReturnType() ) )
return false; return false;
} catch ( DOMException e1 ) { } catch ( DOMException e1 ) {
return false; return false;
} }
for( int i = 0; i < parameters.length; i++ ) for( int i = 0; i < parameters.length; i++ )
if( ! parameters[i].equals( fps[i] ) ) if( ! parameters[i].isSameType( fps[i] ) )
return false; return false;
return true; return true;
} }

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType; import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -30,7 +31,12 @@ public class CPointerType implements ICPointerType, ITypeContainer {
this.nextType = next; this.nextType = next;
} }
public boolean equals( Object obj ){ public boolean isSameType( IType obj ){
if( obj == this )
return true;
if( obj instanceof ITypedef )
return obj.isSameType( this );
if( obj instanceof ICPointerType ){ if( obj instanceof ICPointerType ){
ICPointerType pt = (ICPointerType) obj; ICPointerType pt = (ICPointerType) obj;
try { try {
@ -38,7 +44,7 @@ public class CPointerType implements ICPointerType, ITypeContainer {
if( isRestrict() != pt.isRestrict() ) return false; if( isRestrict() != pt.isRestrict() ) return false;
if( isVolatile() != pt.isVolatile() ) return false; if( isVolatile() != pt.isVolatile() ) return false;
return pt.getType().equals( nextType ); return pt.getType().isSameType( nextType );
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType; import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -72,4 +73,21 @@ public class CQualifiedPointerType implements ICPointerType, ITypeContainer {
} }
return t; return t;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return type.isSameType( this );
if( type instanceof CQualifiedPointerType ){
CQualifiedPointerType qual = (CQualifiedPointerType) type;
if( qual.isConst() == isConst() && qual.isRestrict() == isRestrict() && qual.isVolatile() == isVolatile() )
return getType().isSameType( qual.getType() );
}
return false;
}
} }

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
@ -38,7 +39,12 @@ public class CQualifierType implements ICQualifierType, ITypeContainer {
this.declSpec = declSpec; this.declSpec = declSpec;
} }
public boolean equals( Object obj ){ public boolean isSameType( IType obj ){
if( obj == this )
return true;
if( obj instanceof ITypedef )
return obj.isSameType( this );
if( obj instanceof ICQualifierType ){ if( obj instanceof ICQualifierType ){
ICQualifierType qt = (ICQualifierType) obj; ICQualifierType qt = (ICQualifierType) obj;
try { try {
@ -46,7 +52,7 @@ public class CQualifierType implements ICQualifierType, ITypeContainer {
if( isRestrict() != qt.isRestrict() ) return false; if( isRestrict() != qt.isRestrict() ) return false;
if( isVolatile() != qt.isVolatile() ) return false; if( isVolatile() != qt.isVolatile() ) return false;
return qt.getType().equals( getType() ); return qt.getType().isSameType( getType() );
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
@ -207,4 +208,15 @@ public class CStructure implements ICompositeType, ICInternalBinding {
definition = compositeTypeSpec.getName(); definition = compositeTypeSpec.getName();
compositeTypeSpec.getName().setBinding( this ); compositeTypeSpec.getName().setBinding( this );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return type.isSameType( this );
return false;
}
} }

View file

@ -11,6 +11,7 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -74,4 +75,26 @@ public class CTypeDef implements ITypedef, ITypeContainer {
} }
return t; return t;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType t ) {
if( t == this )
return true;
if( t instanceof ITypedef )
try {
IType temp = getType();
if( temp != null )
return temp.isSameType( ((ITypedef)t).getType());
return false;
} catch ( DOMException e ) {
return false;
}
IType temp = getType();
if( temp != null )
return temp.isSameType( t );
return false;
}
} }

View file

@ -747,7 +747,7 @@ public class CVisitor {
t2 = ((IVariable)binding).getType(); t2 = ((IVariable)binding).getType();
} catch ( DOMException e1 ) { } catch ( DOMException e1 ) {
} }
if( t1 != null && t2 != null && t1.equals( t2 ) ){ if( t1 != null && t2 != null && t1.isSameType( t2 ) ){
if( binding instanceof CVariable ) if( binding instanceof CVariable )
((CVariable)binding).addDeclaration( name ); ((CVariable)binding).addDeclaration( name );
} else { } else {

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/** /**
@ -44,10 +45,15 @@ public class CPPArrayType implements IArrayType, ITypeContainer {
this.type = t; this.type = t;
} }
public boolean equals(Object obj) { public boolean isSameType(IType obj) {
if( obj == this )
return true;
if( obj instanceof ITypedef )
return ((ITypedef)obj).isSameType( this );
if( obj instanceof IArrayType ){ if( obj instanceof IArrayType ){
try { try {
return ((IArrayType) obj).getType().equals( type ); return ((IArrayType) obj).getType().isSameType( type );
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }

View file

@ -34,9 +34,9 @@ public class CPPBasicType implements ICPPBasicType {
qualifierBits = bits; qualifierBits = bits;
} }
public boolean equals( Object object ) { public boolean isSameType( IType object ) {
if( object instanceof CPPTypedef ) if( object instanceof CPPTypedef )
return object.equals( this ); return object.isSameType( this );
if( !(object instanceof CPPBasicType) ) if( !(object instanceof CPPBasicType) )
return false; return false;

View file

@ -19,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@ -192,4 +194,15 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
public void addDefinition(IASTNode node) { public void addDefinition(IASTNode node) {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return ((ITypedef)type).isSameType( this );
return false;
}
} }

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
@ -235,4 +236,15 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
public ICPPMethod[] getConversionOperators() { public ICPPMethod[] getConversionOperators() {
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return ((ITypedef)type).isSameType( this );
return false;
}
} }

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
@ -98,15 +99,15 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType {
public Object clone() { public Object clone() {
return ((ICPPClassType)getBinding()).clone(); return ((ICPPClassType)getBinding()).clone();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalClassType#getConversionOperators()
*/
public ICPPMethod[] getConversionOperators() { public ICPPMethod[] getConversionOperators() {
IBinding binding = getBinding(); IBinding binding = getBinding();
if( binding instanceof ICPPInternalClassType ) if( binding instanceof ICPPInternalClassType )
return ((ICPPInternalClassType)binding).getConversionOperators(); return ((ICPPInternalClassType)binding).getConversionOperators();
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
} }
public boolean isSameType( IType type ) {
return ((ICPPClassType)getBinding()).isSameType( type );
}
} }
public static class CPPClassTypeProblem extends ProblemBinding implements ICPPClassType{ public static class CPPClassTypeProblem extends ProblemBinding implements ICPPClassType{
public CPPClassTypeProblem( IASTNode node, int id, char[] arg ) { public CPPClassTypeProblem( IASTNode node, int id, char[] arg ) {
@ -692,4 +693,15 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType {
public ICPPDelegate createDelegate( IASTName name ) { public ICPPDelegate createDelegate( IASTName name ) {
return new CPPClassTypeDelegate( name, this ); return new CPPClassTypeDelegate( name, this );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return ((ITypedef)type).isSameType( this );
return false;
}
} }

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
@ -40,6 +41,9 @@ public class CPPEnumeration implements IEnumeration, ICPPInternalBinding, ICPPBi
public Object clone() { public Object clone() {
return ((IEnumeration)getBinding()).clone(); return ((IEnumeration)getBinding()).clone();
} }
public boolean isSameType( IType type ) {
return ((IEnumeration)getBinding()).isSameType( type );
}
} }
private IASTName enumName; private IASTName enumName;
@ -165,4 +169,15 @@ public class CPPEnumeration implements IEnumeration, ICPPInternalBinding, ICPPBi
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return ((ITypedef)type).isSameType( this );
return false;
}
} }

View file

@ -17,6 +17,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
/** /**
* @author aniefer * @author aniefer
@ -34,7 +35,9 @@ public class CPPFunctionType implements IFunctionType {
this.parameters = types; this.parameters = types;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( o instanceof ITypedef )
return o.isSameType( this );
if( o instanceof IFunctionType ){ if( o instanceof IFunctionType ){
IFunctionType ft = (IFunctionType) o; IFunctionType ft = (IFunctionType) o;
IType [] fps; IType [] fps;
@ -50,13 +53,13 @@ public class CPPFunctionType implements IFunctionType {
//constructors & destructors have null return type //constructors & destructors have null return type
if( ( returnType == null ) ^ ( ft.getReturnType() == null ) ) if( ( returnType == null ) ^ ( ft.getReturnType() == null ) )
return false; return false;
else if( returnType != null && ! returnType.equals( ft.getReturnType() ) ) else if( returnType != null && ! returnType.isSameType( ft.getReturnType() ) )
return false; return false;
} catch ( DOMException e1 ) { } catch ( DOMException e1 ) {
return false; return false;
} }
for( int i = 0; i < parameters.length; i++ ) for( int i = 0; i < parameters.length; i++ )
if( ! parameters[i].equals( fps[i] ) ) if( ! parameters[i].isSameType( fps[i] ) )
return false; return false;
return true; return true;
} }

View file

@ -198,7 +198,7 @@ public class CPPImplicitMethod extends CPPMethod {
if( ps.length == params.length ){ if( ps.length == params.length ){
int idx = 0; int idx = 0;
for( ; idx < ps.length && ps[idx] != null; idx++ ){ for( ; idx < ps.length && ps[idx] != null; idx++ ){
if( !ps[idx].equals(params[idx]) ) if( !ps[idx].isSameType(params[idx]) )
break; break;
} }
if( idx == ps.length ){ if( idx == ps.length ){

View file

@ -39,22 +39,17 @@ public class CPPPointerToMemberType extends CPPPointerType implements
this.operator = operator; this.operator = operator;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( !super.equals( o ) ) if( !super.isSameType( o ) )
return false; return false;
if( !( o instanceof CPPPointerToMemberType ) ) if( !( o instanceof CPPPointerToMemberType ) )
return false; return false;
if( o instanceof ITypedef )
return o.equals( this );
CPPPointerToMemberType pt = (CPPPointerToMemberType) o; CPPPointerToMemberType pt = (CPPPointerToMemberType) o;
IBinding cls = pt.getMemberOfClass(); ICPPClassType cls = pt.getMemberOfClass();
if( cls != null ) if( cls != null )
return cls.equals( getMemberOfClass() ); return cls.isSameType( getMemberOfClass() );
return false; return false;
} }

View file

@ -49,9 +49,12 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
this.type = type; this.type = type;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( o == this )
return true;
if( o instanceof ITypedef ) if( o instanceof ITypedef )
return o.equals( this ); return ((ITypedef)o).isSameType( this );
if( !( o instanceof CPPPointerType ) ) if( !( o instanceof CPPPointerType ) )
return false; return false;
@ -60,7 +63,7 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
CPPPointerType pt = (CPPPointerType) o; CPPPointerType pt = (CPPPointerType) o;
if( isConst == pt.isConst && isVolatile == pt.isVolatile ) if( isConst == pt.isConst && isVolatile == pt.isVolatile )
return type.equals( pt.getType() ); return type.isSameType( pt.getType() );
return false; return false;
} }

View file

@ -34,15 +34,15 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
this.isVolatile = isVolatile; this.isVolatile = isVolatile;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( o instanceof ITypedef ) if( o instanceof ITypedef )
return o.equals( this ); return o.isSameType( this );
if( !( o instanceof CPPQualifierType ) ) if( !( o instanceof CPPQualifierType ) )
return false; return false;
CPPQualifierType pt = (CPPQualifierType) o; CPPQualifierType pt = (CPPQualifierType) o;
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() ) if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
return type.equals( pt.getType() ); return type.isSameType( pt.getType() );
return false; return false;
} }

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -43,13 +44,18 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer {
type = t; type = t;
} }
public boolean equals(Object obj) { public boolean isSameType(IType obj) {
if( obj == this )
return true;
if( obj instanceof ITypedef )
return ((ITypedef)obj).isSameType( this );
if( type == null ) if( type == null )
return (obj == null); return (obj == null);
if( obj instanceof ICPPReferenceType ){ if( obj instanceof ICPPReferenceType ){
try { try {
return type.equals( ((ICPPReferenceType) obj).getType() ); return type.isSameType( ((ICPPReferenceType) obj).getType() );
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }

View file

@ -1761,7 +1761,7 @@ public class CPPSemantics {
if( varArgs ){ if( varArgs ){
cost = new Cost( source, null ); cost = new Cost( source, null );
cost.rank = Cost.ELLIPSIS_CONVERSION; cost.rank = Cost.ELLIPSIS_CONVERSION;
} else if( source.equals( target ) ){ } else if( source.isSameType( target ) ){
cost = new Cost( source, target ); cost = new Cost( source, target );
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost cost.rank = Cost.IDENTITY_RANK; //exact match, no cost
} else { } else {
@ -1872,7 +1872,7 @@ public class CPPSemantics {
} catch ( DOMException e ) { } catch ( DOMException e ) {
ft = e.getProblem(); ft = e.getProblem();
} }
if( type.equals( ft ) ){ if( type.isSameType( ft ) ){
if( result == null ) if( result == null )
result = fn; result = fn;
else else
@ -2056,7 +2056,7 @@ public class CPPSemantics {
return cost; return cost;
} }
if( cost.source.equals( cost.target ) ){ if( cost.source.isSameType( cost.target ) ){
cost.rank = Cost.IDENTITY_RANK; cost.rank = Cost.IDENTITY_RANK;
return cost; return cost;
} }
@ -2077,7 +2077,7 @@ public class CPPSemantics {
return cost; return cost;
} }
if( s.equals( t ) ){ if( s.isSameType( t ) ){
return cost; return cost;
} }
@ -2326,7 +2326,7 @@ public class CPPSemantics {
IType src = getUltimateType( cost.source, true ); IType src = getUltimateType( cost.source, true );
IType trg = getUltimateType( cost.target, true ); IType trg = getUltimateType( cost.target, true );
if( src.equals( trg ) ) if( src.isSameType( trg ) )
return; return;
if( src instanceof IBasicType && trg instanceof IBasicType ){ if( src instanceof IBasicType && trg instanceof IBasicType ){
@ -2390,7 +2390,7 @@ public class CPPSemantics {
//derived class of B //derived class of B
ICPPPointerToMemberType spm = (ICPPPointerToMemberType) s; ICPPPointerToMemberType spm = (ICPPPointerToMemberType) s;
ICPPPointerToMemberType tpm = (ICPPPointerToMemberType) t; ICPPPointerToMemberType tpm = (ICPPPointerToMemberType) t;
if( spm.getType().equals( tpm.getType() ) ){ if( spm.getType().isSameType( tpm.getType() ) ){
temp = hasBaseClass( tpm.getMemberOfClass(), spm.getMemberOfClass(), false ); temp = hasBaseClass( tpm.getMemberOfClass(), spm.getMemberOfClass(), false );
cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK; cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
cost.conversion = ( temp > -1 ) ? temp : 0; cost.conversion = ( temp > -1 ) ? temp : 0;
@ -2565,7 +2565,7 @@ public class CPPSemantics {
IType type = null; IType type = null;
try { try {
type = function.getType(); type = function.getType();
return type.equals( CPPVisitor.createType( declarator ) ); return type.isSameType( CPPVisitor.createType( declarator ) );
} catch (DOMException e) { } catch (DOMException e) {
} }
return false; return false;

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
@ -140,4 +141,15 @@ public class CPPTemplateParameter implements ICPPTemplateParameter, IType, ICPPI
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType( IType type ) {
if( type == this )
return true;
if( type instanceof ITypedef )
return ((ITypedef)type).isSameType( this );
return false;
}
} }

View file

@ -356,7 +356,7 @@ public class CPPTemplates {
IType type = CPPVisitor.createType( (IASTDeclarator) parent ); IType type = CPPVisitor.createType( (IASTDeclarator) parent );
try { try {
IType ftype = ((ICPPFunction)definition).getType(); IType ftype = ((ICPPFunction)definition).getType();
if( ftype.equals( type ) ) if( ftype.isSameType( type ) )
result = true; result = true;
} catch (DOMException e) { } catch (DOMException e) {
} }
@ -370,7 +370,7 @@ public class CPPTemplates {
for (; i < args.length; i++) { for (; i < args.length; i++) {
IType t1 = CPPVisitor.createType( spec.getArguments()[i] ); IType t1 = CPPVisitor.createType( spec.getArguments()[i] );
IType t2 = CPPVisitor.createType( args[i] ); IType t2 = CPPVisitor.createType( args[i] );
if( t1 != null && t2 != null && t1.equals( t2 ) ) if( t1 != null && t2 != null && t1.isSameType( t2 ) )
continue; continue;
break; break;
} }

View file

@ -45,6 +45,9 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding
} }
return null; return null;
} }
public boolean isSameType( IType type ) {
return ((ITypedef)getBinding()).isSameType( type );
}
} }
private IASTName [] declarations = null; private IASTName [] declarations = null;
private IType type = null; private IType type = null;
@ -71,25 +74,22 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding
return declarations[0]; return declarations[0];
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( o == this ) if( o == this )
return true; return true;
if( o instanceof ITypedef ) if( o instanceof ITypedef )
try { try {
IType t = getType(); IType t = getType();
if( t != null ) if( t != null )
return t.equals( ((ITypedef)o).getType()); return t.isSameType( ((ITypedef)o).getType());
return false; return false;
} catch ( DOMException e ) { } catch ( DOMException e ) {
return false; return false;
} }
if( !( o instanceof IType ) )
return false;
IType t = getType(); IType t = getType();
if( t != null ) if( t != null )
return t.equals( o ); return t.isSameType( o );
return false; return false;
} }

View file

@ -485,7 +485,7 @@ public class CPPVisitor {
try { try {
IType t1 = ((ITypedef)binding).getType(); IType t1 = ((ITypedef)binding).getType();
IType t2 = createType( declarator ); IType t2 = createType( declarator );
if( t1 != null && t2 != null && t1.equals( t2 ) ){ if( t1 != null && t2 != null && t1.isSameType( t2 ) ){
((ICPPInternalBinding)binding).addDeclaration( name ); ((ICPPInternalBinding)binding).addDeclaration( name );
return binding; return binding;
} }
@ -533,7 +533,7 @@ public class CPPVisitor {
} }
} }
if( t1 != null && t2 != null ){ if( t1 != null && t2 != null ){
if( t1.equals( t2 ) ){ if( t1.isSameType( t2 ) ){
if( binding instanceof ICPPInternalBinding ) if( binding instanceof ICPPInternalBinding )
((ICPPInternalBinding)binding).addDeclaration( name ); ((ICPPInternalBinding)binding).addDeclaration( name );
} else { } else {

View file

@ -41,8 +41,8 @@ public class GPPPointerToMemberType extends CPPPointerToMemberType implements
return isRestrict; return isRestrict;
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( !super.equals( o ) ) return false; if( !super.isSameType( o ) ) return false;
if( o instanceof IGPPPointerToMemberType ){ if( o instanceof IGPPPointerToMemberType ){
return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict()); return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict());

View file

@ -52,8 +52,8 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType {
} }
public boolean equals( Object o ){ public boolean isSameType( IType o ){
if( !super.equals( o ) ) return false; if( !super.isSameType( o ) ) return false;
if( o instanceof IGPPPointerType ){ if( o instanceof IGPPPointerType ){
return (isRestrict == ((IGPPPointerType) o).isRestrict()); return (isRestrict == ((IGPPPointerType) o).isRestrict());