From 8e6d9134feea829683efc8e991ec00bfe94db7c2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 3 Mar 2017 15:54:50 -0800 Subject: [PATCH] Bug 513106 - EvalUtil.getVariableValue method does not propagate point of instantiation Change-Id: I2d60e3e8fb635345115705f3f87631bf7a2f940a --- .../core/dom/parser/CompositeValue.java | 2 +- .../dom/parser/cpp/semantics/EvalBinding.java | 2 +- .../parser/cpp/semantics/EvalConstructor.java | 2 +- .../dom/parser/cpp/semantics/EvalUtil.java | 29 ++++++++++++------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java index 1f23c19a46d..1de71a16274 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index 53b34f23edc..dc392d10cbb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -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); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java index fae6783f797..bd38fcc0e16 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java index b9bcd82b410..25408a274db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java @@ -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 getValuePair(ICPPEvaluation eval, ActivationRecord record, ConstexprEvaluationContext context) { + public static Pair 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 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;