1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Add simple evaluation for c++20 three-way comparison

This commit is contained in:
Igor V. Kovalenko 2023-01-26 10:30:18 +03:00 committed by Jonah Graham
parent a0f91038e0
commit a90cbe1736
3 changed files with 33 additions and 1 deletions

View file

@ -4193,6 +4193,32 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertEquals(col.getName(1).toString(), "operator <=>"); assertEquals(col.getName(1).toString(), "operator <=>");
} }
// constexpr bool less(int x, int y) { return x <=> y < 0; }
// constexpr bool equals(int x, int y) { return x <=> y == 0; }
// constexpr bool greater(int x, int y) { return x <=> y > 0; }
//
// static constexpr auto less01 = less(0, 1);
// static constexpr auto less00 = less(0, 0);
// static constexpr auto less10 = less(1, 0);
// static constexpr auto equals01 = equals(0, 1);
// static constexpr auto equals11 = equals(1, 1);
// static constexpr auto equals10 = equals(1, 0);
// static constexpr auto greater01 = greater(0, 1);
// static constexpr auto greater00 = greater(0, 0);
// static constexpr auto greater10 = greater(1, 0);
public void testThreeWayComparisonSimpleCase() throws Exception {
BindingAssertionHelper helper = getAssertionHelper(CPP, ScannerKind.STDCPP20);
helper.assertVariableValue("less01", 1);
helper.assertVariableValue("less00", 0);
helper.assertVariableValue("less10", 0);
helper.assertVariableValue("equals01", 0);
helper.assertVariableValue("equals11", 1);
helper.assertVariableValue("equals10", 0);
helper.assertVariableValue("greater01", 0);
helper.assertVariableValue("greater00", 0);
helper.assertVariableValue("greater10", 1);
}
// typedef int I; // typedef int I;
// typedef int I; // typedef int I;
// typedef I I; // typedef I I;

View file

@ -576,8 +576,13 @@ public abstract class AST2TestBase extends SemanticTestBase {
} }
protected BindingAssertionHelper getAssertionHelper(ParserLanguage lang) throws ParserException, IOException { protected BindingAssertionHelper getAssertionHelper(ParserLanguage lang) throws ParserException, IOException {
return getAssertionHelper(lang, ScannerKind.GNU);
}
protected BindingAssertionHelper getAssertionHelper(ParserLanguage lang, ScannerKind scannerKind)
throws ParserException, IOException {
String code = getAboveComment(); String code = getAboveComment();
return new AST2AssertionHelper(code, lang); return new AST2AssertionHelper(code, lang, scannerKind);
} }
final protected void assertNoProblemBindings(NameCollector col) { final protected void assertNoProblemBindings(NameCollector col) {

View file

@ -226,6 +226,7 @@ public class ValueFactory {
break; break;
case IASTBinaryExpression.op_threewaycomparison: case IASTBinaryExpression.op_threewaycomparison:
// TODO: implement for <=> // TODO: implement for <=>
value = v1 < v2 ? -1l : (v1 > v2 ? 1l : 0);
break; break;
case IASTBinaryExpression.op_binaryAnd: case IASTBinaryExpression.op_binaryAnd:
value = v1 & v2; value = v1 & v2;