Added a new function (typeOfSpec) to the Types module

This commit is contained in:
Neil Brown 2007-10-10 23:10:46 +00:00
parent cc2040679b
commit a68ecfb24b

View File

@ -19,7 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
-- | Type inference and checking. -- | Type inference and checking.
module Types module Types
( (
specTypeOfName, abbrevModeOfName, typeOfName, typeOfExpression, typeOfVariable, underlyingType, stripArrayType, abbrevModeOfVariable, abbrevModeOfSpec specTypeOfName, typeOfSpec, abbrevModeOfName, typeOfName, typeOfExpression, typeOfVariable, underlyingType, stripArrayType, abbrevModeOfVariable, abbrevModeOfSpec
, isRealType, isIntegerType, isCaseableType, resolveUserType, isSafeConversion, isPreciseConversion, isImplicitConversionRain , isRealType, isIntegerType, isCaseableType, resolveUserType, isSafeConversion, isPreciseConversion, isImplicitConversionRain
, returnTypesOfFunction , returnTypesOfFunction
, BytesInResult(..), bytesInType, sizeOfReplicator, sizeOfStructured , BytesInResult(..), bytesInType, sizeOfReplicator, sizeOfStructured
@ -62,14 +62,21 @@ abbrevModeOfName n
typeOfName :: (CSM m, Die m) => A.Name -> m A.Type typeOfName :: (CSM m, Die m) => A.Name -> m A.Type
typeOfName n typeOfName n
= do st <- specTypeOfName n = do st <- specTypeOfName n
case st of t <- typeOfSpec st
A.Declaration _ t -> return t case t of
A.Is _ _ _ v -> typeOfVariable v Just t' -> return t'
A.IsExpr _ _ _ e -> typeOfExpression e Nothing -> die $ "cannot type name " ++ show st
A.IsChannelArray _ _ (c:_) -> liftM (A.Array [A.UnknownDimension]) $ typeOfVariable c
A.Retypes _ _ t _ -> return t typeOfSpec :: (CSM m, Die m) => A.SpecType -> m (Maybe A.Type)
A.RetypesExpr _ _ t _ -> return t typeOfSpec st
_ -> die $ "cannot type name " ++ show st = case st of
A.Declaration _ t -> return $ Just t
A.Is _ _ _ v -> (liftM Just) (typeOfVariable v)
A.IsExpr _ _ _ e -> (liftM Just) (typeOfExpression e)
A.IsChannelArray _ _ (c:_) -> liftM (Just . (A.Array [A.UnknownDimension])) $ typeOfVariable c
A.Retypes _ _ t _ -> return $ Just t
A.RetypesExpr _ _ t _ -> return $ Just t
_ -> return Nothing
--{{{ identifying types --{{{ identifying types
-- | Apply a slice to a type. -- | Apply a slice to a type.