diff --git a/CodeGenTest.hs b/CodeGenTest.hs index c1ec2dc004d02cff488422e7f67b7d1917d8d41b..e4c6a95ad5c5e9218af690fa04e2ed32b39aaabb 100644 --- a/CodeGenTest.hs +++ b/CodeGenTest.hs @@ -13,37 +13,7 @@ import LysKom.ProtocolA.Types )) import LysKom.Internal.NameTransform (transformTree) -proc :: ProtocolAItem -> Int -proc (Comment _) = 0 -proc (DerivedType _ _) = 1 -proc (Request _ _ _ _) = 3 -proc (Async _ _ _) = 5 -proc (ProtoEdition _) = 0 -proc (ProtoVer _) = 0 -proc (LysKomDVersion _) = 0 -proc (TypeAlias _ _) = 2 -proc (RequestAlias _ _) = 4 -proc (AsyncAlias _ _) = 6 -proc (Other _) = 9 - -selection2Enum :: LysType -> LysType -selection2Enum (SELECTION xs) = ENUMERATION [ (n ++ "E", i) | (i, _, (n,_)) <- xs ] - - -isSelect :: String -> ProtocolAItem -> Bool -isSelect m (DerivedType n d) = n == m -isSelect _ _ = False - -enumOf2Enum :: [ProtocolAItem] -> ProtocolAItem -> ProtocolAItem -enumOf2Enum lst (DerivedType n (ENUMERATION_OF t)) - = let (DerivedType m selection) = head $ filter (isSelect t) lst - in DerivedType n . selection2Enum $ selection -enumOf2Enum lst a = a - --- filter out lookup-name since its target is non-existant -g :: ProtocolAItem -> Bool -g (RequestAlias "lookupName1" _) = False -g _ = True +import LysKom.TypesHelper main :: IO () main = do diff --git a/LysKom/TypesHelper.hs b/LysKom/TypesHelper.hs new file mode 100644 index 0000000000000000000000000000000000000000..b9c45ebd6dba697994c5c6d41ecb06e89faee146 --- /dev/null +++ b/LysKom/TypesHelper.hs @@ -0,0 +1,42 @@ +module LysKom.TypesHelper where + +import LysKom.ProtocolA.Data (ProtocolAItem (..)) +import LysKom.ProtocolA.Types + ( LysType ( ENUMERATION_OF + , ENUMERATION + , SELECTION + )) + +proc :: ProtocolAItem -> Int +proc (Comment _) = 0 +proc (DerivedType _ _) = 1 +proc (Request _ _ _ _) = 3 +proc (Async _ _ _) = 5 +proc (ProtoEdition _) = 0 +proc (ProtoVer _) = 0 +proc (LysKomDVersion _) = 0 +proc (TypeAlias _ _) = 2 +proc (RequestAlias _ _) = 4 +proc (AsyncAlias _ _) = 6 +proc (Other _) = 9 + +selection2Enum :: LysType -> LysType +selection2Enum (SELECTION xs) = ENUMERATION [ (n ++ "E", i) | (i, _, (n,_)) <- xs ] + + +isSelect :: String -> ProtocolAItem -> Bool +isSelect m (DerivedType n d) = n == m +isSelect _ _ = False + +enumOf2Enum :: [ProtocolAItem] -> ProtocolAItem -> ProtocolAItem +enumOf2Enum lst (DerivedType n (ENUMERATION_OF t)) + = let (DerivedType m selection) = head $ filter (isSelect t) lst + in DerivedType n . selection2Enum $ selection +enumOf2Enum lst a = a + +-- filter out lookup-name since its target is non-existant +g :: ProtocolAItem -> Bool +g (RequestAlias "lookupName1" _) = False +g _ = True + +