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
* Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Dec 13, 2004
*/
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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
@ -35,16 +32,19 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
this.isVolatile = isVolatile;
}
public boolean isSameType( IType o ){
if( o instanceof ITypedef || o instanceof IIndexType)
return o.isSameType( this );
if( !( o instanceof CPPQualifierType ) )
return false;
CPPQualifierType pt = (CPPQualifierType) o;
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
return type.isSameType( pt.getType() );
return false;
public boolean isSameType(IType o) {
if (o instanceof ITypedef || o instanceof IIndexType)
return o.isSameType(this);
if (!(o instanceof IQualifierType))
return false;
IQualifierType pt = (IQualifierType) o;
try {
if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile())
return type.isSameType(pt.getType());
} catch (DOMException e) {
}
return false;
}
/* (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.CPPPointerToMemberType;
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.CPPTemplateTemplateParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization;
@ -936,22 +937,33 @@ public class CPPTemplates {
}
if (type instanceof ITypeContainer) {
IType temp = ((ITypeContainer) type).getType();
IType newType = instantiateType(temp, argMap, within);
IType nestedType = ((ITypeContainer) type).getType();
IType newNestedType = instantiateType(nestedType, argMap, within);
if (type instanceof ICPPPointerToMemberType) {
ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) type;
IType memberOfClass = ptm.getMemberOfClass();
IType newMemberOfClass = instantiateType(memberOfClass, argMap, within);
if ((newType != temp || newMemberOfClass != memberOfClass) &&
if ((newNestedType != nestedType || newMemberOfClass != memberOfClass) &&
newMemberOfClass instanceof ICPPClassType) {
return new CPPPointerToMemberType(newType, (ICPPClassType) newMemberOfClass,
return new CPPPointerToMemberType(newNestedType, (ICPPClassType) newMemberOfClass,
ptm.isConst(), ptm.isVolatile());
}
}
if (newType != temp) {
temp = (IType) type.clone();
((ITypeContainer) temp).setType(newType);
return temp;
if (newNestedType != nestedType) {
// bug 249085 make sure not to add unnecessary qualifications
if (type instanceof IQualifierType) {
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;
}