@@ -45,38 +45,40 @@ module TermLoc {
45
45
type TermLoc = x : seq < Selector> | ValidTermLoc (x) witness *
46
46
predicate method ValidTermLoc (s : seq <Selector >)
47
47
{
48
- && 0 < |s|
49
- && s[0]. Map?
48
+ SequenceIsSafeBecauseItIsInMemory (s);
49
+ && 0 < |s| as uint64
50
+ && s[0 as uint32]. Map?
50
51
}
51
52
52
53
function method TermLocToString (t : TermLoc ) : string
53
54
{
54
- t[0]. key + SelectorListToString (t[1..])
55
+ t[0 as uint32 ]. key + SelectorListToString (t[1 as uint32 ..])
55
56
}
56
57
function method SelectorListToString (s : SelectorList ) : string
57
58
{
58
- if |s| == 0 then
59
+ SequenceIsSafeBecauseItIsInMemory (s);
60
+ if |s| as uint64 == 0 then
59
61
""
60
- else if s[0]. Map? then
61
- ". " + s[0]. key + SelectorListToString (s[1..])
62
+ else if s[0 as uint32 ]. Map? then
63
+ ". " + s[0 as uint32 ]. key + SelectorListToString (s[1 as uint32 ..])
62
64
else
63
- "[" + String. Base10Int2String (s[0].pos as int) + "]" + SelectorListToString (s[1..])
65
+ "[" + String. Base10Int2String (s[0 as uint32 ].pos as int) + "]" + SelectorListToString (s[1 as uint32 ..])
64
66
}
65
67
66
68
// return true if item does not have the given terminal
67
69
predicate method LacksAttribute (t : TermLoc , item : DDB .AttributeMap)
68
70
{
69
- t[0]. key ! in item
71
+ t[0 as uint32 ]. key ! in item
70
72
}
71
73
72
74
// return the AttributeValue for the given terminal in the given item
73
75
function method TermToAttr (t : TermLoc , item : DDB .AttributeMap, names : Option <DDB .ExpressionAttributeNameMap>)
74
76
: Option< DDB. AttributeValue>
75
77
{
76
- if t[0]. key ! in item then
78
+ if t[0 as uint32 ]. key ! in item then
77
79
None
78
80
else
79
- var res := GetTerminal (item[t[0].key], t[1..], names);
81
+ var res := GetTerminal (item[t[0 as uint32 ].key], t[1 as uint32 ..], names);
80
82
if res. Success? then
81
83
Some (res.value)
82
84
else
@@ -115,7 +117,8 @@ module TermLoc {
115
117
)
116
118
: Result< DDB. AttributeValue, Error>
117
119
{
118
- if |parts| == 0 then
120
+ SequenceIsSafeBecauseItIsInMemory (parts);
121
+ if |parts| as uint64 == 0 then
119
122
Success (v)
120
123
else
121
124
match v {
@@ -128,22 +131,23 @@ module TermLoc {
128
131
case BOOL (b) => Failure (E("Found boolean with parts left over."))
129
132
case NULL (n) => Failure (E("Found null with parts left over."))
130
133
case L (l) =>
131
- if ! parts[0]. List? then
134
+ SequenceIsSafeBecauseItIsInMemory (l);
135
+ if ! parts[0 as uint32]. List? then
132
136
Failure (E("Tried to access list with key"))
133
- else if |l| <= parts[0] . pos as int then
137
+ else if |l| as uint64 <= parts[0 as uint32] . pos then
134
138
Failure (E("Tried to access beyond the end of the list"))
135
139
else
136
- GetTerminal (l[parts[0].pos], parts[1..], names)
140
+ GetTerminal (l[parts[0 as uint32 ].pos], parts[1 as uint32 ..], names)
137
141
case M (m) =>
138
- if ! parts[0]. Map? then
142
+ if ! parts[0 as uint32 ]. Map? then
139
143
Failure (E("Tried to access map with index"))
140
- else if parts[0]. key ! in m then
141
- if names. Some? && parts[0]. key in names. value && names. value[parts[0]. key] in m then
142
- GetTerminal (m[names.value[parts[0].key]], parts[1..], names)
144
+ else if parts[0 as uint32 ]. key ! in m then
145
+ if names. Some? && parts[0 as uint32 ]. key in names. value && names. value[parts[0 as uint32 ]. key] in m then
146
+ GetTerminal (m[names.value[parts[0 as uint32 ].key]], parts[1 as uint32 ..], names)
143
147
else
144
- Failure (E("Tried to access " + parts[0].key + " which is not in the map."))
148
+ Failure (E("Tried to access " + parts[0 as uint32 ].key + " which is not in the map."))
145
149
else
146
- GetTerminal (m[parts[0].key], parts[1..], names)
150
+ GetTerminal (m[parts[0 as uint32 ].key], parts[1 as uint32 ..], names)
147
151
}
148
152
}
149
153
@@ -207,13 +211,13 @@ module TermLoc {
207
211
SequenceIsSafeBecauseItIsInMemory (s);
208
212
if |s| as uint64 == pos then
209
213
Success (acc)
210
- else if '0' <= s[0] <= '9' then
214
+ else if '0' <= s[0 as uint32 ] <= '9' then
211
215
if acc < 0xfff_ffff_ffff_ffff then
212
- GetNumber (s, acc * 10 + s[0] as uint64 - '0' as uint64, Add(pos, 1))
216
+ GetNumber (s, acc * 10 + s[0 as uint32 ] as uint64 - '0' as uint64, Add(pos, 1))
213
217
else
214
218
Failure (E("Number is too big for list index : " + s))
215
219
else
216
- Failure (E("Unexpected character in number : " + [s[0]]))
220
+ Failure (E("Unexpected character in number : " + [s[0 as uint32 ]]))
217
221
}
218
222
219
223
// convert string to Selector
@@ -231,15 +235,15 @@ module TermLoc {
231
235
&& (s[0] == '. ' ==> ret. value. Map?)
232
236
&& (s[0] == '[' ==> ret. value. List?)
233
237
{
234
- if s[0] == '. ' then
235
- Success (Map(s[1..]))
238
+ SequenceIsSafeBecauseItIsInMemory (s);
239
+ if s[0 as uint32] == '. ' then
240
+ Success (Map(s[1 as uint32..]))
236
241
else
237
- if s[|s|- 1] != ']' then
242
+ if s[|s| as uint64 - 1] != ']' then
238
243
Failure (E("List index must end with ]"))
239
244
else
240
- var num :- GetNumber (s[1..|s|-1]);
241
- :- Need (num < UINT64_LIMIT, E("Array selector exceeds maximum."));
242
- Success (List(num as uint64))
245
+ var num :- GetNumber (s[1 as uint32..|s| as uint64 - 1]);
246
+ Success (List(num))
243
247
}
244
248
245
249
// convert string to SelectorList
@@ -248,10 +252,9 @@ module TermLoc {
248
252
requires |s| > 0 && (s[0] == '. ' || s[0] == '[')
249
253
{
250
254
SequenceIsSafeBecauseItIsInMemory (s);
251
- var pos := FindStartOfNext (s[1..]);
255
+ var pos := FindStartOfNext (s[1 as uint32 ..]);
252
256
var end := if pos. None? then |s| as uint64 else Add (pos.value, 1);
253
257
var sel : Selector :- GetSelector (s[..end]);
254
- :- Need (HasUint64Size(|acc|+1), E ("Selector Overflow"));
255
258
if pos. None? then
256
259
Success (acc + [sel])
257
260
else
@@ -263,15 +266,15 @@ module TermLoc {
263
266
: (ret : Result< TermLoc, Error> )
264
267
ensures ret. Success? ==> 0 < |ret. value|
265
268
{
266
- :- Need (0 < |s|, E("Path specification must not be empty."));
269
+ SequenceIsSafeBecauseItIsInMemory (s);
270
+ :- Need (0 < |s| as uint64, E("Path specification must not be empty."));
267
271
var pos := FindStartOfNext (s);
268
272
if pos. None? then
269
273
var m := Map (s);
270
274
Success ([Map(s)])
271
275
else
272
276
var name := s[.. pos. value];
273
277
var selectors :- GetSelectors (s[pos.value..]);
274
- :- Need (HasUint64Size(|selectors|+1), E ("Selector Overflow"));
275
278
Success ([Map(name)] + selectors)
276
279
}
277
280
0 commit comments