Commit bdc7b5ad by Zachary Snow

replace some invariant errors with pattern matching

parent cfff359b
......@@ -261,10 +261,9 @@ convertExpr scopes =
baseOuter' = orientIdx dimOuter baseOuter
start = BinOp Mul idxInner' (rangeSize dimOuter)
baseDec = BinOp Add start baseOuter'
baseInc = case modeOuter of
IndexedPlus -> BinOp Add (BinOp Sub baseDec len) one
IndexedMinus -> BinOp Sub (BinOp Add baseDec len) one
NonIndexed -> error "invariant violated"
baseInc = if modeOuter == IndexedPlus
then BinOp Add (BinOp Sub baseDec len) one
else BinOp Sub (BinOp Add baseDec len) one
base = endianCondExpr dimOuter baseDec baseInc
len = lenOuter
range' = (base, len)
......@@ -309,16 +308,15 @@ convertExpr scopes =
lenOrigMinusOne = BinOp Sub lenOrig (RawNum 1)
baseSwapped =
orientIdx dimInner $
case mode of
IndexedPlus ->
if mode == IndexedPlus
then
endianCondExpr dimInner
baseOrig
(BinOp Add baseOrig lenOrigMinusOne)
IndexedMinus ->
else
endianCondExpr dimInner
(BinOp Sub baseOrig lenOrigMinusOne)
baseOrig
NonIndexed -> error "invariant violated"
base = BinOp Add offsetOuter (BinOp Mul sizeOuter baseSwapped)
mode' = IndexedPlus
len = BinOp Mul sizeOuter lenOrig
......
......@@ -52,8 +52,7 @@ convert files =
isNonDefault = (name /=) . moduleName
alreadyExists = (flip Map.member info) . moduleName
moduleName :: Description -> Identifier
moduleName (Part _ _ _ _ x _ _) = x
moduleName _ = error "not possible"
moduleName = \(Part _ _ _ _ x _ _) -> x
explodeDescription other = [other]
-- remove or rewrite source modules that are no longer needed
......@@ -109,7 +108,7 @@ convert files =
replaceDefault _ other = [other]
removeDefaultTypeParams :: Description -> Description
removeDefaultTypeParams (part @ Part{}) =
removeDefaultTypeParams part =
Part attrs extern kw ml (moduleDefaultName name) p items
where
Part attrs extern kw ml name p items =
......@@ -118,7 +117,6 @@ convert files =
rewriteDecl (ParamType Parameter x _) =
ParamType Parameter x UnknownType
rewriteDecl other = other
removeDefaultTypeParams _ = error "not possible"
isUsed :: Identifier -> Bool
isUsed name =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment