Skip to content

Commit 770406b

Browse files
joaomhmpereirafilipeom
authored andcommitted
Add support for extra regular expression operators
1 parent a6ecea0 commit 770406b

File tree

12 files changed

+100
-3
lines changed

12 files changed

+100
-3
lines changed

src/smtml/bitwuzla_mappings.default.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ module Fresh_bitwuzla (B : Bitwuzla_cxx.S) : M = struct
8181

8282
let roundingMode = mk_rm_sort ()
8383

84+
let regexp = mk_bool_sort ()
85+
8486
let ty t = Term.sort t
8587

8688
let to_ety _ = Fmt.failwith "Bitwuzla_mappings: to_ety not implemented"
@@ -222,6 +224,12 @@ module Fresh_bitwuzla (B : Bitwuzla_cxx.S) : M = struct
222224
end
223225

224226
module Re = struct
227+
let allchar _ = Fmt.failwith "Bitwuzla_mappings: Re.allchar not implemented"
228+
229+
let all _ = Fmt.failwith "Bitwuzla_mappings: Re.all not implemented"
230+
231+
let none _ = Fmt.failwith "Bitwuzla_mappings: Re.none not implemented"
232+
225233
let star _ = Fmt.failwith "Bitwuzla_mappings: Re.star not implemented"
226234

227235
let plus _ = Fmt.failwith "Bitwuzla_mappings: Re.plus not implemented"
@@ -232,6 +240,8 @@ module Fresh_bitwuzla (B : Bitwuzla_cxx.S) : M = struct
232240

233241
let range _ = Fmt.failwith "Bitwuzla_mappings: Re.range not implemented"
234242

243+
let inter _ = Fmt.failwith "Bitwuzla_mappings: Re.inter not implemented"
244+
235245
let loop _ = Fmt.failwith "Bitwuzla_mappings: Re.loop not implemented"
236246

237247
let union _ = Fmt.failwith "Bitwuzla_mappings: Re.union not implemented"

src/smtml/cvc5_mappings.default.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ module Fresh_cvc5 () = struct
7979

8080
let roundingMode = Sort.mk_rm_sort tm
8181

82+
let regexp = Sort.mk_bool_sort tm
83+
8284
let ty t = Term.sort t
8385

8486
let to_ety _ = assert false
@@ -204,6 +206,12 @@ module Fresh_cvc5 () = struct
204206
end
205207

206208
module Re = struct
209+
let allchar () = Term.mk_term tm Kind.Regexp_allchar [||]
210+
211+
let all () = Term.mk_term tm Kind.Regexp_all [||]
212+
213+
let none () = Term.mk_term tm Kind.Regexp_none [||]
214+
207215
let star t = Term.mk_term tm Kind.Regexp_star [| t |]
208216

209217
let plus t = Term.mk_term tm Kind.Regexp_plus [| t |]
@@ -214,6 +222,8 @@ module Fresh_cvc5 () = struct
214222

215223
let range t1 t2 = Term.mk_term tm Kind.Regexp_range [| t1; t2 |]
216224

225+
let inter t1 t2 = Term.mk_term tm Kind.Regexp_inter [| t1; t2 |]
226+
217227
let loop t i1 i2 =
218228
let op = Op.mk_op tm Kind.Regexp_loop [| i1; i2 |] in
219229
Term.mk_term_op tm op [| t |]

src/smtml/dolmenexpr_to_expr.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ module DolmenIntf = struct
144144
module Types = struct
145145
include DTy
146146

147+
let regexp = DTy.string_reg_lang
148+
147149
let ty = DTerm.ty
148150

149151
let to_ety (ty : DTy.t) : Ty.t =
@@ -209,6 +211,12 @@ module DolmenIntf = struct
209211
end
210212

211213
module Re = struct
214+
let all () = DTerm.String.RegLan.all
215+
216+
let allchar () = DTerm.String.RegLan.allchar
217+
218+
let none () = DTerm.String.RegLan.empty
219+
212220
let star = DTerm.String.RegLan.star
213221

214222
let plus = DTerm.String.RegLan.cross
@@ -219,6 +227,8 @@ module DolmenIntf = struct
219227

220228
let range = DTerm.String.RegLan.range
221229

230+
let inter = DTerm.String.RegLan.inter
231+
222232
let loop t i1 i2 = DTerm.String.RegLan.loop i1 i2 t
223233

224234
let union = nary_to_binary DTerm.Const.String.Reg_Lang.union

src/smtml/dolmenexpr_to_expr.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ module DolmenIntf : sig
9292

9393
val roundingMode : ty
9494

95+
val regexp : ty
96+
9597
val ty : term -> ty
9698

9799
val to_ety : ty -> Ty.t
@@ -186,6 +188,12 @@ module DolmenIntf : sig
186188
end
187189

188190
module Re : sig
191+
val allchar : unit -> term
192+
193+
val all : unit -> term
194+
195+
val none : unit -> term
196+
189197
val star : term -> term
190198

191199
val plus : term -> term
@@ -196,6 +204,8 @@ module DolmenIntf : sig
196204

197205
val range : term -> term -> term
198206

207+
val inter : term -> term -> term
208+
199209
val loop : term -> int -> int -> term
200210

201211
val union : term list -> term

src/smtml/mappings.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
6666
| Ty_fp 32 -> f32
6767
| Ty_fp 64 -> f64
6868
| Ty_roundingMode -> M.Types.roundingMode
69-
| (Ty_fp _ | Ty_list | Ty_app | Ty_unit | Ty_none | Ty_regexp) as ty ->
69+
| Ty_regexp -> M.Types.regexp
70+
| (Ty_fp _ | Ty_list | Ty_app | Ty_unit | Ty_none) as ty ->
7071
Fmt.failwith "Unsupported theory: %a@." Ty.pp ty
7172

7273
let make_symbol (ctx : symbol_ctx) (s : Symbol.t) : symbol_ctx * M.term =
@@ -272,6 +273,7 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
272273
let binop op e1 e2 =
273274
match op with
274275
| Binop.Regexp_range -> M.Re.range e1 e2
276+
| Regexp_inter -> M.Re.inter e1 e2
275277
| op ->
276278
Fmt.failwith {|Regexp: Unsupported binop operator "%a"|} Binop.pp op
277279

@@ -687,6 +689,9 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
687689
let base' = v (Bitv (Bitvector.of_int32 base)) in
688690
let ctx, offset' = encode_expr ctx offset in
689691
(ctx, I32.binop Add base' offset')
692+
| Symbol { name = Simple "re.all"; _ } -> (ctx, M.Re.all ())
693+
| Symbol { name = Simple "re.none"; _ } -> (ctx, M.Re.none ())
694+
| Symbol { name = Simple "re.allchar"; _ } -> (ctx, M.Re.allchar ())
690695
| Symbol sym -> make_symbol ctx sym
691696
(* FIXME: add a way to support building these expressions without apps *)
692697
| App ({ name = Simple "fp.add"; _ }, [ rm; a; b ]) ->

src/smtml/mappings.nop.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ module Nop = struct
7575

7676
let roundingMode = `Ty
7777

78+
let regexp = `Ty
79+
7880
let ty _ = assert false
7981

8082
let to_ety _ = assert false
@@ -183,6 +185,12 @@ module Nop = struct
183185
end
184186

185187
module Re = struct
188+
let allchar _ = assert false
189+
190+
let all _ = assert false
191+
192+
let none _ = assert false
193+
186194
let star _ = assert false
187195

188196
let plus _ = assert false
@@ -193,6 +201,8 @@ module Nop = struct
193201

194202
let range _ = assert false
195203

204+
let inter _ = assert false
205+
196206
let loop _ = assert false
197207

198208
let union _ = assert false

src/smtml/mappings_intf.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ module type M = sig
122122

123123
val roundingMode : ty
124124

125+
(** [regexp] represents the regular expression type. *)
126+
val regexp : ty
127+
125128
(** [ty t] retrieves the type of the term [t]. *)
126129
val ty : term -> ty
127130

@@ -318,6 +321,16 @@ module type M = sig
318321
(** {2 Regular Expression Operations} *)
319322

320323
module Re : sig
324+
(** [all] constructs the regular expression that matches all. *)
325+
val all : unit -> term
326+
327+
(** [allchar] constructs the regular expression that matches any character.
328+
*)
329+
val allchar : unit -> term
330+
331+
(** [empty] constructs the empty regular expression. *)
332+
val none : unit -> term
333+
321334
(** [star t] constructs the Kleene star of the regular expression term [t].
322335
*)
323336
val star : term -> term
@@ -337,6 +350,10 @@ module type M = sig
337350
in the range from [t1] to [t2]. *)
338351
val range : term -> term -> term
339352

353+
(** [inter t1 t2] constructs the intersection of the regular expression
354+
terms [t1] and [t2]. *)
355+
val inter : term -> term -> term
356+
340357
(** [loop t min max] constructs a regular expression term matching [t]
341358
repeated between [min] and [max] times. *)
342359
val loop : term -> int -> int -> term

src/smtml/smtlib.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ module Term = struct
7272
| "roundTowardPositive" | "RTP" | "roundTowardNegative" | "RTN"
7373
| "roundTowardZero" | "RTZ" ->
7474
Expr.symbol { id with ty = Ty_roundingMode }
75+
| "re.all" | "re.allchar" | "re.none" ->
76+
Expr.symbol { id with ty = Ty_regexp }
7577
| _ -> Expr.symbol id
7678
end
7779
| Term, Indexed { basename = base; indices } -> begin
@@ -191,6 +193,7 @@ module Term = struct
191193
| "re.opt", [ a ] -> Expr.raw_unop Ty_regexp Regexp_opt a
192194
| "re.comp", [ a ] -> Expr.raw_unop Ty_regexp Regexp_comp a
193195
| "re.range", [ a; b ] -> Expr.raw_binop Ty_regexp Regexp_range a b
196+
| "re.inter", [ a; b ] -> Expr.raw_binop Ty_regexp Regexp_inter a b
194197
| "re.union", n -> Expr.raw_naryop Ty_regexp Regexp_union n
195198
| "re.++", n -> Expr.raw_naryop Ty_regexp Concat n
196199
| "bvnot", [ a ] -> Expr.raw_unop Ty_none Not a

src/smtml/ty.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ module Binop = struct
230230
| String_in_re
231231
(* Regexp *)
232232
| Regexp_range
233+
| Regexp_inter
233234

234235
let equal o1 o2 =
235236
match (o1, o2) with
@@ -261,12 +262,14 @@ module Binop = struct
261262
| String_contains, String_contains
262263
| String_last_index, String_last_index
263264
| String_in_re, String_in_re
264-
| Regexp_range, Regexp_range ->
265+
| Regexp_range, Regexp_range
266+
| Regexp_inter, Regexp_inter ->
265267
true
266268
| ( ( Add | Sub | Mul | Div | DivU | Rem | RemU | Shl | ShrA | ShrL | And
267269
| Or | Xor | Implies | Pow | Min | Max | Copysign | Rotl | Rotr | At
268270
| List_cons | List_append | String_prefix | String_suffix
269-
| String_contains | String_last_index | String_in_re | Regexp_range )
271+
| String_contains | String_last_index | String_in_re | Regexp_range
272+
| Regexp_inter )
270273
, _ ) ->
271274
false
272275

@@ -300,6 +303,7 @@ module Binop = struct
300303
| String_last_index -> Fmt.string fmt "last_indexof"
301304
| String_in_re -> Fmt.string fmt "in_re"
302305
| Regexp_range -> Fmt.string fmt "range"
306+
| Regexp_inter -> Fmt.string fmt "inter"
303307
end
304308

305309
module Relop = struct

src/smtml/ty.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ module Binop : sig
143143
| String_in_re (** Check if a string matches a regular expression. *)
144144
(* Regexp operations *)
145145
| Regexp_range (** Range of characters. *)
146+
| Regexp_inter (** Intersection of regular expressions. *)
146147

147148
(** [equal op1 op2] checks if binary operations [op1] and [op2] are equal. *)
148149
val equal : t -> t -> bool

0 commit comments

Comments
 (0)