Add pretty printing instances for parameters.

This is mostly for debugging.
This commit is contained in:
Iavor Diatchki 2022-10-14 15:38:43 +03:00
parent b66d990343
commit 8de5a7921f
2 changed files with 30 additions and 1 deletions

View File

@ -453,3 +453,10 @@ instance PP n => PP (WithNames (ModuleG n)) where
-- XXX: Print abstarct types/functions
vcat (map (ppWithNames (addTNames mps nm)) mDecls)
where mps = map mtpParam (Map.elems mParamTypes)
instance PP (WithNames TCTopEntity) where
ppPrec _ (WithNames ent nm) =
case ent of
TCTopModule m -> ppWithNames nm m
TCTopSignature n ps ->
hang ("interface module" <+> pp n <+> "where") 2 (ppWithNames nm ps)

View File

@ -25,7 +25,7 @@ import qualified Data.Set as Set
import Data.Text (Text)
import Cryptol.Parser.Selector
import Cryptol.Parser.Position(Located,Range,emptyRange)
import Cryptol.Parser.Position(Located,thing,Range,emptyRange)
import Cryptol.Parser.AST(ImpName(..))
import Cryptol.ModuleSystem.Name
import Cryptol.Utils.Ident (Ident, isInfixIdent, exprModName, ogModule)
@ -1285,3 +1285,25 @@ instance PP TypeSource where
GeneratorOfListComp -> "generator in a list comprehension"
FunApp -> "function call"
TypeErrorPlaceHolder -> "type error place-holder"
instance PP (WithNames ModParamNames) where
ppPrec _ (WithNames ps ns) =
let tps = Map.elems (mpnTypes ps)
in
vcat $ map pp tps ++
if null (mpnConstraints ps) then [] else
[ "type constraint" <+>
parens (commaSep (map (ppWithNames ns . thing)
(mpnConstraints ps)))
] ++
map (ppWithNames ns) (Map.elems (mpnFuns ps))
instance PP ModTParam where
ppPrec _ p =
"type" <+> pp (mtpName p) <+> ":" <+> pp (mtpKind p)
instance PP (WithNames ModVParam) where
ppPrec _ (WithNames p ns) =
pp (mvpName p) <+> ":" <+> ppWithNames ns (mvpType p)