package frama-c

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file engine.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
(**************************************************************************)
(*                                                                        *)
(*  This file is part of WP plug-in of Frama-C.                           *)
(*                                                                        *)
(*  Copyright (C) 2007-2024                                               *)
(*    CEA (Commissariat a l'energie atomique et aux energies              *)
(*         alternatives)                                                  *)
(*                                                                        *)
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
(*  Lesser General Public License as published by the Free Software       *)
(*  Foundation, version 2.1.                                              *)
(*                                                                        *)
(*  It is distributed in the hope that it will be useful,                 *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU Lesser General Public License for more details.                   *)
(*                                                                        *)
(*  See the GNU Lesser General Public License version 2.1                 *)
(*  for more details (enclosed in the file licenses/LGPLv2.1).            *)
(*                                                                        *)
(**************************************************************************)

(* -------------------------------------------------------------------------- *)
(* --- Engine Signature                                                   --- *)
(* -------------------------------------------------------------------------- *)

(** Generic Engine Signature *)

open Format
open Plib

type op =
  | Op of string (** Infix or prefix operator *)
  | Assoc of string (** Left-associative binary operator (like + and -) *)
  | Call of string (** Logic function or predicate *)

type link =
  | F_call  of string (** n-ary function *)
  | F_subst of string * string (** n-ary function with substitution
                                   first value is the link name, second is the
                                   substitution (e.g. "foo(%1,%2)") *)
  | F_left  of string (** 2-ary function left-to-right + *)
  | F_right of string (** 2-ary function right-to-left + *)
  | F_list of string * string (** n-ary function with (cons,nil) constructors *)
  | F_assoc of string (** associative infix operator *)
  | F_bool_prop of string * string (** Has a bool and prop version *)

type callstyle =
  | CallVar  (** Call is [f(x,...)] ; [f()] can be written [f] *)
  | CallVoid (** Call is [f(x,...)] ; in [f()], [()] is mandatory *)
  | CallApply (** Call is [f x ...] *)

type mode =
  | Mpositive  (** Current scope is [Prop] in positive position. *)
  | Mnegative  (** Current scope is [Prop] in negative position. *)
  | Mterm      (** Current scope is [Term]. *)
  | Mterm_int  (** [Int]  is required but actual scope is [Term]. *)
  | Mterm_real (** [Real] is required but actual scope is [Term]. *)
  | Mint       (** Current scope is [Int]. *)
  | Mreal      (** Current scope is [Real]. *)

type flow = Flow | Atom

type cmode = Cprop | Cterm
type amode = Aint | Areal
type pmode = Positive | Negative | Boolean

type ('x,'f) ftrigger =
  | TgAny
  | TgVar  of 'x
  | TgGet  of ('x,'f) ftrigger * ('x,'f) ftrigger
  | TgSet  of ('x,'f) ftrigger * ('x,'f) ftrigger * ('x,'f) ftrigger
  | TgFun  of 'f * ('x,'f) ftrigger list
  | TgProp of 'f * ('x,'f) ftrigger list

type ('t,'f,'c) ftypedef =
  | Tabs
  | Tdef of 't
  | Trec of ('f * 't) list
  | Tsum of ('c * 't list) list

type scope = [ `Auto | `Unfolded | `Defined of string ]

module type Env =
sig
  type t
  type term
  val create : unit -> t
  val copy : t -> t
  val clear : t -> unit
  val used : t -> string -> bool
  val fresh : t -> sanitizer:('a -> string) -> ?suggest:bool -> 'a -> string
  val define : t -> string -> term -> unit
  val unfold : t -> term -> unit
  val shared : t -> term -> bool
  val shareable : t -> term -> bool
  val set_indexed_vars : t -> unit
  val iter : (string -> term -> unit) -> t -> unit
end

(** Generic Engine Signature *)

class type virtual ['z,'adt,'field,'logic,'tau,'var,'term,'env] engine =
  object

    (** {3 Linking} *)

    method sanitize : string -> string
    method virtual datatype : 'adt -> string
    method virtual field : 'field -> string
    method virtual link : 'logic -> link

    (** {3 Global and Local Environment} *)

    method env : 'env
    (** Returns a fresh copy of the current environment. *)

    method set_env : 'env -> unit
    (** Set environment. *)

    method lookup : 'term -> scope
    (** Term scope in the current environment. *)

    method scope : 'env -> (unit -> unit) -> unit
    (** Calls the continuation in the provided environment.
        Previous environment is restored after return. *)

    method local : (unit -> unit) -> unit
    (** Calls the continuation in a local copy of the environment.
        Previous environment is restored after return, but allocators
        are left unchanged to enforce on-the-fly alpha-conversion. *)

    method global : (unit -> unit) -> unit
    (** Calls the continuation in a fresh local environment.
        Previous environment is restored after return. *)

    method bind : 'var -> string
    method find : 'var -> string

    (** {3 Types} *)

    method t_int  : string
    method t_real : string
    method t_bool : string
    method t_prop : string
    method t_atomic : 'tau -> bool

    method pp_array : 'tau printer
    (** For [Z->a] arrays *)

    method pp_farray : 'tau printer2
    (** For [k->a] arrays *)

    method pp_tvar : int printer
    (** Type variables. *)

    method pp_datatype : 'adt -> 'tau list printer

    method pp_tau : 'tau printer
    (** Without parentheses. *)

    method pp_subtau : 'tau printer
    (** With parentheses if non-atomic. *)

    (** {3 Current Mode}

        The mode represents the expected type for a
        term to printed.  A requirement for all term printers in the
        engine is that current mode must be correctly set before call.
        Each term printer is then responsible for setting appropriate
        modes for its sub-terms.
    *)

    method mode : mode
    method with_mode : mode -> (mode -> unit) -> unit
    (** Calls the continuation with given mode for sub-terms.
                The englobing mode is passed to continuation and then restored. *)

    method op_scope : amode -> string option
    (** Optional scoping post-fix operator when entering arithmetic mode. *)

    (** {3 Primitives} *)

    method e_true : cmode -> string
    (** ["true"] *)

    method e_false : cmode -> string
    (** ["false"] *)

    method pp_int : amode -> 'z printer
    method pp_real : Q.t printer

    (** {3 Variables} *)

    method pp_var : string printer

    (** {3 Calls}

        These printers only applies to connective, operators and
        functions that are morphisms {i w.r.t} current mode.
    *)

    method callstyle : callstyle
    method pp_fun : cmode -> 'logic -> 'term list printer
    method pp_apply : cmode -> 'term -> 'term list printer

    (** {3 Arithmetics Operators} *)

    method op_real_of_int : op
    method op_add : amode -> op
    method op_sub : amode -> op
    method op_mul : amode -> op
    method op_div : amode -> op
    method op_mod : amode -> op
    method op_minus : amode -> op

    method pp_times : formatter -> 'z -> 'term -> unit
    (** Defaults to [self#op_minus] or [self#op_mul] *)

    (** {3 Comparison Operators} *)

    method op_equal : cmode -> op
    method op_noteq : cmode -> op
    method op_eq  : cmode -> amode -> op
    method op_neq : cmode -> amode -> op
    method op_lt  : cmode -> amode -> op
    method op_leq : cmode -> amode -> op

    method pp_equal : 'term printer2
    method pp_noteq : 'term printer2

    (** {3 Arrays} *)

    method pp_array_cst : formatter -> 'tau -> 'term -> unit
    (** Constant array ["[v...]"]. *)

    method pp_array_get : formatter -> 'term -> 'term -> unit
    (** Access ["a[k]"]. *)

    method pp_array_set : formatter -> 'term -> 'term -> 'term -> unit
    (** Update ["a[k <- v]"]. *)

    (** {3 Records} *)

    method pp_get_field : formatter -> 'term -> 'field -> unit
    (** Field access. *)

    method pp_def_fields : ('field * 'term) list printer
    (** Record construction. *)

    (** {3 Logical Connectives} *)

    method op_not   : cmode -> op
    method op_and   : cmode -> op
    method op_or    : cmode -> op
    method op_imply : cmode -> op
    method op_equiv : cmode -> op

    (** {3 Conditionals} *)

    method pp_not : 'term printer
    method pp_imply : formatter -> 'term list -> 'term -> unit

    method pp_conditional : formatter -> 'term -> 'term -> 'term -> unit

    (** {3 Binders} *)

    method pp_forall : 'tau -> string list printer
    method pp_exists : 'tau -> string list printer
    method pp_lambda : (string * 'tau) list printer

    (** {3 Bindings} *)

    method shared : 'term -> bool
    method shareable : 'term -> bool
    method subterms : ('term -> unit) -> 'term -> unit
    method pp_let : formatter -> pmode -> string -> 'term -> unit

    (** {3 Terms} *)

    method is_atomic : 'term -> bool
    (** Sub-terms that require parentheses.
                Shared sub-terms are detected on behalf of this method. *)

    method pp_flow : 'term printer
    (** Printer with shared sub-terms printed with their name and
        without parentheses. *)

    method pp_atom : 'term printer
    (** Printer with shared sub-terms printed with their name and
        within parentheses for non-atomic expressions. Additional
        scope terminates the expression when required (typically
        for Coq). *)

    method pp_repr : 'term printer
    (** Raw representation of a term, as it is. This is where you should hook
        a printer to keep sharing, parentheses, and such. *)

    (** {3 Top Level} *)

    method pp_term : 'term printer
    (** Prints in {i term} mode.
        Default uses [self#pp_shared] with mode [Mterm] inside an [<hov>] box. *)

    method pp_prop : 'term printer
    (** Prints in {i prop} mode.
        Default uses [self#pp_shared] with mode [Mprop] inside an [<hv>] box. *)

    method pp_expr : 'tau -> 'term printer
    (** Prints in {i term}, {i arithmetic} or {i prop} mode with
        respect to provided type. *)

    method pp_sort : 'term printer
    (** Prints in {i term}, {i arithmetic} or {i prop} mode with
        respect to the sort of term. Boolean expression that also have a
        property form are printed in [Mprop] mode. *)

  end
OCaml

Innovation. Community. Security.