Skip to content

Commit 844db59

Browse files
committed
Add regular expression constants
1 parent c8cb6bf commit 844db59

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

ksmt-core/src/main/kotlin/io/ksmt/KContext.kt

+35
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ import io.ksmt.decl.KStringLtDecl
140140
import io.ksmt.decl.KStringLeDecl
141141
import io.ksmt.decl.KStringGtDecl
142142
import io.ksmt.decl.KStringGeDecl
143+
import io.ksmt.decl.KEpsilonDecl
144+
import io.ksmt.decl.KAllDecl
145+
import io.ksmt.decl.KAllCharDecl
143146
import io.ksmt.decl.KRegexLiteralDecl
144147
import io.ksmt.decl.KRegexConcatDecl
145148
import io.ksmt.decl.KRegexUnionDecl
@@ -302,6 +305,9 @@ import io.ksmt.expr.KStringLtExpr
302305
import io.ksmt.expr.KStringLeExpr
303306
import io.ksmt.expr.KStringGtExpr
304307
import io.ksmt.expr.KStringGeExpr
308+
import io.ksmt.expr.KEpsilon
309+
import io.ksmt.expr.KAll
310+
import io.ksmt.expr.KAllChar
305311
import io.ksmt.expr.KRegexLiteralExpr
306312
import io.ksmt.expr.KRegexConcatExpr
307313
import io.ksmt.expr.KRegexUnionExpr
@@ -2231,6 +2237,28 @@ open class KContext(
22312237
KRegexComplementExpr(this, arg)
22322238
}
22332239

2240+
val epsilonExpr: KEpsilon = KEpsilon(this)
2241+
2242+
/**
2243+
* Create regex Epsilon constant.
2244+
* Epsilon regular expression denoting the empty set of strings.
2245+
* */
2246+
fun mkEpsilon(): KEpsilon = epsilonExpr
2247+
2248+
val allExpr: KAll = KAll(this)
2249+
2250+
/**
2251+
* Create regex constant denoting the set of all strings.
2252+
* */
2253+
fun mkAll(): KAll = allExpr
2254+
2255+
val allCharExpr: KAllChar = KAllChar(this)
2256+
2257+
/**
2258+
* Create regex constant denoting the set of all strings of length 1.
2259+
* */
2260+
fun mkAllChar(): KAllChar = allCharExpr
2261+
22342262
// bitvectors
22352263
private val bv1Cache = mkAstInterner<KBitVec1Value>()
22362264
private val bv8Cache = mkAstInterner<KBitVec8Value>()
@@ -4854,6 +4882,7 @@ open class KContext(
48544882
fun mkStringGeDecl(): KStringGeDecl = KStringGeDecl(this)
48554883

48564884
// regex
4885+
48574886
fun mkRegexLiteralDecl(value: String): KRegexLiteralDecl = KRegexLiteralDecl(this, value)
48584887

48594888
fun mkRegexConcatDecl(): KRegexConcatDecl = KRegexConcatDecl(this)
@@ -4870,6 +4899,12 @@ open class KContext(
48704899

48714900
fun mkRegexComplementDecl(): KRegexComplementDecl = KRegexComplementDecl(this)
48724901

4902+
fun mkEpsilonDecl(): KEpsilonDecl = KEpsilonDecl(this)
4903+
4904+
fun mkAllDecl(): KAllDecl = KAllDecl(this)
4905+
4906+
fun mkAllCharDecl(): KAllCharDecl = KAllCharDecl(this)
4907+
48734908
// Bit vectors
48744909
fun mkBvDecl(value: Boolean): KDecl<KBv1Sort> =
48754910
KBitVec1ValueDecl(this, value)

ksmt-core/src/main/kotlin/io/ksmt/decl/Regex.kt

+21
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,24 @@ class KRegexComplementDecl internal constructor(
101101
override fun KContext.apply(arg: KExpr<KRegexSort>): KApp<KRegexSort, KRegexSort> = mkRegexComplementNoSimplify(arg)
102102
override fun <R> accept(visitor: KDeclVisitor<R>): R = visitor.visit(this)
103103
}
104+
105+
class KEpsilonDecl internal constructor(
106+
ctx: KContext
107+
) : KConstDecl<KRegexSort>(ctx, "eps", ctx.mkRegexSort()) {
108+
override fun apply(args: List<KExpr<*>>): KApp<KRegexSort, *> = ctx.mkEpsilon()
109+
override fun <R> accept(visitor: KDeclVisitor<R>): R = visitor.visit(this)
110+
}
111+
112+
class KAllDecl internal constructor(
113+
ctx: KContext
114+
) : KConstDecl<KRegexSort>(ctx, "all", ctx.mkRegexSort()) {
115+
override fun apply(args: List<KExpr<*>>): KApp<KRegexSort, *> = ctx.mkAll()
116+
override fun <R> accept(visitor: KDeclVisitor<R>): R = visitor.visit(this)
117+
}
118+
119+
class KAllCharDecl internal constructor(
120+
ctx: KContext
121+
) : KConstDecl<KRegexSort>(ctx, "all_char", ctx.mkRegexSort()) {
122+
override fun apply(args: List<KExpr<*>>): KApp<KRegexSort, *> = ctx.mkAllChar()
123+
override fun <R> accept(visitor: KDeclVisitor<R>): R = visitor.visit(this)
124+
}

ksmt-core/src/main/kotlin/io/ksmt/expr/Regex.kt

+46-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import io.ksmt.cache.hash
55
import io.ksmt.cache.structurallyEqual
66
import io.ksmt.decl.KDecl
77
import io.ksmt.decl.KRegexKleeneClosureDecl
8-
import io.ksmt.decl.KRegexLiteralDecl
98
import io.ksmt.decl.KRegexKleeneCrossDecl
9+
import io.ksmt.decl.KRegexLiteralDecl
1010
import io.ksmt.decl.KRegexComplementDecl
11+
import io.ksmt.decl.KEpsilonDecl
12+
import io.ksmt.decl.KAllDecl
13+
import io.ksmt.decl.KAllCharDecl
1114
import io.ksmt.expr.transformer.KTransformerBase
1215
import io.ksmt.sort.KRegexSort
1316

@@ -172,3 +175,45 @@ class KRegexComplementExpr internal constructor(
172175
override fun internHashCode(): Int = hash(arg)
173176
override fun internEquals(other: Any): Boolean = structurallyEqual(other) { arg }
174177
}
178+
179+
class KEpsilon(ctx: KContext) : KInterpretedValue<KRegexSort>(ctx) {
180+
override val sort: KRegexSort = ctx.regexSort
181+
182+
override val decl: KEpsilonDecl
183+
get() = ctx.mkEpsilonDecl()
184+
185+
override fun accept(transformer: KTransformerBase): KExpr<KRegexSort> {
186+
TODO("Not yet implemented")
187+
}
188+
189+
override fun internHashCode(): Int = hash()
190+
override fun internEquals(other: Any): Boolean = structurallyEqual(other)
191+
}
192+
193+
class KAll(ctx: KContext) : KInterpretedValue<KRegexSort>(ctx) {
194+
override val sort: KRegexSort = ctx.regexSort
195+
196+
override val decl: KAllDecl
197+
get() = ctx.mkAllDecl()
198+
199+
override fun accept(transformer: KTransformerBase): KExpr<KRegexSort> {
200+
TODO("Not yet implemented")
201+
}
202+
203+
override fun internHashCode(): Int = hash()
204+
override fun internEquals(other: Any): Boolean = structurallyEqual(other)
205+
}
206+
207+
class KAllChar(ctx: KContext) : KInterpretedValue<KRegexSort>(ctx) {
208+
override val sort: KRegexSort = ctx.regexSort
209+
210+
override val decl: KAllCharDecl
211+
get() = ctx.mkAllCharDecl()
212+
213+
override fun accept(transformer: KTransformerBase): KExpr<KRegexSort> {
214+
TODO("Not yet implemented")
215+
}
216+
217+
override fun internHashCode(): Int = hash()
218+
override fun internEquals(other: Any): Boolean = structurallyEqual(other)
219+
}

0 commit comments

Comments
 (0)