diff options
author | Nathan Ridge | 2018-11-10 06:10:14 +0000 |
---|---|---|
committer | Nathan Ridge | 2018-11-17 08:02:51 +0000 |
commit | e082f73b56d8ea0f588f5ee8338d44b3f06b5f88 (patch) | |
tree | 385c49a7b8b1a829eec5802f3849010b645ffb5d /core | |
parent | 54f6c19de27012a9e7662ed5cfcbcf1377583bd6 (diff) | |
download | org.eclipse.cdt-e082f73b56d8ea0f588f5ee8338d44b3f06b5f88.tar.gz org.eclipse.cdt-e082f73b56d8ea0f588f5ee8338d44b3f06b5f88.tar.xz org.eclipse.cdt-e082f73b56d8ea0f588f5ee8338d44b3f06b5f88.zip |
Bug 540957 - Implement equivalence checking for expressions
This is used for declaration matching in function templates.
Change-Id: I80044304b2d9dfda085a13f0cfc040f1200a2e1c
Diffstat (limited to 'core')
31 files changed, 372 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 7e5d6696e60..da45492b6d9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -9018,6 +9018,20 @@ public class AST2TemplateTests extends AST2CPPTestBase { parseAndCheckBindings(); } + // template <typename T> + // T __declval(); + // + // template <typename T> + // decltype(__declval<T>()) declval(); + // + // template <typename T> + // decltype(__declval<T>()) declval(); + // + // using T = decltype(declval<int>()); + public void testDeclvalDeclaration_540957() throws Exception { + parseAndCheckBindings(); + } + // template <typename T> // class meta { // typedef T type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java index 3deacd05358..1a2019ef8e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java @@ -114,4 +114,10 @@ public interface IValue { * @noreference This method is not intended to be referenced by clients. */ void marshal(ITypeMarshalBuffer buffer) throws CoreException; + + /** + * Returns true if this value is equivalent to 'other' for declaration matching purposes. + * @noreference This method is not intended to be referenced by clients. + */ + boolean isEquivalentTo(IValue other); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java index 92351356725..e22b6bc3233 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java @@ -241,4 +241,13 @@ public final class CStringValue implements IValue { public String toString() { return new String(fFixedValue); } + + @Override + public boolean isEquivalentTo(IValue other) { + if (!(other instanceof CStringValue)) { + return false; + } + CStringValue o = (CStringValue) other; + return fFixedValue.equals(o.fFixedValue); + } }
\ No newline at end of file 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 8a282422d1f..0bc1c14ca35 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 @@ -299,4 +299,25 @@ public final class CompositeValue implements IValue { } return new CompositeValue(evaluation, values); } + + @Override + public boolean isEquivalentTo(IValue other) { + if (!(other instanceof CompositeValue)) { + return false; + } + CompositeValue o = (CompositeValue) other; + if (!((evaluation == null && o.evaluation == null) || + (evaluation.isEquivalentTo(o.evaluation)))) { + return false; + } + if (values.length != o.values.length) { + return false; + } + for (int i = 0; i < values.length; i++) { + if (!values[i].isEquivalentTo(o.values[i])) { + return false; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java index e080b6d6957..48b7d525cd1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java @@ -128,4 +128,12 @@ public class DependentValue implements IValue { return new DependentValue(fEvaluation); } + @Override + public boolean isEquivalentTo(IValue other) { + if (!(other instanceof DependentValue)) { + return false; + } + DependentValue o = (DependentValue) other; + return fEvaluation.isEquivalentTo(o.fEvaluation); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java index 8b5fc13e502..56e4ff14a85 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java @@ -163,4 +163,13 @@ public final class FloatingPointValue implements IValue { public static IValue unmarshal(short firstBytes, ITypeMarshalBuffer buf) throws CoreException { return new FloatingPointValue(buf.getCharArray()); } + + @Override + public boolean isEquivalentTo(IValue other) { + if (!(other instanceof FloatingPointValue)) { + return false; + } + FloatingPointValue o = (FloatingPointValue) other; + return fFixedValue.equals(o.fFixedValue); + } } 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 8dd0a65d051..ccb02dfdafe 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 @@ -65,7 +65,6 @@ public class IntegralValue implements IValue { private static int sUnique= 0; - // The following invariant always holds: (fFixedValue == null) != (fEvaluation == null) private final char[] fFixedValue; private IntegralValue(char[] fixedValue) { @@ -292,4 +291,13 @@ public class IntegralValue implements IValue { public IValue clone() { return new IntegralValue(Arrays.copyOf(fFixedValue, fFixedValue.length)); } + + @Override + public boolean isEquivalentTo(IValue other) { + if (!(other instanceof IntegralValue)) { + return false; + } + IntegralValue o = (IntegralValue) other; + return fFixedValue.equals(o.fFixedValue); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index df14da0224c..aa854a935ab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -46,6 +46,13 @@ public interface ICPPEvaluation { * @param point the point of instantiation, determines the scope for name lookups */ boolean isConstantExpression(); + + + /** + * Returns {@code true} if this expression is equivalent to 'other' for + * declaration matching purposes. + */ + boolean isEquivalentTo(ICPPEvaluation other); /** * Returns the type of the expression. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index be9b4d90b20..d657c3bb2fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -212,4 +212,72 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return argument; } + + protected static boolean areEquivalentOrNull(ICPPEvaluation a, ICPPEvaluation b) { + if (a == null) { + return (b == null); + } + return a.isEquivalentTo(b); + } + + protected static boolean areEquivalentEvaluations(ICPPEvaluation[] a, ICPPEvaluation[] b) { + if (a == null) { + return (b == null); + } + if (a.length != b.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].isEquivalentTo(b[i])) { + return false; + } + } + return true; + } + + protected static boolean areEquivalentArguments(ICPPTemplateArgument[] a, ICPPTemplateArgument[] b) { + if (a == null) { + return (b == null); + } + if (a.length != b.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].isSameValue(b[i])) { + return false; + } + } + return true; + } + + protected static boolean areEquivalentTypes(IType[] a, IType[] b) { + if (a == null) { + return (b == null); + } + if (a.length != b.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].isSameType(b[i])) { + return false; + } + } + return true; + } + + protected static <T extends IBinding> boolean areEquivalentBindings(T[] a, T[] b) { + if (a == null) { + return (b == null); + } + if (a.length != b.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].equals(b[i])) { + return false; + } + } + return true; + } + }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java index 3bfb20dc58e..878c59f13f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunction; @@ -111,4 +112,15 @@ public class CPPFunctionSet implements ICPPTwoPhaseBinding { return super.toString(); } } + + @Override + public boolean equals(Object other) { + if (!(other instanceof CPPFunctionSet)) { + return false; + } + CPPFunctionSet o = (CPPFunctionSet) other; + return CPPEvaluation.areEquivalentBindings(fBindings, o.fBindings) + && fName == o.fName + && CPPEvaluation.areEquivalentArguments(fTemplateArguments, o.fTemplateArguments); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index 4169813f585..b7a71b1c1ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java @@ -256,6 +256,17 @@ public class EvalBinary extends CPPDependentEvaluation { } return fIsConstantExpression; } + + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalBinary)) { + return false; + } + EvalBinary o = (EvalBinary) other; + return fOperator == o.fOperator + && fArg1.isEquivalentTo(o.fArg1) + && fArg2.isEquivalentTo(o.fArg2); + } private boolean computeIsConstantExpression() { return fArg1.isConstantExpression() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index 50e885ea2f1..ea85be12f2c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -108,6 +108,17 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { public boolean isConstantExpression() { return true; } + + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalBinaryTypeId)) { + return false; + } + EvalBinaryTypeId o = (EvalBinaryTypeId) other; + return fOperator == o.fOperator + && fType1.isSameType(o.fType1) + && fType2.isSameType(o.fType2); + } @Override public ValueCategory getValueCategory() { 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 078ed7d60ad..68dec3e00cf 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 @@ -261,6 +261,19 @@ public class EvalBinding extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalBinding)) { + return false; + } + EvalBinding o = (EvalBinding) other; + if (fBinding != null) { + return fBinding == o.fBinding; + } + return fParameterOwner == o.fParameterOwner + && fParameterPosition == o.fParameterPosition; + } + + @Override public IType getType() { if (fType == null) { fType= computeType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index d0a775e3a3a..61b7ad3624d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -96,6 +96,15 @@ public class EvalComma extends CPPDependentEvaluation { return true; } + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalComma)) { + return false; + } + EvalComma o = (EvalComma) other; + return areEquivalentEvaluations(fArguments, o.fArguments); + } + public ICPPFunction[] getOverloads() { if (fOverloads == null) { fOverloads= computeOverloads(); 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 6058ff7247b..51d4a1351a6 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 @@ -79,6 +79,16 @@ public final class EvalCompositeAccess implements ICPPEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalCompositeAccess)) { + return false; + } + EvalCompositeAccess o = (EvalCompositeAccess) other; + return parent.isEquivalentTo(o.parent) + && elementId == o.elementId; + } + + @Override public IType getType() { IType type = getParent().getType(); type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java index 85e2eb1a4b4..58ce0abb3f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java @@ -74,6 +74,15 @@ public class EvalCompoundStatementExpression extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalCompoundStatementExpression)) { + return false; + } + EvalCompoundStatementExpression o = (EvalCompoundStatementExpression) other; + return fDelegate.isEquivalentTo(o.fDelegate); + } + + @Override public IType getType() { return fDelegate.getType(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java index 32c39bea944..14414e7c538 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java @@ -164,6 +164,17 @@ public class EvalConditional extends CPPDependentEvaluation { && fNegative.isConstantExpression(); } + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalConditional)) { + return false; + } + EvalConditional o = (EvalConditional) other; + return fCondition.isEquivalentTo(o.fCondition) + && areEquivalentOrNull(fPositive, o.fPositive) + && fNegative.isEquivalentTo(o.fNegative); + } + private void evaluate() { if (fValueCategory != null) return; 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 719f4adf21f..0353a1c0974 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 @@ -114,6 +114,17 @@ public final class EvalConstructor extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalConstructor)) { + return false; + } + EvalConstructor o = (EvalConstructor) other; + return fType.isSameType(o.fType) + && fConstructor == o.fConstructor + && areEquivalentEvaluations(fArguments, o.fArguments); + } + + @Override public IType getType() { return fType; } 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 3a48ae0eacc..d80ead28f55 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 @@ -112,6 +112,16 @@ public final class EvalFixed extends CPPEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalFixed)) { + return false; + } + EvalFixed o = (EvalFixed) other; + return fType.isSameType(o.fType) + && fValue.isEquivalentTo(o.fValue); + } + + @Override public IType getType() { return fType; } 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 cc3970425b1..93eb3a7e8c2 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 @@ -126,6 +126,15 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { private boolean computeIsConstantExpression() { return areAllConstantExpressions(fArguments) && isNullOrConstexprFunc(getOverload()); } + + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalFunctionCall)) { + return false; + } + EvalFunctionCall o = (EvalFunctionCall) other; + return areEquivalentEvaluations(fArguments, o.fArguments); + } public ICPPFunction getOverload() { if (fOverload == CPPFunction.UNINITIALIZED_FUNCTION) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index 44c0bc953a9..672446348e4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -159,6 +159,15 @@ public class EvalFunctionSet extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalFunctionSet)) { + return false; + } + EvalFunctionSet o = (EvalFunctionSet) other; + return fFunctionSet.equals(o.fFunctionSet); + } + + @Override public IType getType() { return new FunctionSetType(fFunctionSet, fAddressOf); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 227118f5cff..5888ed1b2f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -52,6 +52,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.DependentValue; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; @@ -156,6 +157,21 @@ public class EvalID extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalID)) { + return false; + } + EvalID o = (EvalID) other; + return areEquivalentOrNull(fFieldOwner, o.fFieldOwner) + && CharArrayUtils.equals(fName, o.fName) + && fNameOwner == o.fNameOwner + && fAddressOf == o.fAddressOf + && fQualified == o.fQualified + && fIsPointerDeref == o.fIsPointerDeref + && areEquivalentArguments(fTemplateArgs, o.fTemplateArgs); + } + + @Override public IType getType() { return new TypeOfDependentExpression(this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java index be8279912fb..ed0f65e21e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java @@ -87,6 +87,15 @@ public class EvalInitList extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalInitList)) { + return false; + } + EvalInitList o = (EvalInitList) other; + return areEquivalentEvaluations(fClauses, o.fClauses); + } + + @Override public IType getType() { return new InitializerListType(this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index af5622c8d36..8ba9a042bfd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -188,6 +188,18 @@ public class EvalMemberAccess extends CPPDependentEvaluation { return false; } + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalMemberAccess)) { + return false; + } + EvalMemberAccess o = (EvalMemberAccess) other; + return fOwnerType.isSameType(o.fOwnerType) + && fMember == o.fMember + && fOwnerValueCategory == o.fOwnerValueCategory + && fIsPointerDeref == o.fIsPointerDeref; + } + public static IType getFieldOwnerType(IType fieldOwnerExpressionType, boolean isDeref, Collection<ICPPFunction> functionBindings, boolean returnDependent) { IType type= fieldOwnerExpressionType; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java index 1a9d27f51e5..151f76f7886 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java @@ -85,6 +85,16 @@ public class EvalNaryTypeId extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalNaryTypeId)) { + return false; + } + EvalNaryTypeId o = (EvalNaryTypeId) other; + return fOperator == o.fOperator + && areEquivalentTypes(fOperands, o.fOperands); + } + + @Override public IType getType() { switch (fOperator) { case __is_trivially_constructible: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java index bea59df4602..e032a52c21f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java @@ -70,6 +70,15 @@ public class EvalPackExpansion extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalPackExpansion)) { + return false; + } + EvalPackExpansion o = (EvalPackExpansion) other; + return fExpansionPattern.isEquivalentTo(o.fExpansionPattern); + } + + @Override public IType getType() { if (fType == null) { IType type = fExpansionPattern.getType(); 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 66eef8c9c28..7cad7396e40 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 @@ -82,6 +82,13 @@ public class EvalReference extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + // This probably doesn't need to be implemented as this evaluation type + // only arises as an intermediate artifact during constexpr processing. + return false; + } + + @Override public IType getType() { return getTargetEvaluation().getType(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 38e30b88cae..1b82b23890c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -232,6 +232,18 @@ public class EvalTypeId extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalTypeId)) { + return false; + } + EvalTypeId o = (EvalTypeId) other; + return fInputType.isSameType(o.fInputType) + && areEquivalentEvaluations(fArguments, o.fArguments) + && fRepresentsNewExpression == o.fRepresentsNewExpression + && fUsesBracedInitList == o.fUsesBracedInitList; + } + + @Override public ValueCategory getValueCategory() { return valueCategoryFromReturnType(fInputType); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index 1f70e61deb7..bd429fbfe18 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -171,6 +171,16 @@ public class EvalUnary extends CPPDependentEvaluation { && isNullOrConstexprFunc(getOverload()); } + @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalUnary)) { + return false; + } + EvalUnary o = (EvalUnary) other; + return fOperator == o.fOperator + && fArgument.isEquivalentTo(o.fArgument); + } + public ICPPFunction getOverload() { if (fOverload == CPPFunction.UNINITIALIZED_FUNCTION) { fOverload= computeOverload(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index 2e3beb57384..a13c16fad6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -137,6 +137,16 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { } @Override + public boolean isEquivalentTo(ICPPEvaluation other) { + if (!(other instanceof EvalUnaryTypeID)) { + return false; + } + EvalUnaryTypeID o = (EvalUnaryTypeID) other; + return fOperator == o.fOperator + && fOrigType.isSameType(o.fOrigType); + } + + @Override public IType getType() { if (fType == null) fType= computeType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java index 1663cf1446c..ab7d0f85940 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java @@ -65,7 +65,7 @@ public class TypeOfDependentExpression extends CPPUnknownBinding implements ICPP @Override public boolean isSameType(IType type) { return type instanceof TypeOfDependentExpression - && fEvaluation == ((TypeOfDependentExpression) type).fEvaluation; + && fEvaluation.isEquivalentTo(((TypeOfDependentExpression) type).fEvaluation); } @Override |