1{-# OPTIONS_GHC -Wall #-}
10 , DependencyInterface(..)
18import Control.Monad (liftM, liftM2, liftM4, liftM5)
20import Data.Map.Strict ((!))
21import qualified Data.Map.Strict as Map
22import qualified Data.Map.Merge.Strict as Map
23import qualified Data.Name as Name
25import qualified AST.Canonical as Can
26import qualified AST.Utils.Binop as Binop
27import qualified Elm.Package as Pkg
28import qualified Reporting.Annotation as A
38 , _values :: Map.Map Name.Name Can.Annotation
39 , _unions :: Map.Map Name.Name Union
40 , _aliases :: Map.Map Name.Name Alias
41 , _binops :: Map.Map Name.Name Binop
48 | ClosedUnion Can.Union
49 | PrivateUnion Can.Union
54 = PublicAlias Can.Alias
55 | PrivateAlias Can.Alias
61 { _op_name :: Name.Name
62 , _op_annotation :: Can.Annotation
63 , _op_associativity :: Binop.Associativity
64 , _op_precedence :: Binop.Precedence
73fromModule :: Pkg.Name -> Can.Module -> Map.Map Name.Name Can.Annotation -> Interface
74fromModule home (Can.Module _ exports _ unions aliases binops _) annotations =
77 , _values = restrict exports annotations
78 , _unions = restrictUnions exports unions
79 , _aliases = restrictAliases exports aliases
80 , _binops = restrict exports (Map.map (toOp annotations) binops)
84restrict :: Can.Exports -> Map.Map Name.Name a -> Map.Map Name.Name a
85restrict exports dict =
87 Can.ExportEverything _ ->
90 Can.Export explicitExports ->
91 Map.intersection dict explicitExports
94toOp :: Map.Map Name.Name Can.Annotation -> Can.Binop -> Binop
95toOp types (Can.Binop_ associativity precedence name) =
96 Binop name (types ! name) associativity precedence
99restrictUnions :: Can.Exports -> Map.Map Name.Name Can.Union -> Map.Map Name.Name Union
100restrictUnions exports unions =
102 Can.ExportEverything _ ->
103 Map.map OpenUnion unions
105 Can.Export explicitExports ->
106 Map.merge onLeft onRight onBoth explicitExports unions
108 onLeft = Map.dropMissing
109 onRight = Map.mapMissing (\_ union -> PrivateUnion union)
110 onBoth = Map.zipWithMatched $ \_ (A.At _ export) union ->
112 Can.ExportUnionOpen -> OpenUnion union
113 Can.ExportUnionClosed -> ClosedUnion union
114 _ -> error "impossible exports discovered in restrictUnions"
117restrictAliases :: Can.Exports -> Map.Map Name.Name Can.Alias -> Map.Map Name.Name Alias
118restrictAliases exports aliases =
120 Can.ExportEverything _ ->
121 Map.map PublicAlias aliases
123 Can.Export explicitExports ->
124 Map.merge onLeft onRight onBoth explicitExports aliases
126 onLeft = Map.dropMissing
127 onRight = Map.mapMissing (\_ a -> PrivateAlias a)
128 onBoth = Map.zipWithMatched (\_ _ a -> PublicAlias a)
135toPublicUnion :: Union -> Maybe Can.Union
136toPublicUnion iUnion =
138 OpenUnion union -> Just union
139 ClosedUnion (Can.Union vars _ _ opts) -> Just (Can.Union vars [] 0 opts)
140 PrivateUnion _ -> Nothing
143toPublicAlias :: Alias -> Maybe Can.Alias
144toPublicAlias iAlias =
146 PublicAlias alias -> Just alias
147 PrivateAlias _ -> Nothing
151-- DEPENDENCY INTERFACE
154data DependencyInterface
156 | Private (Map.Map Name.Name Can.Union) (Map.Map Name.Name Can.Alias)
159public :: Interface -> DependencyInterface
164private :: Interface -> DependencyInterface
165private (Interface _ _ unions aliases _) =
167 (Map.map extractUnion unions)
168 (Map.map extractAlias aliases)
171extractUnion :: Union -> Can.Union
174 OpenUnion union -> union
175 ClosedUnion union -> union
176 PrivateUnion union -> union
179extractAlias :: Alias -> Can.Alias
182 PublicAlias alias -> alias
183 PrivateAlias alias -> alias
186privatize :: DependencyInterface -> DependencyInterface
189 Public i -> private i
197instance Binary Interface where
198 get = liftM5 Interface get get get get get
199 put (Interface a b c d e) = put a >> put b >> put c >> put d >> put e
202instance Binary Union where
205 OpenUnion u -> putWord8 0 >> put u
206 ClosedUnion u -> putWord8 1 >> put u
207 PrivateUnion u -> putWord8 2 >> put u
212 0 -> liftM OpenUnion get
213 1 -> liftM ClosedUnion get
214 2 -> liftM PrivateUnion get
215 _ -> error "binary encoding of Union was corrupted"
218instance Binary Alias where
221 PublicAlias a -> putWord8 0 >> put a
222 PrivateAlias a -> putWord8 1 >> put a
227 0 -> liftM PublicAlias get
228 1 -> liftM PrivateAlias get
229 _ -> error "binary encoding of Alias was corrupted"
232instance Binary Binop where
234 liftM4 Binop get get get get
236 put (Binop a b c d) =
237 put a >> put b >> put c >> put d
240instance Binary DependencyInterface where
243 Public a -> putWord8 0 >> put a
244 Private a b -> putWord8 1 >> put a >> put b
249 0 -> liftM Public get
250 1 -> liftM2 Private get get
251 _ -> error "binary encoding of DependencyInterface was corrupted"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list