summaryrefslogtreecommitdiff
path: root/compiler/main/GHC.hs
diff options
context:
space:
mode:
authorShayan-Najd <sh.najd@gmail.com>2018-11-22 01:23:29 +0000
committerAlan Zimmerman <alan.zimm@gmail.com>2018-11-24 12:30:21 +0200
commit509d5be69c7507ba5d0a5f39ffd1613a59e73eea (patch)
treeb3db08f371014cbf235525843a312f67dea77354 /compiler/main/GHC.hs
parentad2d7612dbdf0e928318394ec0606da3b85a8837 (diff)
downloadhaskell-509d5be69c7507ba5d0a5f39ffd1613a59e73eea.tar.gz
[TTG: Handling Source Locations] Foundation and Pat
This patch removes the ping-pong style from HsPat (only, for now), using the plan laid out at https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations (solution A). - the class `HasSrcSpan`, and its functions (e.g., `cL` and `dL`), are introduced - some instances of `HasSrcSpan` are introduced - some constructors `L` are replaced with `cL` - some patterns `L` are replaced with `dL->L` view pattern - some type annotation are necessarily updated (e.g., `Pat p` --> `Pat (GhcPass p)`) Phab diff: D5036 Trac Issues #15495 Updates haddock submodule
Diffstat (limited to 'compiler/main/GHC.hs')
-rw-r--r--compiler/main/GHC.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs
index da5ef8ba2d..8817b41c8a 100644
--- a/compiler/main/GHC.hs
+++ b/compiler/main/GHC.hs
@@ -1,5 +1,7 @@
{-# LANGUAGE CPP, NondecreasingIndentation, ScopedTypeVariables #-}
{-# LANGUAGE TupleSections, NamedFieldPuns #-}
+{-# LANGUAGE ViewPatterns #-}
+{-# LANGUAGE TypeFamilies #-}
-- -----------------------------------------------------------------------------
--
@@ -250,6 +252,10 @@ module GHC (
-- *** Deconstructing Located
getLoc, unLoc,
+ getRealSrcSpan, unRealSrcSpan,
+
+ -- ** HasSrcSpan
+ HasSrcSpan(..), SrcSpanLess, dL, cL,
-- *** Combining and comparing Located values
eqLocated, cmpLocated, combineLocs, addCLoc,
@@ -1380,7 +1386,7 @@ getRichTokenStream mod = do
addSourceToTokens :: RealSrcLoc -> StringBuffer -> [Located Token]
-> [(Located Token, String)]
addSourceToTokens _ _ [] = []
-addSourceToTokens loc buf (t@(L span _) : ts)
+addSourceToTokens loc buf (t@(dL->L span _) : ts)
= case span of
UnhelpfulSpan _ -> (t,"") : addSourceToTokens loc buf ts
RealSrcSpan s -> (t,str) : addSourceToTokens newLoc newBuf ts
@@ -1406,7 +1412,7 @@ showRichTokenStream ts = go startLoc ts ""
getFile (RealSrcSpan s : _) = srcSpanFile s
startLoc = mkRealSrcLoc sourceFile 1 1
go _ [] = id
- go loc ((L span _, str):ts)
+ go loc ((dL->L span _, str):ts)
= case span of
UnhelpfulSpan _ -> go loc ts
RealSrcSpan s