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 {
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;
public void setStrategy(ITestStrategy strategy) {

View file

@ -18,7 +18,6 @@ import java.util.List;
import junit.framework.TestSuite;
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.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
@ -1378,11 +1377,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// }
public void testClassInstanceWithNonTypeArgument_207871() throws Exception {
ICPPTemplateInstance c256 = getBindingFromASTName("C<256>", 6, ICPPTemplateInstance.class, ICPPClassType.class);
ObjectMap args= c256.getArgumentMap();
assertEquals(1, args.size());
assertInstance(args.keyAt(0), ICPPTemplateNonTypeParameter.class);
ICPPBasicType bt= assertInstance(args.getAt(0), ICPPBasicType.class);
IASTExpression val= bt.getValue();
ICPPTemplateParameterMap paramMap = c256.getTemplateParameterMap();
assertEquals(1, paramMap.getAllParameterPositions().length);
ICPPTemplateArgument arg = paramMap.getArgument(0);
assertEquals(Long.valueOf(256), arg.getNonTypeValue().numericalValue());
assertInstance(arg.getTypeOfNonTypeValue(), ICPPBasicType.class);
ICPPFunction foo = getBindingFromASTName("foo(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;
public void _testSFINAE_a() throws Exception {
public void testSFINAE_a() throws Exception {
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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
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.ICPPBasicType;
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.Value;
import org.eclipse.core.runtime.CoreException;
/**
* Built-in c++ type.
*/
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 NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null);
private final Kind fKind;
private final int fModifiers;
private IASTExpression fExpression;
private Long fAssociatedValue;
public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) {
if (kind == Kind.eUnspecified) {
@ -46,8 +50,14 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
} else {
fKind= kind;
}
if (expression instanceof IASTLiteralExpression &&
((IASTLiteralExpression) expression).getKind() == IASTLiteralExpression.lk_string_literal) {
qualifiers |= FROM_STRING_LITERAL;
}
fModifiers= qualifiers;
fExpression= expression;
if (expression instanceof ICPPASTInitializerClause) {
fAssociatedValue = Value.create(expression, Value.MAX_RECURSION_DEPTH).numericalValue();
}
}
public CPPBasicType(Kind kind, int qualifiers) {
@ -113,11 +123,12 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
if (fKind != t.getKind())
return false;
int modifiers = getModifiers();
if (fKind == Kind.eInt) {
//signed int and int are equivalent
return (fModifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED);
// Signed int and int are equivalent.
return (modifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED);
}
return fModifiers == t.getModifiers();
return modifiers == t.getModifiers();
}
@Override
@ -161,30 +172,42 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
}
@Override
public Object clone() {
IType t = null;
public CPPBasicType clone() {
CPPBasicType t = null;
try {
t = (IType) super.clone();
t = (CPPBasicType) super.clone();
} catch (CloneNotSupportedException e) {
//not going to happen
// Not going to happen.
}
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() {
return fExpression;
public final Long getAssociatedNumericalValue() {
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
public int getModifiers() {
return fModifiers;
public final int getModifiers() {
return fModifiers & ~FROM_STRING_LITERAL;
}
@Override
@ -260,6 +283,6 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
@Override
@Deprecated
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 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.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType;
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.internal.core.dom.parser.ArithmeticConversion;
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.CPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
@ -838,14 +835,10 @@ public class Conversions {
if (srcQTarget.isConst() && !srcQTarget.isVolatile()) {
srcTarget= srcQTarget.getType();
if (srcTarget instanceof CPPBasicType) {
IASTExpression val = ((CPPBasicType) srcTarget).getCreatedFromExpression();
if (val instanceof IASTLiteralExpression) {
IASTLiteralExpression lit= (IASTLiteralExpression) val;
if (lit.getKind() == IASTLiteralExpression.lk_string_literal) {
source= new CPPPointerType(srcTarget, false, false, false);
CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST);
cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3);
}
if (((CPPBasicType) srcTarget).isFromStringLiteral()) {
source= new CPPPointerType(srcTarget, false, false, false);
CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST);
cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3);
}
}
}
@ -1134,12 +1127,9 @@ public class Conversions {
if (basicType.getKind() == Kind.eNullPtr)
return true;
IASTExpression exp = basicType.getCreatedFromExpression();
if (exp != null) {
Long val= Value.create(exp, Value.MAX_RECURSION_DEPTH).numericalValue();
if (val != null && val == 0) {
return true;
}
Long val = basicType.getAssociatedNumericalValue();
if (val != null && val == 0) {
return true;
}
}
return false;

View file

@ -13,15 +13,12 @@
*******************************************************************************/
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.IType;
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.ICPPMethod;
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;
/**
@ -272,14 +269,10 @@ public class Cost {
if (targetKind != Kind.eInt && targetKind != Kind.eFloat && targetKind != Kind.eDouble) {
return true;
}
IASTExpression val = ((CPPBasicType) source).getCreatedFromExpression();
if (val instanceof IASTLiteralExpression) {
// mstodo extend to constant expressions
Long l= Value.create(val, Value.MAX_RECURSION_DEPTH).numericalValue();
if (l != null) {
long n= l.longValue();
return !ArithmeticConversion.fitsIntoType(basicTarget, n);
}
Long val= ((CPPBasicType) source).getAssociatedNumericalValue();
if (val != null) {
long n= val.longValue();
return !ArithmeticConversion.fitsIntoType(basicTarget, n);
}
}
return true;

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.ProblemType;
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.core.runtime.CoreException;
@ -44,6 +45,14 @@ public class EvalFixed extends CPPEvaluation {
private boolean fCheckedIsValueDependent;
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;
fValueCategory= cat;
fValue= value;