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

Instantiation adds superfluous qualifications, bug 249085.

This commit is contained in:
Markus Schorn 2008-10-03 16:20:51 +00:00
parent 86e44ca5fb
commit 4f5b949a8c
2 changed files with 34 additions and 22 deletions

View file

@ -9,12 +9,9 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Dec 13, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IQualifierType;
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.ITypedef;
@ -35,16 +32,19 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
this.isVolatile = isVolatile; this.isVolatile = isVolatile;
} }
public boolean isSameType( IType o ){ public boolean isSameType(IType o) {
if( o instanceof ITypedef || o instanceof IIndexType) if (o instanceof ITypedef || o instanceof IIndexType)
return o.isSameType( this ); return o.isSameType(this);
if( !( o instanceof CPPQualifierType ) ) if (!(o instanceof IQualifierType))
return false; return false;
CPPQualifierType pt = (CPPQualifierType) o; IQualifierType pt = (IQualifierType) o;
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() ) try {
return type.isSameType( pt.getType() ); if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile())
return false; return type.isSameType(pt.getType());
} catch (DOMException e) {
}
return false;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -112,6 +112,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodTemplateSpecializat
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization;
@ -936,22 +937,33 @@ public class CPPTemplates {
} }
if (type instanceof ITypeContainer) { if (type instanceof ITypeContainer) {
IType temp = ((ITypeContainer) type).getType(); IType nestedType = ((ITypeContainer) type).getType();
IType newType = instantiateType(temp, argMap, within); IType newNestedType = instantiateType(nestedType, argMap, within);
if (type instanceof ICPPPointerToMemberType) { if (type instanceof ICPPPointerToMemberType) {
ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) type; ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) type;
IType memberOfClass = ptm.getMemberOfClass(); IType memberOfClass = ptm.getMemberOfClass();
IType newMemberOfClass = instantiateType(memberOfClass, argMap, within); IType newMemberOfClass = instantiateType(memberOfClass, argMap, within);
if ((newType != temp || newMemberOfClass != memberOfClass) && if ((newNestedType != nestedType || newMemberOfClass != memberOfClass) &&
newMemberOfClass instanceof ICPPClassType) { newMemberOfClass instanceof ICPPClassType) {
return new CPPPointerToMemberType(newType, (ICPPClassType) newMemberOfClass, return new CPPPointerToMemberType(newNestedType, (ICPPClassType) newMemberOfClass,
ptm.isConst(), ptm.isVolatile()); ptm.isConst(), ptm.isVolatile());
} }
} }
if (newType != temp) { if (newNestedType != nestedType) {
temp = (IType) type.clone(); // bug 249085 make sure not to add unnecessary qualifications
((ITypeContainer) temp).setType(newType); if (type instanceof IQualifierType) {
return temp; IQualifierType qt1= (IQualifierType) type;
if (newNestedType instanceof IQualifierType) {
IQualifierType qt2= (IQualifierType) newNestedType;
return new CPPQualifierType(qt2.getType(), qt1.isConst() || qt2.isConst(), qt1.isVolatile() || qt2.isVolatile());
} else if (newNestedType instanceof IPointerType) {
IPointerType pt2= (IPointerType) newNestedType;
return new CPPPointerType(pt2.getType(), qt1.isConst() || pt2.isConst(), qt1.isVolatile() || pt2.isVolatile());
}
}
type = (IType) type.clone();
((ITypeContainer) type).setType(newNestedType);
return type;
} }
return type; return type;
} }