Skip to content

Commit 792dc76

Browse files
committed
String theory: extend API with support for code points.
1 parent dbb7ab3 commit 792dc76

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

src/org/sosy_lab/java_smt/api/FunctionDeclarationKind.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ public enum FunctionDeclarationKind {
300300
STR_IN_RE,
301301
STR_TO_INT,
302302
INT_TO_STR,
303+
STR_FROM_CODE,
304+
STR_TO_CODE,
303305
STR_LT,
304306
STR_LE,
305307
RE_PLUS,

src/org/sosy_lab/java_smt/solvers/cvc4/CVC4FormulaCreator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ private Expr normalize(Expr operator) {
511511
.put(Kind.STRING_IN_REGEXP, FunctionDeclarationKind.STR_IN_RE)
512512
.put(Kind.STRING_STOI, FunctionDeclarationKind.STR_TO_INT)
513513
.put(Kind.STRING_ITOS, FunctionDeclarationKind.INT_TO_STR)
514+
.put(Kind.STRING_TO_CODE, FunctionDeclarationKind.STR_TO_CODE)
515+
.put(Kind.STRING_FROM_CODE, FunctionDeclarationKind.STR_FROM_CODE)
514516
.put(Kind.STRING_LT, FunctionDeclarationKind.STR_LT)
515517
.put(Kind.STRING_LEQ, FunctionDeclarationKind.STR_LE)
516518
.put(Kind.REGEXP_PLUS, FunctionDeclarationKind.RE_PLUS)

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FormulaCreator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ private Term normalize(Term operator) {
626626
.put(Kind.STRING_IN_REGEXP, FunctionDeclarationKind.STR_IN_RE)
627627
.put(Kind.STRING_FROM_INT, FunctionDeclarationKind.INT_TO_STR)
628628
.put(Kind.STRING_TO_INT, FunctionDeclarationKind.STR_TO_INT)
629+
.put(Kind.STRING_TO_CODE, FunctionDeclarationKind.STR_TO_CODE)
630+
.put(Kind.STRING_FROM_CODE, FunctionDeclarationKind.STR_FROM_CODE)
629631
.put(Kind.STRING_LT, FunctionDeclarationKind.STR_LT)
630632
.put(Kind.STRING_LEQ, FunctionDeclarationKind.STR_LE)
631633
.put(Kind.REGEXP_PLUS, FunctionDeclarationKind.RE_PLUS)

src/org/sosy_lab/java_smt/solvers/princess/PrincessFormulaCreator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class PrincessFormulaCreator
135135
PrincessEnvironment.stringTheory.str_to_re(), FunctionDeclarationKind.STR_TO_RE);
136136
theoryFunctionKind.put(
137137
PrincessEnvironment.stringTheory.str_to_int(), FunctionDeclarationKind.STR_TO_INT);
138+
theoryFunctionKind.put(
139+
PrincessEnvironment.stringTheory.str_to_code(), FunctionDeclarationKind.STR_TO_CODE);
140+
theoryFunctionKind.put(
141+
PrincessEnvironment.stringTheory.str_from_code(), FunctionDeclarationKind.STR_FROM_CODE);
138142
theoryFunctionKind.put(
139143
PrincessEnvironment.stringTheory.re_range(), FunctionDeclarationKind.RE_RANGE);
140144
theoryFunctionKind.put(

src/org/sosy_lab/java_smt/solvers/z3/Z3FormulaCreator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,10 @@ private FunctionDeclarationKind getDeclarationKind(long f) {
818818
return FunctionDeclarationKind.STR_IN_RE;
819819
case Z3_OP_STR_TO_INT:
820820
return FunctionDeclarationKind.STR_TO_INT;
821+
case Z3_OP_STR_TO_CODE:
822+
return FunctionDeclarationKind.STR_TO_CODE;
823+
case Z3_OP_STR_FROM_CODE:
824+
return FunctionDeclarationKind.STR_FROM_CODE;
821825
case Z3_OP_INT_TO_STR:
822826
return FunctionDeclarationKind.INT_TO_STR;
823827
case Z3_OP_STRING_LT:

src/org/sosy_lab/java_smt/test/SolverVisitorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ public void stringInStringFormulaVisit() throws SolverException, InterruptedExce
736736
StringFormula z = smgr.makeString("zAsString");
737737
IntegerFormula offset = imgr.makeVariable("offset");
738738
IntegerFormula len = imgr.makeVariable("len");
739+
IntegerFormula cp = imgr.makeVariable("cp");
739740

740741
ImmutableList.Builder<StringFormula> formulas =
741742
ImmutableList.<StringFormula>builder()
@@ -744,6 +745,9 @@ public void stringInStringFormulaVisit() throws SolverException, InterruptedExce
744745
.add(smgr.charAt(x, offset))
745746
.add(smgr.toStringFormula(offset))
746747
.add(smgr.concat(x, y, z));
748+
if (solverToUse() != Solvers.PRINCESS) {
749+
formulas.add(smgr.fromCodePoint(cp));
750+
}
747751
if (solverToUse() != Solvers.Z3) {
748752
formulas.add(smgr.replaceAll(x, y, z)); // unsupported in Z3
749753
}

0 commit comments

Comments
 (0)