This file is indexed.

/usr/share/why3/modules/string.mlw is in why3 0.88.3-1ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
(** {1 Characters and Strings} *)

(** {2 Characters} *)

module Char

  use import int.Int

  type char model { code : int }

  function uppercase char : char
  function lowercase char : char

  axiom uppercase_alpha:
    forall c:int. 97 <= c <= 122 ->
      uppercase { code = c } = { code = c - 32 }

  axiom uppercase_other:
    forall c:int. 0 <= c < 97 \/ 122 < c <= 127 ->
      uppercase { code = c } = { code = c }

  axiom lowercase_alpha:
    forall c:int. 65 <= c <= 90 ->
      lowercase { code = c } = { code = c + 32 }

  axiom lowercase_other:
    forall c:int. 0 <= c < 65 \/ 90 < c <= 127 ->
      lowercase { code = c } = { code = c }

  val chr (x:int) : char
    requires { 0 <= x <= 255 }
    ensures  { result = { code = x } }

  val code (c:char) : int
    ensures  { result = c.code /\ 0 <= c.code <= 255 }

  (*** TODO
     - compare ?
   *)

end

(** {2 Strings} *)

module String

  use import int.Int
  use import Char
  use import map.Map as M

  type string model { length: int; mutable chars: map int char }
    invariant { self.length >= 0 }

  val create (len:int) : string
    requires { len >= 0 } ensures { length result = len }

  function ([]) (s: string) (i :int) : char = M.([]) s.chars i
  function get (s: string) (i :int) : char = M.([]) s.chars i

  val make (len:int) (c:char) : string
    requires { len >= 0 }
    ensures  { length result = len }
    ensures  { forall i:int. 0 <= i < len -> result[i] = c }

  val get (s:string) (i:int) : char
    requires { 0 <= i < length s } ensures { result = s[i] }

  val unsafe_get (s:string) (i:int) : char
    ensures { result = s[i] }

  val set (s:string) (i:int) (v:char) : unit writes {s}
    requires { 0 <= i < length s }
    ensures  { s.chars = (old s.chars)[i <- v] }

  val unsafe_set (s:string) (i:int) (v:char) : unit writes {s}
    ensures { s.chars = (old s.chars)[i <- v] }

  val length (s:string) : int ensures { result = length s }

  val copy (s:string) : string
    ensures { length result = length s }
    ensures { forall i:int. 0 <= i < length result -> result[i] = s[i] }

  val uppercase (s:string) : string
    ensures { length result = length s }
    ensures { forall i:int.
      0 <= i < length result -> result[i] = Char.uppercase s[i] }

  val lowercase (s:string) : string
    ensures { length result = length s }
    ensures { forall i:int.
      0 <= i < length result -> result[i] = Char.lowercase s[i] }

  (*** TODO
     - copy
     - sub
     - fill
     - blit
     - concat
     - index / rindex / index_from / rindex_from
     - contains / contains_from / rcontains_from
     - capitalize / uncapitalize
  *)

end

(** {2 Buffers} *)

module Buffer

  use import int.Int
  use import Char
  use import String as S
  use import map.Map as M

  type t model { mutable length: int; mutable contents: map int char }
    invariant { self.length >= 0 }

  val create (size:int) : t
    requires { size >= 0 } ensures { result.length = 0 }
    (** [size] is only given as a hint for the initial size *)

  val contents (b:t) : string
    ensures { S.length result = length b }

  val add_char (b:t) (c:char) : unit writes {b}
    ensures { length b = old (length b) + 1 }
    ensures { forall i: int.
      0 <= i < length b -> b.contents[i] = (old b.contents)[i] }
    ensures { b.contents[length b - 1] = c }

  val add_string (b:t) (s:string) : unit writes {b}
    ensures { length b = old (length b) + S.length s }
    ensures { forall i: int.
      0 <= i < old (length b) -> b.contents[i] = (old b.contents)[i] }
    ensures { forall i: int.
      0 <= i < S.length s -> b.contents[old (length b) + i] = S.get s i }

  (*** TODO
     - add_substring
     - add_buffer
  *)

end