1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 513106 - EvalUtil.getVariableValue method does not propagate point

of instantiation

Change-Id: I2d60e3e8fb635345115705f3f87631bf7a2f940a
This commit is contained in:
Sergey Prigogin 2017-03-03 15:54:50 -08:00
parent 1d4cf78a0f
commit 8e6d9134fe
4 changed files with 22 additions and 13 deletions

View file

@ -223,7 +223,7 @@ public final class CompositeValue implements IValue {
for (ICPPField field : fields) {
if (field.isStatic())
continue;
final ICPPEvaluation value = EvalUtil.getVariableValue(field, record);
final ICPPEvaluation value = EvalUtil.getVariableValue(field, record, point);
int fieldPos = CPPASTFieldReference.getFieldPosition(field);
if (fieldPos == -1) {
continue;

View file

@ -331,7 +331,7 @@ public class EvalBinding extends CPPDependentEvaluation {
if (fBinding instanceof ICPPVariable) {
ICPPEvaluation valueEval = EvalUtil.getVariableValue((ICPPVariable) fBinding,
new ActivationRecord());
new ActivationRecord(), point);
if (valueEval != null) {
value = valueEval.getValue(point);
}

View file

@ -185,7 +185,7 @@ public final class EvalConstructor extends CPPDependentEvaluation {
ExecDeclarator declaratorExec = getDeclaratorExecutionFromMemberInitializerList(initializer);
value = getFieldValue(declaratorExec, classType, localRecord, context);
} else {
value = EvalUtil.getVariableValue(field, localRecord);
value = EvalUtil.getVariableValue(field, localRecord, point);
}
final int fieldPos = CPPASTFieldReference.getFieldPosition(field);
compositeValue.setSubValue(fieldPos, value);

View file

@ -16,6 +16,7 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
@ -43,22 +44,26 @@ public class EvalUtil {
}
};
public static IValue getConditionExprValue(ICPPEvaluation conditionExprEval, ActivationRecord record, ConstexprEvaluationContext context) {
public static IValue getConditionExprValue(ICPPEvaluation conditionExprEval, ActivationRecord record,
ConstexprEvaluationContext context) {
return conditionExprEval.computeForFunctionCall(record, context.recordStep()).getValue(context.getPoint());
}
public static IValue getConditionDeclValue(ExecSimpleDeclaration conditionDeclExec, ActivationRecord record, ConstexprEvaluationContext context) {
public static IValue getConditionDeclValue(ExecSimpleDeclaration conditionDeclExec, ActivationRecord record,
ConstexprEvaluationContext context) {
ICPPBinding declaredBinding = ((ExecDeclarator) conditionDeclExec.getDeclaratorExecutions()[0]).getDeclaredBinding();
conditionDeclExec.executeForFunctionCall(record, context.recordStep());
return record.getVariable(declaredBinding).computeForFunctionCall(record, context).getValue(context.getPoint());
}
public static boolean conditionExprSatisfied(ICPPEvaluation conditionExprEval, ActivationRecord record, ConstexprEvaluationContext context) {
public static boolean conditionExprSatisfied(ICPPEvaluation conditionExprEval, ActivationRecord record,
ConstexprEvaluationContext context) {
Number result = getConditionExprValue(conditionExprEval, record, context).numberValue();
return result != null && result.longValue() != 0;
}
public static boolean conditionDeclSatisfied(ExecSimpleDeclaration conditionDeclExec, ActivationRecord record, ConstexprEvaluationContext context) {
public static boolean conditionDeclSatisfied(ExecSimpleDeclaration conditionDeclExec, ActivationRecord record,
ConstexprEvaluationContext context) {
Number result = getConditionDeclValue(conditionDeclExec, record, context).numberValue();
return result != null && result.longValue() != 0;
}
@ -72,7 +77,8 @@ public class EvalUtil {
}
// A return value != null means that there was a return, break or continue in that statement.
public static ICPPExecution executeStatement(ICPPExecution exec, ActivationRecord record, ConstexprEvaluationContext context) {
public static ICPPExecution executeStatement(ICPPExecution exec, ActivationRecord record,
ConstexprEvaluationContext context) {
if (exec instanceof ExecExpressionStatement
|| exec instanceof ExecDeclarationStatement
|| exec instanceof ExecCase
@ -101,7 +107,8 @@ public class EvalUtil {
}
private static boolean isUpdateable(ICPPEvaluation eval) {
return eval instanceof EvalBinding || (eval instanceof EvalReference && !(eval instanceof EvalPointer)) || eval instanceof EvalCompositeAccess;
return eval instanceof EvalBinding || (eval instanceof EvalReference && !(eval instanceof EvalPointer)) ||
eval instanceof EvalCompositeAccess;
}
/**
@ -110,7 +117,8 @@ public class EvalUtil {
* The second, "fixed", is a value (usually EvalFixed or EvalPointer).
* We return both because, depending on the operation, we may need one representation or another.
*/
public static Pair<ICPPEvaluation, ICPPEvaluation> getValuePair(ICPPEvaluation eval, ActivationRecord record, ConstexprEvaluationContext context) {
public static Pair<ICPPEvaluation, ICPPEvaluation> getValuePair(ICPPEvaluation eval, ActivationRecord record,
ConstexprEvaluationContext context) {
ICPPEvaluation updateable = null;
if (isUpdateable(eval)) {
updateable = eval;
@ -150,7 +158,8 @@ public class EvalUtil {
* Returns the initial value of the given variable, evaluated in the context of
* the given activation record.
*/
public static ICPPEvaluation getVariableValue(ICPPVariable variable, ActivationRecord record) {
public static ICPPEvaluation getVariableValue(ICPPVariable variable, ActivationRecord record,
IASTNode point) {
Set<ICPPVariable> recursionProtectionSet = fInitialValueInProgress.get();
if (!recursionProtectionSet.add(variable)) {
return EvalFixed.INCOMPLETE;
@ -169,7 +178,7 @@ public class EvalUtil {
}
ExecDeclarator declaratorExec = new ExecDeclarator(variable, initializerEval);
ConstexprEvaluationContext context = new ConstexprEvaluationContext(null);
ConstexprEvaluationContext context = new ConstexprEvaluationContext(point);
if (declaratorExec.executeForFunctionCall(record, context) != ExecIncomplete.INSTANCE) {
valueEval = record.getVariable(declaratorExec.getDeclaredBinding());
}
@ -178,7 +187,7 @@ public class EvalUtil {
}
if (valueEval != null && (valueEval == EvalFixed.INCOMPLETE ||
valueEval.getValue(null) == IntegralValue.UNKNOWN)) {
valueEval.getValue(point) == IntegralValue.UNKNOWN)) {
return null;
}
return valueEval;