-
Notifications
You must be signed in to change notification settings - Fork 56
String formulae #250
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
Merged
Merged
String formulae #250
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
0520718
Initial support for String formulae
serras e66962a
Run formatting
serras 5ff9e5b
Return BooleanFormula on equals
serras 0c37762
Do not use the string theory until Features.S is enabled
serras 5eae506
Fix style problem
serras abfba6c
SMTInterpol doesn't really support strings
serras 991b737
Update UFElimination procedure
serras 64896de
Finish removal of SMTInterpol string support
serras 4509941
Another reversal
serras 5808d2c
Merge remote-tracking branch 'sosy-lab/master'
serras 75cc067
Add regular expression support + more tests
serras e5fd0be
fix: add forgotten method for encapsulating Regex formulas.
kfriedberger 70936a6
formatting.
kfriedberger 94c04ea
fix type of empty and full regex.
kfriedberger 4220e30
add more operations for String theory: prefix and suffix.
kfriedberger 238ce26
add more operations for String theory: allow concatenation of several…
kfriedberger b1a622e
update Readme with upcoming support for String and Regex theory.
kfriedberger 1be548c
improve assertion message.
kfriedberger 587cdf0
move JUnit tests for Strings into a separate class.
kfriedberger 49a52ef
formatting Junit test
kfriedberger 95ab89f
replace merged imports by single-class imports, and ignore too many p…
kfriedberger 88fa084
cleanup
kfriedberger a184697
add support for String theory with CVC4.
kfriedberger 00fc6ee
add more operations for String theory: indexOf, contains, charAt, sub…
kfriedberger cce8309
Remove allChar + translation from Java regex
serras bab867b
fixing GEQ,LEQ,LT for String theory, and shortening some code.
kfriedberger 1281b86
remove unused test for removed method "allChar()".
kfriedberger 1d4c133
add more operations for String theory: IntToString and StringToInt.
kfriedberger 685bf4c
more junit tests for String theory.
kfriedberger a562121
fix Checkstyle warning.
kfriedberger a89caac
More tests for String equality constraints + negative length
baierd 92357b0
Add String length inequality tests for < <= > >=
baierd 67de78a
Enable CVC4 to use all String methods by setting its options
baierd d0d7d71
Enable Strings in CVC4 to use unicode by default
baierd 6c71f93
More tests for charAt, unicode and lexicographic ordering + fix a test
baierd 9e27bdd
fix String comparison in Z3.
kfriedberger 90f8b38
more JUnit tests
kfriedberger 2728ed5
introduce variable to apply a common operation only once.
kfriedberger d849dfb
fix model retrieval for Strings in CVC4.
kfriedberger ab3f235
remove unused variables.
kfriedberger 48f7357
Add startIndex to indexOf in Strings according to SMTLIB2 standard
baierd 6722500
More tests for concat, substring, indexOf, contains
baierd 64da1c3
Add more subString tests
baierd f0867f4
Add more tests for substring based on variables
baierd dcf86e0
Add tests for String constants for replace() and replaceAll()
baierd 1cb177d
Add more tests for replace() and replaceAll() for String theories
baierd 820c90f
Fix a bug that StringFormulas used the BooleanFormula type
baierd b2c623d
Add StringFormulas in the type selection of the
baierd 241a91a
Add a basic String Array test
baierd 425632f
Add tests to check whether or not a solver supports all possible Array
baierd f885645
Add basic tests for quantifiers with strings and array int strings
baierd 0659d05
Add more general array type combination tests
baierd f8c351e
remove API methods for building a regex from Java-based regex or patt…
kfriedberger 93e53b8
formatting.
kfriedberger 81167e1
adding basic visitor support for String and Regex theory.
kfriedberger 499275d
improve JUnit test for model evaluation.
kfriedberger ff4c5b1
improve JUnit test for String theory.
kfriedberger 2e46c9d
improve JUnit test for String theory, fix warnings.
kfriedberger 284eb40
CVC4: disable some JUnit tests for theory combination of Arrays and Q…
kfriedberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is part of JavaSMT, | ||
| // an API wrapper for a collection of SMT solvers: | ||
| // https://github.com/sosy-lab/java-smt | ||
| // | ||
| // SPDX-FileCopyrightText: 2021 Alejandro Serrano Mena | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.sosy_lab.java_smt.api; | ||
|
|
||
| import com.google.errorprone.annotations.Immutable; | ||
|
|
||
| /** A formula of the string sort. */ | ||
| @Immutable | ||
| public interface RegexFormula extends Formula {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is part of JavaSMT, | ||
| // an API wrapper for a collection of SMT solvers: | ||
| // https://github.com/sosy-lab/java-smt | ||
| // | ||
| // SPDX-FileCopyrightText: 2021 Alejandro Serrano Mena | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.sosy_lab.java_smt.api; | ||
|
|
||
| import com.google.errorprone.annotations.Immutable; | ||
|
|
||
| /** A formula of the string sort. */ | ||
| @Immutable | ||
| public interface StringFormula extends Formula {} |
190 changes: 190 additions & 0 deletions
190
src/org/sosy_lab/java_smt/api/StringFormulaManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| // This file is part of JavaSMT, | ||
| // an API wrapper for a collection of SMT solvers: | ||
| // https://github.com/sosy-lab/java-smt | ||
| // | ||
| // SPDX-FileCopyrightText: 2021 Alejandro Serrano Mena | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.sosy_lab.java_smt.api; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula; | ||
|
|
||
| /** | ||
| * Manager for dealing with string formulas. Functions come from | ||
| * http://smtlib.cs.uiowa.edu/theories-UnicodeStrings.shtml. | ||
| */ | ||
| public interface StringFormulaManager { | ||
|
|
||
| /** | ||
| * Returns a {@link StringFormula} representing the given constant. | ||
| * | ||
| * @param value the string value the returned <code>Formula</code> should represent | ||
| * @return a Formula representing the given value | ||
| */ | ||
| StringFormula makeString(String value); | ||
|
|
||
| /** | ||
| * Creates a variable of type String with exactly the given name. | ||
| * | ||
| * <p>This variable (symbol) represents a "String" for which the SMT solver needs to find a model. | ||
| * | ||
| * <p>Please make sure that the given name is valid in SMT-LIB2. Take a look at {@link | ||
| * FormulaManager#isValidName} for further information. | ||
| * | ||
| * <p>This method does not quote or unquote the given name, but uses the plain name "AS IS". | ||
| * {@link Formula#toString} can return a different String than the given one. | ||
| */ | ||
| StringFormula makeVariable(String pVar); | ||
|
|
||
| // TODO: There is currently no way to use variables of type "Regex", i.e., that represent full | ||
| // regular expression for which the SMT solver need to find a model. | ||
| // The reason for this is that the current SMT solvers do not support this feature. | ||
| // However, we can build a RegexFormula from basic parts like Strings (including | ||
| // variables of type String) and operations like range, union, or complement. | ||
|
|
||
| BooleanFormula equal(StringFormula str1, StringFormula str2); | ||
|
|
||
| BooleanFormula greaterThan(StringFormula str1, StringFormula str2); | ||
|
|
||
| BooleanFormula greaterOrEquals(StringFormula str1, StringFormula str2); | ||
|
|
||
| BooleanFormula lessThan(StringFormula str1, StringFormula str2); | ||
|
|
||
| BooleanFormula lessOrEquals(StringFormula str1, StringFormula str2); | ||
|
|
||
| /** Check whether the given prefix is a real prefix of str. */ | ||
| BooleanFormula prefix(StringFormula prefix, StringFormula str); | ||
|
|
||
| /** Check whether the given suffix is a real suffix of str. */ | ||
| BooleanFormula suffix(StringFormula suffix, StringFormula str); | ||
|
|
||
| BooleanFormula contains(StringFormula str, StringFormula part); | ||
|
|
||
| /** | ||
| * Get the first index for a substring in a String, or -1 if the substring is not found. | ||
| * startIndex (inlcuded) denotes the start of the search for the index. | ||
| */ | ||
| IntegerFormula indexOf(StringFormula str, StringFormula part, IntegerFormula startIndex); | ||
|
|
||
| /** | ||
| * Get a substring of length 1 from the given String. | ||
| * | ||
| * <p>The result is underspecified, if the index is out of bounds for the given String. | ||
| */ | ||
| StringFormula charAt(StringFormula str, IntegerFormula index); | ||
|
|
||
| /** | ||
| * Get a substring from the given String. | ||
| * | ||
| * <p>The result is underspecified, if the start index is out of bounds for the given String or if | ||
| * the requested length is negative. The length of the result is the minimum of the requested | ||
| * length and the remaining length of the given String. | ||
| */ | ||
| StringFormula substring(StringFormula str, IntegerFormula index, IntegerFormula length); | ||
|
|
||
| /** Replace the first appearances of target in fullStr with the replacement. */ | ||
| StringFormula replace(StringFormula fullStr, StringFormula target, StringFormula replacement); | ||
|
|
||
| /** Replace all appearances of target in fullStr with the replacement. */ | ||
| StringFormula replaceAll(StringFormula fullStr, StringFormula target, StringFormula replacement); | ||
|
|
||
| IntegerFormula length(StringFormula str); | ||
|
|
||
| default StringFormula concat(StringFormula... parts) { | ||
| return concat(Arrays.asList(parts)); | ||
| } | ||
|
|
||
| StringFormula concat(List<StringFormula> parts); | ||
|
|
||
| /** | ||
| * @param str formula representing the string to match | ||
| * @param regex formula representing the regular expression | ||
| * @return a formula representing the acceptance of the string by the regular expression | ||
| */ | ||
| BooleanFormula in(StringFormula str, RegexFormula regex); | ||
|
|
||
| /** | ||
| * Returns a {@link RegexFormula} representing the given constant. | ||
| * | ||
| * <p>This method does not parse an existing regex from String, but uses the String directly as a | ||
| * constant. | ||
| * | ||
| * @param value the regular expression the returned <code>Formula</code> should represent | ||
| */ | ||
| RegexFormula makeRegex(String value); | ||
|
|
||
| // basic regex operations | ||
|
|
||
| /** @return formula denoting the empty set of strings */ | ||
| RegexFormula none(); | ||
|
|
||
| /** @return formula denoting the set of all strings, also known as Regex <code>".*"</code>. */ | ||
| RegexFormula all(); | ||
|
|
||
| /** @return formula denoting the range regular expression over two sequences of length 1. */ | ||
| RegexFormula range(StringFormula start, StringFormula end); | ||
|
|
||
| /** | ||
| * @return formula denoting the range regular expression over two chars. | ||
| * @see #range(StringFormula, StringFormula) | ||
| */ | ||
| default RegexFormula range(char start, char end) { | ||
| return range(makeString(String.valueOf(start)), makeString(String.valueOf(end))); | ||
| } | ||
|
|
||
| /** @return formula denoting the concatenation */ | ||
| default RegexFormula concat(RegexFormula... parts) { | ||
| return concatRegex(Arrays.asList(parts)); | ||
| } | ||
|
|
||
| /** @return formula denoting the concatenation */ | ||
| // TODO the naming of this function collides with #concat(List<StringFormula>). | ||
| // Maybe we should split String and Regex manager. | ||
| RegexFormula concatRegex(List<RegexFormula> parts); | ||
|
|
||
| /** @return formula denoting the union */ | ||
| RegexFormula union(RegexFormula regex1, RegexFormula regex2); | ||
|
|
||
| /** @return formula denoting the intersection */ | ||
| RegexFormula intersection(RegexFormula regex1, RegexFormula regex2); | ||
|
|
||
| /** @return formula denoting the Kleene closure */ | ||
| RegexFormula complement(RegexFormula regex); | ||
|
|
||
| /** @return formula denoting the Kleene closure (0 or more), also known as STAR operand. */ | ||
| RegexFormula closure(RegexFormula regex); | ||
|
|
||
| // derived regex operations | ||
|
|
||
| /** @return formula denoting the difference */ | ||
| RegexFormula difference(RegexFormula regex1, RegexFormula regex2); | ||
|
|
||
| /** @return formula denoting the Kleene cross (1 or more), also known as PLUS operand. */ | ||
| RegexFormula cross(RegexFormula regex); | ||
|
|
||
| /** @return formula denoting the optionality, also known as QUESTIONMARK operand. */ | ||
| RegexFormula optional(RegexFormula regex); | ||
|
|
||
| /** @return formula denoting the concatenation n times */ | ||
| RegexFormula times(RegexFormula regex, int repetitions); | ||
|
|
||
| /** | ||
| * Interpret a String formula as an Integer formula. | ||
| * | ||
| * <p>The number is interpreted in base 10 and has no leading zeros. The method works as expected | ||
| * for positive numbers, including zero. It returns the constant value of <code>-1</code> for | ||
| * negative numbers or invalid number representations, for example if any char is no digit. | ||
| */ | ||
| IntegerFormula toIntegerFormula(StringFormula str); | ||
|
|
||
| /** | ||
| * Interpret an Integer formula as a String formula. | ||
| * | ||
| * <p>The number is in base 10. The method works as expected for positive numbers, including zero. | ||
| * It returns the empty string <code>""</code> for negative numbers. | ||
| */ | ||
| StringFormula toStringFormula(IntegerFormula number); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.