on master help sign in
Use `Location.none` less
commita4c4cf0493027b91836e9da44408498af05cb2f2 authorEvan Czaplicki <info@elm-lang.org> dateTue 30 Jul 2013, 11:55 (13 years ago) parentb26edcc
6 files changed+18−16
compiler/Generate/JavaScript.hs+6−6 compiler/Parse/Expression.hs+2−1 compiler/SourceSyntax/Location.hs+2−1 compiler/Transform/Optimize.hs+3−3 compiler/Type/Constrain/Declaration.hs+2−2 compiler/Type/Constrain/Expression.hs+3−3
compiler/Generate/JavaScript.hs+6−6
@@ -12,7 +12,7 @@ import qualified Text.Pandoc as Pan
1212import Unique
1313import Generate.Cases
1414import SourceSyntax.Everything hiding (parens)
15−import SourceSyntax.Location as Loc
15+import SourceSyntax.Location
1616import qualified Transform.SortDefinitions as SD
1717
1818deprime :: String -> String
@@ -130,12 +130,12 @@ instance ToJS (Def t v) where
130130 | isOp x = globalAssign ("_op['" ++ x ++ "']") `liftM` toJS' e
131131 | otherwise = assign (deprime x) `liftM` toJS' e
132132
133− toJS (Def pattern e) =
133+ toJS (Def pattern e@(L s _)) =
134134 do n <- guid
135135 let x = "_" ++ show n
136− var = Loc.none . Var
136+ var = L s . Var
137137 toDef y' = let y = deprime y' in
138− Def (PVar y) (Loc.none $ Case (var x) [(pattern, var y)])
138+ Def (PVar y) (L s $ Case (var x) [(pattern, var y)])
139139 stmt <- assign x `liftM` toJS' e
140140 vars <- toJS . map toDef . Set.toList $ SD.boundVars pattern
141141 return (stmt ++ vars)
@@ -196,7 +196,7 @@ instance ToJS (Expr t v) where
196196 Record fs -> makeRecord fs
197197 Binop op e1 e2 -> binop op `liftM` toJS' e1 `ap` toJS' e2
198198
199− Lambda p e -> liftM (fastFunc . ret) (toJS' body)
199+ Lambda p e@(L s _) -> liftM (fastFunc . ret) (toJS' body)
200200 where
201201 fastFunc body
202202 | length args < 2 || length args > 9 = foldr jsFunc body args
@@ -207,7 +207,7 @@ instance ToJS (Expr t v) where
207207 case pattern of
208208 PVar x -> (deprime x : args, body)
209209 _ -> let arg = "arg" ++ show n
210− in (arg:args, Loc.none (Case (Loc.none (Var arg)) [(pattern, body)]))
210+ in (arg:args, L s (Case (L s (Var arg)) [(pattern, body)]))
211211
212212 (patterns, innerBody) = collect [p] e
213213
compiler/Parse/Expression.hs+2−1
@@ -157,7 +157,8 @@ ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
157157 thenBranch <- expr
158158 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
159159 elseBranch <- expr
160− return $ MultiIf [(bool, thenBranch), (Location.none (Var "otherwise"), elseBranch)]
160+ return $ MultiIf [(bool, thenBranch),
161+ (Location.sameAs elseBranch (Var "otherwise"), elseBranch)]
161162 multiIf = MultiIf <$> spaceSep1 iff
162163 where iff = do string "|" ; whitespace
163164 b <- expr ; whitespace ; string "->" ; whitespace
compiler/SourceSyntax/Location.hs+2−1
@@ -26,7 +26,6 @@ instance Show SrcSpan where
2626instance Show e => Show (Located e) where
2727 show (L _ e) = show e
2828
29−
3029none = L NoSpan
3130
3231at start end = L (Span (Pos (Parsec.sourceLine start) (Parsec.sourceColumn start))
@@ -37,3 +36,5 @@ merge (L s1 _) (L s2 _) = L span
3736 (Span start _, Span _ end) -> Span start end
3837 (_, NoSpan) -> s1
3938 (NoSpan, _) -> s2
39+
40+sameAs (L s _) = L s
compiler/Transform/Optimize.hs+3−3
@@ -56,9 +56,9 @@ isValue e =
5656 _ -> False
5757
5858
59−binop op ce1@(L t1 s1 e1) ce2@(L t2 s2 e2) =
60− let c1 = L t1 s1
61− c2 = L t2 s2
59+binop op ce1@(L s1 e1) ce2@(L s2 e2) =
60+ let c1 = L s1
61+ c2 = L s2
6262 int = Literal . IntNum
6363 str = Literal . Str
6464 bool = Literal . Boolean
compiler/Type/Constrain/Declaration.hs+2−2
@@ -64,5 +64,5 @@ toDefs decl =
6464arguments :: [String]
6565arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
6666
67−buildFunction body vars =
68− foldr (\p e -> Src.none (Src.Lambda p e)) body (map Src.PVar vars)
67+buildFunction body@(Src.L s _) vars =
68+ foldr (\p e -> Src.L s (Src.Lambda p e)) body (map Src.PVar vars)
compiler/Type/Constrain/Expression.hs+3−3
@@ -182,15 +182,15 @@ constrainDef env info (pattern, expr, maybeTipe) =
182182
183183expandPattern :: (Pattern, LExpr t v, Maybe SrcT.Type)
184184 -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
185−expandPattern triple@(pattern, lexpr, maybeType) =
185+expandPattern triple@(pattern, lexpr@(L s _), maybeType) =
186186 case pattern of
187187 PVar _ -> [triple]
188188 _ -> (PVar x, lexpr, maybeType) : map toDef vars
189189 where
190190 vars = Set.toList $ SD.boundVars pattern
191191 x = concat vars
192− var = Loc.none . Var
193− toDef y = (PVar y, Loc.none $ Case (var x) [(pattern, var y)], Nothing)
192+ var = L s . Var
193+ toDef y = (PVar y, L s $ Case (var x) [(pattern, var y)], Nothing)
194194
195195collapseDefs :: [Def t v] -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
196196collapseDefs = concatMap expandPattern . go [] Map.empty Map.empty