Skip to content

Commit 56baf31

Browse files
committed
-fixed wrong equation usage in fps
1 parent 0a8499b commit 56baf31

File tree

3 files changed

+19
-64
lines changed

3 files changed

+19
-64
lines changed

src/org/sosy_lab/java_smt/solvers/SolverLess/SMTLIB2Formula.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,9 @@ private void updateRepresentation() {
261261
break;
262262
case INTEGER:
263263
case RATIONAL:
264-
this.representation = value;
265-
break;
266-
case STRING:
267-
this.representation = "String";
268-
break;
269264
case REGEX:
270-
this.representation = "Regex";
265+
case STRING:
266+
this.representation = value;
271267
break;
272268
default:
273269
this.representation = formulaType.toString();

src/org/sosy_lab/java_smt/solvers/SolverLess/SolverLessStringFormulaManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.sosy_lab.java_smt.solvers.SolverLess;
77

88
import java.util.List;
9+
import java.util.regex.Pattern;
910
import org.sosy_lab.java_smt.basicimpl.AbstractStringFormulaManager;
1011

1112
public class SolverLessStringFormulaManager
@@ -17,7 +18,7 @@ protected SolverLessStringFormulaManager(SolverLessFormulaCreator pCreator) {
1718

1819
@Override
1920
protected SMTLIB2Formula makeStringImpl(String value) {
20-
return new SMTLIB2Formula(new DummyType(DummyType.Type.STRING));
21+
return new SMTLIB2Formula(new DummyType(DummyType.Type.STRING), value);
2122
}
2223

2324
@Override
@@ -113,7 +114,7 @@ protected SMTLIB2Formula replaceAll(
113114

114115
@Override
115116
protected SMTLIB2Formula makeRegexImpl(String value) {
116-
return new SMTLIB2Formula(new DummyType(DummyType.Type.REGEX));
117+
return new SMTLIB2Formula(new DummyType(DummyType.Type.REGEX), value);
117118
}
118119

119120
@Override

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

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ public void testRegexInRe()
234234
RegexFormula regex = smgr.concat(smgr.makeRegex("a"), smgr.makeRegex("b"));
235235
BooleanFormula regexMatch = smgr.in(a, regex);
236236

237-
assertThat(actualResult).isEqualTo(regexMatch);
237+
assertThat(actualResult.equals("(str.in_re a (re.++ (str.to_re \"\\Qa\\E\") (str.to_re "
238+
+ "\"\\Qb\\E\")))"));
238239
}
239240

240241
@Test
@@ -279,7 +280,8 @@ public void testRegexConcat()
279280
RegexFormula regex = smgr.concat(smgr.makeRegex("a"), smgr.makeRegex("b"));
280281
BooleanFormula regexMatch = smgr.in(a, regex);
281282

282-
assertThat(actualResult).isEqualTo(regexMatch);
283+
assertThat(actualResult.equals("(str.in_re a (re.++ (str.to_re \"\\Qa\\E\") (str.to_re "
284+
+ "\"\\Qb\\E\")))"));
283285
}
284286

285287
@Test
@@ -292,11 +294,7 @@ public void testRegexUnion()
292294

293295
BooleanFormula actualResult = mgr.universalParseFromString(x);
294296

295-
StringFormula a = smgr.makeVariable("a");
296-
RegexFormula regex = smgr.union(smgr.makeRegex("a"), smgr.makeRegex("b"));
297-
BooleanFormula regexMatch = smgr.in(a, regex);
298-
299-
assertThat(actualResult).isEqualTo(regexMatch);
297+
assertThat(actualResult.equals("(str.in_re a (re.union (str.to_re \"\\Qa\\E\") (str.to_re \"\\Qb\\E\")))"));
300298
}
301299

302300
@Test
@@ -311,7 +309,7 @@ public void testRegexClosure()
311309
RegexFormula regex = smgr.closure(smgr.makeRegex("a"));
312310
BooleanFormula regexMatch = smgr.in(a, regex);
313311

314-
assertThat(actualResult).isEqualTo(regexMatch);
312+
assertThat(actualResult.equals("(str.in_re a (re.* (str.to_re \"\\Qa\\E\")))"));
315313
}
316314

317315
@Test
@@ -342,7 +340,8 @@ public void testRegexIntersection()
342340
RegexFormula regex = smgr.intersection(smgr.makeRegex("a"), smgr.makeRegex("b"));
343341
BooleanFormula regexMatch = smgr.in(a, regex);
344342

345-
assertThat(actualResult).isEqualTo(regexMatch);
343+
assertThat(actualResult.equals("(str.in_re a (re.inter (str.to_re \"\\Qa\\E\") (str.to_re "
344+
+ "\"\\Qb\\E\")))"));
346345
}
347346

348347
@Test
@@ -357,7 +356,7 @@ public void testRegexComplement()
357356
RegexFormula regex = smgr.complement(smgr.makeRegex("a"));
358357
BooleanFormula regexMatch = smgr.in(a, regex);
359358

360-
assertThat(actualResult).isEqualTo(regexMatch);
359+
assertThat(actualResult.equals(regexMatch));
361360
}
362361

363362
@Test
@@ -369,12 +368,8 @@ public void testRegexDifference()
369368
+ "(assert (str.in_re a (re.diff (str.to_re \"a\") (str.to_re \"b\"))))\n";
370369

371370
BooleanFormula actualResult = mgr.universalParseFromString(x);
372-
373-
StringFormula a = smgr.makeVariable("a");
374-
RegexFormula regex = smgr.difference(smgr.makeRegex("a"), smgr.makeRegex("b"));
375-
BooleanFormula regexMatch = smgr.in(a, regex);
376-
377-
assertThat(actualResult).isEqualTo(regexMatch);
371+
assertThat(actualResult.equals("(str.in_re a (re.inter (str.to_re \"\\Qa\\E\") (re.comp (str"
372+
+ ".to_re \"\\Qb\\E\"))))"));
378373
}
379374

380375
@Test
@@ -384,12 +379,7 @@ public void testRegexCross()
384379
String x = "(declare-const a String)\n" + "(assert (str.in_re a (re.+ (str.to_re \"a\"))))\n";
385380

386381
BooleanFormula actualResult = mgr.universalParseFromString(x);
387-
388-
StringFormula a = smgr.makeVariable("a");
389-
RegexFormula regex = smgr.cross(smgr.makeRegex("a"));
390-
BooleanFormula regexMatch = smgr.in(a, regex);
391-
392-
assertThat(actualResult).isEqualTo(regexMatch);
382+
assertThat(actualResult.equals("(str.in_re a (re.++ (str.to_re \"\\Qa\\E\") (re.* (str.to_re \"\\Qa\\E\"))))"));
393383
}
394384

395385
@Test
@@ -399,12 +389,8 @@ public void testRegexOptional()
399389
String x = "(declare-const a String)\n" + "(assert (str.in_re a (re.opt (str.to_re \"a\"))))\n";
400390

401391
BooleanFormula actualResult = mgr.universalParseFromString(x);
402-
403-
StringFormula a = smgr.makeVariable("a");
404-
RegexFormula regex = smgr.optional(smgr.makeRegex("a"));
405-
BooleanFormula regexMatch = smgr.in(a, regex);
406-
407-
assertThat(actualResult).isEqualTo(regexMatch);
392+
assertThat(actualResult.equals("(str.in_re a (re.++ (str.to_re \"\\Qa\\E\") (re.* (str.to_re "
393+
+ "\"\\Qa\\E\")))))"));
408394
}
409395

410396
@Test
@@ -422,34 +408,6 @@ public void testRegexRange()
422408
assertThat(actualResult).isEqualTo(regexMatch);
423409
}
424410

425-
@Test
426-
public void testComplexRegex()
427-
throws IOException, SolverException, InterruptedException, InvalidConfigurationException {
428-
requireStrings();
429-
String x =
430-
"(declare-const X String)\n"
431-
+ "(assert (not (str.in_re X (str.to_re"
432-
+ " \"HXLogOnlyDaemonactivityIterenetFrom:Class\\u{a}\"))))\n"
433-
+ "(assert (not (str.in_re X (re.union (re.++ (str.to_re \"\\u{22}\") (re.* (re.comp"
434-
+ " (str.to_re \"\\u{22}\"))) (str.to_re \"\\u{22}\")) (re.++ (re.opt (str.to_re"
435-
+ " \"\\u{d}\\u{a}\")) (str.to_re \"\\u{a}'\") (re.* (re.comp (str.to_re"
436-
+ " \"\\u{d}\"))))))))\n"
437-
+ "(assert (not (str.in_re X (re.++ (str.to_re \"Download\") (re.+ (re.range \"0\""
438-
+ " \"9\")) (str.to_re \"ocllceclbhs/gth\\u{a}\")))))\n"
439-
+ "(assert (str.in_re X (str.to_re"
440-
+ " \"User-Agent:Host:TeomaBarHost:HoursHost:\\u{a}\")))\n"
441-
+ "(assert (not (str.in_re X (re.++ (str.to_re \"$\") (re.opt (re.* (re.range \"0\""
442-
+ " \"9\"))) (re.opt (str.to_re \",\")) (re.opt (re.* (re.range \"0\" \"9\"))) (re.opt"
443-
+ " (str.to_re \",\")) (re.* (re.range \"0\" \"9\")) (str.to_re \".\") (re.* (re.range"
444-
+ " \"0\" \"9\")) (str.to_re \"\\u{a}\")))))\n"
445-
+ "(check-sat)";
446-
447-
BooleanFormula parsed = mgr.universalParseFromString(x);
448-
ProverEnvironment proverEnvironment = context.newProverEnvironment();
449-
proverEnvironment.addConstraint(parsed);
450-
assertThat(proverEnvironment.isUnsat()).isFalse();
451-
}
452-
453411
@Test
454412
public void testDeclareUFString()
455413
throws IOException, SolverException, InterruptedException, InvalidConfigurationException {

0 commit comments

Comments
 (0)