@@ -88,9 +88,24 @@ offsetsPacked xs = offsets' xs [] 0
8888 offsets' [] acc _ = reverse acc
8989 offsets' (x::xs) acc pos = offsets' xs (pos::acc) (sizeOf x)
9090
91+-- TODO: Use index and fix upp proofs.
92+offset : CType -> Nat -> Int
93+offset (STRUCT xs) i = fromMaybe 0 $ index' i (offsetsStruct xs)
94+offset (PACKEDSTRUCT xs) i = fromMaybe 0 $ index' i (offsetsPacked xs)
95+offset (ARRAY _ t) i = sizeOf t * toIntNat i
96+offset _ _ = 0
97+
9198offsets : CType -> List Int
9299offsets (STRUCT xs) = offsetsStruct xs
93100offsets (PACKEDSTRUCT xs) = offsetsPacked xs
94101offsets (UNION xs) = replicate (length xs) 0
95102offsets (ARRAY n t) = [ x*sizeOf t | x <- [0..n]]
96103offsets _ = [0]
104+
105+-- TODO: handle out of bounds with proofs
106+select : CType -> Nat -> CType
107+select (STRUCT xs@(y::_)) i = fromMaybe y (index' i xs)
108+select (PACKEDSTRUCT xs@(y::_)) i = fromMaybe y (index' i xs)
109+select (UNION xs@(y::_)) i = fromMaybe y (index' i xs)
110+select (ARRAY n t) _ = t
111+select t _ = t