summaryrefslogtreecommitdiff
path: root/compiler/prelude
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2016-11-08 21:37:48 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2016-12-07 21:31:13 +0200
commit499e43824bda967546ebf95ee33ec1f84a114a7c (patch)
tree58b313d734cfba014395ea5876db48e8400296a8 /compiler/prelude
parent83d69dca896c7df1f2a36268d5b45c9283985ebf (diff)
downloadhaskell-499e43824bda967546ebf95ee33ec1f84a114a7c.tar.gz
Add HsSyn prettyprinter tests
Summary: Add prettyprinter tests, which take a file, parse it, pretty print it, re-parse the pretty printed version and then compare the original and new ASTs (ignoring locations) Updates haddock submodule to match the AST changes. There are three issues outstanding 1. Extra parens around a context are not reproduced. This will require an AST change and will be done in a separate patch. 2. Currently if an `HsTickPragma` is found, this is not pretty-printed, to prevent noise in the output. I am not sure what the desired behaviour in this case is, so have left it as before. Test Ppr047 is marked as expected fail for this. 3. Apart from in a context, the ParsedSource AST keeps all the parens from the original source. Something is happening in the renamer to remove the parens around visible type application, causing T12530 to fail, as the dumped splice decl is after the renamer. This needs to be fixed by keeping the parens, but I do not know where they are being removed. I have amended the test to pass, by removing the parens in the expected output. Test Plan: ./validate Reviewers: goldfire, mpickering, simonpj, bgamari, austin Reviewed By: simonpj, bgamari Subscribers: simonpj, goldfire, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D2752 GHC Trac Issues: #3384
Diffstat (limited to 'compiler/prelude')
-rw-r--r--compiler/prelude/ForeignCall.hs12
-rw-r--r--compiler/prelude/PrimOp.hs3
-rw-r--r--compiler/prelude/TysWiredIn.hs30
3 files changed, 27 insertions, 18 deletions
diff --git a/compiler/prelude/ForeignCall.hs b/compiler/prelude/ForeignCall.hs
index 8411f11e71..ff893ede02 100644
--- a/compiler/prelude/ForeignCall.hs
+++ b/compiler/prelude/ForeignCall.hs
@@ -22,7 +22,7 @@ import FastString
import Binary
import Outputable
import Module
-import BasicTypes ( SourceText )
+import BasicTypes ( SourceText, pprWithSourceText )
import Data.Char
import Data.Data
@@ -203,14 +203,14 @@ instance Outputable CCallSpec where
gc_suf | playSafe safety = text "_GC"
| otherwise = empty
- ppr_fun (StaticTarget _ fn mPkgId isFun)
+ ppr_fun (StaticTarget st _fn mPkgId isFun)
= text (if isFun then "__pkg_ccall"
else "__pkg_ccall_value")
<> gc_suf
<+> (case mPkgId of
Nothing -> empty
Just pkgId -> ppr pkgId)
- <+> pprCLabelString fn
+ <+> (pprWithSourceText st empty)
ppr_fun DynamicTarget
= text "__dyn_ccall" <> gc_suf <+> text "\"\""
@@ -221,7 +221,7 @@ data Header = Header SourceText FastString
deriving (Eq, Data)
instance Outputable Header where
- ppr (Header _ h) = quotes $ ppr h
+ ppr (Header st h) = pprWithSourceText st (doubleQuotes $ ppr h)
-- | A C type, used in CAPI FFI calls
--
@@ -236,7 +236,9 @@ data CType = CType SourceText -- Note [Pragma source text] in BasicTypes
deriving (Eq, Data)
instance Outputable CType where
- ppr (CType _ mh (_,ct)) = hDoc <+> ftext ct
+ ppr (CType stp mh (stct,ct))
+ = pprWithSourceText stp (text "{-# CTYPE") <+> hDoc
+ <+> pprWithSourceText stct (doubleQuotes (ftext ct)) <+> text "#-}"
where hDoc = case mh of
Nothing -> empty
Just h -> ppr h
diff --git a/compiler/prelude/PrimOp.hs b/compiler/prelude/PrimOp.hs
index e174aedcf4..0acac6639f 100644
--- a/compiler/prelude/PrimOp.hs
+++ b/compiler/prelude/PrimOp.hs
@@ -38,7 +38,8 @@ import OccName ( OccName, pprOccName, mkVarOccFS )
import TyCon ( TyCon, isPrimTyCon, PrimRep(..) )
import Type
import RepType ( typePrimRep, tyConPrimRep )
-import BasicTypes ( Arity, Fixity(..), FixityDirection(..), Boxity(..) )
+import BasicTypes ( Arity, Fixity(..), FixityDirection(..), Boxity(..),
+ SourceText(..) )
import ForeignCall ( CLabelString )
import Unique ( Unique, mkPrimOpIdUnique )
import Outputable
diff --git a/compiler/prelude/TysWiredIn.hs b/compiler/prelude/TysWiredIn.hs
index 1c47922a36..18cf53093d 100644
--- a/compiler/prelude/TysWiredIn.hs
+++ b/compiler/prelude/TysWiredIn.hs
@@ -144,7 +144,8 @@ import Class ( Class, mkClass )
import RdrName
import Name
import NameSet ( NameSet, mkNameSet, elemNameSet )
-import BasicTypes ( Arity, Boxity(..), TupleSort(..), ConTagZ )
+import BasicTypes ( Arity, Boxity(..), TupleSort(..), ConTagZ,
+ SourceText(..) )
import ForeignCall
import SrcLoc ( noSrcSpan )
import Unique
@@ -525,7 +526,7 @@ pcDataConWithFixity' declared_infix dc_name wrk_key rri tyvars ex_tyvars arg_tys
(mkDataConWorkId wrk_name data_con)
NoDataConRep -- Wired-in types are too simple to need wrappers
- no_bang = HsSrcBang Nothing NoSrcUnpack NoSrcStrict
+ no_bang = HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict
wrk_name = mkDataConWorkerName data_con wrk_key
@@ -1179,8 +1180,9 @@ charTy = mkTyConTy charTyCon
charTyCon :: TyCon
charTyCon = pcNonEnumTyCon charTyConName
- (Just (CType "" Nothing ("HsChar",fsLit "HsChar")))
- [] [charDataCon]
+ (Just (CType NoSourceText Nothing
+ (NoSourceText,fsLit "HsChar")))
+ [] [charDataCon]
charDataCon :: DataCon
charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon
@@ -1192,8 +1194,8 @@ intTy = mkTyConTy intTyCon
intTyCon :: TyCon
intTyCon = pcNonEnumTyCon intTyConName
- (Just (CType "" Nothing ("HsInt",fsLit "HsInt"))) []
- [intDataCon]
+ (Just (CType NoSourceText Nothing (NoSourceText,fsLit "HsInt")))
+ [] [intDataCon]
intDataCon :: DataCon
intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon
@@ -1202,8 +1204,8 @@ wordTy = mkTyConTy wordTyCon
wordTyCon :: TyCon
wordTyCon = pcNonEnumTyCon wordTyConName
- (Just (CType "" Nothing ("HsWord", fsLit "HsWord"))) []
- [wordDataCon]
+ (Just (CType NoSourceText Nothing (NoSourceText, fsLit "HsWord")))
+ [] [wordDataCon]
wordDataCon :: DataCon
wordDataCon = pcDataCon wordDataConName [] [wordPrimTy] wordTyCon
@@ -1212,7 +1214,8 @@ word8Ty = mkTyConTy word8TyCon
word8TyCon :: TyCon
word8TyCon = pcNonEnumTyCon word8TyConName
- (Just (CType "" Nothing ("HsWord8", fsLit "HsWord8"))) []
+ (Just (CType NoSourceText Nothing
+ (NoSourceText, fsLit "HsWord8"))) []
[word8DataCon]
word8DataCon :: DataCon
word8DataCon = pcDataCon word8DataConName [] [wordPrimTy] word8TyCon
@@ -1222,7 +1225,8 @@ floatTy = mkTyConTy floatTyCon
floatTyCon :: TyCon
floatTyCon = pcNonEnumTyCon floatTyConName
- (Just (CType "" Nothing ("HsFloat", fsLit "HsFloat"))) []
+ (Just (CType NoSourceText Nothing
+ (NoSourceText, fsLit "HsFloat"))) []
[floatDataCon]
floatDataCon :: DataCon
floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon
@@ -1232,7 +1236,8 @@ doubleTy = mkTyConTy doubleTyCon
doubleTyCon :: TyCon
doubleTyCon = pcNonEnumTyCon doubleTyConName
- (Just (CType "" Nothing ("HsDouble",fsLit "HsDouble"))) []
+ (Just (CType NoSourceText Nothing
+ (NoSourceText,fsLit "HsDouble"))) []
[doubleDataCon]
doubleDataCon :: DataCon
@@ -1293,7 +1298,8 @@ boolTy = mkTyConTy boolTyCon
boolTyCon :: TyCon
boolTyCon = pcTyCon True boolTyConName
- (Just (CType "" Nothing ("HsBool", fsLit "HsBool")))
+ (Just (CType NoSourceText Nothing
+ (NoSourceText, fsLit "HsBool")))
[] [falseDataCon, trueDataCon]
falseDataCon, trueDataCon :: DataCon