Move applyDimension into Types.

This commit is contained in:
Adam Sampson 2008-04-06 15:32:35 +00:00
parent 3fcf363a31
commit 1640b9ce63
2 changed files with 8 additions and 7 deletions

View File

@ -27,7 +27,7 @@ module Types
, makeAbbrevAM, makeConstant, makeDimension, addOne, addExprs, subExprs,
mulExprs, divExprs
, addDimensions, removeFixedDimensions, trivialSubscriptType, subscriptType, unsubscriptType
, addDimensions, applyDimension, removeFixedDimensions, trivialSubscriptType, subscriptType, unsubscriptType
, recordFields, protocolItems
, leastGeneralSharedTypeRain
@ -320,6 +320,11 @@ addDimensions :: [A.Dimension] -> A.Type -> A.Type
addDimensions newDs (A.Array ds t) = A.Array (newDs ++ ds) t
addDimensions ds t = A.Array ds t
-- | Set the first dimension of an array type.
applyDimension :: A.Dimension -> A.Type -> A.Type
applyDimension dim (A.Array (_:ds) t) = A.Array (dim : ds) t
applyDimension _ t = t
-- | Return a type with any enclosing arrays removed; useful for identifying
-- things that should be channel names, timer names, etc. in the parser.
stripArrayType :: A.Type -> A.Type

View File

@ -828,7 +828,8 @@ inferTypes = applyExplicitM9 doExpression doDimension doSubscript
A.Array _ _ ->
do subT <- trivialSubscriptType m underT
taes <- mapM (doArrayElem subT) aes
return (applyDim (length aes) wantT,
return (applyDimension (makeDimension m $ length aes)
wantT,
A.ArrayElemArray (map snd taes))
-- FIXME: Implement this
A.Record n -> dieP m "FIXME: implement record constants"
@ -846,11 +847,6 @@ inferTypes = applyExplicitM9 doExpression doDimension doSubscript
return (addDimensions dims elemT,
A.ArrayElemArray (map snd taes))
_ -> diePC m $ formatCode "Table literal is not valid for type %" wantT
where
-- | Set the first dimension of an array type.
applyDim :: Int -> A.Type -> A.Type
applyDim n (A.Array (_:ds) t) = A.Array (makeDimension m n : ds) t
applyDim _ t = t
-- An expression: descend into it with the right context.
doArrayElem wantT (A.ArrayElemExpr e)
= do let ctx = case wantT of