Skip to content

Commit 84d54c3

Browse files
committed
Add regular expression constants
1 parent c8cb6bf commit 84d54c3

File tree

3 files changed

+101
-5
lines changed

3 files changed

+101
-5
lines changed

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

Lines changed: 35 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.ksmt.decl
33
import io.ksmt.KContext
44
import io.ksmt.expr.KApp
55
import io.ksmt.expr.KExpr
6+
import io.ksmt.sort.KBoolSort
67
import io.ksmt.sort.KRegexSort
78

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

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

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package io.ksmt.expr
33
import io.ksmt.KContext
44
import io.ksmt.cache.hash
55
import io.ksmt.cache.structurallyEqual
6-
import io.ksmt.decl.KDecl
7-
import io.ksmt.decl.KRegexKleeneClosureDecl
8-
import io.ksmt.decl.KRegexLiteralDecl
9-
import io.ksmt.decl.KRegexKleeneCrossDecl
10-
import io.ksmt.decl.KRegexComplementDecl
6+
import io.ksmt.decl.*
117
import io.ksmt.expr.transformer.KTransformerBase
8+
import io.ksmt.sort.KBoolSort
129
import io.ksmt.sort.KRegexSort
1310

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

0 commit comments

Comments
 (0)