Split UserDataType and Record
This commit is contained in:
parent
5480262836
commit
ff3bd7fd71
|
@ -8,7 +8,7 @@ import Metadata
|
|||
|
||||
data NameType =
|
||||
ChannelName | DataTypeName | FunctionName | FieldName | PortName
|
||||
| ProcName | ProtocolName | TagName | TimerName | VariableName
|
||||
| ProcName | ProtocolName | RecordName | TagName | TimerName | VariableName
|
||||
deriving (Show, Eq, Typeable, Data)
|
||||
|
||||
data Name = Name {
|
||||
|
@ -42,6 +42,7 @@ data Type =
|
|||
| Real32 | Real64
|
||||
| Array [Dimension] Type
|
||||
| UserDataType Name
|
||||
| Record Name
|
||||
| UserProtocol Name
|
||||
| Chan Type
|
||||
| Counted Type Type
|
||||
|
@ -208,7 +209,7 @@ data SpecType =
|
|||
| IsExpr Meta AbbrevMode Type Expression
|
||||
| IsChannelArray Meta Type [Variable]
|
||||
| DataType Meta Type
|
||||
| DataTypeRecord Meta Bool [(Name, Type)]
|
||||
| RecordType Meta Bool [(Name, Type)]
|
||||
| Protocol Meta [Type]
|
||||
| ProtocolCase Meta [(Name, [Type])]
|
||||
| Proc Meta SpecMode [Formal] Process
|
||||
|
|
|
@ -132,7 +132,7 @@ genType :: A.Type -> CGen ()
|
|||
genType (A.Array _ t)
|
||||
= do genType t
|
||||
tell ["*"]
|
||||
genType (A.UserDataType n) = genName n
|
||||
genType (A.Record n) = genName n
|
||||
-- UserProtocol -- not used
|
||||
genType (A.Chan t) = tell ["Channel *"]
|
||||
-- Counted -- not used
|
||||
|
@ -175,7 +175,7 @@ genBytesIn' (A.Array ds t) v
|
|||
case free of
|
||||
Nothing -> return $ Just i
|
||||
Just _ -> die "genBytesIn' type with more than one free dimension"
|
||||
genBytesIn' (A.UserDataType n) _
|
||||
genBytesIn' (A.Record n) _
|
||||
= do tell ["sizeof ("]
|
||||
genName n
|
||||
tell [")"]
|
||||
|
@ -199,7 +199,7 @@ genDeclType am t
|
|||
case t of
|
||||
A.Array _ _ -> return ()
|
||||
A.Chan _ -> return ()
|
||||
A.UserDataType _ -> tell [" *"]
|
||||
A.Record _ -> tell [" *"]
|
||||
_ -> when (am == A.Abbrev) $ tell [" *"]
|
||||
|
||||
genDecl :: A.AbbrevMode -> A.Type -> A.Name -> CGen ()
|
||||
|
@ -408,8 +408,8 @@ genVariable' checkValid v
|
|||
(_, A.Array _ _) -> ""
|
||||
(A.Original, A.Chan _) -> if isSub then "" else "&"
|
||||
(A.Abbrev, A.Chan _) -> ""
|
||||
(A.Original, A.UserDataType _) -> "&"
|
||||
(A.Abbrev, A.UserDataType _) -> ""
|
||||
(A.Original, A.Record _) -> "&"
|
||||
(A.Abbrev, A.Record _) -> ""
|
||||
(A.Abbrev, _) -> "*"
|
||||
_ -> ""
|
||||
|
||||
|
@ -767,7 +767,7 @@ abbrevVariable am (A.Array _ _) v
|
|||
= (genVariable v, genArraySize True (genVariable v >> tell ["_sizes"]))
|
||||
abbrevVariable am (A.Chan _) v
|
||||
= (genVariable v, noSize)
|
||||
abbrevVariable am (A.UserDataType _) v
|
||||
abbrevVariable am (A.Record _) v
|
||||
= (genVariable v, noSize)
|
||||
abbrevVariable am t v
|
||||
= (genVariableAM v am, noSize)
|
||||
|
@ -963,7 +963,7 @@ introduceSpec (A.Specification _ n (A.IsChannelArray _ t cs))
|
|||
tell ["};\n"]
|
||||
declareArraySizes [A.Dimension $ length cs] (genName n)
|
||||
--introduceSpec (A.Specification m n (A.DataType m t))
|
||||
introduceSpec (A.Specification _ n (A.DataTypeRecord _ b fs))
|
||||
introduceSpec (A.Specification _ n (A.RecordType _ b fs))
|
||||
= do tell ["typedef struct {\n"]
|
||||
sequence_ [case t of
|
||||
_ ->
|
||||
|
|
|
@ -352,7 +352,7 @@ postSubscript :: A.Type -> OccParser A.Subscript
|
|||
postSubscript t
|
||||
= do m <- md
|
||||
case t of
|
||||
A.UserDataType _ ->
|
||||
A.Record _ ->
|
||||
do f <- tryXV sLeft fieldName
|
||||
sRight
|
||||
return $ A.SubscriptField m f
|
||||
|
@ -582,6 +582,7 @@ functionName = name A.FunctionName
|
|||
portName = name A.PortName
|
||||
procName = name A.ProcName
|
||||
protocolName = name A.ProtocolName
|
||||
recordName = name A.RecordName
|
||||
timerName = name A.TimerName
|
||||
variableName = name A.VariableName
|
||||
|
||||
|
@ -591,6 +592,7 @@ newFunctionName = newName A.FunctionName
|
|||
newPortName = newName A.PortName
|
||||
newProcName = newName A.ProcName
|
||||
newProtocolName = newName A.ProtocolName
|
||||
newRecordName = newName A.RecordName
|
||||
newTimerName = newName A.TimerName
|
||||
newVariableName = newName A.VariableName
|
||||
|
||||
|
@ -628,6 +630,7 @@ dataType
|
|||
<|> do { sREAL64; return A.Real64 }
|
||||
<|> arrayType dataType
|
||||
<|> do { n <- try dataTypeName; return $ A.UserDataType n }
|
||||
<|> do { n <- try recordName; return $ A.Record n }
|
||||
<?> "data type"
|
||||
|
||||
-- FIXME should probably make CHAN INT work, since that'd be trivial...
|
||||
|
@ -1255,9 +1258,8 @@ definition
|
|||
= do m <- md
|
||||
sDATA
|
||||
sTYPE
|
||||
n <- newDataTypeName
|
||||
do { sIS; t <- dataType; sColon; eol; return $ A.Specification m n (A.DataType m t) }
|
||||
<|> do { eol; indent; rec <- structuredType; outdent; sColon; eol; return $ A.Specification m n rec }
|
||||
do { n <- tryVX newDataTypeName sIS; t <- dataType; sColon; eol; return $ A.Specification m n (A.DataType m t) }
|
||||
<|> do { n <- newRecordName; eol; indent; rec <- structuredType; outdent; sColon; eol; return $ A.Specification m n rec }
|
||||
<|> do m <- md
|
||||
sPROTOCOL
|
||||
n <- newProtocolName
|
||||
|
@ -1425,7 +1427,7 @@ structuredType
|
|||
indent
|
||||
fs <- many1 structuredTypeField
|
||||
outdent
|
||||
return $ A.DataTypeRecord m isPacked (concat fs)
|
||||
return $ A.RecordType m isPacked (concat fs)
|
||||
<?> "structured type"
|
||||
|
||||
recordKeyword :: OccParser Bool
|
||||
|
|
|
@ -60,10 +60,10 @@ sliceType m _ _ _ = dieP m "slice of non-array type"
|
|||
|
||||
-- | Get the type of a record field.
|
||||
typeOfRecordField :: (PSM m, Die m) => Meta -> A.Type -> A.Name -> m A.Type
|
||||
typeOfRecordField m (A.UserDataType rec) field
|
||||
typeOfRecordField m (A.Record rec) field
|
||||
= do st <- specTypeOfName rec
|
||||
case st of
|
||||
A.DataTypeRecord _ _ fs -> checkJust "unknown record field" $ lookup field fs
|
||||
A.RecordType _ _ fs -> checkJust "unknown record field" $ lookup field fs
|
||||
_ -> dieP m "not record type"
|
||||
typeOfRecordField m _ _ = dieP m "not record type"
|
||||
|
||||
|
@ -294,11 +294,11 @@ isCaseableType t = isIntegerType t
|
|||
-- | Simplify a type as far as possible: resolve data type aliases to their
|
||||
-- real types, and remove non-constant array dimensions.
|
||||
simplifyType :: (PSM m, Die m) => A.Type -> m A.Type
|
||||
simplifyType origT@(A.UserDataType n)
|
||||
simplifyType origT@(A.Record n)
|
||||
= do st <- specTypeOfName n
|
||||
case st of
|
||||
A.DataType _ t -> simplifyType t
|
||||
A.DataTypeRecord _ _ _ -> return origT
|
||||
A.RecordType _ _ _ -> return origT
|
||||
simplifyType (A.Array ds t)
|
||||
= do t' <- simplifyType t
|
||||
return $ A.Array ds t'
|
||||
|
@ -344,12 +344,12 @@ bytesInType a@(A.Array _ _) = bytesInArray 0 a
|
|||
(A.UnknownDimension, BIJust m) -> return $ BIOneFree m num
|
||||
(A.UnknownDimension, BIOneFree _ _) -> return BIManyFree
|
||||
(_, _) -> return ts
|
||||
bytesInType (A.UserDataType n)
|
||||
bytesInType (A.Record n)
|
||||
= do st <- specTypeOfName n
|
||||
case st of
|
||||
-- We can only do this for *packed* records -- for normal records,
|
||||
-- the compiler might insert padding.
|
||||
(A.DataTypeRecord _ True nts) -> bytesInList nts
|
||||
(A.RecordType _ True nts) -> bytesInList nts
|
||||
_ -> return $ BIUnknown
|
||||
where
|
||||
bytesInList :: (PSM m, Die m) => [(A.Name, A.Type)] -> m BytesInResult
|
||||
|
|
|
@ -179,7 +179,7 @@ removeNesting p
|
|||
canPull :: A.SpecType -> Bool
|
||||
canPull (A.Proc _ _ _ _) = True
|
||||
canPull (A.DataType _ _) = True
|
||||
canPull (A.DataTypeRecord _ _ _) = True
|
||||
canPull (A.RecordType _ _ _) = True
|
||||
canPull (A.Protocol _ _) = True
|
||||
canPull (A.ProtocolCase _ _) = True
|
||||
canPull _ = False
|
||||
|
|
Loading…
Reference in New Issue
Block a user