mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 497875 - Avoid evaluating isConstantExpression multiple times
Change-Id: I54d6b533f5b21294a92319ea1d45d4f18962a460
This commit is contained in:
parent
f2af760266
commit
b7ecc46eca
9 changed files with 108 additions and 18 deletions
|
@ -81,6 +81,8 @@ public class EvalBinary extends CPPDependentEvaluation {
|
||||||
|
|
||||||
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
||||||
private IType fType;
|
private IType fType;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalBinary(int operator, ICPPEvaluation arg1, ICPPEvaluation arg2, IASTNode pointOfDefinition) {
|
public EvalBinary(int operator, ICPPEvaluation arg1, ICPPEvaluation arg2, IASTNode pointOfDefinition) {
|
||||||
this(operator, arg1, arg2, findEnclosingTemplate(pointOfDefinition));
|
this(operator, arg1, arg2, findEnclosingTemplate(pointOfDefinition));
|
||||||
|
@ -204,6 +206,14 @@ public class EvalBinary extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return fArg1.isConstantExpression(point)
|
return fArg1.isConstantExpression(point)
|
||||||
&& fArg2.isConstantExpression(point)
|
&& fArg2.isConstantExpression(point)
|
||||||
&& isNullOrConstexprFunc(getOverload(point));
|
&& isNullOrConstexprFunc(getOverload(point));
|
||||||
|
|
|
@ -36,6 +36,8 @@ public class EvalComma extends CPPDependentEvaluation {
|
||||||
private ICPPFunction[] fOverloads;
|
private ICPPFunction[] fOverloads;
|
||||||
|
|
||||||
private IType fType;
|
private IType fType;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalComma(ICPPEvaluation[] evals, IASTNode pointOfDefinition) {
|
public EvalComma(ICPPEvaluation[] evals, IASTNode pointOfDefinition) {
|
||||||
this(evals, findEnclosingTemplate(pointOfDefinition));
|
this(evals, findEnclosingTemplate(pointOfDefinition));
|
||||||
|
@ -75,6 +77,14 @@ public class EvalComma extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
if (!areAllConstantExpressions(fArguments, point)) {
|
if (!areAllConstantExpressions(fArguments, point)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,8 @@ public class EvalConditional extends CPPDependentEvaluation {
|
||||||
private ValueCategory fValueCategory;
|
private ValueCategory fValueCategory;
|
||||||
private IType fType;
|
private IType fType;
|
||||||
private ICPPFunction fOverload;
|
private ICPPFunction fOverload;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalConditional(ICPPEvaluation condition, ICPPEvaluation positive, ICPPEvaluation negative,
|
public EvalConditional(ICPPEvaluation condition, ICPPEvaluation positive, ICPPEvaluation negative,
|
||||||
boolean positiveThrows, boolean negativeThrows, IASTNode pointOfDefinition) {
|
boolean positiveThrows, boolean negativeThrows, IASTNode pointOfDefinition) {
|
||||||
|
@ -149,6 +151,14 @@ public class EvalConditional extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return fCondition.isConstantExpression(point)
|
return fCondition.isConstantExpression(point)
|
||||||
&& (fPositive == null || fPositive.isConstantExpression(point))
|
&& (fPositive == null || fPositive.isConstantExpression(point))
|
||||||
&& fNegative.isConstantExpression(point);
|
&& fNegative.isConstantExpression(point);
|
||||||
|
|
|
@ -45,6 +45,8 @@ public class EvalFixed extends CPPEvaluation {
|
||||||
private boolean fCheckedIsTypeDependent;
|
private boolean fCheckedIsTypeDependent;
|
||||||
private boolean fIsValueDependent;
|
private boolean fIsValueDependent;
|
||||||
private boolean fCheckedIsValueDependent;
|
private boolean fCheckedIsValueDependent;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalFixed(IType type, ValueCategory cat, IValue value) {
|
public EvalFixed(IType type, ValueCategory cat, IValue value) {
|
||||||
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
|
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
|
||||||
|
@ -110,6 +112,14 @@ public class EvalFixed extends CPPEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return (fType instanceof ICPPClassType && TypeTraits.isEmpty(fType, point))
|
return (fType instanceof ICPPClassType && TypeTraits.isEmpty(fType, point))
|
||||||
|| isConstexprValue(fValue, point);
|
|| isConstexprValue(fValue, point);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ public class EvalFunctionCall extends CPPDependentEvaluation {
|
||||||
private final ICPPEvaluation[] fArguments;
|
private final ICPPEvaluation[] fArguments;
|
||||||
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
||||||
private IType fType;
|
private IType fType;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalFunctionCall(ICPPEvaluation[] args, IASTNode pointOfDefinition) {
|
public EvalFunctionCall(ICPPEvaluation[] args, IASTNode pointOfDefinition) {
|
||||||
this(args, findEnclosingTemplate(pointOfDefinition));
|
this(args, findEnclosingTemplate(pointOfDefinition));
|
||||||
|
@ -85,6 +87,14 @@ public class EvalFunctionCall extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return areAllConstantExpressions(fArguments, point) && isNullOrConstexprFunc(getOverload(point));
|
return areAllConstantExpressions(fArguments, point) && isNullOrConstexprFunc(getOverload(point));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ public class EvalFunctionSet extends CPPDependentEvaluation {
|
||||||
// by asking the first function in the set for its name.)
|
// by asking the first function in the set for its name.)
|
||||||
// Exactly one of fFunctionSet and fName should be non-null.
|
// Exactly one of fFunctionSet and fName should be non-null.
|
||||||
private final char[] fName;
|
private final char[] fName;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalFunctionSet(CPPFunctionSet set, boolean qualified, boolean addressOf, IType impliedObjectType,
|
public EvalFunctionSet(CPPFunctionSet set, boolean qualified, boolean addressOf, IType impliedObjectType,
|
||||||
IASTNode pointOfDefinition) {
|
IASTNode pointOfDefinition) {
|
||||||
|
@ -140,6 +142,14 @@ public class EvalFunctionSet extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
if (fFunctionSet == null)
|
if (fFunctionSet == null)
|
||||||
return false;
|
return false;
|
||||||
for (ICPPFunction f : fFunctionSet.getBindings()) {
|
for (ICPPFunction f : fFunctionSet.getBindings()) {
|
||||||
|
|
|
@ -31,6 +31,8 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*/
|
*/
|
||||||
public class EvalInitList extends CPPDependentEvaluation {
|
public class EvalInitList extends CPPDependentEvaluation {
|
||||||
private final ICPPEvaluation[] fClauses;
|
private final ICPPEvaluation[] fClauses;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalInitList(ICPPEvaluation[] clauses, IASTNode pointOfDefinition) {
|
public EvalInitList(ICPPEvaluation[] clauses, IASTNode pointOfDefinition) {
|
||||||
this(clauses, findEnclosingTemplate(pointOfDefinition));
|
this(clauses, findEnclosingTemplate(pointOfDefinition));
|
||||||
|
@ -67,6 +69,14 @@ public class EvalInitList extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return areAllConstantExpressions(fClauses, point);
|
return areAllConstantExpressions(fClauses, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ public class EvalTypeId extends CPPDependentEvaluation {
|
||||||
private ICPPFunction fConstructor = CPPFunction.UNINITIALIZED_FUNCTION;
|
private ICPPFunction fConstructor = CPPFunction.UNINITIALIZED_FUNCTION;
|
||||||
private boolean fCheckedIsTypeDependent;
|
private boolean fCheckedIsTypeDependent;
|
||||||
private boolean fIsTypeDependent;
|
private boolean fIsTypeDependent;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalTypeId(IType type, IASTNode pointOfDefinition, ICPPEvaluation... arguments) {
|
public EvalTypeId(IType type, IASTNode pointOfDefinition, ICPPEvaluation... arguments) {
|
||||||
this(type, findEnclosingTemplate(pointOfDefinition), false, arguments);
|
this(type, findEnclosingTemplate(pointOfDefinition), false, arguments);
|
||||||
|
@ -151,6 +153,14 @@ public class EvalTypeId extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return !fRepresentsNewExpression
|
return !fRepresentsNewExpression
|
||||||
&& areAllConstantExpressions(fArguments, point)
|
&& areAllConstantExpressions(fArguments, point)
|
||||||
&& isNullOrConstexprFunc(getConstructor(point));
|
&& isNullOrConstexprFunc(getConstructor(point));
|
||||||
|
|
|
@ -79,6 +79,8 @@ public class EvalUnary extends CPPDependentEvaluation {
|
||||||
private final IBinding fAddressOfQualifiedNameBinding;
|
private final IBinding fAddressOfQualifiedNameBinding;
|
||||||
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
||||||
private IType fType;
|
private IType fType;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalUnary(int operator, ICPPEvaluation operand, IBinding addressOfQualifiedNameBinding,
|
public EvalUnary(int operator, ICPPEvaluation operand, IBinding addressOfQualifiedNameBinding,
|
||||||
IASTNode pointOfDefinition) {
|
IASTNode pointOfDefinition) {
|
||||||
|
@ -152,6 +154,14 @@ public class EvalUnary extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return fArgument.isConstantExpression(point)
|
return fArgument.isConstantExpression(point)
|
||||||
&& isNullOrConstexprFunc(getOverload(point));
|
&& isNullOrConstexprFunc(getOverload(point));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue