package electrod

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

Source file Var.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
(*******************************************************************************
 * electrod - a model finder for relational first-order linear temporal logic
 * 
 * Copyright (C) 2016-2020 ONERA
 * Authors: Julien Brunel (ONERA), David Chemouil (ONERA)
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * SPDX-License-Identifier: MPL-2.0
 * License-Filename: LICENSE.md
 ******************************************************************************)

(** Provides fresh identifiers for variables (in formulas) at every stage. *)

(** type of an identifier *)
type t =
  { id : int  (** [id] identifies an identifier uniquely *)
  ; name : string
        (** [name] is a base string used to give a 
                                    human-friendly display *)
  ; sep : string
  ; loc : Location.t option
  }

let fresh =
  let c = ref 0 in
  fun ?(sep = "/") ?loc s ->
    assert (!c < max_int);
    let res = { id = !c; name = s; sep; loc } in
    incr c;
    res


let fresh_copy var = fresh @@ var.name

let fresh_of_raw_ident ?(sep = "/") v =
  fresh ~sep ~loc:(Raw_ident.location v) (Raw_ident.basename v)


let compare id1 id2 = CCInt.compare id1.id id2.id

let equal { id = id1; _ } { id = id2; _ } = id1 = id2

let style = `Yellow

let pp out { id; name; sep; _ } =
  Fmtc.pf
    out
    "%a%a%a"
    Fmtc.(styled style string)
    name
    Fmtc.(styled style string)
    sep
    Fmtc.(styled style int)
    id


module P = Intf.Print.Mixin (struct
  type nonrec t = t

  let pp = pp
end)

include P
OCaml

Innovation. Community. Security.