on master help sign in
cosmetic: minor whitespace stuff
commit73b288a54cc2fd56d49a3d4eaa0f5df77c89acde authorEvan Czaplicki <info@elm-lang.org> dateThu 27 Aug 2015, 17:06 (11 years ago) parent43ab5e1
3 files changed+62−40
src/AST/Variable.hs+23−13 src/Canonicalize/Setup.hs+5−5 src/Canonicalize/Variable.hs+34−22
src/AST/Variable.hs+23−13
@@ -33,15 +33,18 @@ data Canonical = Canonical
3333
3434
3535local :: String -> Canonical
36−local x = Canonical Local x
36+local x =
37+ Canonical Local x
3738
3839
3940topLevel :: [String] -> String -> Canonical
40−topLevel names x = Canonical (TopLevel names) x
41+topLevel names x =
42+ Canonical (TopLevel names) x
4143
4244
4345builtin :: String -> Canonical
44−builtin x = Canonical BuiltIn x
46+builtin x =
47+ Canonical BuiltIn x
4548
4649
4750fromModule :: [String] -> String -> Canonical
@@ -127,10 +130,17 @@ instance ToString Raw where
127130instance ToString Canonical where
128131 toString (Canonical home name) =
129132 case home of
130− BuiltIn -> name
131− Module path -> List.intercalate "." (path ++ [name])
132− Local -> name
133− TopLevel _ -> name
133+ BuiltIn ->
134+ name
135+
136+ Module path ->
137+ List.intercalate "." (path ++ [name])
138+
139+ TopLevel _ ->
140+ name
141+
142+ Local ->
143+ name
134144
135145
136146-- LISTINGS
@@ -255,19 +265,19 @@ instance Binary Canonical where
255265 Module path ->
256266 putWord8 1 >> put path >> put name
257267
258− Local ->
259− putWord8 2 >> put name
260−
261268 TopLevel path ->
262− putWord8 3 >> put path >> put name
269+ putWord8 2 >> put path >> put name
270+
271+ Local ->
272+ putWord8 3 >> put name
263273
264274 get =
265275 do tag <- getWord8
266276 case tag of
267277 0 -> Canonical BuiltIn <$> get
268278 1 -> Canonical . Module <$> get <*> get
269− 2 -> Canonical Local <$> get
270− 3 -> Canonical . TopLevel <$> get <*> get
279+ 2 -> Canonical . TopLevel <$> get <*> get
280+ 3 -> Canonical Local <$> get
271281 _ -> error "Unexpected tag when deserializing canonical variable"
272282
273283
src/Canonicalize/Setup.hs+5−5
@@ -282,11 +282,11 @@ declarationsToPatches moduleName decls =
282282 (Maybe.catMaybes maybeNodes, concat patchLists)
283283
284284
285−-- When canonicalizing, all _values should be Local, except for top-level definitions
286−-- However _adts and _patterns
287−-- should be fully namespaced, thought constructors are top_level.
288−-- With _adts, they may appear in types that can
289−-- escape the module.
285+-- When canonicalizing, it is important that:
286+-- _adts are fully namespaced (Var.Module ...)
287+-- _patterns are fully namespaced (Var.Module ...)
288+-- _values that are defined as top-level declarations are (Var.TopLevel ...)
289+-- all other _values are local (Var.Local)
290290declToPatches
291291 :: Module.Name
292292 -> D.ValidDecl
src/Canonicalize/Variable.hs+34−22
@@ -30,10 +30,10 @@ variable region env var =
3030 Just [v] ->
3131 Result.var v
3232
33− Just vs ->
33+ Just vs ->
3434 preferLocals region env "variable" vs var
3535
36− Nothing ->
36+ Nothing ->
3737 notFound region "variable" (Map.keys (Env._values env)) var
3838
3939
@@ -110,7 +110,7 @@ preferLocals'
110110 -> String
111111 -> Result.ResultErr a
112112preferLocals' region env extract kind possibilities var =
113− case filter (isLocal . extract) possibilities of
113+ case filter (isLocal (Env._home env) . extract) possibilities of
114114 [] ->
115115 ambiguous possibilities
116116
@@ -118,36 +118,48 @@ preferLocals' region env extract kind possibilities var =
118118 Result.var' extract v
119119
120120 --Local vars shadow top-level vars
121− [v1, v2] | isTopLevel (extract v1) ->
122− Result.var' extract v2
121+ [v1, v2]
122+ | isTopLevel (extract v1) ->
123+ Result.var' extract v2
123124
124− [v1, v2] | isTopLevel (extract v2) ->
125− Result.var' extract v1
125+ | isTopLevel (extract v2) ->
126+ Result.var' extract v1
126127
127128 locals ->
128129 ambiguous locals
129130 where
130− isLocal :: Var.Canonical -> Bool
131− isLocal (Var.Canonical home _) =
132− case home of
133− Var.Local -> True
134− Var.TopLevel _ -> True
135− Var.BuiltIn -> False
136− Var.Module name ->
137− name == Env._home env
138−
139− isTopLevel :: Var.Canonical -> Bool
140− isTopLevel (Var.Canonical home _) =
141− case home of
142− Var.TopLevel _ -> True
143− _ -> False
144−
145131 ambiguous possibleVars =
146132 Result.err (A.A region (Error.variable kind var Error.Ambiguous vars))
147133 where
148134 vars = map (Var.toString . extract) possibleVars
149135
150136
137+isLocal :: [String] -> Var.Canonical -> Bool
138+isLocal contextName (Var.Canonical home _) =
139+ case home of
140+ Var.Local ->
141+ True
142+
143+ Var.TopLevel _ ->
144+ True
145+
146+ Var.BuiltIn ->
147+ False
148+
149+ Var.Module name ->
150+ name == contextName
151+
152+
153+isTopLevel :: Var.Canonical -> Bool
154+isTopLevel (Var.Canonical home _) =
155+ case home of
156+ Var.TopLevel _ ->
157+ True
158+
159+ _ ->
160+ False
161+
162+
151163-- NOT FOUND HELPERS
152164
153165type VarName =