|
1 | 1 | package io.ksmt.expr.rewrite.simplify |
2 | 2 |
|
3 | 3 | import io.ksmt.KContext |
4 | | -import io.ksmt.expr.KExpr |
5 | | -import io.ksmt.expr.KInterpretedValue |
6 | | -import io.ksmt.expr.KStringConcatExpr |
7 | | -import io.ksmt.expr.KStringLiteralExpr |
| 4 | +import io.ksmt.expr.* |
8 | 5 | import io.ksmt.sort.KBoolSort |
9 | 6 | import io.ksmt.sort.KIntSort |
10 | 7 | import io.ksmt.sort.KSort |
@@ -77,8 +74,8 @@ inline fun KContext.simplifyStringLenExpr( |
77 | 74 | arg: KExpr<KStringSort>, |
78 | 75 | cont: (KExpr<KStringSort>) -> KExpr<KIntSort> |
79 | 76 | ): KExpr<KIntSort> = |
80 | | - tryEvalStringLiteralOperation(arg, { literalArg -> |
81 | | - mkIntNum(literalArg.value.length) |
| 77 | + tryEvalStringLiteralOperation(arg, { |
| 78 | + a -> StringUtils.getStringLen(a) |
82 | 79 | }) { |
83 | 80 | cont(arg) |
84 | 81 | } |
@@ -157,6 +154,52 @@ inline fun KContext.simplifyStringBasicGeExpr( |
157 | 154 | cont(arg0, arg1) |
158 | 155 | } |
159 | 156 |
|
| 157 | +/* |
| 158 | +* String contains expression simplifications |
| 159 | +* */ |
| 160 | + |
| 161 | +/** Basic simplify string contains expression |
| 162 | + * (str_contains strConst1 strConst2) ==> boolConst */ |
| 163 | +inline fun KContext.simplifyStringBasicContainsExpr( |
| 164 | + arg0: KExpr<KStringSort>, |
| 165 | + arg1: KExpr<KStringSort>, |
| 166 | + cont: (KExpr<KStringSort>, KExpr<KStringSort>) -> KExpr<KBoolSort> |
| 167 | +): KExpr<KBoolSort> = |
| 168 | + tryEvalStringLiteralOperation(arg0, arg1, { a0, a1 -> StringUtils.stringContains(a0, a1) }) { |
| 169 | + cont(arg0, arg1) |
| 170 | + } |
| 171 | + |
| 172 | +/* |
| 173 | +* String to lower/upper case expression simplifications |
| 174 | +* */ |
| 175 | + |
| 176 | +/** Converting all letters of a string constant to lowercase. */ |
| 177 | +inline fun KContext.simplifyStringBasicToLowerExpr( |
| 178 | + arg: KExpr<KStringSort>, |
| 179 | + cont: (KExpr<KStringSort>) -> KExpr<KStringSort> |
| 180 | +): KExpr<KStringSort> = |
| 181 | + tryEvalStringLiteralOperation(arg, { a -> StringUtils.stringToLowerCase(a) }) { |
| 182 | + cont(arg) |
| 183 | + } |
| 184 | + |
| 185 | +/** Converting all letters of a string constant to uppercase. */ |
| 186 | +inline fun KContext.simplifyStringBasicToUpperExpr( |
| 187 | + arg: KExpr<KStringSort>, |
| 188 | + cont: (KExpr<KStringSort>) -> KExpr<KStringSort> |
| 189 | +): KExpr<KStringSort> = |
| 190 | + tryEvalStringLiteralOperation(arg, { a -> StringUtils.stringToUpperCase(a) }) { |
| 191 | + cont(arg) |
| 192 | + } |
| 193 | + |
| 194 | +/** Reverses a string constant */ |
| 195 | +inline fun KContext.simplifyStringBasicReverseExpr( |
| 196 | + arg: KExpr<KStringSort>, |
| 197 | + cont: (KExpr<KStringSort>) -> KExpr<KStringSort> |
| 198 | +): KExpr<KStringSort> = |
| 199 | + tryEvalStringLiteralOperation(arg, { a -> StringUtils.stringReverse(a) }) { |
| 200 | + cont(arg) |
| 201 | + } |
| 202 | + |
160 | 203 | inline fun <K : KSort> tryEvalStringLiteralOperation( |
161 | 204 | arg: KExpr<KStringSort>, |
162 | 205 | operation: (KStringLiteralExpr) -> KInterpretedValue<K>, |
|
0 commit comments