diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java index c94d8e41a99..24d7e0f2f43 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java @@ -83,17 +83,17 @@ public class IntegralValue implements IValue { } @Override - public Number numberValue() { + public final Number numberValue() { return fFixedValue == null ? null : parseLong(fFixedValue); } @Override - public ICPPEvaluation getEvaluation() { + public final ICPPEvaluation getEvaluation() { return fEvaluation; } @Override - public char[] getSignature() { + public final char[] getSignature() { if (fSignature == null) { fSignature = fFixedValue != null ? fFixedValue : fEvaluation.getSignature(); } @@ -315,35 +315,35 @@ public class IntegralValue implements IValue { } @Override - public int numberOfSubValues() { + public final int numberOfSubValues() { return 1; } @Override - public ICPPEvaluation getSubValue(int index) { - return index == 0 ? (fEvaluation != null ? fEvaluation : EvalFixed.INCOMPLETE) : EvalFixed.INCOMPLETE; + public final ICPPEvaluation getSubValue(int index) { + return index == 0 && fEvaluation != null ? fEvaluation : EvalFixed.INCOMPLETE; } @Override - public ICPPEvaluation[] getAllSubValues() { + public final ICPPEvaluation[] getAllSubValues() { return new ICPPEvaluation[] { getEvaluation() }; } @Override public void setSubValue(int position, ICPPEvaluation newValue) { if (fEvaluation == null) { - throw new RuntimeException("trying to set incomplete value"); //$NON-NLS-1$ + throw new IllegalStateException("Trying to set incomplete value"); //$NON-NLS-1$ } if (position == 0) { fEvaluation = newValue; } else { - throw new RuntimeException("invalid offset in POD value: " + position); //$NON-NLS-1$ + throw new IllegalArgumentException("Invalid offset in POD value: " + position); //$NON-NLS-1$ } } @Override public IValue clone() { - char[] newFixedValue = fFixedValue != null ? Arrays.copyOf(fFixedValue, fFixedValue.length) : null; + char[] newFixedValue = fFixedValue == null ? null : Arrays.copyOf(fFixedValue, fFixedValue.length); return new IntegralValue(newFixedValue, fEvaluation); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java index b9d91b27da5..791382557cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java @@ -32,9 +32,9 @@ import org.eclipse.core.runtime.CoreException; * Represents an access to a sub-value of a composite value, identified by an index. * Composite values can include arrays, structures, and parameter packs (see {@code CompositeValue}). */ -public class EvalCompositeAccess implements ICPPEvaluation { - private final ICPPEvaluation parent; // the composite value being accessed - private final int elementId; // the index of the sub-value being accessed +public final class EvalCompositeAccess implements ICPPEvaluation { + private final ICPPEvaluation parent; // The composite value being accessed + private final int elementId; // The index of the sub-value being accessed public EvalCompositeAccess(ICPPEvaluation parent, int elementId) { this.parent = parent; @@ -42,7 +42,7 @@ public class EvalCompositeAccess implements ICPPEvaluation { } public void update(ICPPEvaluation newValue) { - parent.getValue(null).setSubValue(getElementId(), newValue); + parent.getValue(null).setSubValue(elementId, newValue); } @Override @@ -51,7 +51,7 @@ public class EvalCompositeAccess implements ICPPEvaluation { } private ICPPEvaluation getTargetEvaluation() { - return getParent().getValue(null).getSubValue(getElementId()); + return parent.getValue(null).getSubValue(elementId); } @Override @@ -84,13 +84,13 @@ public class EvalCompositeAccess implements ICPPEvaluation { return arrayType.getType(); } else if (type instanceof InitializerListType) { InitializerListType initListType = (InitializerListType) type; - return initListType.getEvaluation().getClauses()[getElementId()].getType(point); + return initListType.getEvaluation().getClauses()[elementId].getType(point); } else if (type instanceof ICompositeType) { ICompositeType compositeType = (ICompositeType) type; - return compositeType.getFields()[getElementId()].getType(); + return compositeType.getFields()[elementId].getType(); } else if (type instanceof ParameterPackType) { ParameterPackType parameterPackType = (ParameterPackType) type; - return parameterPackType.getTypes()[getElementId()]; + return parameterPackType.getTypes()[elementId]; } else if (type instanceof ICPPBasicType) { return type; } @@ -99,7 +99,7 @@ public class EvalCompositeAccess implements ICPPEvaluation { @Override public IValue getValue(IASTNode point) { - return getTargetEvaluation().getValue(null); + return getTargetEvaluation().getValue(point); } @Override @@ -118,7 +118,7 @@ public class EvalCompositeAccess implements ICPPEvaluation { return getTargetEvaluation().computeForFunctionCall(record, context); } else { ICPPEvaluation evaluatedComposite = parent.computeForFunctionCall(record, context); - return evaluatedComposite.getValue(context.getPoint()).getSubValue(getElementId()).computeForFunctionCall(record, context); + return evaluatedComposite.getValue(context.getPoint()).getSubValue(elementId).computeForFunctionCall(record, context); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java index ca5d950ed2e..81e88bb6867 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java @@ -34,12 +34,10 @@ import org.eclipse.core.runtime.CoreException; /** * Performs evaluation of an expression. */ -public class EvalFixed extends CPPEvaluation { +public final class EvalFixed extends CPPEvaluation { public static final ICPPEvaluation INCOMPLETE = new EvalFixed(ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, IntegralValue.ERROR); - - private final IType fType; private final IValue fValue; private final ValueCategory fValueCategory; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index 84b36c35495..df3cf4620e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -18,6 +18,8 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import java.util.Arrays; + import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -46,9 +48,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode; import org.eclipse.core.runtime.CoreException; -import java.util.Arrays; - -public class EvalFunctionCall extends CPPDependentEvaluation { +public final class EvalFunctionCall extends CPPDependentEvaluation { private final ICPPEvaluation[] fArguments; private ICPPFunction fOverload = CPPFunction.UNINITIALIZED_FUNCTION; private IType fType; @@ -156,8 +156,7 @@ public class EvalFunctionCall extends CPPDependentEvaluation { if (eval == this) { return IntegralValue.create(eval); } - IValue value = eval.getValue(point); - return value; + return eval.getValue(point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java index 77d692cc79c..ea7d6bb77c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; -public class EvalPointer extends EvalReference { +public final class EvalPointer extends EvalReference { // The position will only be nonzero if the EvalReference has a referredSubValue, // not a referredBinding. private int position; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java index d94b75f9155..74c685a4d3f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java @@ -50,27 +50,27 @@ public class EvalReference extends CPPDependentEvaluation { } @Override - public boolean isInitializerList() { + public final boolean isInitializerList() { return getTargetEvaluation().isInitializerList(); } @Override - public boolean isFunctionSet() { + public final boolean isFunctionSet() { return getTargetEvaluation().isFunctionSet(); } @Override - public boolean isTypeDependent() { + public final boolean isTypeDependent() { return getTargetEvaluation().isTypeDependent(); } @Override - public boolean isValueDependent() { + public final boolean isValueDependent() { return getTargetEvaluation().isValueDependent(); } @Override - public boolean isConstantExpression(IASTNode point) { + public final boolean isConstantExpression(IASTNode point) { return getTargetEvaluation().isConstantExpression(point); } @@ -81,10 +81,10 @@ public class EvalReference extends CPPDependentEvaluation { @Override public IValue getValue(IASTNode point) { - return getTargetEvaluation().getValue(null); + return getTargetEvaluation().getValue(point); } - public ICPPEvaluation getTargetEvaluation() { + public final ICPPEvaluation getTargetEvaluation() { if (referredSubValue != null) { return referredSubValue; } @@ -104,7 +104,7 @@ public class EvalReference extends CPPDependentEvaluation { } } - public IBinding getReferredBinding() { + public final IBinding getReferredBinding() { return referredBinding; } 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 6ff75034b5d..291af3edea8 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 @@ -57,22 +57,23 @@ public class EvalUtil { return null; } - // a return value != null means that there was a return, break or continue in that statement + // 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) { if (exec instanceof ExecExpressionStatement - || exec instanceof ExecDeclarationStatement - || exec instanceof ExecCase - || exec instanceof ExecDefault) { + || exec instanceof ExecDeclarationStatement + || exec instanceof ExecCase + || exec instanceof ExecDefault) { exec.executeForFunctionCall(record, context.recordStep()); return null; - } else if (exec instanceof ExecCompoundStatement - || exec instanceof ExecWhile - || exec instanceof ExecFor - || exec instanceof ExecRangeBasedFor - || exec instanceof ExecDo - || exec instanceof ExecIf - || exec instanceof ExecSwitch) { + } + if (exec instanceof ExecCompoundStatement + || exec instanceof ExecWhile + || exec instanceof ExecFor + || exec instanceof ExecRangeBasedFor + || exec instanceof ExecDo + || exec instanceof ExecIf + || exec instanceof ExecSwitch) { ICPPExecution innerResult = exec.executeForFunctionCall(record, context.recordStep()); if (innerResult instanceof ExecReturn || innerResult instanceof ExecBreak || innerResult instanceof ExecContinue) { return innerResult; @@ -80,16 +81,16 @@ public class EvalUtil { return ExecIncomplete.INSTANCE; } return null; - } else { - return exec; } + + return exec; } private static boolean isUpdateable(ICPPEvaluation eval) { return eval instanceof EvalBinding || (eval instanceof EvalReference && !(eval instanceof EvalPointer)) || eval instanceof EvalCompositeAccess; } - /* + /** * Returns a pair of evaluations, each representing the value of 'eval'. * The first, "updateable", is an lvalue (EvalBinding, EvalReference, or EvalCompositeAccess). * The second, "fixed", is a value (usually EvalFixed or EvalPointer). @@ -132,7 +133,7 @@ public class EvalUtil { } /** - * Get the initial value of the given variable, evaluated in the context of + * 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java index 269d22dde0c..f02af72c508 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPExecution; import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext; import org.eclipse.core.runtime.CoreException; -public class ExecDeclarator implements ICPPExecution { +public final class ExecDeclarator implements ICPPExecution { private final ICPPBinding declaredBinding; private final ICPPEvaluation initializerEval; @@ -69,16 +69,17 @@ public class ExecDeclarator implements ICPPExecution { ICPPEvaluation computedInitializerEval = initializerEval.computeForFunctionCall(record, context.recordStep()); - //if a compositevalue with only one member is initialized with an initializer list - //it evaluates to a EvalFixed with a Value instead of a CompositeValue because the initializer list - //doesn't know that it is initializing a composite. + // If a composite value with only one member is initialized with an initializer list, + // it evaluates to a EvalFixed with a Value instead of a CompositeValue because the initializer list + // doesn't know that it is initializing a composite. IType nestedType = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (isClassType(nestedType) && computedInitializerEval instanceof EvalFixed) { EvalFixed evalFixed = (EvalFixed) computedInitializerEval; IValue val = evalFixed.getValue(); if (!(val instanceof CompositeValue)) { CompositeValue compVal = new CompositeValue(initializerEval, new ICPPEvaluation[]{evalFixed}); - computedInitializerEval = new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), compVal); + computedInitializerEval = + new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), compVal); } } @@ -93,7 +94,8 @@ public class ExecDeclarator implements ICPPExecution { ICPPEvaluation defaultValue = new EvalTypeId(type, context.getPoint(), false, new ICPPEvaluation[]{}); return new EvalFixed(type, defaultValue.getValueCategory(context.getPoint()), defaultValue.getValue(context.getPoint())); } else { - return new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), computedInitializerEval.getValue(context.getPoint())); + return new EvalFixed(type, computedInitializerEval.getValueCategory(context.getPoint()), + computedInitializerEval.getValue(context.getPoint())); } } @@ -109,7 +111,8 @@ public class ExecDeclarator implements ICPPExecution { return initialValue; } - private ICPPEvaluation createReferenceValue(ActivationRecord record, ConstexprEvaluationContext context, ICPPEvaluation computedInitializerEval) { + private ICPPEvaluation createReferenceValue(ActivationRecord record, ConstexprEvaluationContext context, + ICPPEvaluation computedInitializerEval) { ICPPEvaluation initValue = initializerEval; if (!(initValue instanceof EvalBinding)) { initValue = initializerEval.getValue(context.getPoint()).getSubValue(0); @@ -124,7 +127,8 @@ public class ExecDeclarator implements ICPPExecution { } } - private ICPPEvaluation createPointerValue(ActivationRecord record, ConstexprEvaluationContext context, ICPPEvaluation computedInitializerEval) { + private ICPPEvaluation createPointerValue(ActivationRecord record, ConstexprEvaluationContext context, + ICPPEvaluation computedInitializerEval) { ICPPEvaluation initValue = initializerEval.getValue(context.getPoint()).getSubValue(0); if (isPointerToArray(initValue, context)) { EvalCompositeAccess arrayPointer = new EvalCompositeAccess(computedInitializerEval, 0); @@ -148,15 +152,18 @@ public class ExecDeclarator implements ICPPExecution { return eval.getType(context.getPoint()) instanceof IArrayType; } - private static ICPPEvaluation createReferenceFromBinding(ActivationRecord record, ConstexprEvaluationContext context, EvalBinding evalBinding) { + private static ICPPEvaluation createReferenceFromBinding(ActivationRecord record, + ConstexprEvaluationContext context, EvalBinding evalBinding) { return new EvalReference(record, evalBinding.getBinding(), context.getPoint()); } - private static ICPPEvaluation createReferenceFromCompositeAccess(ActivationRecord record, ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { + private static ICPPEvaluation createReferenceFromCompositeAccess(ActivationRecord record, + ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { return new EvalReference(record, evalCompAccess, context.getPoint()); } - private static ICPPEvaluation createPointerFromCompositeAccess(ActivationRecord record, ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { + private static ICPPEvaluation createPointerFromCompositeAccess(ActivationRecord record, + ConstexprEvaluationContext context, EvalCompositeAccess evalCompAccess) { return new EvalPointer(record, evalCompAccess, context.getPoint()); } @@ -197,10 +204,12 @@ public class ExecDeclarator implements ICPPExecution { ICPPVariable declaredVariable = (ICPPVariable) declaredBinding; newDeclaredBinding = CPPTemplates.createVariableSpecialization(context, declaredVariable); } else { - newDeclaredBinding = (ICPPBinding)CPPTemplates.createSpecialization(context.getContextSpecialization(), declaredBinding, context.getPoint()); + newDeclaredBinding = (ICPPBinding)CPPTemplates.createSpecialization(context.getContextSpecialization(), + declaredBinding, context.getPoint()); } - ICPPEvaluation newInitializerEval = initializerEval != null ? initializerEval.instantiate(context, maxDepth) : null; + ICPPEvaluation newInitializerEval = + initializerEval == null ? null : initializerEval.instantiate(context, maxDepth); return new ExecDeclarator(newDeclaredBinding, newInitializerEval); }