Skip to content

Commit

Permalink
Add variable read/write flag test for c++20 three-way comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
i-garrison authored and jonahgraham committed Jan 28, 2023
1 parent a8b3401 commit ae8da7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,12 @@ public AST2AssertionHelper(String contents, boolean isCPP) throws ParserExceptio
}

public AST2AssertionHelper(String contents, ParserLanguage lang) throws ParserException {
super(contents, parse(contents, lang, ScannerKind.GNU, false));
this(contents, lang, ScannerKind.GNU);
}

public AST2AssertionHelper(String contents, ParserLanguage lang, ScannerKind scannerKind)
throws ParserException {
super(contents, parse(contents, lang, scannerKind, false));
this.isCPP = lang.isCPP();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Optional;

import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.c.CVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.parser.ParserException;
Expand All @@ -36,6 +37,10 @@ protected class AssertionHelper extends AST2AssertionHelper {
super(contents, isCPP);
}

AssertionHelper(String contents, ParserLanguage lang, ScannerKind scannerKind) throws ParserException {
super(contents, lang, scannerKind);
}

void assertReadWriteFlags(String context, String name, Optional<Integer> expectedFlags) throws Exception {
IASTName variable = findName(context, name);
assertNotNull(variable);
Expand Down Expand Up @@ -95,6 +100,11 @@ protected AssertionHelper getCPPAssertionHelper() throws ParserException, IOExce
return new AssertionHelper(code, true);
}

protected AssertionHelper getCPP20AssertionHelper() throws ParserException, IOException {
String code = getAboveComment();
return new AssertionHelper(code, ParserLanguage.CPP, ScannerKind.STDCPP20);
}

// int test(int a) {
// a = 2;
// a *= 3;
Expand All @@ -107,6 +117,14 @@ public void testSimpleAccess() throws Exception {
a.assertReadWriteFlags("a + 1", "a", READ);
}

// auto test(int a) {
// return a <=> 1;
// }
public void testThreeWayComparisonAccess() throws Exception {
AssertionHelper a = getCPP20AssertionHelper();
a.assertReadWriteFlags("a <=> 1", "a", READ);
}

// class C {
// public:
// C(int);
Expand Down

0 comments on commit ae8da7e

Please sign in to comment.