summaryrefslogtreecommitdiff
path: root/ddl/Language.hs
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-03-21 12:37:37 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-03-21 14:12:26 +0100
commitd022971b99be214c71429d58f97f85b13e33a426 (patch)
tree712da683ad7167833c93e6671263d04bff39995d /ddl/Language.hs
parent4d40c4ee5ed15544d2ac7fb1ea7b61e89766d277 (diff)
work on java json loader
Diffstat (limited to 'ddl/Language.hs')
-rw-r--r--ddl/Language.hs31
1 files changed, 19 insertions, 12 deletions
diff --git a/ddl/Language.hs b/ddl/Language.hs
index afa87fa..be684db 100644
--- a/ddl/Language.hs
+++ b/ddl/Language.hs
@@ -81,6 +81,10 @@ data Type
81 | Data { name_ :: String } 81 | Data { name_ :: String }
82 deriving (Show,Generic,Eq,Ord) 82 deriving (Show,Generic,Eq,Ord)
83 83
84hasEnumConstructor :: DataDef -> Bool
85hasEnumConstructor DataDef{..} = or [null fields | ConstructorDef{..} <- constructors]
86hasEnumConstructor _ = False
87
84collectTypes :: AliasMap -> ModuleDef -> Set Type 88collectTypes :: AliasMap -> ModuleDef -> Set Type
85collectTypes aliasMap ModuleDef{..} = Set.fromList $ map (normalize aliasMap) $ concat 89collectTypes aliasMap ModuleDef{..} = Set.fromList $ map (normalize aliasMap) $ concat
86 [Data dataName : concatMap flatType [fieldType | ConstructorDef{..} <- constructors, Field{..} <- fields] | DataDef{..} <- definitions] 90 [Data dataName : concatMap flatType [fieldType | ConstructorDef{..} <- constructors, Field{..} <- fields] | DataDef{..} <- definitions]
@@ -255,11 +259,14 @@ javaType aliasMap a = case normalize aliasMap a of
255 Array t -> "ArrayList<" ++ javaType aliasMap t ++ ">" 259 Array t -> "ArrayList<" ++ javaType aliasMap t ++ ">"
256 List t -> "ArrayList<" ++ javaType aliasMap t ++ ">" 260 List t -> "ArrayList<" ++ javaType aliasMap t ++ ">"
257 Map k v -> "HashMap<" ++ javaType aliasMap k ++ ", " ++ javaType aliasMap v ++ ">" 261 Map k v -> "HashMap<" ++ javaType aliasMap k ++ ", " ++ javaType aliasMap v ++ ">"
258 _ -> "Integer" 262 V2 t -> "V2<" ++ javaType aliasMap t ++ ">"
259 --x -> error $ "javaType: " ++ show x 263 V3 t -> "V3<" ++ javaType aliasMap t ++ ">"
260 264 V4 t -> "V4<" ++ javaType aliasMap t ++ ">"
261csTypeEnum :: AliasMap -> Type -> String 265 Maybe t -> "Maybe<" ++ parens (javaType aliasMap t) ++ ">"
262csTypeEnum aliasMap a = case normalize aliasMap a of 266 x -> error $ "javaType: " ++ show x
267
268typeEnum :: AliasMap -> Type -> String
269typeEnum aliasMap a = case normalize aliasMap a of
263 Data t -> t 270 Data t -> t
264 Int -> "Int" 271 Int -> "Int"
265 Int32 -> "Int32" 272 Int32 -> "Int32"
@@ -268,13 +275,13 @@ csTypeEnum aliasMap a = case normalize aliasMap a of
268 Float -> "Float" 275 Float -> "Float"
269 Bool -> "Bool" 276 Bool -> "Bool"
270 String -> "String" 277 String -> "String"
271 Array t -> "Array_" ++ csTypeEnum aliasMap t 278 Array t -> "Array_" ++ typeEnum aliasMap t
272 List t -> "List_" ++ csTypeEnum aliasMap t 279 List t -> "List_" ++ typeEnum aliasMap t
273 Map k v -> "Map_" ++ csTypeEnum aliasMap k ++ "_" ++ csTypeEnum aliasMap v 280 Map k v -> "Map_" ++ typeEnum aliasMap k ++ "_" ++ typeEnum aliasMap v
274 V2 t -> "V2_" ++ csTypeEnum aliasMap t 281 V2 t -> "V2_" ++ typeEnum aliasMap t
275 V3 t -> "V3_" ++ csTypeEnum aliasMap t 282 V3 t -> "V3_" ++ typeEnum aliasMap t
276 V4 t -> "V4_" ++ csTypeEnum aliasMap t 283 V4 t -> "V4_" ++ typeEnum aliasMap t
277 Maybe t -> "Maybe_" ++ csTypeEnum aliasMap t 284 Maybe t -> "Maybe_" ++ typeEnum aliasMap t
278 x -> error $ "unknown type: " ++ show x 285 x -> error $ "unknown type: " ++ show x
279 286
280csType :: String -> AliasMap -> Type -> String -- TODO 287csType :: String -> AliasMap -> Type -> String -- TODO