/src/debug/Language/Haskell/Tools/Debug/DebugGhcAST.hs

https://github.com/haskell-tools/haskell-tools · Haskell · 393 lines · 358 code · 19 blank · 16 comment · 0 complexity · a2a610167201f3704a6878a670428b82 MD5 · raw file

  1. {-# LANGUAGE FlexibleContexts #-}
  2. {-# LANGUAGE FlexibleInstances #-}
  3. {-# LANGUAGE StandaloneDeriving #-}
  4. {-# LANGUAGE UndecidableInstances #-}
  5. -- | A module for showing GHC's syntax tree representation.
  6. module Language.Haskell.Tools.Debug.DebugGhcAST where
  7. import Language.Haskell.Tools.AST (shortShowSpan)
  8. import Bag (bagToList, Bag(..))
  9. import BasicTypes
  10. import BooleanFormula (BooleanFormula(..))
  11. import Coercion (Var(..), Role(..))
  12. import ConLike (ConLike(..))
  13. import CoreSyn (Tickish(..))
  14. import FieldLabel (FieldLbl(..))
  15. import ForeignCall
  16. import GHC
  17. import Module (Module(..), ModuleName(..))
  18. import OccName (OccName(..))
  19. import Outputable (Outputable(..), showSDocUnsafe)
  20. import PatSyn (PatSyn(..))
  21. import RdrName (RdrName(..))
  22. import TcEvidence
  23. import UniqFM (UniqFM(..))
  24. import UniqSet (UniqSet(..))
  25. instance Show a => Show (Located a) where
  26. show (L l a) = "L(" ++ shortShowSpan l ++ ") (" ++ show a ++ ")"
  27. deriving instance Show (ABExport GhcPs)
  28. deriving instance Show (AmbiguousFieldOcc GhcPs)
  29. deriving instance Show (AnnDecl GhcPs)
  30. deriving instance Show (AnnProvenance RdrName)
  31. deriving instance Show (ApplicativeArg GhcPs)
  32. deriving instance Show (ArithSeqInfo GhcPs)
  33. deriving instance Show (BooleanFormula (Located RdrName))
  34. deriving instance Show (ClsInstDecl GhcPs)
  35. deriving instance Show (ConDecl GhcPs)
  36. deriving instance Show (ConDeclField GhcPs)
  37. deriving instance Show (DataFamInstDecl GhcPs)
  38. deriving instance Show (DefaultDecl GhcPs)
  39. deriving instance Show (DerivDecl GhcPs)
  40. deriving instance Show (FamilyDecl GhcPs)
  41. deriving instance Show (FamilyInfo GhcPs)
  42. deriving instance Show (FamilyResultSig GhcPs)
  43. deriving instance Show (FieldLbl RdrName)
  44. deriving instance Show (FieldOcc GhcPs)
  45. deriving instance Show (FixitySig GhcPs)
  46. deriving instance Show (ForeignDecl GhcPs)
  47. deriving instance Show a => Show (GRHS GhcPs a)
  48. deriving instance Show a => Show (GRHSs GhcPs a)
  49. deriving instance Show (InjectivityAnn GhcPs)
  50. -- deriving instance Show (HsAppType GhcPs)
  51. deriving instance Show (HsBindLR GhcPs GhcPs)
  52. deriving instance Show (HsBracket GhcPs)
  53. deriving instance Show (HsCmd GhcPs)
  54. deriving instance Show (HsCmdTop GhcPs)
  55. deriving instance Show (HsConDeclDetails GhcPs)
  56. deriving instance Show (HsConPatDetails GhcPs)
  57. deriving instance Show (HsDataDefn GhcPs)
  58. deriving instance Show (HsDerivingClause GhcPs)
  59. deriving instance Show (DerivStrategy GhcPs)
  60. deriving instance Show (HsDecl GhcPs)
  61. deriving instance Show (HsExpr GhcPs)
  62. deriving instance Show (HsGroup GhcPs)
  63. deriving instance Show (HsLit GhcPs)
  64. deriving instance Show (HsLocalBindsLR GhcPs GhcPs)
  65. deriving instance Show (HsModule GhcPs)
  66. deriving instance Show (HsOverLit GhcPs)
  67. deriving instance Show (HsPatSynDetails (Located RdrName))
  68. deriving instance Show (HsPatSynDir GhcPs)
  69. deriving instance Show (HsRecFields GhcPs (LPat GhcPs))
  70. deriving instance Show (HsRecordBinds GhcPs)
  71. deriving instance Show (HsSplice GhcPs)
  72. deriving instance Show (HsSplicedThing GhcPs)
  73. deriving instance Show (HsStmtContext RdrName)
  74. deriving instance Show (HsTupArg GhcPs)
  75. deriving instance Show (HsTyVarBndr GhcPs)
  76. deriving instance Show (HsType GhcPs)
  77. deriving instance Show (HsValBindsLR GhcPs GhcPs)
  78. deriving instance Show (IE GhcPs)
  79. deriving instance Show (IEWrappedName RdrName)
  80. deriving instance Show (ImportDecl GhcPs)
  81. deriving instance Show (InstDecl GhcPs)
  82. deriving instance Show (LHsQTyVars GhcPs)
  83. deriving instance Show a => Show (Match GhcPs a)
  84. deriving instance Show (HsMatchContext RdrName)
  85. deriving instance Show a => Show (MatchGroup GhcPs a)
  86. deriving instance Show (ParStmtBlock GhcPs GhcPs)
  87. deriving instance Show (Pat GhcPs)
  88. deriving instance Show (PatSynBind GhcPs GhcPs)
  89. deriving instance Show (RecordPatSynField (Located RdrName))
  90. deriving instance Show (RoleAnnotDecl GhcPs)
  91. deriving instance Show (RuleBndr GhcPs)
  92. deriving instance Show (RuleDecl GhcPs)
  93. deriving instance Show (RuleDecls GhcPs)
  94. deriving instance Show (Sig GhcPs)
  95. deriving instance Show (SpliceDecl GhcPs)
  96. deriving instance Show (SyntaxExpr GhcPs)
  97. deriving instance Show a => Show (StmtLR GhcPs GhcPs a)
  98. deriving instance Show (TyClDecl GhcPs)
  99. deriving instance Show (TyClGroup GhcPs)
  100. deriving instance (Show a, Show b) => Show (FamEqn GhcPs a b)
  101. deriving instance Show (TyFamInstDecl GhcPs)
  102. -- deriving instance Show (VectDecl GhcPs)
  103. deriving instance Show (WarnDecl GhcPs)
  104. deriving instance Show (WarnDecls GhcPs)
  105. deriving instance Show (NHsValBindsLR GhcPs)
  106. deriving instance Show (ABExport GhcRn)
  107. deriving instance Show (AmbiguousFieldOcc GhcRn)
  108. deriving instance Show (AnnDecl GhcRn)
  109. deriving instance Show (AnnProvenance Name)
  110. deriving instance Show (ApplicativeArg GhcRn)
  111. deriving instance Show (ArithSeqInfo GhcRn)
  112. deriving instance Show (BooleanFormula (Located Name))
  113. deriving instance Show (ClsInstDecl GhcRn)
  114. deriving instance Show (ConDecl GhcRn)
  115. deriving instance Show (ConDeclField GhcRn)
  116. deriving instance Show (DataFamInstDecl GhcRn)
  117. deriving instance Show (DefaultDecl GhcRn)
  118. deriving instance Show (DerivDecl GhcRn)
  119. deriving instance Show (FamilyDecl GhcRn)
  120. deriving instance Show (FamilyInfo GhcRn)
  121. deriving instance Show (FamilyResultSig GhcRn)
  122. deriving instance Show (FieldLbl Name)
  123. deriving instance Show (FieldOcc GhcRn)
  124. deriving instance Show (FixitySig GhcRn)
  125. deriving instance Show (ForeignDecl GhcRn)
  126. deriving instance Show a => Show (GRHS GhcRn a)
  127. deriving instance Show a => Show (GRHSs GhcRn a)
  128. deriving instance Show (InjectivityAnn GhcRn)
  129. -- deriving instance Show (HsAppType GhcRn)
  130. deriving instance Show (HsBindLR GhcRn GhcRn)
  131. deriving instance Show (HsBracket GhcRn)
  132. deriving instance Show (HsCmd GhcRn)
  133. deriving instance Show (HsCmdTop GhcRn)
  134. deriving instance Show (HsConDeclDetails GhcRn)
  135. deriving instance Show (HsConPatDetails GhcRn)
  136. deriving instance Show (HsDataDefn GhcRn)
  137. deriving instance Show (HsDerivingClause GhcRn)
  138. deriving instance Show (DerivStrategy GhcRn)
  139. deriving instance Show (HsDecl GhcRn)
  140. deriving instance Show (HsExpr GhcRn)
  141. deriving instance Show (HsGroup GhcRn)
  142. deriving instance Show (HsLit GhcRn)
  143. deriving instance Show (HsLocalBindsLR GhcRn GhcRn)
  144. deriving instance Show (HsMatchContext Name)
  145. deriving instance Show (HsModule GhcRn)
  146. deriving instance Show (HsOverLit GhcRn)
  147. deriving instance Show (HsPatSynDetails (Located Name))
  148. deriving instance Show (HsPatSynDir GhcRn)
  149. deriving instance Show (HsRecFields GhcRn (LPat GhcRn))
  150. deriving instance Show (HsRecordBinds GhcRn)
  151. deriving instance Show (HsSplice GhcRn)
  152. deriving instance Show (HsSplicedThing GhcRn)
  153. deriving instance Show (HsStmtContext Name)
  154. deriving instance Show (HsTupArg GhcRn)
  155. deriving instance Show (HsTyVarBndr GhcRn)
  156. deriving instance Show (HsType GhcRn)
  157. deriving instance Show (HsValBindsLR GhcRn GhcRn)
  158. deriving instance Show (IE GhcRn)
  159. deriving instance Show (IEWrappedName Name)
  160. deriving instance Show (ImportDecl GhcRn)
  161. deriving instance Show (InstDecl GhcRn)
  162. deriving instance Show (LHsQTyVars GhcRn)
  163. deriving instance Show a => Show (Match GhcRn a)
  164. deriving instance Show a => Show (MatchGroup GhcRn a)
  165. deriving instance Show (ParStmtBlock GhcRn GhcRn)
  166. deriving instance Show (Pat GhcRn)
  167. deriving instance Show (PatSynBind GhcRn GhcRn)
  168. deriving instance Show (RecordPatSynField (Located Name))
  169. deriving instance Show (RoleAnnotDecl GhcRn)
  170. deriving instance Show (RuleBndr GhcRn)
  171. deriving instance Show (RuleDecl GhcRn)
  172. deriving instance Show (RuleDecls GhcRn)
  173. deriving instance Show (Sig GhcRn)
  174. deriving instance Show (SpliceDecl GhcRn)
  175. deriving instance Show (SyntaxExpr GhcRn)
  176. deriving instance Show a => Show (StmtLR GhcRn GhcRn a)
  177. deriving instance Show (TyClDecl GhcRn)
  178. deriving instance Show (TyClGroup GhcRn)
  179. deriving instance (Show a, Show b) => Show (FamEqn GhcRn a b)
  180. deriving instance Show (TyFamInstDecl GhcRn)
  181. -- deriving instance Show (VectDecl GhcRn)
  182. deriving instance Show (WarnDecl GhcRn)
  183. deriving instance Show (WarnDecls GhcRn)
  184. deriving instance Show (NHsValBindsLR GhcRn)
  185. deriving instance Show (ABExport GhcTc)
  186. deriving instance Show (AmbiguousFieldOcc GhcTc)
  187. deriving instance Show (AnnDecl GhcTc)
  188. deriving instance Show (AnnProvenance Id)
  189. deriving instance Show (ApplicativeArg GhcTc)
  190. deriving instance Show (ArithSeqInfo GhcTc)
  191. deriving instance Show (BooleanFormula (Located Id))
  192. deriving instance Show (ClsInstDecl GhcTc)
  193. deriving instance Show (ConDecl GhcTc)
  194. deriving instance Show (ConDeclField GhcTc)
  195. deriving instance Show (DataFamInstDecl GhcTc)
  196. deriving instance Show (DefaultDecl GhcTc)
  197. deriving instance Show (DerivDecl GhcTc)
  198. deriving instance Show (DerivStrategy GhcTc)
  199. deriving instance Show (FamilyDecl GhcTc)
  200. deriving instance Show (FamilyInfo GhcTc)
  201. deriving instance Show (FamilyResultSig GhcTc)
  202. deriving instance Show (FieldLbl Id)
  203. deriving instance Show (FieldOcc GhcTc)
  204. deriving instance Show (FixitySig GhcTc)
  205. deriving instance Show (ForeignDecl GhcTc)
  206. deriving instance Show a => Show (GRHS GhcTc a)
  207. deriving instance Show a => Show (GRHSs GhcTc a)
  208. deriving instance Show (InjectivityAnn GhcTc)
  209. -- deriving instance Show (HsAppType GhcTc)
  210. deriving instance Show (HsBindLR GhcTc GhcTc)
  211. deriving instance Show (HsBracket GhcTc)
  212. deriving instance Show (HsCmd GhcTc)
  213. deriving instance Show (HsCmdTop GhcTc)
  214. deriving instance Show (HsConDeclDetails GhcTc)
  215. deriving instance Show (HsConPatDetails GhcTc)
  216. deriving instance Show (HsDataDefn GhcTc)
  217. deriving instance Show (HsDerivingClause GhcTc)
  218. deriving instance Show (HsDecl GhcTc)
  219. deriving instance Show (HsExpr GhcTc)
  220. deriving instance Show (HsGroup GhcTc)
  221. deriving instance Show (HsLit GhcTc)
  222. deriving instance Show (HsLocalBindsLR GhcTc GhcTc)
  223. deriving instance Show (HsMatchContext Id)
  224. deriving instance Show (HsModule GhcTc)
  225. deriving instance Show (HsOverLit GhcTc)
  226. deriving instance Show (HsPatSynDetails (Located Id))
  227. deriving instance Show (HsPatSynDir GhcTc)
  228. deriving instance Show (HsRecFields GhcTc (LPat GhcTc))
  229. deriving instance Show (HsRecordBinds GhcTc)
  230. deriving instance Show (HsSplice GhcTc)
  231. deriving instance Show (HsSplicedThing GhcTc)
  232. deriving instance Show (HsStmtContext Id)
  233. deriving instance Show (HsTupArg GhcTc)
  234. deriving instance Show (HsTyVarBndr GhcTc)
  235. deriving instance Show (HsType GhcTc)
  236. deriving instance Show (HsValBindsLR GhcTc GhcTc)
  237. deriving instance Show (IE GhcTc)
  238. deriving instance Show (IEWrappedName Id)
  239. deriving instance Show (ImportDecl GhcTc)
  240. deriving instance Show (InstDecl GhcTc)
  241. deriving instance Show (LHsQTyVars GhcTc)
  242. deriving instance Show a => Show (Match GhcTc a)
  243. deriving instance Show a => Show (MatchGroup GhcTc a)
  244. deriving instance Show (ParStmtBlock GhcTc GhcTc)
  245. deriving instance Show (Pat GhcTc)
  246. deriving instance Show (PatSynBind GhcTc GhcTc)
  247. deriving instance Show (RecordPatSynField (Located Id))
  248. deriving instance Show (RoleAnnotDecl GhcTc)
  249. deriving instance Show (RuleBndr GhcTc)
  250. deriving instance Show (RuleDecl GhcTc)
  251. deriving instance Show (RuleDecls GhcTc)
  252. deriving instance Show (Sig GhcTc)
  253. deriving instance Show (SpliceDecl GhcTc)
  254. deriving instance Show (SyntaxExpr GhcTc)
  255. deriving instance Show a => Show (StmtLR GhcTc GhcTc a)
  256. deriving instance Show (TyClDecl GhcTc)
  257. deriving instance Show (TyClGroup GhcTc)
  258. deriving instance (Show a, Show b) => Show (FamEqn GhcTc a b)
  259. deriving instance Show (TyFamInstDecl GhcTc)
  260. -- deriving instance Show (VectDecl GhcTc)
  261. deriving instance Show (WarnDecl GhcTc)
  262. deriving instance Show (WarnDecls GhcTc)
  263. deriving instance Show (NHsValBindsLR GhcTc)
  264. deriving instance Show Activation
  265. deriving instance Show HsArrAppType
  266. deriving instance Show Boxity
  267. deriving instance Show CType
  268. deriving instance Show CImportSpec
  269. deriving instance Show CExportSpec
  270. deriving instance Show CCallConv
  271. deriving instance Show CCallTarget
  272. deriving instance Show ConLike
  273. deriving instance Show DocDecl
  274. deriving instance Show Fixity
  275. deriving instance Show FixityDirection
  276. deriving instance Show ForeignImport
  277. deriving instance Show ForeignExport
  278. deriving instance Show Header
  279. deriving instance Show HsIPName
  280. deriving instance Show HsTupleSort
  281. deriving instance Show HsSrcBang
  282. deriving instance Show InlinePragma
  283. deriving instance Show NewOrData
  284. deriving instance Show Origin
  285. deriving instance Show OverLitVal
  286. deriving instance Show OverlapMode
  287. -- deriving instance Show PlaceHolder
  288. deriving instance Show Role
  289. deriving instance Show RecFlag
  290. deriving instance Show SpliceExplicitFlag
  291. deriving instance Show TcSpecPrag
  292. deriving instance Show TcSpecPrags
  293. deriving instance Show TransForm
  294. deriving instance Show WarningTxt
  295. deriving instance Show PendingRnSplice
  296. deriving instance Show PendingTcSplice
  297. deriving instance Show OverLitTc
  298. deriving instance Show RecordConTc
  299. deriving instance Show CmdTopTc
  300. deriving instance Show NPatBindTc
  301. deriving instance Show NewHsTypeX
  302. deriving instance Show RecordUpdTc
  303. instance Show UnboundVar where
  304. show (OutOfScope n _) = "OutOfScope " ++ show n
  305. show (TrueExprHole n) = "TrueExprHole " ++ show n
  306. instance Show ModuleName where
  307. show = showSDocUnsafe . ppr
  308. instance Show TyCon where
  309. show = showSDocUnsafe . ppr
  310. instance Show ClsInst where
  311. show = showSDocUnsafe . ppr
  312. instance Show Type where
  313. show = showSDocUnsafe . ppr
  314. instance Show OccName where
  315. show = showSDocUnsafe . ppr
  316. -- instance Show RdrName where
  317. -- show = showSDocUnsafe . ppr
  318. deriving instance Show RdrName
  319. deriving instance Show NoExt
  320. deriving instance Show Module
  321. deriving instance Show StringLiteral
  322. deriving instance Show UntypedSpliceFlavour
  323. deriving instance Show SrcUnpackedness
  324. deriving instance Show SrcStrictness
  325. deriving instance Show IEWildcard
  326. deriving instance Show HsWildCardInfo
  327. deriving instance Show HsIBRn
  328. deriving instance Show DataDeclRn
  329. deriving instance Show RecStmtTc
  330. deriving instance Show HsRuleRn
  331. deriving instance Show ListPatTc
  332. deriving instance Show MatchGroupTc
  333. deriving instance Show HsQTvsRn
  334. deriving instance (Show t) => Show (HsImplicitBndrs GhcPs t)
  335. deriving instance (Show t) => Show (HsImplicitBndrs GhcRn t)
  336. deriving instance (Show t) => Show (HsImplicitBndrs GhcTc t)
  337. deriving instance (Show t) => Show (HsWildCardBndrs GhcPs t)
  338. deriving instance (Show t) => Show (HsWildCardBndrs GhcRn t)
  339. deriving instance (Show t) => Show (HsWildCardBndrs GhcTc t)
  340. deriving instance (Show a, Show b) => Show (HsRecField' a b)
  341. instance Show Name where
  342. show = showSDocUnsafe . ppr
  343. instance Show HsTyLit where
  344. show = showSDocUnsafe . ppr
  345. instance Show Var where
  346. show = showSDocUnsafe . ppr
  347. instance Show DataCon where
  348. show = showSDocUnsafe . ppr
  349. instance Show PatSyn where
  350. show = showSDocUnsafe . ppr
  351. instance Show TcEvBinds where
  352. show = showSDocUnsafe . ppr
  353. instance Show HsWrapper where
  354. show = showSDocUnsafe . ppr
  355. instance Show Class where
  356. show = showSDocUnsafe . ppr
  357. instance Show TcCoercion where
  358. show = showSDocUnsafe . ppr
  359. -- instance Show DerivStrategy where
  360. -- show = showSDocUnsafe . ppr
  361. instance Outputable a => Show (UniqFM a) where
  362. show = showSDocUnsafe . ppr
  363. instance Outputable a => Show (UniqSet a) where
  364. show = showSDocUnsafe . ppr
  365. instance Outputable a => Show (Tickish a) where
  366. show = showSDocUnsafe . ppr
  367. instance (OutputableBndrId (GhcPass p)) => Show (HsIPBinds (GhcPass p)) where
  368. show = showSDocUnsafe . ppr
  369. instance Show LexicalFixity where
  370. show = showSDocUnsafe . ppr
  371. instance Show a => Show (Bag a) where
  372. show = show . bagToList
  373. instance Show ThModFinalizers where
  374. show _ = ""