Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allChar function, fix #281 #282

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/org/sosy_lab/java_smt/api/StringFormulaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ default StringFormula concat(StringFormula... parts) {
*/
RegexFormula all();

/**
* @return formula denoting the set of all strings of length 1, also known as DOT operator which
* represents an arbitrary char. .
*/
RegexFormula allChar();

/**
* @return formula denoting the range regular expression over two sequences of length 1.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ public RegexFormula all() {

protected abstract TFormulaInfo allImpl();

@Override
public RegexFormula allChar() {
return wrapRegex(allCharImpl());
}

protected abstract TFormulaInfo allCharImpl();

@Override
public RegexFormula range(StringFormula start, StringFormula end) {
return wrapRegex(range(extractInfo(start), extractInfo(end)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public RegexFormula all() {
return delegate.all();
}

@Override
public RegexFormula allChar() {
stats.stringOperations.getAndIncrement();
return delegate.allChar();
}

@Override
public RegexFormula range(StringFormula start, StringFormula end) {
stats.stringOperations.getAndIncrement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public RegexFormula all() {
}
}

@Override
public RegexFormula allChar() {
synchronized (sync) {
return delegate.allChar();
}
}

@Override
public RegexFormula range(StringFormula start, StringFormula end) {
synchronized (sync) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ protected Expr allImpl() {
return exprManager.mkExpr(Kind.REGEXP_COMPLEMENT, noneImpl());
}

@Override
protected Expr allCharImpl() {
return exprManager.mkExpr(Kind.REGEXP_SIGMA, noneImpl());
}

@Override
protected Expr range(Expr start, Expr end) {
return exprManager.mkExpr(Kind.REGEXP_RANGE, start, end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ protected Long allImpl() {
return Native.mkReFull(z3context, formulaCreator.getRegexType());
}

@Override
protected Long allCharImpl() {
return Native.mkReAllchar(z3context, formulaCreator.getRegexType());
}

@Override
protected Long range(Long start, Long end) {
return Native.mkReRange(z3context, start, end);
Expand Down
8 changes: 8 additions & 0 deletions src/org/sosy_lab/java_smt/test/StringFormulaManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public void testRegexAll3() throws SolverException, InterruptedException {
assertThatFormula(smgr.in(smgr.makeString(".*"), regex)).isSatisfiable();
}

@Test
public void testRegexAllChar() throws SolverException, InterruptedException {
RegexFormula regexAllChar = smgr.allChar();
RegexFormula regexDot = smgr.makeRegex(".");
assertThatFormula(smgr.in(smgr.makeString("a"), regexAllChar)).isSatisfiable();
assertThatFormula(smgr.in(smgr.makeString("a"), regexDot)).isUnsatisfiable();
}

Swalkyn marked this conversation as resolved.
Show resolved Hide resolved
@Test
public void testStringRegex2() throws SolverException, InterruptedException {
RegexFormula regex = smgr.concat(smgr.closure(a2z), smgr.makeRegex("ll"), smgr.closure(a2z));
Expand Down