Type cleanups

This commit is contained in:
Adam Sampson 2007-04-11 13:02:54 +00:00
parent 5cf4683cb0
commit e6cf94c60e
3 changed files with 36 additions and 15 deletions

View File

@ -7,8 +7,8 @@ module GenerateC where
-- FIXME: Checks should be done in the parser, not here -- for example, the -- FIXME: Checks should be done in the parser, not here -- for example, the
-- expressionList production should take an argument with a list of types. -- expressionList production should take an argument with a list of types.
-- FIXME: Arrays. Should be a struct that contains the data and size, and we -- FIXME: Arrays should support multiple dimensions (and never be nested).
-- then use a pointer to the struct to pass around. -- AST should have A.Array [Expression] Type.
-- FIXME: The show instance for types should produce occam-looking types. -- FIXME: The show instance for types should produce occam-looking types.
@ -74,16 +74,19 @@ genName n = tell [[if c == '.' then '_' else c | c <- A.nameName n]]
--}}} --}}}
--{{{ types --{{{ types
genType :: A.Type -> CGen () scalarType :: A.Type -> Maybe String
genType A.Bool = tell ["bool"] scalarType A.Bool = Just "bool"
-- FIXME: This probably isn't right; we might have to explicitly cast string literals... -- FIXME: This probably isn't right; we might have to explicitly cast string literals...
genType A.Byte = tell ["char"] scalarType A.Byte = Just "char"
genType A.Int = tell ["int"] scalarType A.Int = Just "int"
genType A.Int16 = tell ["int16_t"] scalarType A.Int16 = Just "int16_t"
genType A.Int32 = tell ["int32_t"] scalarType A.Int32 = Just "int32_t"
genType A.Int64 = tell ["int64_t"] scalarType A.Int64 = Just "int64_t"
genType A.Real32 = tell ["float"] scalarType A.Real32 = Just "float"
genType A.Real64 = tell ["double"] scalarType A.Real64 = Just "double"
scalarType _ = Nothing
genType :: A.Type -> CGen ()
genType (A.Array e t) genType (A.Array e t)
= do genType t = do genType t
tell ["["] tell ["["]
@ -93,9 +96,11 @@ genType (A.ArrayUnsized t)
= do genType t = do genType t
tell ["[]"] tell ["[]"]
genType (A.UserDataType n) = genName n genType (A.UserDataType n) = genName n
genType (A.Chan t) genType (A.Chan t) = tell ["Channel *"]
= do tell ["Channel*"] genType t
genType t = missing $ "genType " ++ show t = case scalarType t of
Just s -> tell [s]
Nothing -> missing $ "genType " ++ show t
--}}} --}}}
--{{{ declarations --{{{ declarations
@ -226,6 +231,7 @@ genExpression (A.False m) = tell ["false"]
--genExpression (A.FunctionCall m n es) --genExpression (A.FunctionCall m n es)
--genExpression (A.SubscriptedExpr m s e) --genExpression (A.SubscriptedExpr m s e)
--genExpression (A.BytesInExpr m e) --genExpression (A.BytesInExpr m e)
-- FIXME This needs to do special stuff with arrays.
genExpression (A.BytesInType m t) genExpression (A.BytesInType m t)
= do tell ["sizeof ("] = do tell ["sizeof ("]
genType t genType t
@ -234,7 +240,10 @@ genExpression (A.BytesInType m t)
genExpression t = missing $ "genExpression " ++ show t genExpression t = missing $ "genExpression " ++ show t
genTypeConstant :: String -> A.Type -> CGen () genTypeConstant :: String -> A.Type -> CGen ()
genTypeConstant s t = missing $ "genTypeConstant " ++ show t genTypeConstant s t
= case scalarType t of
Just ct -> tell ["occam_", s, "_", ct]
Nothing -> missing $ "genTypeConstant " ++ show t
--}}} --}}}
--{{{ operators --{{{ operators

View File

@ -109,3 +109,9 @@ abbrevModeOfSpec s
A.RetypesExpr _ am _ _ -> am A.RetypesExpr _ am _ _ -> am
_ -> A.Original _ -> A.Original
isArrayType :: ParseState -> A.Type -> Bool
isArrayType ps (A.Array _ _) = True
isArrayType ps (A.ArrayUnsized _) = True
-- FIXME Should handle user data types
isArrayType _ _ = False

View File

@ -204,4 +204,10 @@ removeNesting p
canPull :: A.SpecType -> Bool canPull :: A.SpecType -> Bool
canPull (A.Proc _ _ _) = True canPull (A.Proc _ _ _) = True
canPull (A.DataType _ _) = True
canPull (A.DataTypeRecord _ _ _) = True
canPull (A.Protocol _ _) = True
canPull (A.ProtocolCase _ _) = True
-- FIXME: Should pull up constant expressions too
canPull _ = False canPull _ = False