module Language.Haskell.Tools.AST.Gen.Types where
import qualified Name as GHC
import Data.List
import Data.String
import Data.Function (on)
import Control.Reference
import Language.Haskell.Tools.AST
import Language.Haskell.Tools.AST.ElementTypes
import Language.Haskell.Tools.AST.Gen.Names
import Language.Haskell.Tools.AST.Gen.Kinds
import Language.Haskell.Tools.AST.Gen.Utils
import Language.Haskell.Tools.Transform
mkForallType :: [TyVar dom] -> Type dom -> Type dom
mkForallType vars t = mkAnn ("forall " <> child <> " . " <> child) (UTyForall (mkAnnList (separatedBy " " list) vars) t)
mkTypeVar' :: GHC.Name -> TyVar dom
mkTypeVar' = mkTypeVar . mkUnqualName'
mkCtxType :: Context dom -> Type dom -> Type dom
mkCtxType ctx t = mkAnn (child <> " " <> child) (UTyCtx ctx t)
mkFunctionType :: Type dom -> Type dom -> Type dom
mkFunctionType at rt = mkAnn (child <> " -> " <> child) (UTyFun at rt)
mkTupleType :: [Type dom] -> Type dom
mkTupleType args = mkAnn ("(" <> child <> ")") (UTyTuple (mkAnnList (separatedBy ", " list) args))
mkUnboxedTupleType :: [Type dom] -> Type dom
mkUnboxedTupleType args = mkAnn ("(#" <> child <> "#)") (UTyUnbTuple (mkAnnList (separatedBy ", " list) args))
mkListType :: Type dom -> Type dom
mkListType = mkAnn ("[" <> child <> "]") . UTyList
mkParArrayType :: Type dom -> Type dom
mkParArrayType = mkAnn ("[:" <> child <> ":]") . UTyParArray
mkTypeApp :: Type dom -> Type dom -> Type dom
mkTypeApp ft at = mkAnn (child <> " " <> child) (UTyApp ft at)
mkInfixTypeApp :: Type dom -> Operator dom -> Type dom -> Type dom
mkInfixTypeApp left op right = mkAnn (child <> " " <> child <> " " <> child) (UTyInfix left op right)
mkParenType :: Type dom -> Type dom
mkParenType = mkAnn ("(" <> child <> ")") . UTyParen
mkTypeVar :: Name dom -> TyVar dom
mkTypeVar n = mkAnn (child <> child) (UTyVarDecl n noth)
mkKindedTypeVar :: Name dom -> Kind dom -> TyVar dom
mkKindedTypeVar n k = mkAnn (child <> child) (UTyVarDecl n (justVal (mkKindConstraint k)))
mkVarType :: Name dom -> Type dom
mkVarType = wrapperAnn . UTyVar
mkKindedType :: Type dom -> Kind dom -> Type dom
mkKindedType t k = mkAnn (child <> " :: " <> child) (UTyKinded t k)
mkBangType :: Type dom -> Type dom
mkBangType = mkAnn ("!" <> child) . UTyBang
mkLazyType :: Type dom -> Type dom
mkLazyType = mkAnn ("~" <> child) . UTyLazy
mkUnpackType :: Type dom -> Type dom
mkUnpackType = mkAnn ("{-# UNPACK #-} " <> child) . UTyUnpack
mkNoUnpackType :: Type dom -> Type dom
mkNoUnpackType = mkAnn ("{-# NOUNPACK #-} " <> child) . UTyNoUnpack
mkWildcardType :: Type dom
mkWildcardType = mkAnn "_" UTyWildcard
mkNamedWildcardType :: Name dom -> Type dom
mkNamedWildcardType = mkAnn ("_" <> child) . UTyNamedWildc
mkSpliceType :: Splice dom -> Type dom
mkSpliceType = mkAnn child . UTySplice
mkQuasiQuoteType :: QuasiQuote dom -> Type dom
mkQuasiQuoteType = mkAnn child . UTyQuasiQuote
mkPromotedIntType :: Integer -> Type dom
mkPromotedIntType i = mkAnn child $ UTyPromoted $ mkAnn (fromString $ show i) (UPromotedInt i)
mkPromotedStringType :: String -> Type dom
mkPromotedStringType i = mkAnn child $ UTyPromoted $ mkAnn (fromString $ show i) (UPromotedString i)
mkPromotedConType :: Name dom -> Type dom
mkPromotedConType = mkAnn child . UTyPromoted . mkAnn child . UPromotedCon
mkPromotedListType :: [Type dom] -> Type dom
mkPromotedListType
= mkAnn child . UTyPromoted . mkAnn ("[" <> child <> "]") . UPromotedList . mkAnnList (separatedBy ", " list)
mkPromotedTupleType :: [Type dom] -> Type dom
mkPromotedTupleType
= mkAnn child . UTyPromoted . mkAnn ("(" <> child <> ")") . UPromotedTuple . mkAnnList (separatedBy ", " list)
mkPromotedUnitType :: Type dom
mkPromotedUnitType = mkAnn child $ UTyPromoted $ mkAnn "()" UPromotedUnit
mkContextOne :: Assertion dom -> Context dom
mkContextOne = mkAnn (child <> " =>") . UContextOne
mkContextMulti :: [Assertion dom] -> Context dom
mkContextMulti = mkAnn ("(" <> child <> ") =>") . UContextMulti . mkAnnList (separatedBy ", " list)
mkClassAssert :: Name dom -> [Type dom] -> Assertion dom
mkClassAssert n args = mkAnn (child <> " " <> child) $ UClassAssert n (mkAnnList (separatedBy " " list) args)
mkInfixAssert :: Type dom -> Operator dom -> Type dom -> Assertion dom
mkInfixAssert left op right = mkAnn (child <> " " <> child <> " " <> child) $ UInfixAssert left op right
mkImplicitAssert :: Name dom -> Type dom -> Assertion dom
mkImplicitAssert n t = mkAnn (child <> " :: " <> child) $ UImplicitAssert n t