From d32764016cf67067d28f21865e06812b87baefa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@lysator.liu.se> Date: Wed, 24 Feb 2021 12:35:55 +0100 Subject: [PATCH] Move code from CodeGenTest to library module. --- CodeGenTest.hs | 32 +------------------------------- LysKom/TypesHelper.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 LysKom/TypesHelper.hs diff --git a/CodeGenTest.hs b/CodeGenTest.hs index c1ec2dc..e4c6a95 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 0000000..b9c45eb --- /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 + + -- GitLab