Browse Source

ivory backend: split producer and consumer schemas into different modules.

Pat Hickey 9 years ago
parent
commit
b7de4bf927
2 changed files with 12 additions and 10 deletions
  1. 5 2
      src/Gidl/Backend/Ivory.hs
  2. 7 8
      src/Gidl/Backend/Ivory/Interface.hs

+ 5 - 2
src/Gidl/Backend/Ivory.hs

@@ -2,6 +2,7 @@ module Gidl.Backend.Ivory where
 
 import Gidl.Types
 import Gidl.Interface
+import Gidl.Schema
 import Gidl.Backend.Cabal
 import Gidl.Backend.Ivory.Types
 import Gidl.Backend.Ivory.Interface
@@ -24,11 +25,13 @@ ivoryBackend (TypeEnv te) (InterfaceEnv ie) pkgname namespace_raw =
   userDefinedTypes = [ t | (_,t) <- te, isUserDefined t ]
   tmods = [ typeModule (namespace ++ ["Types"]) t
           | t <- userDefinedTypes ]
-  imods =[ interfaceModule (namespace ++ ["Interface"]) i
+  imods =[ [ interfaceModule (namespace ++ ["Interface"]) i (producerSchema i)
+           , interfaceModule (namespace ++ ["Interface"]) i (consumerSchema i)
+           ]
          | (_iname, i) <- ie
          ]
   sourceMods = tmods
-            ++ imods
+            ++ concat imods
             ++ [ typeUmbrella namespace userDefinedTypes
                , unpackModule namespace
                ]

+ 7 - 8
src/Gidl/Backend/Ivory/Interface.hs

@@ -13,10 +13,10 @@ import Gidl.Backend.Ivory.Types
 import Ivory.Artifact
 import Text.PrettyPrint.Mainland
 
-interfaceModule :: [String] -> Interface -> Artifact
-interfaceModule modulepath ir =
-  artifactPath (intercalate "/" modulepath) $
-  artifactText ((ifModuleName ir) ++ ".hs") $
+interfaceModule :: [String] -> Interface -> Schema -> Artifact
+interfaceModule modulepath ir schema =
+  artifactPath (intercalate "/" (modulepath ++ [ifModuleName ir])) $
+  artifactText (schemaName ++ ".hs") $
   prettyLazyText 80 $
   stack
     [ text "{-# LANGUAGE DataKinds #-}"
@@ -25,16 +25,15 @@ interfaceModule modulepath ir =
     , text "{-# OPTIONS_GHC -fno-warn-unused-imports #-}"
     , empty
     , text "module"
-      <+> im (ifModuleName ir)
+      <+> im (ifModuleName ir) <> dot <> text schemaName
       <+> text "where"
     , empty
     , stack $ typeimports ++ extraimports
     , empty
-    , schemaDoc (ifModuleName ir) (producerSchema ir)
-    , empty
-    , schemaDoc (ifModuleName ir) (consumerSchema ir)
+    , schemaDoc (ifModuleName ir) schema
     ]
   where
+  (Schema schemaName _) = schema
   rootpath = reverse . drop 1 . reverse
   modAt path = mconcat (punctuate dot (map text path))
   im mname = modAt (modulepath ++ [mname])