@@ -45,38 +45,40 @@ module TermLoc {
4545 type TermLoc = x : seq < Selector> | ValidTermLoc (x) witness *
4646 predicate method ValidTermLoc (s : seq <Selector >)
4747 {
48- && 0 < |s|
49- && s[0]. Map?
48+ SequenceIsSafeBecauseItIsInMemory (s);
49+ && 0 < |s| as uint64
50+ && s[0 as uint32]. Map?
5051 }
5152
5253 function method TermLocToString (t : TermLoc ) : string
5354 {
54- t[0]. key + SelectorListToString (t[1..])
55+ t[0 as uint32 ]. key + SelectorListToString (t[1 as uint32 ..])
5556 }
5657 function method SelectorListToString (s : SelectorList ) : string
5758 {
58- if |s| == 0 then
59+ SequenceIsSafeBecauseItIsInMemory (s);
60+ if |s| as uint64 == 0 then
5961 ""
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 ..])
6264 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 ..])
6466 }
6567
6668 // return true if item does not have the given terminal
6769 predicate method LacksAttribute (t : TermLoc , item : DDB .AttributeMap)
6870 {
69- t[0]. key ! in item
71+ t[0 as uint32 ]. key ! in item
7072 }
7173
7274 // return the AttributeValue for the given terminal in the given item
7375 function method TermToAttr (t : TermLoc , item : DDB .AttributeMap, names : Option <DDB .ExpressionAttributeNameMap>)
7476 : Option< DDB. AttributeValue>
7577 {
76- if t[0]. key ! in item then
78+ if t[0 as uint32 ]. key ! in item then
7779 None
7880 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);
8082 if res. Success? then
8183 Some (res.value)
8284 else
@@ -115,7 +117,8 @@ module TermLoc {
115117 )
116118 : Result< DDB. AttributeValue, Error>
117119 {
118- if |parts| == 0 then
120+ SequenceIsSafeBecauseItIsInMemory (parts);
121+ if |parts| as uint64 == 0 then
119122 Success (v)
120123 else
121124 match v {
@@ -128,22 +131,23 @@ module TermLoc {
128131 case BOOL (b) => Failure (E("Found boolean with parts left over."))
129132 case NULL (n) => Failure (E("Found null with parts left over."))
130133 case L (l) =>
131- if ! parts[0]. List? then
134+ SequenceIsSafeBecauseItIsInMemory (l);
135+ if ! parts[0 as uint32]. List? then
132136 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
134138 Failure (E("Tried to access beyond the end of the list"))
135139 else
136- GetTerminal (l[parts[0].pos], parts[1..], names)
140+ GetTerminal (l[parts[0 as uint32 ].pos], parts[1 as uint32 ..], names)
137141 case M (m) =>
138- if ! parts[0]. Map? then
142+ if ! parts[0 as uint32 ]. Map? then
139143 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)
143147 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."))
145149 else
146- GetTerminal (m[parts[0].key], parts[1..], names)
150+ GetTerminal (m[parts[0 as uint32 ].key], parts[1 as uint32 ..], names)
147151 }
148152 }
149153
@@ -207,13 +211,13 @@ module TermLoc {
207211 SequenceIsSafeBecauseItIsInMemory (s);
208212 if |s| as uint64 == pos then
209213 Success (acc)
210- else if '0' <= s[0] <= '9' then
214+ else if '0' <= s[0 as uint32 ] <= '9' then
211215 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))
213217 else
214218 Failure (E("Number is too big for list index : " + s))
215219 else
216- Failure (E("Unexpected character in number : " + [s[0]]))
220+ Failure (E("Unexpected character in number : " + [s[0 as uint32 ]]))
217221 }
218222
219223 // convert string to Selector
@@ -231,15 +235,15 @@ module TermLoc {
231235 && (s[0] == '. ' ==> ret. value. Map?)
232236 && (s[0] == '[' ==> ret. value. List?)
233237 {
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..]))
236241 else
237- if s[|s|- 1] != ']' then
242+ if s[|s| as uint64 - 1] != ']' then
238243 Failure (E("List index must end with ]"))
239244 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))
243247 }
244248
245249 // convert string to SelectorList
@@ -248,10 +252,9 @@ module TermLoc {
248252 requires |s| > 0 && (s[0] == '. ' || s[0] == '[')
249253 {
250254 SequenceIsSafeBecauseItIsInMemory (s);
251- var pos := FindStartOfNext (s[1..]);
255+ var pos := FindStartOfNext (s[1 as uint32 ..]);
252256 var end := if pos. None? then |s| as uint64 else Add (pos.value, 1);
253257 var sel : Selector :- GetSelector (s[..end]);
254- :- Need (HasUint64Size(|acc|+1), E ("Selector Overflow"));
255258 if pos. None? then
256259 Success (acc + [sel])
257260 else
@@ -263,15 +266,15 @@ module TermLoc {
263266 : (ret : Result< TermLoc, Error> )
264267 ensures ret. Success? ==> 0 < |ret. value|
265268 {
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."));
267271 var pos := FindStartOfNext (s);
268272 if pos. None? then
269273 var m := Map (s);
270274 Success ([Map(s)])
271275 else
272276 var name := s[.. pos. value];
273277 var selectors :- GetSelectors (s[pos.value..]);
274- :- Need (HasUint64Size(|selectors|+1), E ("Selector Overflow"));
275278 Success ([Map(name)] + selectors)
276279 }
277280
0 commit comments