-
Notifications
You must be signed in to change notification settings - Fork 14
/
DsDec.hs
87 lines (71 loc) · 2.59 KB
/
DsDec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{- Tests for the th-desugar package
(c) Richard Eisenberg 2013
eir@cis.upenn.edu
-}
{-# LANGUAGE TemplateHaskell, GADTs, PolyKinds, TypeFamilies,
MultiParamTypeClasses, FunctionalDependencies,
FlexibleInstances, DataKinds, CPP, RankNTypes,
StandaloneDeriving, DefaultSignatures,
ConstraintKinds #-}
#if __GLASGOW_HASKELL__ >= 707
{-# LANGUAGE RoleAnnotations #-}
#endif
#if __GLASGOW_HASKELL__ >= 801
{-# LANGUAGE DerivingStrategies #-}
#endif
{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-incomplete-patterns
-fno-warn-name-shadowing #-}
#if __GLASGOW_HASKELL__ >= 711
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
#endif
module DsDec where
import qualified Splices as S
import Splices ( dsDecSplice, unqualify )
import Language.Haskell.TH ( reportError )
import Language.Haskell.TH.Desugar
import Control.Monad
$(dsDecSplice S.dectest1)
$(dsDecSplice S.dectest2)
$(dsDecSplice S.dectest3)
$(dsDecSplice S.dectest4)
$(dsDecSplice S.dectest5)
$(dsDecSplice S.dectest6)
$(dsDecSplice S.dectest7)
$(dsDecSplice S.dectest8)
$(dsDecSplice S.dectest9)
$(dsDecSplice (fmap unqualify S.instance_test))
$(dsDecSplice (fmap unqualify S.imp_inst_test1))
$(dsDecSplice (fmap unqualify S.imp_inst_test2))
$(dsDecSplice (fmap unqualify S.imp_inst_test3))
$(dsDecSplice (fmap unqualify S.imp_inst_test4))
#if __GLASGOW_HASKELL__ < 707
$(return $ decsToTH [S.ds_dectest10])
#else
$(dsDecSplice S.dectest10)
#endif
#if __GLASGOW_HASKELL__ >= 709
$(dsDecSplice S.dectest11)
$(dsDecSplice S.standalone_deriving_test)
#endif
#if __GLASGOW_HASKELL__ >= 801
$(dsDecSplice S.deriv_strat_test)
#endif
$(dsDecSplice S.dectest12)
$(dsDecSplice S.dectest13)
$(do decs <- S.rec_sel_test
[DDataD nd [] name [DPlainTV tvbName] cons []] <- dsDecs decs
let arg_ty = (DConT name) `DAppT` (DVarT tvbName)
recsels <- fmap concat $ mapM (getRecordSelectors arg_ty) cons
let num_sels = length recsels `div` 2 -- ignore type sigs
when (num_sels /= S.rec_sel_test_num_sels) $
reportError $ "Wrong number of record selectors extracted.\n"
++ "Wanted " ++ show S.rec_sel_test_num_sels
++ ", Got " ++ show num_sels
let unrecord c@(DCon _ _ _ (DNormalC {}) _) = c
unrecord (DCon tvbs cxt con_name (DRecC fields) rty) =
let (_names, stricts, types) = unzip3 fields
fields' = zip stricts types
in
DCon tvbs cxt con_name (DNormalC fields') rty
plaindata = [DDataD nd [] name [DPlainTV tvbName] (map unrecord cons) []]
return (decsToTH plaindata ++ map letDecToTH recsels))