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

Bug 299911. Fixed IndexCPPTemplateResolutionTest.testSFINAE_a

This commit is contained in:
Sergey Prigogin 2012-08-14 11:47:43 -07:00
parent 18128ed115
commit 62ca84cc0e
6 changed files with 68 additions and 54 deletions

View file

@ -66,7 +66,7 @@ import org.osgi.framework.Bundle;
*/ */
public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
private static final boolean DEBUG= false; private static final boolean DEBUG= false;
private static final int INDEXER_TIMEOUT_SEC = 360; private static final int INDEXER_TIMEOUT_SEC = 1200;
protected ITestStrategy strategy; protected ITestStrategy strategy;
public void setStrategy(ITestStrategy strategy) { public void setStrategy(ITestStrategy strategy) {

View file

@ -18,7 +18,6 @@ import java.util.List;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
@ -1378,11 +1377,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// } // }
public void testClassInstanceWithNonTypeArgument_207871() throws Exception { public void testClassInstanceWithNonTypeArgument_207871() throws Exception {
ICPPTemplateInstance c256 = getBindingFromASTName("C<256>", 6, ICPPTemplateInstance.class, ICPPClassType.class); ICPPTemplateInstance c256 = getBindingFromASTName("C<256>", 6, ICPPTemplateInstance.class, ICPPClassType.class);
ObjectMap args= c256.getArgumentMap(); ICPPTemplateParameterMap paramMap = c256.getTemplateParameterMap();
assertEquals(1, args.size()); assertEquals(1, paramMap.getAllParameterPositions().length);
assertInstance(args.keyAt(0), ICPPTemplateNonTypeParameter.class); ICPPTemplateArgument arg = paramMap.getArgument(0);
ICPPBasicType bt= assertInstance(args.getAt(0), ICPPBasicType.class); assertEquals(Long.valueOf(256), arg.getNonTypeValue().numericalValue());
IASTExpression val= bt.getValue(); assertInstance(arg.getTypeOfNonTypeValue(), ICPPBasicType.class);
ICPPFunction foo = getBindingFromASTName("foo(t)", 3, ICPPFunction.class); ICPPFunction foo = getBindingFromASTName("foo(t)", 3, ICPPFunction.class);
ICPPFunction bar = getBindingFromASTName("bar(t)", 3, ICPPFunction.class); ICPPFunction bar = getBindingFromASTName("bar(t)", 3, ICPPFunction.class);
@ -2000,7 +1999,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// }; // };
// //
// typedef A<C> type; // typedef A<C> type;
public void _testSFINAE_a() throws Exception { public void testSFINAE_a() throws Exception {
checkBindings(); checkBindings();
} }

View file

@ -13,26 +13,30 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
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;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* Built-in c++ type. * Built-in c++ type.
*/ */
public class CPPBasicType implements ICPPBasicType, ISerializableType { public class CPPBasicType implements ICPPBasicType, ISerializableType {
private static final int FROM_STRING_LITERAL = 1 << 31;
public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null); public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null);
public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null); public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null);
private final Kind fKind; private final Kind fKind;
private final int fModifiers; private final int fModifiers;
private IASTExpression fExpression; private Long fAssociatedValue;
public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) { public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) {
if (kind == Kind.eUnspecified) { if (kind == Kind.eUnspecified) {
@ -46,8 +50,14 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
} else { } else {
fKind= kind; fKind= kind;
} }
if (expression instanceof IASTLiteralExpression &&
((IASTLiteralExpression) expression).getKind() == IASTLiteralExpression.lk_string_literal) {
qualifiers |= FROM_STRING_LITERAL;
}
fModifiers= qualifiers; fModifiers= qualifiers;
fExpression= expression; if (expression instanceof ICPPASTInitializerClause) {
fAssociatedValue = Value.create(expression, Value.MAX_RECURSION_DEPTH).numericalValue();
}
} }
public CPPBasicType(Kind kind, int qualifiers) { public CPPBasicType(Kind kind, int qualifiers) {
@ -113,11 +123,12 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
if (fKind != t.getKind()) if (fKind != t.getKind())
return false; return false;
int modifiers = getModifiers();
if (fKind == Kind.eInt) { if (fKind == Kind.eInt) {
//signed int and int are equivalent // Signed int and int are equivalent.
return (fModifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED); return (modifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED);
} }
return fModifiers == t.getModifiers(); return modifiers == t.getModifiers();
} }
@Override @Override
@ -161,30 +172,42 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
} }
@Override @Override
public Object clone() { public CPPBasicType clone() {
IType t = null; CPPBasicType t = null;
try { try {
t = (IType) super.clone(); t = (CPPBasicType) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
//not going to happen // Not going to happen.
} }
return t; return t;
} }
public void setFromExpression(IASTExpression val) { /**
fExpression = val; * Sets the numerical value this type was created for.
*
* @param value the numerical value of {@code null}
*/
public final void setAssociatedNumericalValue(Long value) {
fAssociatedValue = value;
} }
/** /**
* Returns the expression the type was created for, or <code>null</code>. * Returns the numerical value this type was created for, or {@code null}.
*/ */
public IASTExpression getCreatedFromExpression() { public final Long getAssociatedNumericalValue() {
return fExpression; return fAssociatedValue;
}
/**
* Returns {@code true} if the type was created for a string literal.
*/
public final boolean isFromStringLiteral() {
return (fModifiers & FROM_STRING_LITERAL) != 0;
} }
@Override @Override
public int getModifiers() { public final int getModifiers() {
return fModifiers; return fModifiers & ~FROM_STRING_LITERAL;
} }
@Override @Override
@ -260,6 +283,6 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
@Override @Override
@Deprecated @Deprecated
public IASTExpression getValue() { public IASTExpression getValue() {
return fExpression; return null;
} }
} }

View file

@ -30,9 +30,7 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
import java.util.Collections; import java.util.Collections;
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.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
@ -60,7 +58,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
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;
@ -838,17 +835,13 @@ public class Conversions {
if (srcQTarget.isConst() && !srcQTarget.isVolatile()) { if (srcQTarget.isConst() && !srcQTarget.isVolatile()) {
srcTarget= srcQTarget.getType(); srcTarget= srcQTarget.getType();
if (srcTarget instanceof CPPBasicType) { if (srcTarget instanceof CPPBasicType) {
IASTExpression val = ((CPPBasicType) srcTarget).getCreatedFromExpression(); if (((CPPBasicType) srcTarget).isFromStringLiteral()) {
if (val instanceof IASTLiteralExpression) {
IASTLiteralExpression lit= (IASTLiteralExpression) val;
if (lit.getKind() == IASTLiteralExpression.lk_string_literal) {
source= new CPPPointerType(srcTarget, false, false, false); source= new CPPPointerType(srcTarget, false, false, false);
CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST); CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST);
cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3); cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3);
} }
} }
} }
}
return source; return source;
} }
@ -1134,14 +1127,11 @@ public class Conversions {
if (basicType.getKind() == Kind.eNullPtr) if (basicType.getKind() == Kind.eNullPtr)
return true; return true;
IASTExpression exp = basicType.getCreatedFromExpression(); Long val = basicType.getAssociatedNumericalValue();
if (exp != null) {
Long val= Value.create(exp, Value.MAX_RECURSION_DEPTH).numericalValue();
if (val != null && val == 0) { if (val != null && val == 0) {
return true; return true;
} }
} }
}
return false; return false;
} }

View file

@ -13,15 +13,12 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
/** /**
@ -272,16 +269,12 @@ public class Cost {
if (targetKind != Kind.eInt && targetKind != Kind.eFloat && targetKind != Kind.eDouble) { if (targetKind != Kind.eInt && targetKind != Kind.eFloat && targetKind != Kind.eDouble) {
return true; return true;
} }
IASTExpression val = ((CPPBasicType) source).getCreatedFromExpression(); Long val= ((CPPBasicType) source).getAssociatedNumericalValue();
if (val instanceof IASTLiteralExpression) { if (val != null) {
// mstodo extend to constant expressions long n= val.longValue();
Long l= Value.create(val, Value.MAX_RECURSION_DEPTH).numericalValue();
if (l != null) {
long n= l.longValue();
return !ArithmeticConversion.fitsIntoType(basicTarget, n); return !ArithmeticConversion.fitsIntoType(basicTarget, n);
} }
} }
}
return true; return true;
} }
return false; return false;

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -44,6 +45,14 @@ public class EvalFixed extends CPPEvaluation {
private boolean fCheckedIsValueDependent; private boolean fCheckedIsValueDependent;
public EvalFixed(IType type, ValueCategory cat, IValue value) { public EvalFixed(IType type, ValueCategory cat, IValue value) {
if (type instanceof CPPBasicType) {
Long num = value.numericalValue();
if (num != null) {
CPPBasicType t = (CPPBasicType) type.clone();
t.setAssociatedNumericalValue(num);
type = t;
}
}
fType= type; fType= type;
fValueCategory= cat; fValueCategory= cat;
fValue= value; fValue= value;