{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

{-
Forked from GHC v8.10.1 to work around the readFile side effect in mkHiefile

Main functions for .hie file generation
-}
{- HLINT ignore -}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Compat.HieAst ( enrichHie ) where

import GhcPrelude

import Avail                      ( Avails )
import Bag                        ( Bag, bagToList )
import BasicTypes
import BooleanFormula
import Class                      ( FunDep )
import CoreUtils                  ( exprType )
import ConLike                    ( conLikeName )
import Desugar                    ( deSugarExpr )
import FieldLabel
import GHC.Hs
import HscTypes
import Module                     ( ModuleName )
import MonadUtils                 ( concatMapM, liftIO )
import Name                       ( Name, nameSrcSpan )
import NameEnv                    ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
import SrcLoc
import TcHsSyn                    ( hsLitType, hsPatType )
import Type                       ( mkVisFunTys, Type )
import TysWiredIn                 ( mkListTy, mkSumTy )
import Var                        ( Id, Var, setVarName, varName, varType )
import Panic

import HieTypes
import HieUtils

import qualified Data.Map as M
import qualified Data.Set as S
import Data.Data                  ( Data, Typeable )
import Data.List                  ( foldl1' )
import Data.Maybe                 ( listToMaybe )
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Class  ( lift )

{- Note [Updating HieAst for changes in the GHC AST]

When updating the code in this file for changes in the GHC AST, you
need to pay attention to the following things:

1) Symbols (Names/Vars/Modules) in the following categories:

   a) Symbols that appear in the source file that directly correspond to
   something the user typed
   b) Symbols that don't appear in the source, but should be in some sense
   "visible" to a user, particularly via IDE tooling or the like. This
   includes things like the names introduced by RecordWildcards (We record
   all the names introduced by a (..) in HIE files), and will include implicit
   parameters and evidence variables after one of my pending MRs lands.

2) Subtrees that may contain such symbols, or correspond to a SrcSpan in
   the file. This includes all `Located` things

For 1), you need to call `toHie` for one of the following instances

instance ToHie (Context (Located Name)) where ...
instance ToHie (Context (Located Var)) where ...
instance ToHie (IEContext (Located ModuleName)) where ...

`Context` is a data type that looks like:

data Context a = C ContextInfo a -- Used for names and bindings

`ContextInfo` is defined in `HieTypes`, and looks like

data ContextInfo
  = Use                -- ^ regular variable
  | MatchBind
  | IEThing IEType     -- ^ import/export
  | TyDecl
  -- | Value binding
  | ValBind
      BindType     -- ^ whether or not the binding is in an instance
      Scope        -- ^ scope over which the value is bound
      (Maybe Span) -- ^ span of entire binding
  ...

It is used to annotate symbols in the .hie files with some extra information on
the context in which they occur and should be fairly self explanatory. You need
to select one that looks appropriate for the symbol usage. In very rare cases,
you might need to extend this sum type if none of the cases seem appropriate.

So, given a `Located Name` that is just being "used", and not defined at a
particular location, you would do the following:

   toHie $ C Use located_name

If you select one that corresponds to a binding site, you will need to
provide a `Scope` and a `Span` for your binding. Both of these are basically
`SrcSpans`.

The `SrcSpan` in the `Scope` is supposed to span over the part of the source
where the symbol can be legally allowed to occur. For more details on how to
calculate this, see Note [Capturing Scopes and other non local information]
in HieAst.

The binding `Span` is supposed to be the span of the entire binding for
the name.

For a function definition `foo`:

foo x = x + y
  where y = x^2

The binding `Span` is the span of the entire function definition from `foo x`
to `x^2`.  For a class definition, this is the span of the entire class, and
so on.  If this isn't well defined for your bit of syntax (like a variable
bound by a lambda), then you can just supply a `Nothing`

There is a test that checks that all symbols in the resulting HIE file
occur inside their stated `Scope`. This can be turned on by passing the
-fvalidate-ide-info flag to ghc along with -fwrite-ide-info to generate the
.hie file.

You may also want to provide a test in testsuite/test/hiefile that includes
a file containing your new construction, and tests that the calculated scope
is valid (by using -fvalidate-ide-info)

For subtrees in the AST that may contain symbols, the procedure is fairly
straightforward.  If you are extending the GHC AST, you will need to provide a
`ToHie` instance for any new types you may have introduced in the AST.

Here are is an extract from the `ToHie` instance for (LHsExpr (GhcPass p)):

  toHie e@(L mspan oexpr) = concatM $ getTypeNode e : case oexpr of
      HsVar _ (L _ var) ->
        [ toHie $ C Use (L mspan var)
             -- Patch up var location since typechecker removes it
        ]
      HsConLikeOut _ con ->
        [ toHie $ C Use $ L mspan $ conLikeName con
        ]
      ...
      HsApp _ a b ->
        [ toHie a
        , toHie b
        ]

If your subtree is `Located` or has a `SrcSpan` available, the output list
should contain a HieAst `Node` corresponding to the subtree. You can use
either `makeNode` or `getTypeNode` for this purpose, depending on whether it
makes sense to assign a `Type` to the subtree. After this, you just need
to concatenate the result of calling `toHie` on all subexpressions and
appropriately annotated symbols contained in the subtree.

The code above from the ToHie instance of `LhsExpr (GhcPass p)` is supposed
to work for both the renamed and typechecked source. `getTypeNode` is from
the `HasType` class defined in this file, and it has different instances
for `GhcTc` and `GhcRn` that allow it to access the type of the expression
when given a typechecked AST:

class Data a => HasType a where
  getTypeNode :: a -> HieM [HieAST Type]
instance HasType (LHsExpr GhcTc) where
  getTypeNode e@(L spn e') = ... -- Actually get the type for this expression
instance HasType (LHsExpr GhcRn) where
  getTypeNode (L spn e) = makeNode e spn -- Fallback to a regular `makeNode` without recording the type

If your subtree doesn't have a span available, you can omit the `makeNode`
call and just recurse directly in to the subexpressions.

-}

-- These synonyms match those defined in main/GHC.hs
type RenamedSource     = ( HsGroup GhcRn, [LImportDecl GhcRn]
                         , Maybe [(LIE GhcRn, Avails)]
                         , Maybe LHsDocString )
type TypecheckedSource = LHsBinds GhcTc


{- Note [Name Remapping]
The Typechecker introduces new names for mono names in AbsBinds.
We don't care about the distinction between mono and poly bindings,
so we replace all occurrences of the mono name with the poly name.
-}
newtype HieState = HieState
  { HieState -> NameEnv Id
name_remapping :: NameEnv Id
  }

initState :: HieState
initState :: HieState
initState = NameEnv Id -> HieState
HieState NameEnv Id
forall a. NameEnv a
emptyNameEnv

class ModifyState a where -- See Note [Name Remapping]
  addSubstitution :: a -> a -> HieState -> HieState

instance ModifyState Name where
  addSubstitution :: Name -> Name -> HieState -> HieState
addSubstitution Name
_ Name
_ HieState
hs = HieState
hs

instance ModifyState Id where
  addSubstitution :: Id -> Id -> HieState -> HieState
addSubstitution Id
mono Id
poly HieState
hs =
    HieState
hs{name_remapping :: NameEnv Id
name_remapping = NameEnv Id -> Name -> Id -> NameEnv Id
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv (HieState -> NameEnv Id
name_remapping HieState
hs) (Id -> Name
varName Id
mono) Id
poly}

modifyState :: ModifyState (IdP p) => [ABExport p] -> HieState -> HieState
modifyState :: [ABExport p] -> HieState -> HieState
modifyState = (ABExport p -> (HieState -> HieState) -> HieState -> HieState)
-> (HieState -> HieState) -> [ABExport p] -> HieState -> HieState
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ABExport p -> (HieState -> HieState) -> HieState -> HieState
forall p a.
ModifyState (IdP p) =>
ABExport p -> (a -> HieState) -> a -> HieState
go HieState -> HieState
forall a. a -> a
id
  where
    go :: ABExport p -> (a -> HieState) -> a -> HieState
go ABE{abe_poly :: forall p. ABExport p -> IdP p
abe_poly=IdP p
poly,abe_mono :: forall p. ABExport p -> IdP p
abe_mono=IdP p
mono} a -> HieState
f = IdP p -> IdP p -> HieState -> HieState
forall a. ModifyState a => a -> a -> HieState -> HieState
addSubstitution IdP p
mono IdP p
poly (HieState -> HieState) -> (a -> HieState) -> a -> HieState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> HieState
f
    go ABExport p
_ a -> HieState
f = a -> HieState
f

type HieM = ReaderT HieState Hsc

enrichHie :: TypecheckedSource -> RenamedSource -> Hsc (HieASTs Type)
enrichHie :: TypecheckedSource -> RenamedSource -> Hsc (HieASTs Type)
enrichHie TypecheckedSource
ts (HsGroup GhcRn
hsGrp, [LImportDecl GhcRn]
imports, Maybe [(LIE GhcRn, Avails)]
exports, Maybe LHsDocString
_) = (ReaderT HieState Hsc (HieASTs Type)
 -> HieState -> Hsc (HieASTs Type))
-> HieState
-> ReaderT HieState Hsc (HieASTs Type)
-> Hsc (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT HieState Hsc (HieASTs Type)
-> HieState -> Hsc (HieASTs Type)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT HieState
initState (ReaderT HieState Hsc (HieASTs Type) -> Hsc (HieASTs Type))
-> ReaderT HieState Hsc (HieASTs Type) -> Hsc (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ do
    [HieAST Type]
tasts <- Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBindLR GhcTc GhcTc -> BindContext (LHsBindLR GhcTc GhcTc))
-> TypecheckedSource -> Bag (BindContext (LHsBindLR GhcTc GhcTc))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> LHsBindLR GhcTc GhcTc
-> BindContext (LHsBindLR GhcTc GhcTc)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
ModuleScope) TypecheckedSource
ts
    [HieAST Type]
rasts <- HsGroup GhcRn -> HieM [HieAST Type]
forall p.
(HasType (LHsBind p), ModifyState (IdP p),
 Data (GRHS p (Located (HsExpr p))), Data (HsLocalBinds p),
 Data (HsBind p), ToHie (LMatch p (Located (HsExpr p))),
 ToHie (Located (HsExpr p)),
 ToHie (GenLocated SrcSpan (SpliceDecl p)),
 ToHie (GenLocated SrcSpan (DerivDecl p)),
 ToHie (GenLocated SrcSpan (FixitySig p)),
 ToHie (GenLocated SrcSpan (DefaultDecl p)),
 ToHie (GenLocated SrcSpan (ForeignDecl p)),
 ToHie (GenLocated SrcSpan (WarnDecls p)),
 ToHie (GenLocated SrcSpan (AnnDecl p)),
 ToHie (GenLocated SrcSpan (RuleDecls p)),
 ToHie (Context (Located (IdP p))), ToHie (PScoped (XRec p Pat)),
 ToHie (SigContext (LSig p)), ToHie (RScoped (XXValBindsLR p p)),
 ToHie (RScoped (GuardLStmt p)), ToHie (TyClGroup p)) =>
HsGroup p -> HieM [HieAST Type]
processGrp HsGroup GhcRn
hsGrp
    [HieAST Type]
imps <- [LImportDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([LImportDecl GhcRn] -> HieM [HieAST Type])
-> [LImportDecl GhcRn] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LImportDecl GhcRn -> Bool)
-> [LImportDecl GhcRn] -> [LImportDecl GhcRn]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> (LImportDecl GhcRn -> Bool) -> LImportDecl GhcRn -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImportDecl GhcRn -> Bool
forall pass. ImportDecl pass -> Bool
ideclImplicit (ImportDecl GhcRn -> Bool)
-> (LImportDecl GhcRn -> ImportDecl GhcRn)
-> LImportDecl GhcRn
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LImportDecl GhcRn -> ImportDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LImportDecl GhcRn]
imports
    [HieAST Type]
exps <- Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type])
-> Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([(LIE GhcRn, Avails)] -> [IEContext (LIE GhcRn)])
-> Maybe [(LIE GhcRn, Avails)] -> Maybe [IEContext (LIE GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((LIE GhcRn, Avails) -> IEContext (LIE GhcRn))
-> [(LIE GhcRn, Avails)] -> [IEContext (LIE GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (((LIE GhcRn, Avails) -> IEContext (LIE GhcRn))
 -> [(LIE GhcRn, Avails)] -> [IEContext (LIE GhcRn)])
-> ((LIE GhcRn, Avails) -> IEContext (LIE GhcRn))
-> [(LIE GhcRn, Avails)]
-> [IEContext (LIE GhcRn)]
forall a b. (a -> b) -> a -> b
$ IEType -> LIE GhcRn -> IEContext (LIE GhcRn)
forall a. IEType -> a -> IEContext a
IEC IEType
Export (LIE GhcRn -> IEContext (LIE GhcRn))
-> ((LIE GhcRn, Avails) -> LIE GhcRn)
-> (LIE GhcRn, Avails)
-> IEContext (LIE GhcRn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LIE GhcRn, Avails) -> LIE GhcRn
forall a b. (a, b) -> a
fst) Maybe [(LIE GhcRn, Avails)]
exports
    let spanFile :: [HieAST a] -> RealSrcSpan
spanFile [HieAST a]
children = case [HieAST a]
children of
          [] -> RealSrcLoc -> RealSrcLoc -> RealSrcSpan
mkRealSrcSpan (FastString -> Int -> Int -> RealSrcLoc
mkRealSrcLoc FastString
"" Int
1 Int
1) (FastString -> Int -> Int -> RealSrcLoc
mkRealSrcLoc FastString
"" Int
1 Int
1)
          [HieAST a]
_ -> RealSrcLoc -> RealSrcLoc -> RealSrcSpan
mkRealSrcSpan (RealSrcSpan -> RealSrcLoc
realSrcSpanStart (RealSrcSpan -> RealSrcLoc) -> RealSrcSpan -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan (HieAST a -> RealSrcSpan) -> HieAST a -> RealSrcSpan
forall a b. (a -> b) -> a -> b
$ [HieAST a] -> HieAST a
forall a. [a] -> a
head [HieAST a]
children)
                             (RealSrcSpan -> RealSrcLoc
realSrcSpanEnd   (RealSrcSpan -> RealSrcLoc) -> RealSrcSpan -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan (HieAST a -> RealSrcSpan) -> HieAST a -> RealSrcSpan
forall a b. (a -> b) -> a -> b
$ [HieAST a] -> HieAST a
forall a. [a] -> a
last [HieAST a]
children)

        modulify :: [HieAST a] -> HieAST a
modulify [HieAST a]
xs =
          NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
forall a. NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node (FastString -> FastString -> NodeInfo a
forall a. FastString -> FastString -> NodeInfo a
simpleNodeInfo FastString
"Module" FastString
"Module") ([HieAST a] -> RealSrcSpan
forall a. [HieAST a] -> RealSrcSpan
spanFile [HieAST a]
xs) [HieAST a]
xs

        asts :: HieASTs Type
asts = Map FastString (HieAST Type) -> HieASTs Type
forall a. Map FastString (HieAST a) -> HieASTs a
HieASTs
          (Map FastString (HieAST Type) -> HieASTs Type)
-> Map FastString (HieAST Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ Map FastString (HieAST Type) -> Map FastString (HieAST Type)
forall a. Map FastString (HieAST a) -> Map FastString (HieAST a)
resolveTyVarScopes
          (Map FastString (HieAST Type) -> Map FastString (HieAST Type))
-> Map FastString (HieAST Type) -> Map FastString (HieAST Type)
forall a b. (a -> b) -> a -> b
$ ([HieAST Type] -> HieAST Type)
-> Map FastString [HieAST Type] -> Map FastString (HieAST Type)
forall a b k. (a -> b) -> Map k a -> Map k b
M.map ([HieAST Type] -> HieAST Type
forall a. [HieAST a] -> HieAST a
modulify ([HieAST Type] -> HieAST Type)
-> ([HieAST Type] -> [HieAST Type]) -> [HieAST Type] -> HieAST Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [HieAST Type] -> [HieAST Type]
mergeSortAsts)
          (Map FastString [HieAST Type] -> Map FastString (HieAST Type))
-> Map FastString [HieAST Type] -> Map FastString (HieAST Type)
forall a b. (a -> b) -> a -> b
$ ([HieAST Type] -> [HieAST Type] -> [HieAST Type])
-> [(FastString, [HieAST Type])] -> Map FastString [HieAST Type]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
(++)
          ([(FastString, [HieAST Type])] -> Map FastString [HieAST Type])
-> [(FastString, [HieAST Type])] -> Map FastString [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HieAST Type -> (FastString, [HieAST Type]))
-> [HieAST Type] -> [(FastString, [HieAST Type])]
forall a b. (a -> b) -> [a] -> [b]
map (\HieAST Type
x -> (RealSrcSpan -> FastString
srcSpanFile (HieAST Type -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan HieAST Type
x),[HieAST Type
x])) [HieAST Type]
flat_asts

        flat_asts :: [HieAST Type]
flat_asts = [[HieAST Type]] -> [HieAST Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
          [ [HieAST Type]
tasts
          , [HieAST Type]
rasts
          , [HieAST Type]
imps
          , [HieAST Type]
exps
          ]
    HieASTs Type -> ReaderT HieState Hsc (HieASTs Type)
forall (m :: * -> *) a. Monad m => a -> m a
return HieASTs Type
asts
  where
    processGrp :: HsGroup p -> HieM [HieAST Type]
processGrp HsGroup p
grp = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RScoped (HsValBinds p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBinds p) -> HieM [HieAST Type])
-> RScoped (HsValBinds p) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsValBinds p -> RScoped (HsValBinds p))
-> (HsGroup p -> HsValBinds p)
-> HsGroup p
-> RScoped (HsValBinds p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Scope -> HsValBinds p -> RScoped (HsValBinds p)
forall a. Scope -> a -> RScoped a
RS Scope
ModuleScope ) HsGroup p -> HsValBinds p
forall p. HsGroup p -> HsValBinds p
hs_valds HsGroup p
grp
      , [GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (SpliceDecl p)]
forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds HsGroup p
grp
      , [TyClGroup p] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TyClGroup p] -> HieM [HieAST Type])
-> [TyClGroup p] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [TyClGroup p]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds HsGroup p
grp
      , [GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (DerivDecl p)]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds HsGroup p
grp
      , [GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (FixitySig p)]
forall p. HsGroup p -> [LFixitySig p]
hs_fixds HsGroup p
grp
      , [GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (DefaultDecl p)]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds HsGroup p
grp
      , [GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (ForeignDecl p)]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords HsGroup p
grp
      , [GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (WarnDecls p)]
forall p. HsGroup p -> [LWarnDecls p]
hs_warnds HsGroup p
grp
      , [GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (AnnDecl p)]
forall p. HsGroup p -> [LAnnDecl p]
hs_annds HsGroup p
grp
      , [GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (RuleDecls p)]
forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds HsGroup p
grp
      ]

getRealSpan :: SrcSpan -> Maybe Span
getRealSpan :: SrcSpan -> Maybe RealSrcSpan
getRealSpan (RealSrcSpan RealSrcSpan
sp) = RealSrcSpan -> Maybe RealSrcSpan
forall a. a -> Maybe a
Just RealSrcSpan
sp
getRealSpan SrcSpan
_ = Maybe RealSrcSpan
forall a. Maybe a
Nothing

grhss_span :: GRHSs p body -> SrcSpan
grhss_span :: GRHSs p body -> SrcSpan
grhss_span (GRHSs XCGRHSs p body
_ [LGRHS p body]
xs LHsLocalBinds p
bs) = (SrcSpan -> SrcSpan -> SrcSpan) -> SrcSpan -> [SrcSpan] -> SrcSpan
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (LHsLocalBinds p -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc LHsLocalBinds p
bs) ((LGRHS p body -> SrcSpan) -> [LGRHS p body] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map LGRHS p body -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc [LGRHS p body]
xs)
grhss_span (XGRHSs XXGRHSs p body
_) = String -> SrcSpan
forall a. String -> a
panic String
"XGRHS has no span"

bindingsOnly :: [Context Name] -> [HieAST a]
bindingsOnly :: [Context Name] -> [HieAST a]
bindingsOnly [] = []
bindingsOnly (C ContextInfo
c Name
n : [Context Name]
xs) = case Name -> SrcSpan
nameSrcSpan Name
n of
  RealSrcSpan RealSrcSpan
span -> NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
forall a. NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node NodeInfo a
nodeinfo RealSrcSpan
span [] HieAST a -> [HieAST a] -> [HieAST a]
forall a. a -> [a] -> [a]
: [Context Name] -> [HieAST a]
forall a. [Context Name] -> [HieAST a]
bindingsOnly [Context Name]
xs
    where nodeinfo :: NodeInfo a
nodeinfo = Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (Either ModuleName Name -> IdentifierDetails a -> NodeIdentifiers a
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
forall a b. b -> Either a b
Right Name
n) IdentifierDetails a
info)
          info :: IdentifierDetails a
info = IdentifierDetails a
forall a. Monoid a => a
mempty{identInfo :: Set ContextInfo
identInfo = ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
c}
  SrcSpan
_ -> [Context Name] -> [HieAST a]
forall a. [Context Name] -> [HieAST a]
bindingsOnly [Context Name]
xs

concatM :: Monad m => [m [a]] -> m [a]
concatM :: [m [a]] -> m [a]
concatM [m [a]]
xs = [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[a]] -> [a]) -> m [[a]] -> m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [m [a]] -> m [[a]]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [m [a]]
xs

{- Note [Capturing Scopes and other non local information]
toHie is a local tranformation, but scopes of bindings cannot be known locally,
hence we have to push the relevant info down into the binding nodes.
We use the following types (*Context and *Scoped) to wrap things and
carry the required info
(Maybe Span) always carries the span of the entire binding, including rhs
-}
data Context a = C ContextInfo a -- Used for names and bindings

data RContext a = RC RecFieldContext a
data RFContext a = RFC RecFieldContext (Maybe Span) a
-- ^ context for record fields

data IEContext a = IEC IEType a
-- ^ context for imports/exports

data BindContext a = BC BindType Scope a
-- ^ context for imports/exports

data PatSynFieldContext a = PSC (Maybe Span) a
-- ^ context for pattern synonym fields.

data SigContext a = SC SigInfo a
-- ^ context for type signatures

data SigInfo = SI SigType (Maybe Span)

data SigType = BindSig | ClassSig | InstSig

data RScoped a = RS Scope a
-- ^ Scope spans over everything to the right of a, (mostly) not
-- including a itself
-- (Includes a in a few special cases like recursive do bindings) or
-- let/where bindings

-- | Pattern scope
data PScoped a = PS (Maybe Span)
                    Scope       -- ^ use site of the pattern
                    Scope       -- ^ pattern to the right of a, not including a
                    a
  deriving (Typeable, Typeable (PScoped a)
DataType
Constr
Typeable (PScoped a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PScoped a -> c (PScoped a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PScoped a))
-> (PScoped a -> Constr)
-> (PScoped a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PScoped a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PScoped a)))
-> ((forall b. Data b => b -> b) -> PScoped a -> PScoped a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PScoped a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PScoped a -> r)
-> (forall u. (forall d. Data d => d -> u) -> PScoped a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PScoped a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> Data (PScoped a)
PScoped a -> DataType
PScoped a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
forall a. Data a => Typeable (PScoped a)
forall a. Data a => PScoped a -> DataType
forall a. Data a => PScoped a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> PScoped a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PScoped a -> u
forall u. (forall d. Data d => d -> u) -> PScoped a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
$cPS :: Constr
$tPScoped :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapMp :: (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapM :: (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> PScoped a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> PScoped a -> u
gmapQ :: (forall d. Data d => d -> u) -> PScoped a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapT :: (forall b. Data b => b -> b) -> PScoped a -> PScoped a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
dataTypeOf :: PScoped a -> DataType
$cdataTypeOf :: forall a. Data a => PScoped a -> DataType
toConstr :: PScoped a -> Constr
$ctoConstr :: forall a. Data a => PScoped a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
$cp1Data :: forall a. Data a => Typeable (PScoped a)
Data) -- Pattern Scope

{- Note [TyVar Scopes]
Due to -XScopedTypeVariables, type variables can be in scope quite far from
their original binding. We resolve the scope of these type variables
in a separate pass
-}
data TScoped a = TS TyVarScope a -- TyVarScope

data TVScoped a = TVS TyVarScope Scope a -- TyVarScope
-- ^ First scope remains constant
-- Second scope is used to build up the scope of a tyvar over
-- things to its right, ala RScoped

-- | Each element scopes over the elements to the right
listScopes :: Scope -> [Located a] -> [RScoped (Located a)]
listScopes :: Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
_ [] = []
listScopes Scope
rhsScope [Located a
pat] = [Scope -> Located a -> RScoped (Located a)
forall a. Scope -> a -> RScoped a
RS Scope
rhsScope Located a
pat]
listScopes Scope
rhsScope (Located a
pat : [Located a]
pats) = Scope -> Located a -> RScoped (Located a)
forall a. Scope -> a -> RScoped a
RS Scope
sc Located a
pat RScoped (Located a)
-> [RScoped (Located a)] -> [RScoped (Located a)]
forall a. a -> [a] -> [a]
: [RScoped (Located a)]
pats'
  where
    pats' :: [RScoped (Located a)]
pats'@((RS Scope
scope Located a
p):[RScoped (Located a)]
_) = Scope -> [Located a] -> [RScoped (Located a)]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
rhsScope [Located a]
pats
    sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ Located a -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc Located a
p

-- | 'listScopes' specialised to 'PScoped' things
patScopes
  :: Maybe Span
  -> Scope
  -> Scope
  -> [LPat (GhcPass p)]
  -> [PScoped (LPat (GhcPass p))]
patScopes :: Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
rsp Scope
useScope Scope
patScope [LPat (GhcPass p)]
xs =
  (RScoped (Located (Pat (GhcPass p)))
 -> PScoped (Located (Pat (GhcPass p))))
-> [RScoped (Located (Pat (GhcPass p)))]
-> [PScoped (Located (Pat (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc Located (Pat (GhcPass p))
a) -> Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
useScope Scope
sc (Located (SrcSpanLess (Located (Pat (GhcPass p))))
-> Located (Pat (GhcPass p))
forall a. HasSrcSpan a => Located (SrcSpanLess a) -> a
composeSrcSpan Located (Pat (GhcPass p))
Located (SrcSpanLess (Located (Pat (GhcPass p))))
a)) ([RScoped (Located (Pat (GhcPass p)))]
 -> [PScoped (Located (Pat (GhcPass p)))])
-> [RScoped (Located (Pat (GhcPass p)))]
-> [PScoped (Located (Pat (GhcPass p)))]
forall a b. (a -> b) -> a -> b
$
    Scope
-> [Located (Pat (GhcPass p))]
-> [RScoped (Located (Pat (GhcPass p)))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
patScope ((Located (Pat (GhcPass p)) -> Located (Pat (GhcPass p)))
-> [Located (Pat (GhcPass p))] -> [Located (Pat (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map Located (Pat (GhcPass p)) -> Located (Pat (GhcPass p))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL [LPat (GhcPass p)]
[Located (Pat (GhcPass p))]
xs)

-- | 'listScopes' specialised to 'TVScoped' things
tvScopes
  :: TyVarScope
  -> Scope
  -> [LHsTyVarBndr a]
  -> [TVScoped (LHsTyVarBndr a)]
tvScopes :: TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes TyVarScope
tvScope Scope
rhsScope [LHsTyVarBndr a]
xs =
  (RScoped (LHsTyVarBndr a) -> TVScoped (LHsTyVarBndr a))
-> [RScoped (LHsTyVarBndr a)] -> [TVScoped (LHsTyVarBndr a)]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc LHsTyVarBndr a
a)-> TyVarScope -> Scope -> LHsTyVarBndr a -> TVScoped (LHsTyVarBndr a)
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tvScope Scope
sc LHsTyVarBndr a
a) ([RScoped (LHsTyVarBndr a)] -> [TVScoped (LHsTyVarBndr a)])
-> [RScoped (LHsTyVarBndr a)] -> [TVScoped (LHsTyVarBndr a)]
forall a b. (a -> b) -> a -> b
$ Scope -> [LHsTyVarBndr a] -> [RScoped (LHsTyVarBndr a)]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
rhsScope [LHsTyVarBndr a]
xs

{- Note [Scoping Rules for SigPat]
Explicitly quantified variables in pattern type signatures are not
brought into scope in the rhs, but implicitly quantified variables
are (HsWC and HsIB).
This is unlike other signatures, where explicitly quantified variables
are brought into the RHS Scope
For example
foo :: forall a. ...;
foo = ... -- a is in scope here

bar (x :: forall a. a -> a) = ... -- a is not in scope here
--   ^ a is in scope here (pattern body)

bax (x :: a) = ... -- a is in scope here
Because of HsWC and HsIB pass on their scope to their children
we must wrap the LHsType in pattern signatures in a
Shielded explictly, so that the HsWC/HsIB scope is not passed
on the the LHsType
-}

data Shielded a = SH Scope a -- Ignores its TScope, uses its own scope instead

type family ProtectedSig a where
  ProtectedSig GhcRn = HsWildCardBndrs GhcRn (HsImplicitBndrs
                                                GhcRn
                                                (Shielded (LHsType GhcRn)))
  ProtectedSig GhcTc = NoExtField

class ProtectSig a where
  protectSig :: Scope -> LHsSigWcType (NoGhcTc a) -> ProtectedSig a

instance (HasLoc a) => HasLoc (Shielded a) where
  loc :: Shielded a -> SrcSpan
loc (SH Scope
_ a
a) = a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
a

instance (ToHie (TScoped a)) => ToHie (TScoped (Shielded a)) where
  toHie :: TScoped (Shielded a) -> HieM [HieAST Type]
toHie (TS TyVarScope
_ (SH Scope
sc a
a)) = TScoped a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TyVarScope -> a -> TScoped a
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) a
a)

instance ProtectSig GhcTc where
  protectSig :: Scope -> LHsSigWcType (NoGhcTc GhcTc) -> ProtectedSig GhcTc
protectSig Scope
_ LHsSigWcType (NoGhcTc GhcTc)
_ = NoExtField
ProtectedSig GhcTc
noExtField

instance ProtectSig GhcRn where
  protectSig :: Scope -> LHsSigWcType (NoGhcTc GhcRn) -> ProtectedSig GhcRn
protectSig Scope
sc (HsWC XHsWC (NoGhcTc GhcRn) (LHsSigType (NoGhcTc GhcRn))
a (HsIB XHsIB (NoGhcTc GhcRn) (LHsType (NoGhcTc GhcRn))
b LHsType (NoGhcTc GhcRn)
sig)) =
    XHsWC GhcRn (HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn)))
-> HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn))
-> HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn)))
forall pass thing.
XHsWC pass thing -> thing -> HsWildCardBndrs pass thing
HsWC XHsWC GhcRn (HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn)))
XHsWC (NoGhcTc GhcRn) (LHsSigType (NoGhcTc GhcRn))
a (XHsIB GhcRn (Shielded (LHsType GhcRn))
-> Shielded (LHsType GhcRn)
-> HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn))
forall pass thing.
XHsIB pass thing -> thing -> HsImplicitBndrs pass thing
HsIB XHsIB GhcRn (Shielded (LHsType GhcRn))
XHsIB (NoGhcTc GhcRn) (LHsType (NoGhcTc GhcRn))
b (Scope -> LHsType GhcRn -> Shielded (LHsType GhcRn)
forall a. Scope -> a -> Shielded a
SH Scope
sc LHsType GhcRn
LHsType (NoGhcTc GhcRn)
sig))
  protectSig Scope
_ (HsWC XHsWC (NoGhcTc GhcRn) (LHsSigType (NoGhcTc GhcRn))
_ (XHsImplicitBndrs XXHsImplicitBndrs (NoGhcTc GhcRn) (LHsType (NoGhcTc GhcRn))
nec)) = NoExtCon
-> HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn)))
forall a. NoExtCon -> a
noExtCon NoExtCon
XXHsImplicitBndrs (NoGhcTc GhcRn) (LHsType (NoGhcTc GhcRn))
nec
  protectSig Scope
_ (XHsWildCardBndrs XXHsWildCardBndrs (NoGhcTc GhcRn) (LHsSigType (NoGhcTc GhcRn))
nec) = NoExtCon
-> HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Shielded (LHsType GhcRn)))
forall a. NoExtCon -> a
noExtCon NoExtCon
XXHsWildCardBndrs (NoGhcTc GhcRn) (LHsSigType (NoGhcTc GhcRn))
nec

class HasLoc a where
  -- ^ defined so that HsImplicitBndrs and HsWildCardBndrs can
  -- know what their implicit bindings are scoping over
  loc :: a -> SrcSpan

instance HasLoc thing => HasLoc (TScoped thing) where
  loc :: TScoped thing -> SrcSpan
loc (TS TyVarScope
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a

instance HasLoc thing => HasLoc (PScoped thing) where
  loc :: PScoped thing -> SrcSpan
loc (PS Maybe RealSrcSpan
_ Scope
_ Scope
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a

instance HasLoc (LHsQTyVars GhcRn) where
  loc :: LHsQTyVars GhcRn -> SrcSpan
loc (HsQTvs XHsQTvs GhcRn
_ [LHsTyVarBndr GhcRn]
vs) = [LHsTyVarBndr GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsTyVarBndr GhcRn]
vs
  loc LHsQTyVars GhcRn
_ = SrcSpan
noSrcSpan

instance HasLoc thing => HasLoc (HsImplicitBndrs a thing) where
  loc :: HsImplicitBndrs a thing -> SrcSpan
loc (HsIB XHsIB a thing
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  loc HsImplicitBndrs a thing
_ = SrcSpan
noSrcSpan

instance HasLoc thing => HasLoc (HsWildCardBndrs a thing) where
  loc :: HsWildCardBndrs a thing -> SrcSpan
loc (HsWC XHsWC a thing
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  loc HsWildCardBndrs a thing
_ = SrcSpan
noSrcSpan

instance HasLoc (Located a) where
  loc :: Located a -> SrcSpan
loc (L SrcSpan
l a
_) = SrcSpan
l

instance HasLoc a => HasLoc [a] where
  loc :: [a] -> SrcSpan
loc [] = SrcSpan
noSrcSpan
  loc [a]
xs = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans ([SrcSpan] -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a b. (a -> b) -> a -> b
$ (a -> SrcSpan) -> [a] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [a]
xs

instance HasLoc a => HasLoc (FamEqn s a) where
  loc :: FamEqn s a -> SrcSpan
loc (FamEqn XCFamEqn s a
_ Located (IdP s)
a Maybe [LHsTyVarBndr s]
Nothing HsTyPats s
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [Located (IdP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdP s)
a, HsTyPats s -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc HsTyPats s
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]
  loc (FamEqn XCFamEqn s a
_ Located (IdP s)
a (Just [LHsTyVarBndr s]
tvs) HsTyPats s
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans
                                              [Located (IdP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdP s)
a, [LHsTyVarBndr s] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsTyVarBndr s]
tvs, HsTyPats s -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc HsTyPats s
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]
  loc FamEqn s a
_ = SrcSpan
noSrcSpan
instance (HasLoc tm, HasLoc ty) => HasLoc (HsArg tm ty) where
  loc :: HsArg tm ty -> SrcSpan
loc (HsValArg tm
tm) = tm -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc tm
tm
  loc (HsTypeArg SrcSpan
_ ty
ty) = ty -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc ty
ty
  loc (HsArgPar SrcSpan
sp)  = SrcSpan
sp

instance HasLoc (HsDataDefn GhcRn) where
  loc :: HsDataDefn GhcRn -> SrcSpan
loc def :: HsDataDefn GhcRn
def@(HsDataDefn{}) = [LConDecl GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc ([LConDecl GhcRn] -> SrcSpan) -> [LConDecl GhcRn] -> SrcSpan
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> [LConDecl GhcRn]
forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons HsDataDefn GhcRn
def
    -- Only used for data family instances, so we only need rhs
    -- Most probably the rest will be unhelpful anyway
  loc HsDataDefn GhcRn
_ = SrcSpan
noSrcSpan

{- Note [Real DataCon Name]
The typechecker subtitutes the conLikeWrapId for the name, but we don't want
this showing up in the hieFile, so we replace the name in the Id with the
original datacon name
See also Note [Data Constructor Naming]
-}
class HasRealDataConName p where
  getRealDataCon :: XRecordCon p -> Located (IdP p) -> Located (IdP p)

instance HasRealDataConName GhcRn where
  getRealDataCon :: XRecordCon GhcRn -> Located (IdP GhcRn) -> Located (IdP GhcRn)
getRealDataCon XRecordCon GhcRn
_ Located (IdP GhcRn)
n = Located (IdP GhcRn)
n
instance HasRealDataConName GhcTc where
  getRealDataCon :: XRecordCon GhcTc -> Located (IdP GhcTc) -> Located (IdP GhcTc)
getRealDataCon RecordConTc{rcon_con_like = con} (L SrcSpan
sp IdP GhcTc
var) =
    SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp (Id -> Name -> Id
setVarName IdP GhcTc
Id
var (ConLike -> Name
conLikeName ConLike
con))

-- | The main worker class
-- See Note [Updating HieAst for changes in the GHC AST] for more information
-- on how to add/modify instances for this.
class ToHie a where
  toHie :: a -> HieM [HieAST Type]

-- | Used to collect type info
class Data a => HasType a where
  getTypeNode :: a -> HieM [HieAST Type]

instance (ToHie a) => ToHie [a] where
  toHie :: [a] -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> [a] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance (ToHie a) => ToHie (Bag a) where
  toHie :: Bag a -> HieM [HieAST Type]
toHie = [a] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([a] -> HieM [HieAST Type])
-> (Bag a -> [a]) -> Bag a -> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bag a -> [a]
forall a. Bag a -> [a]
bagToList

instance (ToHie a) => ToHie (Maybe a) where
  toHie :: Maybe a -> HieM [HieAST Type]
toHie = HieM [HieAST Type]
-> (a -> HieM [HieAST Type]) -> Maybe a -> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance ToHie (Context (Located NoExtField)) where
  toHie :: Context (Located NoExtField) -> HieM [HieAST Type]
toHie Context (Located NoExtField)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (TScoped NoExtField) where
  toHie :: TScoped NoExtField -> HieM [HieAST Type]
toHie TScoped NoExtField
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (IEContext (Located ModuleName)) where
  toHie :: IEContext (Located ModuleName) -> HieM [HieAST Type]
toHie (IEC IEType
c (L (RealSrcSpan RealSrcSpan
span) ModuleName
mname)) =
      [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [NodeInfo Type -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a. NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node (Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] NodeIdentifiers Type
idents) RealSrcSpan
span []]
    where details :: IdentifierDetails Type
details = IdentifierDetails Type
forall a. Monoid a => a
mempty{identInfo :: Set ContextInfo
identInfo = ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton (IEType -> ContextInfo
IEThing IEType
c)}
          idents :: NodeIdentifiers Type
idents = Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (ModuleName -> Either ModuleName Name
forall a b. a -> Either a b
Left ModuleName
mname) IdentifierDetails Type
details
  toHie IEContext (Located ModuleName)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located Var)) where
  toHie :: Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
toHie Context (GenLocated SrcSpan Id)
c = case Context (GenLocated SrcSpan Id)
c of
      C ContextInfo
context (L (RealSrcSpan RealSrcSpan
span) Id
name')
        -> do
        NameEnv Id
m <- (HieState -> NameEnv Id) -> ReaderT HieState Hsc (NameEnv Id)
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
asks HieState -> NameEnv Id
name_remapping
        let name :: Id
name = case NameEnv Id -> Name -> Maybe Id
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv Id
m (Id -> Name
varName Id
name') of
              Just Id
var -> Id
var
              Maybe Id
Nothing-> Id
name'
        [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
          [NodeInfo Type -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a. NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node
            (Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$
              Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
forall a b. b -> Either a b
Right (Name -> Either ModuleName Name) -> Name -> Either ModuleName Name
forall a b. (a -> b) -> a -> b
$ Id -> Name
varName Id
name)
                          (Maybe Type -> Set ContextInfo -> IdentifierDetails Type
forall a. Maybe a -> Set ContextInfo -> IdentifierDetails a
IdentifierDetails (Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type) -> Type -> Maybe Type
forall a b. (a -> b) -> a -> b
$ Id -> Type
varType Id
name')
                                             (ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
context)))
            RealSrcSpan
span
            []]
      Context (GenLocated SrcSpan Id)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located Name)) where
  toHie :: Context (Located Name) -> HieM [HieAST Type]
toHie Context (Located Name)
c = case Context (Located Name)
c of
      C ContextInfo
context (L (RealSrcSpan RealSrcSpan
span) Name
name') -> do
        NameEnv Id
m <- (HieState -> NameEnv Id) -> ReaderT HieState Hsc (NameEnv Id)
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
asks HieState -> NameEnv Id
name_remapping
        let name :: Name
name = case NameEnv Id -> Name -> Maybe Id
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv Id
m Name
name' of
              Just Id
var -> Id -> Name
varName Id
var
              Maybe Id
Nothing -> Name
name'
        [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
          [NodeInfo Type -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a. NodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node
            (Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$
              Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
forall a b. b -> Either a b
Right Name
name)
                          (Maybe Type -> Set ContextInfo -> IdentifierDetails Type
forall a. Maybe a -> Set ContextInfo -> IdentifierDetails a
IdentifierDetails Maybe Type
forall a. Maybe a
Nothing
                                             (ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
context)))
            RealSrcSpan
span
            []]
      Context (Located Name)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

-- | Dummy instances - never called
instance ToHie (TScoped (LHsSigWcType GhcTc)) where
  toHie :: TScoped (LHsSigWcType GhcTc) -> HieM [HieAST Type]
toHie TScoped (LHsSigWcType GhcTc)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
instance ToHie (TScoped (LHsWcType GhcTc)) where
  toHie :: TScoped (LHsWcType GhcTc) -> HieM [HieAST Type]
toHie TScoped (LHsWcType GhcTc)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
instance ToHie (SigContext (LSig GhcTc)) where
  toHie :: SigContext (LSig GhcTc) -> HieM [HieAST Type]
toHie SigContext (LSig GhcTc)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
instance ToHie (TScoped Type) where
  toHie :: TScoped Type -> HieM [HieAST Type]
toHie TScoped Type
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HasType (LHsBind GhcRn) where
  getTypeNode :: LHsBind GhcRn -> HieM [HieAST Type]
getTypeNode (L SrcSpan
spn HsBindLR GhcRn GhcRn
bind) = HsBindLR GhcRn GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsBindLR GhcRn GhcRn
bind SrcSpan
spn

instance HasType (LHsBind GhcTc) where
  getTypeNode :: LHsBindLR GhcTc GhcTc -> HieM [HieAST Type]
getTypeNode (L SrcSpan
spn HsBindLR GhcTc GhcTc
bind) = case HsBindLR GhcTc GhcTc
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP GhcTc)
name} -> HsBindLR GhcTc GhcTc -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Applicative m, Data a) =>
a -> SrcSpan -> Type -> m [HieAST Type]
makeTypeNode HsBindLR GhcTc GhcTc
bind SrcSpan
spn (Id -> Type
varType (Id -> Type) -> Id -> Type
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpan Id -> SrcSpanLess (GenLocated SrcSpan Id)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located (IdP GhcTc)
GenLocated SrcSpan Id
name)
      HsBindLR GhcTc GhcTc
_ -> HsBindLR GhcTc GhcTc -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsBindLR GhcTc GhcTc
bind SrcSpan
spn

instance HasType (Located (Pat GhcRn)) where
  getTypeNode :: Located (Pat GhcRn) -> HieM [HieAST Type]
getTypeNode (Located (Pat GhcRn) -> Located (SrcSpanLess (Located (Pat GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL -> L SrcSpan
spn SrcSpanLess (Located (Pat GhcRn))
pat) = Pat GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode Pat GhcRn
SrcSpanLess (Located (Pat GhcRn))
pat SrcSpan
spn

instance HasType (Located (Pat GhcTc)) where
  getTypeNode :: Located (Pat GhcTc) -> HieM [HieAST Type]
getTypeNode (Located (Pat GhcTc) -> Located (SrcSpanLess (Located (Pat GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL -> L SrcSpan
spn SrcSpanLess (Located (Pat GhcTc))
opat) = Pat GhcTc -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Applicative m, Data a) =>
a -> SrcSpan -> Type -> m [HieAST Type]
makeTypeNode Pat GhcTc
SrcSpanLess (Located (Pat GhcTc))
opat SrcSpan
spn (Pat GhcTc -> Type
hsPatType Pat GhcTc
SrcSpanLess (Located (Pat GhcTc))
opat)

instance HasType (LHsExpr GhcRn) where
  getTypeNode :: LHsExpr GhcRn -> HieM [HieAST Type]
getTypeNode (L SrcSpan
spn HsExpr GhcRn
e) = HsExpr GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsExpr GhcRn
e SrcSpan
spn

-- | This instance tries to construct 'HieAST' nodes which include the type of
-- the expression. It is not yet possible to do this efficiently for all
-- expression forms, so we skip filling in the type for those inputs.
--
-- 'HsApp', for example, doesn't have any type information available directly on
-- the node. Our next recourse would be to desugar it into a 'CoreExpr' then
-- query the type of that. Yet both the desugaring call and the type query both
-- involve recursive calls to the function and argument! This is particularly
-- problematic when you realize that the HIE traversal will eventually visit
-- those nodes too and ask for their types again.
--
-- Since the above is quite costly, we just skip cases where computing the
-- expression's type is going to be expensive.
--
-- See #16233
instance HasType (LHsExpr GhcTc) where
  getTypeNode :: LHsExpr GhcTc -> HieM [HieAST Type]
getTypeNode e :: LHsExpr GhcTc
e@(L SrcSpan
spn HsExpr GhcTc
e') = Hsc [HieAST Type] -> HieM [HieAST Type]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Hsc [HieAST Type] -> HieM [HieAST Type])
-> Hsc [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    -- Some expression forms have their type immediately available
    let tyOpt :: Maybe Type
tyOpt = case HsExpr GhcTc
e' of
          HsLit XLitE GhcTc
_ HsLit GhcTc
l -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsLit GhcTc -> Type
forall (p :: Pass). HsLit (GhcPass p) -> Type
hsLitType HsLit GhcTc
l)
          HsOverLit XOverLitE GhcTc
_ HsOverLit GhcTc
o -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsOverLit GhcTc -> Type
overLitType HsOverLit GhcTc
o)

          HsLam     XLam GhcTc
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG GhcTc (LHsExpr GhcTc)
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
matchGroupType MatchGroupTc
XMG GhcTc (LHsExpr GhcTc)
groupTy)
          HsLamCase XLamCase GhcTc
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG GhcTc (LHsExpr GhcTc)
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
matchGroupType MatchGroupTc
XMG GhcTc (LHsExpr GhcTc)
groupTy)
          HsCase XCase GhcTc
_  LHsExpr GhcTc
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG GhcTc (LHsExpr GhcTc)
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
mg_res_ty MatchGroupTc
XMG GhcTc (LHsExpr GhcTc)
groupTy)

          ExplicitList  XExplicitList GhcTc
ty Maybe (SyntaxExpr GhcTc)
_ [LHsExpr GhcTc]
_   -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Type
mkListTy XExplicitList GhcTc
Type
ty)
          ExplicitSum   XExplicitSum GhcTc
ty Int
_ Int
_ LHsExpr GhcTc
_ -> Type -> Maybe Type
forall a. a -> Maybe a
Just ([Type] -> Type
mkSumTy [Type]
XExplicitSum GhcTc
ty)
          HsDo          XDo GhcTc
ty HsStmtContext Name
_ Located [ExprLStmt GhcTc]
_   -> Type -> Maybe Type
forall a. a -> Maybe a
Just XDo GhcTc
Type
ty
          HsMultiIf     XMultiIf GhcTc
ty [LGRHS GhcTc (LHsExpr GhcTc)]
_     -> Type -> Maybe Type
forall a. a -> Maybe a
Just XMultiIf GhcTc
Type
ty

          HsExpr GhcTc
_ -> Maybe Type
forall a. Maybe a
Nothing

    in
    case Maybe Type
tyOpt of
      Just Type
t -> HsExpr GhcTc -> SrcSpan -> Type -> Hsc [HieAST Type]
forall (m :: * -> *) a.
(Applicative m, Data a) =>
a -> SrcSpan -> Type -> m [HieAST Type]
makeTypeNode HsExpr GhcTc
e' SrcSpan
spn Type
t
      Maybe Type
Nothing
        | HsExpr GhcTc -> Bool
forall a. HsExpr a -> Bool
skipDesugaring HsExpr GhcTc
e' -> Hsc [HieAST Type]
fallback
        | Bool
otherwise -> do
            HscEnv
hs_env <- (HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
-> Hsc HscEnv
forall a.
(HscEnv -> WarningMessages -> IO (a, WarningMessages)) -> Hsc a
Hsc ((HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
 -> Hsc HscEnv)
-> (HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
-> Hsc HscEnv
forall a b. (a -> b) -> a -> b
$ \HscEnv
e WarningMessages
w -> (HscEnv, WarningMessages) -> IO (HscEnv, WarningMessages)
forall (m :: * -> *) a. Monad m => a -> m a
return (HscEnv
e,WarningMessages
w)
            (Messages
_,Maybe CoreExpr
mbe) <- IO (Messages, Maybe CoreExpr) -> Hsc (Messages, Maybe CoreExpr)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Messages, Maybe CoreExpr) -> Hsc (Messages, Maybe CoreExpr))
-> IO (Messages, Maybe CoreExpr) -> Hsc (Messages, Maybe CoreExpr)
forall a b. (a -> b) -> a -> b
$ HscEnv -> LHsExpr GhcTc -> IO (Messages, Maybe CoreExpr)
deSugarExpr HscEnv
hs_env LHsExpr GhcTc
e
            Hsc [HieAST Type]
-> (CoreExpr -> Hsc [HieAST Type])
-> Maybe CoreExpr
-> Hsc [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Hsc [HieAST Type]
fallback (HsExpr GhcTc -> SrcSpan -> Type -> Hsc [HieAST Type]
forall (m :: * -> *) a.
(Applicative m, Data a) =>
a -> SrcSpan -> Type -> m [HieAST Type]
makeTypeNode HsExpr GhcTc
e' SrcSpan
spn (Type -> Hsc [HieAST Type])
-> (CoreExpr -> Type) -> CoreExpr -> Hsc [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoreExpr -> Type
exprType) Maybe CoreExpr
mbe
    where
      fallback :: Hsc [HieAST Type]
fallback = HsExpr GhcTc -> SrcSpan -> Hsc [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsExpr GhcTc
e' SrcSpan
spn

      matchGroupType :: MatchGroupTc -> Type
      matchGroupType :: MatchGroupTc -> Type
matchGroupType (MatchGroupTc [Type]
args Type
res) = [Type] -> Type -> Type
mkVisFunTys [Type]
args Type
res

      -- | Skip desugaring of these expressions for performance reasons.
      --
      -- See impact on Haddock output (esp. missing type annotations or links)
      -- before marking more things here as 'False'. See impact on Haddock
      -- performance before marking more things as 'True'.
      skipDesugaring :: HsExpr a -> Bool
      skipDesugaring :: HsExpr a -> Bool
skipDesugaring HsExpr a
e = case HsExpr a
e of
        HsVar{}        -> Bool
False
        HsUnboundVar{} -> Bool
False
        HsConLikeOut{} -> Bool
False
        HsRecFld{}     -> Bool
False
        HsOverLabel{}  -> Bool
False
        HsIPVar{}      -> Bool
False
        HsWrap{}       -> Bool
False
        HsExpr a
_              -> Bool
True

instance ( ToHie (Context (Located (IdP a)))
         , ToHie (MatchGroup a (LHsExpr a))
         , ToHie (PScoped (LPat a))
         , ToHie (GRHSs a (LHsExpr a))
         , ToHie (LHsExpr a)
         , ToHie (Located (PatSynBind a a))
         , HasType (LHsBind a)
         , ModifyState (IdP a)
         , Data (HsBind a)
         ) => ToHie (BindContext (LHsBind a)) where
  toHie :: BindContext (LHsBind a) -> HieM [HieAST Type]
toHie (BC BindType
context Scope
scope b :: LHsBind a
b@(L SrcSpan
span HsBind a
bind)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ LHsBind a -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LHsBind a
b HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsBind a
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP a)
name, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup a (LHsExpr a)
matches} ->
        [ Context (Located (IdP a)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP a)) -> HieM [HieAST Type])
-> Context (Located (IdP a)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdP a) -> Context (Located (IdP a))
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
context Scope
scope (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP a)
name
        , MatchGroup a (LHsExpr a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup a (LHsExpr a)
matches
        ]
      PatBind{pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat a
lhs, pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs a (LHsExpr a)
rhs} ->
        [ PScoped (LPat a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LPat a) -> HieM [HieAST Type])
-> PScoped (LPat a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan -> Scope -> Scope -> LPat a -> PScoped (LPat a)
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Scope
scope Scope
NoScope LPat a
lhs
        , GRHSs a (LHsExpr a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs a (LHsExpr a)
rhs
        ]
      VarBind{var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr a
expr} ->
        [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
expr
        ]
      AbsBinds{abs_exports :: forall idL idR. HsBindLR idL idR -> [ABExport idL]
abs_exports = [ABExport a]
xs, abs_binds :: forall idL idR. HsBindLR idL idR -> LHsBinds idL
abs_binds = LHsBinds a
binds} ->
        [ (HieState -> HieState) -> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local ([ABExport a] -> HieState -> HieState
forall p.
ModifyState (IdP p) =>
[ABExport p] -> HieState -> HieState
modifyState [ABExport a]
xs) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ -- Note [Name Remapping]
            Bag (BindContext (LHsBind a)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBind a)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBind a)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBind a -> BindContext (LHsBind a))
-> LHsBinds a -> Bag (BindContext (LHsBind a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType -> Scope -> LHsBind a -> BindContext (LHsBind a)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
context Scope
scope) LHsBinds a
binds
        ]
      PatSynBind XPatSynBind a a
_ PatSynBind a a
psb ->
        [ Located (PatSynBind a a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Located (PatSynBind a a) -> HieM [HieAST Type])
-> Located (PatSynBind a a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> PatSynBind a a -> Located (PatSynBind a a)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span PatSynBind a a
psb -- PatSynBinds only occur at the top level
        ]
      XHsBindsLR XXHsBindsLR a a
_ -> []

instance ( ToHie (LMatch a body)
         ) => ToHie (MatchGroup a body) where
  toHie :: MatchGroup a body -> HieM [HieAST Type]
toHie MatchGroup a body
mg = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case MatchGroup a body
mg of
    MG{ mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = (L SrcSpan
span [LMatch a body]
alts) , mg_origin :: forall p body. MatchGroup p body -> Origin
mg_origin = Origin
FromSource } ->
      [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
span
      , [LMatch a body] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LMatch a body]
alts
      ]
    MG{} -> []
    XMatchGroup XXMatchGroup a body
_ -> []

instance ( ToHie (Context (Located (IdP a)))
         , ToHie (PScoped (LPat a))
         , ToHie (HsPatSynDir a)
         ) => ToHie (Located (PatSynBind a a)) where
    toHie :: Located (PatSynBind a a) -> HieM [HieAST Type]
toHie (L SrcSpan
sp PatSynBind a a
psb) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case PatSynBind a a
psb of
      PSB{psb_id :: forall idL idR. PatSynBind idL idR -> Located (IdP idL)
psb_id=Located (IdP a)
var, psb_args :: forall idL idR.
PatSynBind idL idR -> HsPatSynDetails (Located (IdP idR))
psb_args=HsPatSynDetails (Located (IdP a))
dets, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def=LPat a
pat, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir=HsPatSynDir a
dir} ->
        [ Context (Located (IdP a)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP a)) -> HieM [HieAST Type])
-> Context (Located (IdP a)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdP a) -> Context (Located (IdP a))
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
PatSynDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
sp) Located (IdP a)
var
        , HsConDetails
  (Context (Located (IdP a)))
  [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (Context (Located (IdP a)))
   [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
 -> HieM [HieAST Type])
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsPatSynDetails (Located (IdP a))
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
toBind HsPatSynDetails (Located (IdP a))
dets
        , PScoped (LPat a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LPat a) -> HieM [HieAST Type])
-> PScoped (LPat a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan -> Scope -> Scope -> LPat a -> PScoped (LPat a)
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing Scope
lhsScope Scope
NoScope LPat a
pat
        , HsPatSynDir a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsPatSynDir a
dir
        ]
        where
          lhsScope :: Scope
lhsScope = Scope -> Scope -> Scope
combineScopes Scope
varScope Scope
detScope
          varScope :: Scope
varScope = Located (IdP a) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdP a)
var
          detScope :: Scope
detScope = case HsPatSynDetails (Located (IdP a))
dets of
            (PrefixCon [Located (IdP a)]
args) -> (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (Located (IdP a) -> Scope) -> [Located (IdP a)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdP a) -> Scope
forall a. Located a -> Scope
mkLScope [Located (IdP a)]
args
            (InfixCon Located (IdP a)
a Located (IdP a)
b) -> Scope -> Scope -> Scope
combineScopes (Located (IdP a) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdP a)
a) (Located (IdP a) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdP a)
b)
            (RecCon [RecordPatSynField (Located (IdP a))]
r) -> (RecordPatSynField (Located (IdP a)) -> Scope -> Scope)
-> Scope -> [RecordPatSynField (Located (IdP a))] -> Scope
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RecordPatSynField (Located (IdP a)) -> Scope -> Scope
forall a. RecordPatSynField (Located a) -> Scope -> Scope
go Scope
NoScope [RecordPatSynField (Located (IdP a))]
r
          go :: RecordPatSynField (Located a) -> Scope -> Scope
go (RecordPatSynField Located a
a Located a
b) Scope
c = Scope -> Scope -> Scope
combineScopes Scope
c
            (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
a) (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
b)
          detSpan :: Maybe RealSrcSpan
detSpan = case Scope
detScope of
            LocalScope RealSrcSpan
a -> RealSrcSpan -> Maybe RealSrcSpan
forall a. a -> Maybe a
Just RealSrcSpan
a
            Scope
_ -> Maybe RealSrcSpan
forall a. Maybe a
Nothing
          toBind :: HsPatSynDetails (Located (IdP a))
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
toBind (PrefixCon [Located (IdP a)]
args) = [Context (Located (IdP a))]
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ([Context (Located (IdP a))]
 -> HsConDetails
      (Context (Located (IdP a)))
      [PatSynFieldContext (RecordPatSynField (Located (IdP a)))])
-> [Context (Located (IdP a))]
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall a b. (a -> b) -> a -> b
$ (Located (IdP a) -> Context (Located (IdP a)))
-> [Located (IdP a)] -> [Context (Located (IdP a))]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located (IdP a) -> Context (Located (IdP a))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP a)]
args
          toBind (InfixCon Located (IdP a)
a Located (IdP a)
b) = Context (Located (IdP a))
-> Context (Located (IdP a))
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon (ContextInfo -> Located (IdP a) -> Context (Located (IdP a))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP a)
a) (ContextInfo -> Located (IdP a) -> Context (Located (IdP a))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP a)
b)
          toBind (RecCon [RecordPatSynField (Located (IdP a))]
r) = [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall arg rec. rec -> HsConDetails arg rec
RecCon ([PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
 -> HsConDetails
      (Context (Located (IdP a)))
      [PatSynFieldContext (RecordPatSynField (Located (IdP a)))])
-> [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
-> HsConDetails
     (Context (Located (IdP a)))
     [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall a b. (a -> b) -> a -> b
$ (RecordPatSynField (Located (IdP a))
 -> PatSynFieldContext (RecordPatSynField (Located (IdP a))))
-> [RecordPatSynField (Located (IdP a))]
-> [PatSynFieldContext (RecordPatSynField (Located (IdP a)))]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe RealSrcSpan
-> RecordPatSynField (Located (IdP a))
-> PatSynFieldContext (RecordPatSynField (Located (IdP a)))
forall a. Maybe RealSrcSpan -> a -> PatSynFieldContext a
PSC Maybe RealSrcSpan
detSpan) [RecordPatSynField (Located (IdP a))]
r
      XPatSynBind XXPatSynBind a a
_ -> []

instance ( ToHie (MatchGroup a (LHsExpr a))
         ) => ToHie (HsPatSynDir a) where
  toHie :: HsPatSynDir a -> HieM [HieAST Type]
toHie HsPatSynDir a
dir = case HsPatSynDir a
dir of
    ExplicitBidirectional MatchGroup a (LHsExpr a)
mg -> MatchGroup a (LHsExpr a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup a (LHsExpr a)
mg
    HsPatSynDir a
_ -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( a ~ GhcPass p
         , ToHie body
         , ToHie (HsMatchContext (NameOrRdrName (IdP a)))
         , ToHie (PScoped (LPat a))
         , ToHie (GRHSs a body)
         , Data (Match a body)
         ) => ToHie (LMatch (GhcPass p) body) where
  toHie :: LMatch (GhcPass p) body -> HieM [HieAST Type]
toHie (L SrcSpan
span Match (GhcPass p) body
m ) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Match (GhcPass p) body -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode Match (GhcPass p) body
m SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Match (GhcPass p) body
m of
    Match{m_ctxt :: forall p body.
Match p body -> HsMatchContext (NameOrRdrName (IdP p))
m_ctxt=HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
mctx, m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat (GhcPass p)]
pats, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss =  GRHSs (GhcPass p) body
grhss } ->
      [ HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
mctx
      , let rhsScope :: Scope
rhsScope = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) body -> SrcSpan
forall p body. GRHSs p body -> SrcSpan
grhss_span GRHSs (GhcPass p) body
grhss
          in [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
forall a. Maybe a
Nothing Scope
rhsScope Scope
NoScope [LPat (GhcPass p)]
pats
      , GRHSs (GhcPass p) body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) body
grhss
      ]
    XMatch XXMatch (GhcPass p) body
_ -> []

instance ( ToHie (Context (Located a))
         ) => ToHie (HsMatchContext a) where
  toHie :: HsMatchContext a -> HieM [HieAST Type]
toHie (FunRhs{mc_fun :: forall id. HsMatchContext id -> Located id
mc_fun=Located a
name}) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located a) -> HieM [HieAST Type])
-> Context (Located a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
MatchBind Located a
name
  toHie (StmtCtxt HsStmtContext a
a) = HsStmtContext a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext a
a
  toHie HsMatchContext a
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( ToHie (HsMatchContext a)
         ) => ToHie (HsStmtContext a) where
  toHie :: HsStmtContext a -> HieM [HieAST Type]
toHie (PatGuard HsMatchContext a
a) = HsMatchContext a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsMatchContext a
a
  toHie (ParStmtCtxt HsStmtContext a
a) = HsStmtContext a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext a
a
  toHie (TransStmtCtxt HsStmtContext a
a) = HsStmtContext a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext a
a
  toHie HsStmtContext a
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( a ~ GhcPass p
         , ToHie (Context (Located (IdP a)))
         , ToHie (RContext (HsRecFields a (PScoped (LPat a))))
         , ToHie (LHsExpr a)
         , ToHie (TScoped (LHsSigWcType a))
         , ProtectSig a
         , ToHie (TScoped (ProtectedSig a))
         , HasType (LPat a)
         , Data (HsSplice a)
         ) => ToHie (PScoped (Located (Pat (GhcPass p)))) where
  toHie :: PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
toHie (PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope lpat :: Located (Pat (GhcPass p))
lpat@(Located (Pat (GhcPass p))
-> Located (SrcSpanLess (Located (Pat (GhcPass p))))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL -> L SrcSpan
ospan SrcSpanLess (Located (Pat (GhcPass p)))
opat)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Located (Pat (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode Located (Pat (GhcPass p))
lpat HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case SrcSpanLess (Located (Pat (GhcPass p)))
opat of
      WildPat _ ->
        []
      VarPat _ lname ->
        [ Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type])
-> Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> Located (IdP (GhcPass p)) -> Context (Located (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe RealSrcSpan -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe RealSrcSpan
rsp) Located (IdP (GhcPass p))
lname
        ]
      LazyPat _ p ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
p
        ]
      AsPat _ lname pat ->
        [ Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type])
-> Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> Located (IdP (GhcPass p)) -> Context (Located (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe RealSrcSpan -> ContextInfo
PatternBind Scope
scope
                                 (Scope -> Scope -> Scope
combineScopes (Located (Pat (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope (Located (Pat (GhcPass p))
-> Located (SrcSpanLess (Located (Pat (GhcPass p))))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL LPat (GhcPass p)
Located (Pat (GhcPass p))
pat)) Scope
pscope)
                                 Maybe RealSrcSpan
rsp)
                    Located (IdP (GhcPass p))
lname
        , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        ]
      ParPat _ pat ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        ]
      BangPat _ pat ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        ]
      ListPat _ pats ->
        [ [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      TuplePat _ pats _ ->
        [ [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      SumPat _ pat _ _ ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        ]
      ConPatIn c dets ->
        [ Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type])
-> Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> Located (IdP (GhcPass p)) -> Context (Located (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP (GhcPass p))
c
        , HsConDetails
  (PScoped (Located (Pat (GhcPass p))))
  (RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (PScoped (Located (Pat (GhcPass p))))
   (RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
 -> HieM [HieAST Type])
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (Located (Pat (GhcPass p)))
  (HsRecFields (GhcPass p) (Located (Pat (GhcPass p))))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (Located (Pat (GhcPass p)))
  (HsRecFields (GhcPass p) (Located (Pat (GhcPass p))))
dets
        ]
      ConPatOut {pat_con = con, pat_args = dets}->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ (ConLike -> Name) -> GenLocated SrcSpan ConLike -> Located Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName GenLocated SrcSpan ConLike
con
        , HsConDetails
  (PScoped (Located (Pat (GhcPass p))))
  (RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (PScoped (Located (Pat (GhcPass p))))
   (RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
 -> HieM [HieAST Type])
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (Located (Pat (GhcPass p)))
  (HsRecFields (GhcPass p) (Located (Pat (GhcPass p))))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (Located (Pat (GhcPass p)))
  (HsRecFields (GhcPass p) (Located (Pat (GhcPass p))))
dets
        ]
      ViewPat _ expr pat ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        ]
      SplicePat _ sp ->
        [ GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> HsSplice (GhcPass p)
-> GenLocated SrcSpan (HsSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan HsSplice (GhcPass p)
sp
        ]
      LitPat _ _ ->
        []
      NPat _ _ _ _ ->
        []
      NPlusKPat _ n _ _ _ _ ->
        [ Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type])
-> Context (Located (IdP (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> Located (IdP (GhcPass p)) -> Context (Located (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe RealSrcSpan -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe RealSrcSpan
rsp) Located (IdP (GhcPass p))
n
        ]
      SigPat _ pat sig ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        , let cscope :: Scope
cscope = Located (Pat (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope (Located (Pat (GhcPass p))
-> Located (SrcSpanLess (Located (Pat (GhcPass p))))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL LPat (GhcPass p)
Located (Pat (GhcPass p))
pat) in
            TScoped (ProtectedSig (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (ProtectedSig (GhcPass p)) -> HieM [HieAST Type])
-> TScoped (ProtectedSig (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> ProtectedSig (GhcPass p) -> TScoped (ProtectedSig (GhcPass p))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
cscope, Scope
scope, Scope
pscope])
                       (Scope -> LHsSigWcType (NoGhcTc a) -> ProtectedSig a
forall a.
ProtectSig a =>
Scope -> LHsSigWcType (NoGhcTc a) -> ProtectedSig a
protectSig @a Scope
cscope LHsSigWcType (NoGhcTc a)
LHsSigWcType (NoGhcTc (GhcPass p))
sig)
              -- See Note [Scoping Rules for SigPat]
        ]
      CoPat _ _ _ _ ->
        []
      XPat _ -> []
    where
      contextify :: HsConDetails
  (Located (Pat (GhcPass p)))
  (HsRecFields (GhcPass p) (Located (Pat (GhcPass p))))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
contextify (PrefixCon [Located (Pat (GhcPass p))]
args) = [PScoped (Located (Pat (GhcPass p)))]
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ([PScoped (Located (Pat (GhcPass p)))]
 -> HsConDetails
      (PScoped (Located (Pat (GhcPass p))))
      (RContext
         (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))))
-> [PScoped (Located (Pat (GhcPass p)))]
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
[Located (Pat (GhcPass p))]
args
      contextify (InfixCon Located (Pat (GhcPass p))
a Located (Pat (GhcPass p))
b) = PScoped (Located (Pat (GhcPass p)))
-> PScoped (Located (Pat (GhcPass p)))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon PScoped (Located (Pat (GhcPass p)))
a' PScoped (Located (Pat (GhcPass p)))
b'
        where [PScoped (Located (Pat (GhcPass p)))
a', PScoped (Located (Pat (GhcPass p)))
b'] = Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
rsp Scope
scope Scope
pscope [LPat (GhcPass p)
Located (Pat (GhcPass p))
a,LPat (GhcPass p)
Located (Pat (GhcPass p))
b]
      contextify (RecCon HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
r) = RContext
  (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall arg rec. rec -> HsConDetails arg rec
RecCon (RContext
   (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
 -> HsConDetails
      (PScoped (Located (Pat (GhcPass p))))
      (RContext
         (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsConDetails
     (PScoped (Located (Pat (GhcPass p))))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldMatch (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
 -> RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
contextify_rec HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
r
      contextify_rec :: HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
contextify_rec (HsRecFields [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
fds Maybe (Located Int)
a) = [LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))]
-> Maybe (Located Int)
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall p arg.
[LHsRecField p arg] -> Maybe (Located Int) -> HsRecFields p arg
HsRecFields ((RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
 -> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
-> [LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))]
forall a b. (a -> b) -> [a] -> [b]
map RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
go [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
scoped_fds) Maybe (Located Int)
a
        where
          go :: RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
go (RS Scope
fscope (L SrcSpan
spn (HsRecField Located (FieldOcc (GhcPass p))
lbl Located (Pat (GhcPass p))
pat Bool
pun))) =
            SrcSpan
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall l e. l -> e -> GenLocated l e
L SrcSpan
spn (HsRecField'
   (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
 -> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall a b. (a -> b) -> a -> b
$ Located (FieldOcc (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
-> Bool
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField Located (FieldOcc (GhcPass p))
lbl (Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
fscope Located (Pat (GhcPass p))
pat) Bool
pun
          scoped_fds :: [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
scoped_fds = Scope
-> [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
-> [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
pscope [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
fds

instance ( ToHie body
         , ToHie (LGRHS a body)
         , ToHie (RScoped (LHsLocalBinds a))
         ) => ToHie (GRHSs a body) where
  toHie :: GRHSs a body -> HieM [HieAST Type]
toHie GRHSs a body
grhs = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case GRHSs a body
grhs of
    GRHSs XCGRHSs a body
_ [LGRHS a body]
grhss LHsLocalBinds a
binds ->
     [ [LGRHS a body] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS a body]
grhss
     , RScoped (LHsLocalBinds a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds a) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> LHsLocalBinds a -> RScoped (LHsLocalBinds a)
forall a. Scope -> a -> RScoped a
RS (SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs a body -> SrcSpan
forall p body. GRHSs p body -> SrcSpan
grhss_span GRHSs a body
grhs) LHsLocalBinds a
binds
     ]
    XGRHSs XXGRHSs a body
_ -> []

instance ( ToHie (Located body)
         , ToHie (RScoped (GuardLStmt a))
         , Data (GRHS a (Located body))
         ) => ToHie (LGRHS a (Located body)) where
  toHie :: LGRHS a (Located body) -> HieM [HieAST Type]
toHie (L SrcSpan
span GRHS a (Located body)
g) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GRHS a (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode GRHS a (Located body)
g SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case GRHS a (Located body)
g of
    GRHS XCGRHS a (Located body)
_ [GuardLStmt a]
guards Located body
body ->
      [ [RScoped (GuardLStmt a)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (GuardLStmt a)] -> HieM [HieAST Type])
-> [RScoped (GuardLStmt a)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> [GuardLStmt a] -> [RScoped (GuardLStmt a)]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes (Located body -> Scope
forall a. Located a -> Scope
mkLScope Located body
body) [GuardLStmt a]
guards
      , Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
      ]
    XGRHS XXGRHS a (Located body)
_ -> []

instance ( a ~ GhcPass p
         , ToHie (Context (Located (IdP a)))
         , HasType (LHsExpr a)
         , ToHie (PScoped (LPat a))
         , ToHie (MatchGroup a (LHsExpr a))
         , ToHie (LGRHS a (LHsExpr a))
         , ToHie (RContext (HsRecordBinds a))
         , ToHie (RFContext (Located (AmbiguousFieldOcc a)))
         , ToHie (ArithSeqInfo a)
         , ToHie (LHsCmdTop a)
         , ToHie (RScoped (GuardLStmt a))
         , ToHie (RScoped (LHsLocalBinds a))
         , ToHie (TScoped (LHsWcType (NoGhcTc a)))
         , ToHie (TScoped (LHsSigWcType (NoGhcTc a)))
         , Data (HsExpr a)
         , Data (HsSplice a)
         , Data (HsTupArg a)
         , Data (AmbiguousFieldOcc a)
         , (HasRealDataConName a)
         ) => ToHie (LHsExpr (GhcPass p)) where
  toHie :: LHsExpr (GhcPass p) -> HieM [HieAST Type]
toHie e :: LHsExpr (GhcPass p)
e@(L SrcSpan
mspan HsExpr (GhcPass p)
oexpr) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LHsExpr (GhcPass p)
e HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsExpr (GhcPass p)
oexpr of
      HsVar XVar (GhcPass p)
_ (L SrcSpan
_ IdP (GhcPass p)
var) ->
        [ Context (GenLocated SrcSpan (IdP (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (IdP (GhcPass p)))
 -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (IdP (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (IdP (GhcPass p))
-> Context (GenLocated SrcSpan (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (SrcSpan -> IdP (GhcPass p) -> GenLocated SrcSpan (IdP (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan IdP (GhcPass p)
var)
             -- Patch up var location since typechecker removes it
        ]
      HsUnboundVar XUnboundVar (GhcPass p)
_ UnboundVar
_ ->
        []
      HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
con ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan (Name -> Located Name) -> Name -> Located Name
forall a b. (a -> b) -> a -> b
$ ConLike -> Name
conLikeName ConLike
con
        ]
      HsRecFld XRecFld (GhcPass p)
_ AmbiguousFieldOcc (GhcPass p)
fld ->
        [ RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
 -> HieM [HieAST Type])
-> RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe RealSrcSpan
-> GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p))
-> RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe RealSrcSpan
forall a. Maybe a
Nothing (SrcSpan
-> AmbiguousFieldOcc (GhcPass p)
-> GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan AmbiguousFieldOcc (GhcPass p)
fld)
        ]
      HsOverLabel XOverLabel (GhcPass p)
_ Maybe (IdP (GhcPass p))
_ FastString
_ -> []
      HsIPVar XIPVar (GhcPass p)
_ HsIPName
_ -> []
      HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
_ -> []
      HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
_ -> []
      HsLam XLam (GhcPass p)
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsLamCase XLamCase (GhcPass p)
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsApp XApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsAppType XAppTypeE (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsWcType (NoGhcTc (GhcPass p))
sig ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , TScoped (LHsWcType (GhcPass (NoGhcTcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
 -> HieM [HieAST Type])
-> TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsWcType (GhcPass (NoGhcTcPass p))
-> TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (GhcPass (NoGhcTcPass p))
LHsWcType (NoGhcTc (GhcPass p))
sig
        ]
      OpApp XOpApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
c
        ]
      NegApp XNegApp (GhcPass p)
_ LHsExpr (GhcPass p)
a SyntaxExpr (GhcPass p)
_ ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        ]
      HsPar XPar (GhcPass p)
_ LHsExpr (GhcPass p)
a ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        ]
      SectionL XSectionL (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      SectionR XSectionR (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      ExplicitTuple XExplicitTuple (GhcPass p)
_ [LHsTupArg (GhcPass p)]
args Boxity
_ ->
        [ [LHsTupArg (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsTupArg (GhcPass p)]
args
        ]
      ExplicitSum XExplicitSum (GhcPass p)
_ Int
_ Int
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsCase XCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches
        ]
      HsIf XIf (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
c
        ]
      HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss ->
        [ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss
        ]
      HsLet XLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsExpr (GhcPass p)
expr ->
        [ RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBinds (GhcPass p) -> RScoped (LHsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LHsExpr (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr (GhcPass p)
expr) LHsLocalBinds (GhcPass p)
binds
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsDo XDo (GhcPass p)
_ HsStmtContext Name
_ (L SrcSpan
ispan [ExprLStmt (GhcPass p)]
stmts) ->
        [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
ispan
        , [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [ExprLStmt (GhcPass p)] -> [RScoped (ExprLStmt (GhcPass p))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
stmts
        ]
      ExplicitList XExplicitList (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ [LHsExpr (GhcPass p)]
exprs ->
        [ [LHsExpr (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsExpr (GhcPass p)]
exprs
        ]
      RecordCon {rcon_ext :: forall p. HsExpr p -> XRecordCon p
rcon_ext = XRecordCon (GhcPass p)
mrealcon, rcon_con_name :: forall p. HsExpr p -> Located (IdP p)
rcon_con_name = GenLocated SrcSpan (IdP (GhcPass p))
name, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds (GhcPass p)
binds} ->
        [ Context (GenLocated SrcSpan (IdP (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (IdP (GhcPass p)))
 -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (IdP (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (IdP (GhcPass p))
-> Context (GenLocated SrcSpan (IdP (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (XRecordCon a -> Located (IdP a) -> Located (IdP a)
forall p.
HasRealDataConName p =>
XRecordCon p -> Located (IdP p) -> Located (IdP p)
getRealDataCon @a XRecordCon a
XRecordCon (GhcPass p)
mrealcon Located (IdP a)
GenLocated SrcSpan (IdP (GhcPass p))
name)
            -- See Note [Real DataCon Name]
        , RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type])
-> RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecordBinds (GhcPass p)
-> RContext (HsRecordBinds (GhcPass p))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign (HsRecordBinds (GhcPass p) -> RContext (HsRecordBinds (GhcPass p)))
-> HsRecordBinds (GhcPass p)
-> RContext (HsRecordBinds (GhcPass p))
forall a b. (a -> b) -> a -> b
$ HsRecordBinds (GhcPass p)
binds
        ]
      RecordUpd {rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr, rupd_flds :: forall p. HsExpr p -> [LHsRecUpdField p]
rupd_flds = [LHsRecUpdField (GhcPass p)]
upds}->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , [RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type])
-> [RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsRecUpdField (GhcPass p)
 -> RContext (LHsRecUpdField (GhcPass p)))
-> [LHsRecUpdField (GhcPass p)]
-> [RContext (LHsRecUpdField (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> LHsRecUpdField (GhcPass p)
-> RContext (LHsRecUpdField (GhcPass p))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [LHsRecUpdField (GhcPass p)]
upds
        ]
      ExprWithTySig XExprWithTySig (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
 -> HieM [HieAST Type])
-> TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsSigWcType (GhcPass (NoGhcTcPass p))
-> TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [LHsExpr (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr (GhcPass p)
expr]) LHsSigWcType (GhcPass (NoGhcTcPass p))
LHsSigWcType (NoGhcTc (GhcPass p))
sig
        ]
      ArithSeq XArithSeq (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ ArithSeqInfo (GhcPass p)
info ->
        [ ArithSeqInfo (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ArithSeqInfo (GhcPass p)
info
        ]
      HsSCC XSCC (GhcPass p)
_ SourceText
_ StringLiteral
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsCoreAnn XCoreAnn (GhcPass p)
_ SourceText
_ StringLiteral
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat LHsCmdTop (GhcPass p)
cmdtop ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing (LHsCmdTop (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsCmdTop (GhcPass p)
cmdtop) Scope
NoScope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        , LHsCmdTop (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmdTop (GhcPass p)
cmdtop
        ]
      HsStatic XStatic (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsTick XTick (GhcPass p)
_ Tickish (IdP (GhcPass p))
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsBinTick XBinTick (GhcPass p)
_ Int
_ Int
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsTickPragma XTickPragma (GhcPass p)
_ SourceText
_ (StringLiteral, (Int, Int), (Int, Int))
_ ((SourceText, SourceText), (SourceText, SourceText))
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsWrap XWrap (GhcPass p)
_ HsWrapper
_ HsExpr (GhcPass p)
a ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LHsExpr (GhcPass p) -> HieM [HieAST Type])
-> LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsExpr (GhcPass p) -> LHsExpr (GhcPass p)
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsExpr (GhcPass p)
a
        ]
      HsBracket XBracket (GhcPass p)
_ HsBracket (GhcPass p)
b ->
        [ HsBracket (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket (GhcPass p)
b
        ]
      HsRnBracketOut XRnBracketOut (GhcPass p)
_ HsBracket GhcRn
b [PendingRnSplice]
p ->
        [ HsBracket GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket GhcRn
b
        , [PendingRnSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingRnSplice]
p
        ]
      HsTcBracketOut XTcBracketOut (GhcPass p)
_ HsBracket GhcRn
b [PendingTcSplice]
p ->
        [ HsBracket GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket GhcRn
b
        , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
        ]
      HsSpliceE XSpliceE (GhcPass p)
_ HsSplice (GhcPass p)
x ->
        [ GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> HsSplice (GhcPass p)
-> GenLocated SrcSpan (HsSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsSplice (GhcPass p)
x
        ]
      XExpr XXExpr (GhcPass p)
_ -> []

instance ( a ~ GhcPass p
         , ToHie (LHsExpr a)
         , Data (HsTupArg a)
         ) => ToHie (LHsTupArg (GhcPass p)) where
  toHie :: LHsTupArg (GhcPass p) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsTupArg (GhcPass p)
arg) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsTupArg (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsTupArg (GhcPass p)
arg SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsTupArg (GhcPass p)
arg of
    Present XPresent (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
      [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
      ]
    Missing XMissing (GhcPass p)
_ -> []
    XTupArg XXTupArg (GhcPass p)
_ -> []

instance ( a ~ GhcPass p
         , ToHie (PScoped (LPat a))
         , ToHie (LHsExpr a)
         , ToHie (SigContext (LSig a))
         , ToHie (RScoped (LHsLocalBinds a))
         , ToHie (RScoped (ApplicativeArg a))
         , ToHie (Located body)
         , Data (StmtLR a a (Located body))
         , Data (StmtLR a a (Located (HsExpr a)))
         ) => ToHie (RScoped (LStmt (GhcPass p) (Located body))) where
  toHie :: RScoped (LStmt (GhcPass p) (Located body)) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
span StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ StmtLR (GhcPass p) (GhcPass p) (Located body)
-> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt of
      LastStmt XLastStmt (GhcPass p) (GhcPass p) (Located body)
_ Located body
body Bool
_ SyntaxExpr (GhcPass p)
_ ->
        [ Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      BindStmt XBindStmt (GhcPass p) (GhcPass p) (Located body)
_ LPat (GhcPass p)
pat Located body
body SyntaxExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ Located body -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc Located body
body) Scope
scope Scope
NoScope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
        , Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      ApplicativeStmt XApplicativeStmt (GhcPass p) (GhcPass p) (Located body)
_ [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
stmts Maybe (SyntaxExpr (GhcPass p))
_ ->
        [ ((SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
 -> HieM [HieAST Type])
-> [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
-> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type])
-> ((SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
    -> RScoped (ApplicativeArg (GhcPass p)))
-> (SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Scope
-> ApplicativeArg (GhcPass p)
-> RScoped (ApplicativeArg (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope (ApplicativeArg (GhcPass p)
 -> RScoped (ApplicativeArg (GhcPass p)))
-> ((SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
    -> ApplicativeArg (GhcPass p))
-> (SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
-> RScoped (ApplicativeArg (GhcPass p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))
-> ApplicativeArg (GhcPass p)
forall a b. (a, b) -> b
snd) [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
stmts
        ]
      BodyStmt XBodyStmt (GhcPass p) (GhcPass p) (Located body)
_ Located body
body SyntaxExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      LetStmt XLetStmt (GhcPass p) (GhcPass p) (Located body)
_ LHsLocalBindsLR (GhcPass p) (GhcPass p)
binds ->
        [ RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBindsLR (GhcPass p) (GhcPass p)
-> RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope LHsLocalBindsLR (GhcPass p) (GhcPass p)
binds
        ]
      ParStmt XParStmt (GhcPass p) (GhcPass p) (Located body)
_ [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts HsExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ (ParStmtBlock (GhcPass p) (GhcPass p) -> HieM [HieAST Type])
-> [ParStmtBlock (GhcPass p) (GhcPass p)] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (\(ParStmtBlock XParStmtBlock (GhcPass p) (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts [IdP (GhcPass p)]
_ SyntaxExpr (GhcPass p)
_) ->
                          [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [ExprLStmt (GhcPass p)] -> [RScoped (ExprLStmt (GhcPass p))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
stmts)
                     [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts
        ]
      TransStmt {trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [ExprLStmt (GhcPass p)]
stmts, trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr (GhcPass p)
using, trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr (GhcPass p))
by} ->
        [ [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [ExprLStmt (GhcPass p)] -> [RScoped (ExprLStmt (GhcPass p))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
scope [ExprLStmt (GhcPass p)]
stmts
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
using
        , Maybe (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsExpr (GhcPass p))
by
        ]
      RecStmt {recS_stmts :: forall idL idR body. StmtLR idL idR body -> [LStmtLR idL idR body]
recS_stmts = [LStmt (GhcPass p) (Located body)]
stmts} ->
        [ [RScoped (LStmt (GhcPass p) (Located body))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (LStmt (GhcPass p) (Located body))]
 -> HieM [HieAST Type])
-> [RScoped (LStmt (GhcPass p) (Located body))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LStmt (GhcPass p) (Located body)
 -> RScoped (LStmt (GhcPass p) (Located body)))
-> [LStmt (GhcPass p) (Located body)]
-> [RScoped (LStmt (GhcPass p) (Located body))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> LStmt (GhcPass p) (Located body)
-> RScoped (LStmt (GhcPass p) (Located body))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> LStmt (GhcPass p) (Located body)
 -> RScoped (LStmt (GhcPass p) (Located body)))
-> Scope
-> LStmt (GhcPass p) (Located body)
-> RScoped (LStmt (GhcPass p) (Located body))
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes Scope
scope (SrcSpan -> Scope
mkScope SrcSpan
span)) [LStmt (GhcPass p) (Located body)]
stmts
        ]
      XStmtLR XXStmtLR (GhcPass p) (GhcPass p) (Located body)
_ -> []

instance ( ToHie (LHsExpr a)
         , ToHie (PScoped (LPat a))
         , ToHie (BindContext (LHsBind a))
         , ToHie (SigContext (LSig a))
         , ToHie (RScoped (HsValBindsLR a a))
         , Data (HsLocalBinds a)
         ) => ToHie (RScoped (LHsLocalBinds a)) where
  toHie :: RScoped (LHsLocalBinds a) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
sp HsLocalBinds a
binds)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsLocalBinds a -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsLocalBinds a
binds SrcSpan
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsLocalBinds a
binds of
      EmptyLocalBinds XEmptyLocalBinds a a
_ -> []
      HsIPBinds XHsIPBinds a a
_ HsIPBinds a
_ -> []
      HsValBinds XHsValBinds a a
_ HsValBindsLR a a
valBinds ->
        [ RScoped (HsValBindsLR a a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBindsLR a a) -> HieM [HieAST Type])
-> RScoped (HsValBindsLR a a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> HsValBindsLR a a -> RScoped (HsValBindsLR a a)
forall a. Scope -> a -> RScoped a
RS (Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
mkScope SrcSpan
sp)
                      HsValBindsLR a a
valBinds
        ]
      XHsLocalBindsLR XXHsLocalBindsLR a a
_ -> []

instance ( ToHie (BindContext (LHsBind a))
         , ToHie (SigContext (LSig a))
         , ToHie (RScoped (XXValBindsLR a a))
         ) => ToHie (RScoped (HsValBindsLR a a)) where
  toHie :: RScoped (HsValBindsLR a a) -> HieM [HieAST Type]
toHie (RS Scope
sc HsValBindsLR a a
v) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case HsValBindsLR a a
v of
    ValBinds XValBinds a a
_ LHsBindsLR a a
binds [LSig a]
sigs ->
      [ Bag (BindContext (LHsBind a)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBind a)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBind a)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBind a -> BindContext (LHsBind a))
-> LHsBindsLR a a -> Bag (BindContext (LHsBind a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType -> Scope -> LHsBind a -> BindContext (LHsBind a)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) LHsBindsLR a a
binds
      , [SigContext (LSig a)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig a)] -> HieM [HieAST Type])
-> [SigContext (LSig a)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig a -> SigContext (LSig a))
-> [LSig a] -> [SigContext (LSig a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> LSig a -> SigContext (LSig a)
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
BindSig Maybe RealSrcSpan
forall a. Maybe a
Nothing)) [LSig a]
sigs
      ]
    XValBindsLR XXValBindsLR a a
x -> [ RScoped (XXValBindsLR a a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (XXValBindsLR a a) -> HieM [HieAST Type])
-> RScoped (XXValBindsLR a a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> XXValBindsLR a a -> RScoped (XXValBindsLR a a)
forall a. Scope -> a -> RScoped a
RS Scope
sc XXValBindsLR a a
x ]

instance ToHie (RScoped (NHsValBindsLR GhcTc)) where
  toHie :: RScoped (NHsValBindsLR GhcTc) -> HieM [HieAST Type]
toHie (RS Scope
sc (NValBinds [(RecFlag, TypecheckedSource)]
binds [LSig GhcRn]
sigs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [BindContext (LHsBindLR GhcTc GhcTc)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag, TypecheckedSource)
 -> [BindContext (LHsBindLR GhcTc GhcTc)])
-> [(RecFlag, TypecheckedSource)]
-> [BindContext (LHsBindLR GhcTc GhcTc)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((LHsBindLR GhcTc GhcTc -> BindContext (LHsBindLR GhcTc GhcTc))
-> [LHsBindLR GhcTc GhcTc] -> [BindContext (LHsBindLR GhcTc GhcTc)]
forall a b. (a -> b) -> [a] -> [b]
map (BindType
-> Scope
-> LHsBindLR GhcTc GhcTc
-> BindContext (LHsBindLR GhcTc GhcTc)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([LHsBindLR GhcTc GhcTc] -> [BindContext (LHsBindLR GhcTc GhcTc)])
-> ((RecFlag, TypecheckedSource) -> [LHsBindLR GhcTc GhcTc])
-> (RecFlag, TypecheckedSource)
-> [BindContext (LHsBindLR GhcTc GhcTc)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypecheckedSource -> [LHsBindLR GhcTc GhcTc]
forall a. Bag a -> [a]
bagToList (TypecheckedSource -> [LHsBindLR GhcTc GhcTc])
-> ((RecFlag, TypecheckedSource) -> TypecheckedSource)
-> (RecFlag, TypecheckedSource)
-> [LHsBindLR GhcTc GhcTc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag, TypecheckedSource) -> TypecheckedSource
forall a b. (a, b) -> b
snd) [(RecFlag, TypecheckedSource)]
binds)
    , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
BindSig Maybe RealSrcSpan
forall a. Maybe a
Nothing)) [LSig GhcRn]
sigs
    ]
instance ToHie (RScoped (NHsValBindsLR GhcRn)) where
  toHie :: RScoped (NHsValBindsLR GhcRn) -> HieM [HieAST Type]
toHie (RS Scope
sc (NValBinds [(RecFlag, LHsBinds GhcRn)]
binds [LSig GhcRn]
sigs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [BindContext (LHsBind GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag, LHsBinds GhcRn) -> [BindContext (LHsBind GhcRn)])
-> [(RecFlag, LHsBinds GhcRn)] -> [BindContext (LHsBind GhcRn)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((LHsBind GhcRn -> BindContext (LHsBind GhcRn))
-> [LHsBind GhcRn] -> [BindContext (LHsBind GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (BindType -> Scope -> LHsBind GhcRn -> BindContext (LHsBind GhcRn)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([LHsBind GhcRn] -> [BindContext (LHsBind GhcRn)])
-> ((RecFlag, LHsBinds GhcRn) -> [LHsBind GhcRn])
-> (RecFlag, LHsBinds GhcRn)
-> [BindContext (LHsBind GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsBinds GhcRn -> [LHsBind GhcRn]
forall a. Bag a -> [a]
bagToList (LHsBinds GhcRn -> [LHsBind GhcRn])
-> ((RecFlag, LHsBinds GhcRn) -> LHsBinds GhcRn)
-> (RecFlag, LHsBinds GhcRn)
-> [LHsBind GhcRn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag, LHsBinds GhcRn) -> LHsBinds GhcRn
forall a b. (a, b) -> b
snd) [(RecFlag, LHsBinds GhcRn)]
binds)
    , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
BindSig Maybe RealSrcSpan
forall a. Maybe a
Nothing)) [LSig GhcRn]
sigs
    ]

instance ( ToHie (RContext (LHsRecField a arg))
         ) => ToHie (RContext (HsRecFields a arg)) where
  toHie :: RContext (HsRecFields a arg) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (HsRecFields [LHsRecField a arg]
fields Maybe (Located Int)
_)) = [RContext (LHsRecField a arg)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext (LHsRecField a arg)] -> HieM [HieAST Type])
-> [RContext (LHsRecField a arg)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsRecField a arg -> RContext (LHsRecField a arg))
-> [LHsRecField a arg] -> [RContext (LHsRecField a arg)]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> LHsRecField a arg -> RContext (LHsRecField a arg)
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
c) [LHsRecField a arg]
fields

instance ( ToHie (RFContext (Located label))
         , ToHie arg
         , HasLoc arg
         , Data label
         , Data arg
         ) => ToHie (RContext (LHsRecField' label arg)) where
  toHie :: RContext (LHsRecField' label arg) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (L SrcSpan
span HsRecField' label arg
recfld)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsRecField' label arg -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsRecField' label arg
recfld SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsRecField' label arg
recfld of
    HsRecField Located label
label arg
expr Bool
_ ->
      [ RFContext (Located label) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (Located label) -> HieM [HieAST Type])
-> RFContext (Located label) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe RealSrcSpan -> Located label -> RFContext (Located label)
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
c (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ arg -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc arg
expr) Located label
label
      , arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
expr
      ]

instance ToHie (RFContext (LFieldOcc GhcRn)) where
  toHie :: RFContext (LFieldOcc GhcRn) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
rhs (L SrcSpan
nspan FieldOcc GhcRn
f)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case FieldOcc GhcRn
f of
    FieldOcc XCFieldOcc GhcRn
name Located RdrName
_ ->
      [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan XCFieldOcc GhcRn
Name
name)
      ]
    XFieldOcc XXFieldOcc GhcRn
_ -> []

instance ToHie (RFContext (LFieldOcc GhcTc)) where
  toHie :: RFContext (LFieldOcc GhcTc) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
rhs (L SrcSpan
nspan FieldOcc GhcTc
f)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case FieldOcc GhcTc
f of
    FieldOcc XCFieldOcc GhcTc
var Located RdrName
_ ->
      let var' :: Id
var' = Id -> Name -> Id
setVarName XCFieldOcc GhcTc
Id
var (Id -> Name
varName XCFieldOcc GhcTc
Id
var)
      in [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
var')
         ]
    XFieldOcc XXFieldOcc GhcTc
_ -> []

instance ToHie (RFContext (Located (AmbiguousFieldOcc GhcRn))) where
  toHie :: RFContext (Located (AmbiguousFieldOcc GhcRn)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
rhs (L SrcSpan
nspan AmbiguousFieldOcc GhcRn
afo)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case AmbiguousFieldOcc GhcRn
afo of
    Unambiguous XUnambiguous GhcRn
name Located RdrName
_ ->
      [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan XUnambiguous GhcRn
Name
name
      ]
    Ambiguous XAmbiguous GhcRn
_name Located RdrName
_ ->
      [ ]
    XAmbiguousFieldOcc XXAmbiguousFieldOcc GhcRn
_ -> []

instance ToHie (RFContext (Located (AmbiguousFieldOcc GhcTc))) where
  toHie :: RFContext (Located (AmbiguousFieldOcc GhcTc)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
rhs (L SrcSpan
nspan AmbiguousFieldOcc GhcTc
afo)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case AmbiguousFieldOcc GhcTc
afo of
    Unambiguous XUnambiguous GhcTc
var Located RdrName
_ ->
      let var' :: Id
var' = Id -> Name -> Id
setVarName XUnambiguous GhcTc
Id
var (Id -> Name
varName XUnambiguous GhcTc
Id
var)
      in [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
var')
         ]
    Ambiguous XAmbiguous GhcTc
var Located RdrName
_ ->
      let var' :: Id
var' = Id -> Name -> Id
setVarName XAmbiguous GhcTc
Id
var (Id -> Name
varName XAmbiguous GhcTc
Id
var)
      in [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
var')
         ]
    XAmbiguousFieldOcc XXAmbiguousFieldOcc GhcTc
_ -> []

instance ( a ~ GhcPass p
         , ToHie (PScoped (LPat a))
         , ToHie (BindContext (LHsBind a))
         , ToHie (LHsExpr a)
         , ToHie (SigContext (LSig a))
         , ToHie (RScoped (HsValBindsLR a a))
         , Data (StmtLR a a (Located (HsExpr a)))
         , Data (HsLocalBinds a)
         ) => ToHie (RScoped (ApplicativeArg (GhcPass p))) where
  toHie :: RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
sc (ApplicativeArgOne XApplicativeArgOne (GhcPass p)
_ LPat (GhcPass p)
pat LHsExpr (GhcPass p)
expr Bool
_ SyntaxExpr (GhcPass p)
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
    , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
    ]
  toHie (RS Scope
sc (ApplicativeArgMany XApplicativeArgMany (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts HsExpr (GhcPass p)
_ LPat (GhcPass p)
pat)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (ExprLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [ExprLStmt (GhcPass p)] -> [RScoped (ExprLStmt (GhcPass p))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
stmts
    , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
Located (Pat (GhcPass p))
pat
    ]
  toHie (RS Scope
_ (XApplicativeArg XXApplicativeArg (GhcPass p)
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance (ToHie arg, ToHie rec) => ToHie (HsConDetails arg rec) where
  toHie :: HsConDetails arg rec -> HieM [HieAST Type]
toHie (PrefixCon [arg]
args) = [arg] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [arg]
args
  toHie (RecCon rec
rec) = rec -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie rec
rec
  toHie (InfixCon arg
a arg
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
a, arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
b]

instance ( ToHie (LHsCmd a)
         , Data  (HsCmdTop a)
         ) => ToHie (LHsCmdTop a) where
  toHie :: LHsCmdTop a -> HieM [HieAST Type]
toHie (L SrcSpan
span HsCmdTop a
top) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsCmdTop a -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsCmdTop a
top SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsCmdTop a
top of
    HsCmdTop XCmdTop a
_ LHsCmd a
cmd ->
      [ LHsCmd a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd a
cmd
      ]
    XCmdTop XXCmdTop a
_ -> []

instance ( a ~ GhcPass p
         , ToHie (PScoped (LPat a))
         , ToHie (BindContext (LHsBind a))
         , ToHie (LHsExpr a)
         , ToHie (MatchGroup a (LHsCmd a))
         , ToHie (SigContext (LSig a))
         , ToHie (RScoped (HsValBindsLR a a))
         , Data (HsCmd a)
         , Data (HsCmdTop a)
         , Data (StmtLR a a (Located (HsCmd a)))
         , Data (HsLocalBinds a)
         , Data (StmtLR a a (Located (HsExpr a)))
         ) => ToHie (LHsCmd (GhcPass p)) where
  toHie :: LHsCmd (GhcPass p) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsCmd (GhcPass p)
cmd) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsCmd (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsCmd (GhcPass p)
cmd SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsCmd (GhcPass p)
cmd of
      HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b HsArrAppType
_ Bool
_ ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
a LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop (GhcPass p)]
cmdtops ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , [LHsCmdTop (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsCmdTop (GhcPass p)]
cmdtops
        ]
      HsCmdApp XCmdApp (GhcPass p)
_ LHsCmd (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsCmdLam XCmdLam (GhcPass p)
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg
        ]
      HsCmdPar XCmdPar (GhcPass p)
_ LHsCmd (GhcPass p)
a ->
        [ LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
a
        ]
      HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (LHsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts
        ]
      HsCmdIf XCmdIf (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ LHsExpr (GhcPass p)
a LHsCmd (GhcPass p)
b LHsCmd (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
b
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
c
        ]
      HsCmdLet XCmdLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsCmd (GhcPass p)
cmd' ->
        [ RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBinds (GhcPass p) -> RScoped (LHsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LHsCmd (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsCmd (GhcPass p)
cmd') LHsLocalBinds (GhcPass p)
binds
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
cmd'
        ]
      HsCmdDo XCmdDo (GhcPass p)
_ (L SrcSpan
ispan [CmdLStmt (GhcPass p)]
stmts) ->
        [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
ispan
        , [RScoped (CmdLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (CmdLStmt (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (CmdLStmt (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> [CmdLStmt (GhcPass p)] -> [RScoped (CmdLStmt (GhcPass p))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [CmdLStmt (GhcPass p)]
stmts
        ]
      HsCmdWrap XCmdWrap (GhcPass p)
_ HsWrapper
_ HsCmd (GhcPass p)
_ -> []
      XCmd XXCmd (GhcPass p)
_ -> []

instance ToHie (TyClGroup GhcRn) where
  toHie :: TyClGroup GhcRn -> HieM [HieAST Type]
toHie TyClGroup{ group_tyclds :: forall pass. TyClGroup pass -> [LTyClDecl pass]
group_tyclds = [LTyClDecl GhcRn]
classes
                 , group_roles :: forall pass. TyClGroup pass -> [LRoleAnnotDecl pass]
group_roles  = [LRoleAnnotDecl GhcRn]
roles
                 , group_kisigs :: forall pass. TyClGroup pass -> [LStandaloneKindSig pass]
group_kisigs = [LStandaloneKindSig GhcRn]
sigs
                 , group_instds :: forall pass. TyClGroup pass -> [LInstDecl pass]
group_instds = [LInstDecl GhcRn]
instances } =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [LTyClDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyClDecl GhcRn]
classes
    , [LStandaloneKindSig GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LStandaloneKindSig GhcRn]
sigs
    , [LRoleAnnotDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRoleAnnotDecl GhcRn]
roles
    , [LInstDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LInstDecl GhcRn]
instances
    ]
  toHie (XTyClGroup XXTyClGroup GhcRn
_) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LTyClDecl GhcRn) where
  toHie :: LTyClDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span TyClDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyClDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode TyClDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case TyClDecl GhcRn
decl of
      FamDecl {tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl GhcRn
fdecl} ->
        [ GenLocated SrcSpan (FamilyDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan
-> FamilyDecl GhcRn -> GenLocated SrcSpan (FamilyDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span FamilyDecl GhcRn
fdecl)
        ]
      SynDecl {tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType GhcRn
typ} ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
SynDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc LHsType GhcRn
typ]) LHsQTyVars GhcRn
vars
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
typ
        ]
      DataDecl {tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars, tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn GhcRn
defn} ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
DataDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
quant_scope, Scope
rhs_scope]) LHsQTyVars GhcRn
vars
        , HsDataDefn GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsDataDefn GhcRn
defn
        ]
        where
          quant_scope :: Scope
quant_scope = Located (HsContext GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope (Located (HsContext GhcRn) -> Scope)
-> Located (HsContext GhcRn) -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Located (HsContext GhcRn)
forall pass. HsDataDefn pass -> LHsContext pass
dd_ctxt HsDataDefn GhcRn
defn
          rhs_scope :: Scope
rhs_scope = Scope
sig_sc Scope -> Scope -> Scope
`combineScopes` Scope
con_sc Scope -> Scope -> Scope
`combineScopes` Scope
deriv_sc
          sig_sc :: Scope
sig_sc = Scope -> (LHsType GhcRn -> Scope) -> Maybe (LHsType GhcRn) -> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope LHsType GhcRn -> Scope
forall a. Located a -> Scope
mkLScope (Maybe (LHsType GhcRn) -> Scope) -> Maybe (LHsType GhcRn) -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Maybe (LHsType GhcRn)
forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig HsDataDefn GhcRn
defn
          con_sc :: Scope
con_sc = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (LConDecl GhcRn -> Scope) -> [LConDecl GhcRn] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map LConDecl GhcRn -> Scope
forall a. Located a -> Scope
mkLScope ([LConDecl GhcRn] -> [Scope]) -> [LConDecl GhcRn] -> [Scope]
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> [LConDecl GhcRn]
forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons HsDataDefn GhcRn
defn
          deriv_sc :: Scope
deriv_sc = Located [LHsDerivingClause GhcRn] -> Scope
forall a. Located a -> Scope
mkLScope (Located [LHsDerivingClause GhcRn] -> Scope)
-> Located [LHsDerivingClause GhcRn] -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Located [LHsDerivingClause GhcRn]
forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs HsDataDefn GhcRn
defn
      ClassDecl { tcdCtxt :: forall pass. TyClDecl pass -> LHsContext pass
tcdCtxt = Located (HsContext GhcRn)
context
                , tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name
                , tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars
                , tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFDs = [LHsFunDep GhcRn]
deps
                , tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig GhcRn]
sigs
                , tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths = LHsBinds GhcRn
meths
                , tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs = [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs
                , tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl GhcRn]
deftyps
                } ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
ClassDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , Located (HsContext GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsContext GhcRn)
context
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
context_scope, Scope
rhs_scope]) LHsQTyVars GhcRn
vars
        , [Located (FunDep (Located Name))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsFunDep GhcRn]
[Located (FunDep (Located Name))]
deps
        , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn))
-> SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
ClassSig (Maybe RealSrcSpan -> SigInfo) -> Maybe RealSrcSpan -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) [LSig GhcRn]
sigs
        , Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBind GhcRn -> BindContext (LHsBind GhcRn))
-> LHsBinds GhcRn -> Bag (BindContext (LHsBind GhcRn))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType -> Scope -> LHsBind GhcRn -> BindContext (LHsBind GhcRn)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) LHsBinds GhcRn
meths
        , [GenLocated SrcSpan (FamilyDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs
        , (LTyFamDefltDecl GhcRn -> HieM [HieAST Type])
-> [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM ([HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> (LTyFamDefltDecl GhcRn -> [HieAST Type])
-> LTyFamDefltDecl GhcRn
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (LTyFamDefltDecl GhcRn -> SrcSpan)
-> LTyFamDefltDecl GhcRn
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamDefltDecl GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) [LTyFamDefltDecl GhcRn]
deftyps
        , [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyFamDefltDecl GhcRn]
deftyps
        ]
        where
          context_scope :: Scope
context_scope = Located (HsContext GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsContext GhcRn)
context
          rhs_scope :: Scope
rhs_scope = (Scope -> Scope -> Scope) -> [Scope] -> Scope
forall a. (a -> a -> a) -> [a] -> a
foldl1' Scope -> Scope -> Scope
combineScopes ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (SrcSpan -> Scope) -> [SrcSpan] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> Scope
mkScope
            [ [Located (FunDep (Located Name))] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsFunDep GhcRn]
[Located (FunDep (Located Name))]
deps, [LSig GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LSig GhcRn]
sigs, [LHsBind GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc (LHsBinds GhcRn -> [LHsBind GhcRn]
forall a. Bag a -> [a]
bagToList LHsBinds GhcRn
meths), [GenLocated SrcSpan (FamilyDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs, [LTyFamDefltDecl GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LTyFamDefltDecl GhcRn]
deftyps]
      XTyClDecl XXTyClDecl GhcRn
_ -> []

instance ToHie (LFamilyDecl GhcRn) where
  toHie :: GenLocated SrcSpan (FamilyDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span FamilyDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FamilyDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode FamilyDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FamilyDecl GhcRn
decl of
      FamilyDecl XCFamilyDecl GhcRn
_ FamilyInfo GhcRn
info Located (IdP GhcRn)
name LHsQTyVars GhcRn
vars LexicalFixity
_ LFamilyResultSig GhcRn
sig Maybe (LInjectivityAnn GhcRn)
inj ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
FamDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
rhsSpan]) LHsQTyVars GhcRn
vars
        , FamilyInfo GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamilyInfo GhcRn
info
        , RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type])
-> RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> LFamilyResultSig GhcRn -> RScoped (LFamilyResultSig GhcRn)
forall a. Scope -> a -> RScoped a
RS Scope
injSpan LFamilyResultSig GhcRn
sig
        , Maybe (LInjectivityAnn GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LInjectivityAnn GhcRn)
inj
        ]
        where
          rhsSpan :: Scope
rhsSpan = Scope
sigSpan Scope -> Scope -> Scope
`combineScopes` Scope
injSpan
          sigSpan :: Scope
sigSpan = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LFamilyResultSig GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc LFamilyResultSig GhcRn
sig
          injSpan :: Scope
injSpan = Scope
-> (LInjectivityAnn GhcRn -> Scope)
-> Maybe (LInjectivityAnn GhcRn)
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope (SrcSpan -> Scope
mkScope (SrcSpan -> Scope)
-> (LInjectivityAnn GhcRn -> SrcSpan)
-> LInjectivityAnn GhcRn
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LInjectivityAnn GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) Maybe (LInjectivityAnn GhcRn)
inj
      XFamilyDecl XXFamilyDecl GhcRn
_ -> []

instance ToHie (FamilyInfo GhcRn) where
  toHie :: FamilyInfo GhcRn -> HieM [HieAST Type]
toHie (ClosedTypeFamily (Just [LTyFamInstEqn GhcRn]
eqns)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ (LTyFamInstEqn GhcRn -> HieM [HieAST Type])
-> [LTyFamInstEqn GhcRn] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM ([HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> (LTyFamInstEqn GhcRn -> [HieAST Type])
-> LTyFamInstEqn GhcRn
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (LTyFamInstEqn GhcRn -> SrcSpan)
-> LTyFamInstEqn GhcRn
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamInstEqn GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) [LTyFamInstEqn GhcRn]
eqns
    , [TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type])
-> [TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LTyFamInstEqn GhcRn -> TScoped (TyFamInstEqn GhcRn))
-> [LTyFamInstEqn GhcRn] -> [TScoped (TyFamInstEqn GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map LTyFamInstEqn GhcRn -> TScoped (TyFamInstEqn GhcRn)
forall a. GenLocated SrcSpan a -> TScoped a
go [LTyFamInstEqn GhcRn]
eqns
    ]
    where
      go :: GenLocated SrcSpan a -> TScoped a
go (L SrcSpan
l a
ib) = TyVarScope -> a -> TScoped a
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
l]) a
ib
  toHie FamilyInfo GhcRn
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (RScoped (LFamilyResultSig GhcRn)) where
  toHie :: RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type]
toHie (RS Scope
sc (L SrcSpan
span FamilyResultSig GhcRn
sig)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FamilyResultSig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode FamilyResultSig GhcRn
sig SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FamilyResultSig GhcRn
sig of
      NoSig XNoSig GhcRn
_ ->
        []
      KindSig XCKindSig GhcRn
_ LHsType GhcRn
k ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
k
        ]
      TyVarSig XTyVarSig GhcRn
_ LHsTyVarBndr GhcRn
bndr ->
        [ TVScoped (LHsTyVarBndr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TVScoped (LHsTyVarBndr GhcRn) -> HieM [HieAST Type])
-> TVScoped (LHsTyVarBndr GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope -> LHsTyVarBndr GhcRn -> TVScoped (LHsTyVarBndr GhcRn)
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) Scope
NoScope LHsTyVarBndr GhcRn
bndr
        ]
      XFamilyResultSig XXFamilyResultSig GhcRn
_ -> []

instance ToHie (Located (FunDep (Located Name))) where
  toHie :: Located (FunDep (Located Name)) -> HieM [HieAST Type]
toHie (L SrcSpan
span fd :: FunDep (Located Name)
fd@([Located Name]
lhs, [Located Name]
rhs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ FunDep (Located Name) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode FunDep (Located Name)
fd SrcSpan
span
    , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
lhs
    , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
rhs
    ]

instance (ToHie rhs, HasLoc rhs)
    => ToHie (TScoped (FamEqn GhcRn rhs)) where
  toHie :: TScoped (FamEqn GhcRn rhs) -> HieM [HieAST Type]
toHie (TS TyVarScope
_ FamEqn GhcRn rhs
f) = FamEqn GhcRn rhs -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamEqn GhcRn rhs
f

instance (ToHie rhs, HasLoc rhs)
    => ToHie (FamEqn GhcRn rhs) where
  toHie :: FamEqn GhcRn rhs -> HieM [HieAST Type]
toHie fe :: FamEqn GhcRn rhs
fe@(FamEqn XCFamEqn GhcRn rhs
_ Located (IdP GhcRn)
var Maybe [LHsTyVarBndr GhcRn]
tybndrs HsTyPats GhcRn
pats LexicalFixity
_ rhs
rhs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
InstDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ FamEqn GhcRn rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc FamEqn GhcRn rhs
fe) Located (IdP GhcRn)
Located Name
var
    , Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type])
-> Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)])
-> Maybe [LHsTyVarBndr GhcRn]
-> Maybe [TVScoped (LHsTyVarBndr GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TyVarScope
-> Scope -> [LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)]
forall a.
TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope) Maybe [LHsTyVarBndr GhcRn]
tybndrs
    , HsTyPats GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsTyPats GhcRn
pats
    , rhs -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie rhs
rhs
    ]
    where scope :: Scope
scope = Scope -> Scope -> Scope
combineScopes Scope
patsScope Scope
rhsScope
          patsScope :: Scope
patsScope = SrcSpan -> Scope
mkScope (HsTyPats GhcRn -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc HsTyPats GhcRn
pats)
          rhsScope :: Scope
rhsScope = SrcSpan -> Scope
mkScope (rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc rhs
rhs)
  toHie (XFamEqn XXFamEqn GhcRn rhs
_) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LInjectivityAnn GhcRn) where
  toHie :: LInjectivityAnn GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span InjectivityAnn GhcRn
ann) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ InjectivityAnn GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode InjectivityAnn GhcRn
ann SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InjectivityAnn GhcRn
ann of
      InjectivityAnn Located (IdP GhcRn)
lhs [Located (IdP GhcRn)]
rhs ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP GhcRn)
Located Name
lhs
        , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP GhcRn)]
[Located Name]
rhs
        ]

instance ToHie (HsDataDefn GhcRn) where
  toHie :: HsDataDefn GhcRn -> HieM [HieAST Type]
toHie (HsDataDefn XCHsDataDefn GhcRn
_ NewOrData
_ Located (HsContext GhcRn)
ctx Maybe (Located CType)
_ Maybe (LHsType GhcRn)
mkind [LConDecl GhcRn]
cons Located [LHsDerivingClause GhcRn]
derivs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ Located (HsContext GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsContext GhcRn)
ctx
    , Maybe (LHsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsType GhcRn)
mkind
    , [LConDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LConDecl GhcRn]
cons
    , Located [LHsDerivingClause GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [LHsDerivingClause GhcRn]
derivs
    ]
  toHie (XHsDataDefn XXHsDataDefn GhcRn
_) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (HsDeriving GhcRn) where
  toHie :: Located [LHsDerivingClause GhcRn] -> HieM [HieAST Type]
toHie (L SrcSpan
span [LHsDerivingClause GhcRn]
clauses) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
span
    , [LHsDerivingClause GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsDerivingClause GhcRn]
clauses
    ]

instance ToHie (LHsDerivingClause GhcRn) where
  toHie :: LHsDerivingClause GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span HsDerivingClause GhcRn
cl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsDerivingClause GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsDerivingClause GhcRn
cl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsDerivingClause GhcRn
cl of
      HsDerivingClause XCHsDerivingClause GhcRn
_ Maybe (LDerivStrategy GhcRn)
strat (L SrcSpan
ispan [LHsSigType GhcRn]
tys) ->
        [ Maybe (LDerivStrategy GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LDerivStrategy GhcRn)
strat
        , [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
ispan
        , [TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type])
-> [TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsSigType GhcRn -> TScoped (LHsSigType GhcRn))
-> [LHsSigType GhcRn] -> [TScoped (LHsSigType GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType GhcRn]
tys
        ]
      XHsDerivingClause XXHsDerivingClause GhcRn
_ -> []

instance ToHie (Located (DerivStrategy GhcRn)) where
  toHie :: LDerivStrategy GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span DerivStrategy GhcRn
strat) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivStrategy GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode DerivStrategy GhcRn
strat SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivStrategy GhcRn
strat of
      DerivStrategy GhcRn
StockStrategy -> []
      DerivStrategy GhcRn
AnyclassStrategy -> []
      DerivStrategy GhcRn
NewtypeStrategy -> []
      ViaStrategy XViaStrategy GhcRn
s -> [ TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
XViaStrategy GhcRn
s ]

instance ToHie (Located OverlapMode) where
  toHie :: Located OverlapMode -> HieM [HieAST Type]
toHie (L SrcSpan
span OverlapMode
_) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
span

instance ToHie (LConDecl GhcRn) where
  toHie :: LConDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span ConDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ConDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode ConDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDecl GhcRn
decl of
      ConDeclGADT { con_names :: forall pass. ConDecl pass -> [Located (IdP pass)]
con_names = [Located (IdP GhcRn)]
names, con_qvars :: forall pass. ConDecl pass -> LHsQTyVars pass
con_qvars = LHsQTyVars GhcRn
qvars
                  , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (Located (HsContext GhcRn))
ctx, con_args :: forall pass. ConDecl pass -> HsConDeclDetails pass
con_args = HsConDeclDetails GhcRn
args, con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType GhcRn
typ } ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
ConDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span)) [Located (IdP GhcRn)]
[Located Name]
names
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
ctxScope, Scope
rhsScope]) LHsQTyVars GhcRn
qvars
        , Maybe (Located (HsContext GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (HsContext GhcRn))
ctx
        , HsConDeclDetails GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclDetails GhcRn
args
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
typ
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
argsScope Scope
tyScope
          ctxScope :: Scope
ctxScope = Scope
-> (Located (HsContext GhcRn) -> Scope)
-> Maybe (Located (HsContext GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope Located (HsContext GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope Maybe (Located (HsContext GhcRn))
ctx
          argsScope :: Scope
argsScope = HsConDeclDetails GhcRn -> Scope
forall a a. HsConDetails (Located a) (Located a) -> Scope
condecl_scope HsConDeclDetails GhcRn
args
          tyScope :: Scope
tyScope = LHsType GhcRn -> Scope
forall a. Located a -> Scope
mkLScope LHsType GhcRn
typ
      ConDeclH98 { con_name :: forall pass. ConDecl pass -> Located (IdP pass)
con_name = Located (IdP GhcRn)
name, con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr pass]
con_ex_tvs = [LHsTyVarBndr GhcRn]
qvars
                 , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (Located (HsContext GhcRn))
ctx, con_args :: forall pass. ConDecl pass -> HsConDeclDetails pass
con_args = HsConDeclDetails GhcRn
dets } ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
ConDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type])
-> [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope -> [LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)]
forall a.
TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
rhsScope [LHsTyVarBndr GhcRn]
qvars
        , Maybe (Located (HsContext GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (HsContext GhcRn))
ctx
        , HsConDeclDetails GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclDetails GhcRn
dets
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
ctxScope Scope
argsScope
          ctxScope :: Scope
ctxScope = Scope
-> (Located (HsContext GhcRn) -> Scope)
-> Maybe (Located (HsContext GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope Located (HsContext GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope Maybe (Located (HsContext GhcRn))
ctx
          argsScope :: Scope
argsScope = HsConDeclDetails GhcRn -> Scope
forall a a. HsConDetails (Located a) (Located a) -> Scope
condecl_scope HsConDeclDetails GhcRn
dets
      XConDecl XXConDecl GhcRn
_ -> []
    where condecl_scope :: HsConDetails (Located a) (Located a) -> Scope
condecl_scope HsConDetails (Located a) (Located a)
args = case HsConDetails (Located a) (Located a)
args of
            PrefixCon [Located a]
xs -> (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (Located a -> Scope) -> [Located a] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map Located a -> Scope
forall a. Located a -> Scope
mkLScope [Located a]
xs
            InfixCon Located a
a Located a
b -> Scope -> Scope -> Scope
combineScopes (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
a) (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
b)
            RecCon Located a
x -> Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
x

instance ToHie (Located [LConDeclField GhcRn]) where
  toHie :: Located [LConDeclField GhcRn] -> HieM [HieAST Type]
toHie (L SrcSpan
span [LConDeclField GhcRn]
decls) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
span
    , [LConDeclField GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LConDeclField GhcRn]
decls
    ]

instance ( HasLoc thing
         , ToHie (TScoped thing)
         ) => ToHie (TScoped (HsImplicitBndrs GhcRn thing)) where
  toHie :: TScoped (HsImplicitBndrs GhcRn thing) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsIB XHsIB GhcRn thing
ibrn thing
a)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [Context Name] -> [HieAST Type]
forall a. [Context Name] -> [HieAST a]
bindingsOnly ([Context Name] -> [HieAST Type])
-> [Context Name] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsIB GhcRn thing
ibrn
      , TScoped thing -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped thing -> HieM [HieAST Type])
-> TScoped thing -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> thing -> TScoped thing
forall a. TyVarScope -> a -> TScoped a
TS TyVarScope
sc thing
a
      ]
    where span :: SrcSpan
span = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  toHie (TS TyVarScope
_ (XHsImplicitBndrs XXHsImplicitBndrs GhcRn thing
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( HasLoc thing
         , ToHie (TScoped thing)
         ) => ToHie (TScoped (HsWildCardBndrs GhcRn thing)) where
  toHie :: TScoped (HsWildCardBndrs GhcRn thing) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsWC XHsWC GhcRn thing
names thing
a)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [Context Name] -> [HieAST Type]
forall a. [Context Name] -> [HieAST a]
bindingsOnly ([Context Name] -> [HieAST Type])
-> [Context Name] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsWC GhcRn thing
names
      , TScoped thing -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped thing -> HieM [HieAST Type])
-> TScoped thing -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> thing -> TScoped thing
forall a. TyVarScope -> a -> TScoped a
TS TyVarScope
sc thing
a
      ]
    where span :: SrcSpan
span = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  toHie (TS TyVarScope
_ (XHsWildCardBndrs XXHsWildCardBndrs GhcRn thing
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LStandaloneKindSig GhcRn) where
  toHie :: LStandaloneKindSig GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
sp StandaloneKindSig GhcRn
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [StandaloneKindSig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode StandaloneKindSig GhcRn
sig SrcSpan
sp, StandaloneKindSig GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie StandaloneKindSig GhcRn
sig]

instance ToHie (StandaloneKindSig GhcRn) where
  toHie :: StandaloneKindSig GhcRn -> HieM [HieAST Type]
toHie StandaloneKindSig GhcRn
sig = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case StandaloneKindSig GhcRn
sig of
    StandaloneKindSig XStandaloneKindSig GhcRn
_ Located (IdP GhcRn)
name LHsSigType GhcRn
typ ->
      [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl Located (IdP GhcRn)
Located Name
name
      , TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
typ
      ]
    XStandaloneKindSig XXStandaloneKindSig GhcRn
_ -> []

instance ToHie (SigContext (LSig GhcRn)) where
  toHie :: SigContext (LSig GhcRn) -> HieM [HieAST Type]
toHie (SC (SI SigType
styp Maybe RealSrcSpan
msp) (L SrcSpan
sp Sig GhcRn
sig)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Sig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode Sig GhcRn
sig SrcSpan
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Sig GhcRn
sig of
      TypeSig XTypeSig GhcRn
_ [Located (IdP GhcRn)]
names LHsSigWcType GhcRn
typ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [Located (IdP GhcRn)]
[Located Name]
names
        , TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigWcType GhcRn -> TScoped (LHsSigWcType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP GhcRn)]
[Located Name]
names) Maybe RealSrcSpan
forall a. Maybe a
Nothing) LHsSigWcType GhcRn
typ
        ]
      PatSynSig XPatSynSig GhcRn
_ [Located (IdP GhcRn)]
names LHsSigType GhcRn
typ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [Located (IdP GhcRn)]
[Located Name]
names
        , TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP GhcRn)]
[Located Name]
names) Maybe RealSrcSpan
forall a. Maybe a
Nothing) LHsSigType GhcRn
typ
        ]
      ClassOpSig XClassOpSig GhcRn
_ Bool
_ [Located (IdP GhcRn)]
names LHsSigType GhcRn
typ ->
        [ case SigType
styp of
            SigType
ClassSig -> [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Located Name -> Context (Located Name))
-> ContextInfo -> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan -> ContextInfo
ClassTyDecl (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
sp) [Located (IdP GhcRn)]
[Located Name]
names
            SigType
_  -> [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Located Name -> Context (Located Name))
-> ContextInfo -> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ ContextInfo
TyDecl) [Located (IdP GhcRn)]
[Located Name]
names
        , TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP GhcRn)]
[Located Name]
names) Maybe RealSrcSpan
msp) LHsSigType GhcRn
typ
        ]
      IdSig XIdSig GhcRn
_ Id
_ -> []
      FixSig XFixSig GhcRn
_ FixitySig GhcRn
fsig ->
        [ GenLocated SrcSpan (FixitySig GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (FixitySig GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (FixitySig GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> FixitySig GhcRn -> GenLocated SrcSpan (FixitySig GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp FixitySig GhcRn
fsig
        ]
      InlineSig XInlineSig GhcRn
_ Located (IdP GhcRn)
name InlinePragma
_ ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Located (IdP GhcRn)
Located Name
name
        ]
      SpecSig XSpecSig GhcRn
_ Located (IdP GhcRn)
name [LHsSigType GhcRn]
typs InlinePragma
_ ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Located (IdP GhcRn)
Located Name
name
        , [TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type])
-> [TScoped (LHsSigType GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsSigType GhcRn -> TScoped (LHsSigType GhcRn))
-> [LHsSigType GhcRn] -> [TScoped (LHsSigType GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType GhcRn]
typs
        ]
      SpecInstSig XSpecInstSig GhcRn
_ SourceText
_ LHsSigType GhcRn
typ ->
        [ TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
typ
        ]
      MinimalSig XMinimalSig GhcRn
_ SourceText
_ LBooleanFormula (Located (IdP GhcRn))
form ->
        [ LBooleanFormula (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (Located (IdP GhcRn))
LBooleanFormula (Located Name)
form
        ]
      SCCFunSig XSCCFunSig GhcRn
_ SourceText
_ Located (IdP GhcRn)
name Maybe (Located StringLiteral)
mtxt ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Located (IdP GhcRn)
Located Name
name
        , [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieAST Type]
-> (Located StringLiteral -> [HieAST Type])
-> Maybe (Located StringLiteral)
-> [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (Located StringLiteral -> SrcSpan)
-> Located StringLiteral
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located StringLiteral -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) Maybe (Located StringLiteral)
mtxt
        ]
      CompleteMatchSig XCompleteMatchSig GhcRn
_ SourceText
_ (L SrcSpan
ispan [Located (IdP GhcRn)]
names) Maybe (Located (IdP GhcRn))
typ ->
        [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
ispan
        , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP GhcRn)]
[Located Name]
names
        , Maybe (Context (Located Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Context (Located Name)) -> HieM [HieAST Type])
-> Maybe (Context (Located Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> Maybe (Located Name) -> Maybe (Context (Located Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Maybe (Located (IdP GhcRn))
Maybe (Located Name)
typ
        ]
      XSig XXSig GhcRn
_ -> []

instance ToHie (LHsType GhcRn) where
  toHie :: LHsType GhcRn -> HieM [HieAST Type]
toHie LHsType GhcRn
x = TScoped (LHsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsType GhcRn -> TScoped (LHsType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsType GhcRn
x

instance ToHie (TScoped (LHsType GhcRn)) where
  toHie :: TScoped (LHsType GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
tsc (L SrcSpan
span HsType GhcRn
t)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsType GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsType GhcRn
t SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsType GhcRn
t of
      HsForAllTy XForAllTy GhcRn
_ ForallVisFlag
_ [LHsTyVarBndr GhcRn]
bndrs LHsType GhcRn
body ->
        [ [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type])
-> [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope -> [LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)]
forall a.
TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes TyVarScope
tsc (SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc LHsType GhcRn
body) [LHsTyVarBndr GhcRn]
bndrs
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
body
        ]
      HsQualTy XQualTy GhcRn
_ Located (HsContext GhcRn)
ctx LHsType GhcRn
body ->
        [ Located (HsContext GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsContext GhcRn)
ctx
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
body
        ]
      HsTyVar XTyVar GhcRn
_ PromotionFlag
_ Located (IdP GhcRn)
var ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP GhcRn)
Located Name
var
        ]
      HsAppTy XAppTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
b
        ]
      HsAppKindTy XAppKindTy GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
ki ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
ty
        , TScoped (LHsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsType GhcRn -> TScoped (LHsType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsType GhcRn
ki
        ]
      HsFunTy XFunTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
b
        ]
      HsListTy XListTy GhcRn
_ LHsType GhcRn
a ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        ]
      HsTupleTy XTupleTy GhcRn
_ HsTupleSort
_ HsContext GhcRn
tys ->
        [ HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
tys
        ]
      HsSumTy XSumTy GhcRn
_ HsContext GhcRn
tys ->
        [ HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
tys
        ]
      HsOpTy XOpTy GhcRn
_ LHsType GhcRn
a Located (IdP GhcRn)
op LHsType GhcRn
b ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        , Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP GhcRn)
Located Name
op
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
b
        ]
      HsParTy XParTy GhcRn
_ LHsType GhcRn
a ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        ]
      HsIParamTy XIParamTy GhcRn
_ Located HsIPName
ip LHsType GhcRn
ty ->
        [ Located HsIPName -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located HsIPName
ip
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
ty
        ]
      HsKindSig XKindSig GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
b
        ]
      HsSpliceTy XSpliceTy GhcRn
_ HsSplice GhcRn
a ->
        [ GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsSplice GhcRn -> GenLocated SrcSpan (HsSplice GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span HsSplice GhcRn
a
        ]
      HsDocTy XDocTy GhcRn
_ LHsType GhcRn
a LHsDocString
_ ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
a
        ]
      HsBangTy XBangTy GhcRn
_ HsSrcBang
_ LHsType GhcRn
ty ->
        [ LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
ty
        ]
      HsRecTy XRecTy GhcRn
_ [LConDeclField GhcRn]
fields ->
        [ [LConDeclField GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LConDeclField GhcRn]
fields
        ]
      HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ HsContext GhcRn
tys ->
        [ HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
tys
        ]
      HsExplicitTupleTy XExplicitTupleTy GhcRn
_ HsContext GhcRn
tys ->
        [ HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
tys
        ]
      HsTyLit XTyLit GhcRn
_ HsTyLit
_ -> []
      HsWildCardTy XWildCardTy GhcRn
_ -> []
      HsStarTy XStarTy GhcRn
_ Bool
_ -> []
      XHsType XXType GhcRn
_ -> []

instance (ToHie tm, ToHie ty) => ToHie (HsArg tm ty) where
  toHie :: HsArg tm ty -> HieM [HieAST Type]
toHie (HsValArg tm
tm) = tm -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie tm
tm
  toHie (HsTypeArg SrcSpan
_ ty
ty) = ty -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ty
ty
  toHie (HsArgPar SrcSpan
sp) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
sp

instance ToHie (TVScoped (LHsTyVarBndr GhcRn)) where
  toHie :: TVScoped (LHsTyVarBndr GhcRn) -> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc (L SrcSpan
span HsTyVarBndr GhcRn
bndr)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsTyVarBndr GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsTyVarBndr GhcRn
bndr SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsTyVarBndr GhcRn
bndr of
      UserTyVar XUserTyVar GhcRn
_ Located (IdP GhcRn)
var ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) Located (IdP GhcRn)
Located Name
var
        ]
      KindedTyVar XKindedTyVar GhcRn
_ Located (IdP GhcRn)
var LHsType GhcRn
kind ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) Located (IdP GhcRn)
Located Name
var
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
kind
        ]
      XTyVarBndr XXTyVarBndr GhcRn
_ -> []

instance ToHie (TScoped (LHsQTyVars GhcRn)) where
  toHie :: TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsQTvs XHsQTvs GhcRn
implicits [LHsTyVarBndr GhcRn]
vars)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [Context Name] -> [HieAST Type]
forall a. [Context Name] -> [HieAST a]
bindingsOnly [Context Name]
bindings
    , [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type])
-> [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope -> [LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)]
forall a.
TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes TyVarScope
sc Scope
NoScope [LHsTyVarBndr GhcRn]
vars
    ]
    where
      varLoc :: SrcSpan
varLoc = [LHsTyVarBndr GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsTyVarBndr GhcRn]
vars
      bindings :: [Context Name]
bindings = (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
mkScope SrcSpan
varLoc) TyVarScope
sc) [Name]
XHsQTvs GhcRn
implicits
  toHie (TS TyVarScope
_ (XLHsQTyVars XXLHsQTyVars GhcRn
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LHsContext GhcRn) where
  toHie :: Located (HsContext GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsContext GhcRn
tys) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
span
      , HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
tys
      ]

instance ToHie (LConDeclField GhcRn) where
  toHie :: LConDeclField GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span ConDeclField GhcRn
field) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ConDeclField GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode ConDeclField GhcRn
field SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDeclField GhcRn
field of
      ConDeclField XConDeclField GhcRn
_ [LFieldOcc GhcRn]
fields LHsType GhcRn
typ Maybe LHsDocString
_ ->
        [ [RFContext (LFieldOcc GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RFContext (LFieldOcc GhcRn)] -> HieM [HieAST Type])
-> [RFContext (LFieldOcc GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LFieldOcc GhcRn -> RFContext (LFieldOcc GhcRn))
-> [LFieldOcc GhcRn] -> [RFContext (LFieldOcc GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> Maybe RealSrcSpan
-> LFieldOcc GhcRn
-> RFContext (LFieldOcc GhcRn)
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
RecFieldDecl (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc LHsType GhcRn
typ)) [LFieldOcc GhcRn]
fields
        , LHsType GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
typ
        ]
      XConDeclField XXConDeclField GhcRn
_ -> []

instance ToHie (LHsExpr a) => ToHie (ArithSeqInfo a) where
  toHie :: ArithSeqInfo a -> HieM [HieAST Type]
toHie (From LHsExpr a
expr) = LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
expr
  toHie (FromThen LHsExpr a
a LHsExpr a
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    ]
  toHie (FromTo LHsExpr a
a LHsExpr a
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    ]
  toHie (FromThenTo LHsExpr a
a LHsExpr a
b LHsExpr a
c) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
c
    ]

instance ToHie (LSpliceDecl GhcRn) where
  toHie :: LSpliceDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span SpliceDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SpliceDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode SpliceDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case SpliceDecl GhcRn
decl of
      SpliceDecl XSpliceDecl GhcRn
_ GenLocated SrcSpan (HsSplice GhcRn)
splice SpliceExplicitFlag
_ ->
        [ GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpan (HsSplice GhcRn)
splice
        ]
      XSpliceDecl XXSpliceDecl GhcRn
_ -> []

instance ToHie (HsBracket a) where
  toHie :: HsBracket a -> HieM [HieAST Type]
toHie HsBracket a
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingRnSplice where
  toHie :: PendingRnSplice -> HieM [HieAST Type]
toHie PendingRnSplice
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingTcSplice where
  toHie :: PendingTcSplice -> HieM [HieAST Type]
toHie PendingTcSplice
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LBooleanFormula (Located Name)) where
  toHie :: LBooleanFormula (Located Name) -> HieM [HieAST Type]
toHie (L SrcSpan
span BooleanFormula (Located Name)
form) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ BooleanFormula (Located Name) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode BooleanFormula (Located Name)
form SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case BooleanFormula (Located Name)
form of
      Var Located Name
a ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located Name
a
        ]
      And [LBooleanFormula (Located Name)]
forms ->
        [ [LBooleanFormula (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (Located Name)]
forms
        ]
      Or [LBooleanFormula (Located Name)]
forms ->
        [ [LBooleanFormula (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (Located Name)]
forms
        ]
      Parens LBooleanFormula (Located Name)
f ->
        [ LBooleanFormula (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (Located Name)
f
        ]

instance ToHie (Located HsIPName) where
  toHie :: Located HsIPName -> HieM [HieAST Type]
toHie (L SrcSpan
span HsIPName
e) = HsIPName -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsIPName
e SrcSpan
span

instance ( ToHie (LHsExpr a)
         , Data (HsSplice a)
         ) => ToHie (Located (HsSplice a)) where
  toHie :: Located (HsSplice a) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsSplice a
sp) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsSplice a -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode HsSplice a
sp SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsSplice a
sp of
      HsTypedSplice XTypedSplice a
_ SpliceDecoration
_ IdP a
_ LHsExpr a
expr ->
        [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
expr
        ]
      HsUntypedSplice XUntypedSplice a
_ SpliceDecoration
_ IdP a
_ LHsExpr a
expr ->
        [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
expr
        ]
      HsQuasiQuote XQuasiQuote a
_ IdP a
_ IdP a
_ SrcSpan
ispan FastString
_ ->
        [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
ispan
        ]
      HsSpliced XSpliced a
_ ThModFinalizers
_ HsSplicedThing a
_ ->
        []
      HsSplicedT DelayedSplice
_ ->
        []
      XSplice XXSplice a
_ -> []

instance ToHie (LRoleAnnotDecl GhcRn) where
  toHie :: LRoleAnnotDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span RoleAnnotDecl GhcRn
annot) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RoleAnnotDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode RoleAnnotDecl GhcRn
annot SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RoleAnnotDecl GhcRn
annot of
      RoleAnnotDecl XCRoleAnnotDecl GhcRn
_ Located (IdP GhcRn)
var [Located (Maybe Role)]
roles ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP GhcRn)
Located Name
var
        , (Located (Maybe Role) -> HieM [HieAST Type])
-> [Located (Maybe Role)] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM ([HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> (Located (Maybe Role) -> [HieAST Type])
-> Located (Maybe Role)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (Located (Maybe Role) -> SrcSpan)
-> Located (Maybe Role)
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Maybe Role) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) [Located (Maybe Role)]
roles
        ]
      XRoleAnnotDecl XXRoleAnnotDecl GhcRn
_ -> []

instance ToHie (LInstDecl GhcRn) where
  toHie :: LInstDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span InstDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ InstDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode InstDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InstDecl GhcRn
decl of
      ClsInstD XClsInstD GhcRn
_ ClsInstDecl GhcRn
d ->
        [ GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> ClsInstDecl GhcRn -> GenLocated SrcSpan (ClsInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span ClsInstDecl GhcRn
d
        ]
      DataFamInstD XDataFamInstD GhcRn
_ DataFamInstDecl GhcRn
d ->
        [ GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> DataFamInstDecl GhcRn
-> GenLocated SrcSpan (DataFamInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span DataFamInstDecl GhcRn
d
        ]
      TyFamInstD XTyFamInstD GhcRn
_ TyFamInstDecl GhcRn
d ->
        [ LTyFamDefltDecl GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LTyFamDefltDecl GhcRn -> HieM [HieAST Type])
-> LTyFamDefltDecl GhcRn -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> TyFamInstDecl GhcRn -> LTyFamDefltDecl GhcRn
forall l e. l -> e -> GenLocated l e
L SrcSpan
span TyFamInstDecl GhcRn
d
        ]
      XInstDecl XXInstDecl GhcRn
_ -> []

instance ToHie (LClsInstDecl GhcRn) where
  toHie :: GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ClsInstDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
span]) (LHsSigType GhcRn -> TScoped (LHsSigType GhcRn))
-> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> LHsSigType GhcRn
forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty ClsInstDecl GhcRn
decl
    , Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBind GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBind GhcRn -> BindContext (LHsBind GhcRn))
-> LHsBinds GhcRn -> Bag (BindContext (LHsBind GhcRn))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType -> Scope -> LHsBind GhcRn -> BindContext (LHsBind GhcRn)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) (LHsBinds GhcRn -> Bag (BindContext (LHsBind GhcRn)))
-> LHsBinds GhcRn -> Bag (BindContext (LHsBind GhcRn))
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> LHsBinds GhcRn
forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds ClsInstDecl GhcRn
decl
    , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn))
-> SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
InstSig (Maybe RealSrcSpan -> SigInfo) -> Maybe RealSrcSpan -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) ([LSig GhcRn] -> [SigContext (LSig GhcRn)])
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LSig GhcRn]
forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs ClsInstDecl GhcRn
decl
    , [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LTyFamDefltDecl GhcRn -> [HieAST Type])
-> [LTyFamDefltDecl GhcRn] -> [HieAST Type]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (LTyFamDefltDecl GhcRn -> SrcSpan)
-> LTyFamDefltDecl GhcRn
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamDefltDecl GhcRn -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) ([LTyFamDefltDecl GhcRn] -> [HieAST Type])
-> [LTyFamDefltDecl GhcRn] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LTyFamDefltDecl GhcRn]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl GhcRn
decl
    , [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([LTyFamDefltDecl GhcRn] -> HieM [HieAST Type])
-> [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LTyFamDefltDecl GhcRn]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl GhcRn
decl
    , [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl GhcRn)] -> [HieAST Type]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type])
-> (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpan (DataFamInstDecl GhcRn)
-> [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (DataFamInstDecl GhcRn) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) ([GenLocated SrcSpan (DataFamInstDecl GhcRn)] -> [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl GhcRn)] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [GenLocated SrcSpan (DataFamInstDecl GhcRn)]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , [GenLocated SrcSpan (DataFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DataFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [GenLocated SrcSpan (DataFamInstDecl GhcRn)]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Located OverlapMode) -> HieM [HieAST Type])
-> Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> Maybe (Located OverlapMode)
forall pass. ClsInstDecl pass -> Maybe (Located OverlapMode)
cid_overlap_mode ClsInstDecl GhcRn
decl
    ]

instance ToHie (LDataFamInstDecl GhcRn) where
  toHie :: GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
sp (DataFamInstDecl FamInstEqn GhcRn (HsDataDefn GhcRn)
d)) = TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
 -> HieM [HieAST Type])
-> TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> FamInstEqn GhcRn (HsDataDefn GhcRn)
-> TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
sp]) FamInstEqn GhcRn (HsDataDefn GhcRn)
d

instance ToHie (LTyFamInstDecl GhcRn) where
  toHie :: LTyFamDefltDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
sp (TyFamInstDecl TyFamInstEqn GhcRn
d)) = TScoped (TyFamInstEqn GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (TyFamInstEqn GhcRn) -> HieM [HieAST Type])
-> TScoped (TyFamInstEqn GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> TyFamInstEqn GhcRn -> TScoped (TyFamInstEqn GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
sp]) TyFamInstEqn GhcRn
d

instance ToHie (Context a)
         => ToHie (PatSynFieldContext (RecordPatSynField a)) where
  toHie :: PatSynFieldContext (RecordPatSynField a) -> HieM [HieAST Type]
toHie (PSC Maybe RealSrcSpan
sp (RecordPatSynField a
a a
b)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context a -> HieM [HieAST Type])
-> Context a -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> a -> Context a
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
RecFieldDecl Maybe RealSrcSpan
sp) a
a
    , Context a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context a -> HieM [HieAST Type])
-> Context a -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> a -> Context a
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use a
b
    ]

instance ToHie (LDerivDecl GhcRn) where
  toHie :: LDerivDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span DerivDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode DerivDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivDecl GhcRn
decl of
      DerivDecl XCDerivDecl GhcRn
_ LHsSigWcType GhcRn
typ Maybe (LDerivStrategy GhcRn)
strat Maybe (Located OverlapMode)
overlap ->
        [ TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigWcType GhcRn -> TScoped (LHsSigWcType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigWcType GhcRn
typ
        , Maybe (LDerivStrategy GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LDerivStrategy GhcRn)
strat
        , Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located OverlapMode)
overlap
        ]
      XDerivDecl XXDerivDecl GhcRn
_ -> []

instance ToHie (LFixitySig GhcRn) where
  toHie :: GenLocated SrcSpan (FixitySig GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span FixitySig GhcRn
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FixitySig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode FixitySig GhcRn
sig SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FixitySig GhcRn
sig of
      FixitySig XFixitySig GhcRn
_ [Located (IdP GhcRn)]
vars Fixity
_ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP GhcRn)]
[Located Name]
vars
        ]
      XFixitySig XXFixitySig GhcRn
_ -> []

instance ToHie (LDefaultDecl GhcRn) where
  toHie :: LDefaultDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span DefaultDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DefaultDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode DefaultDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DefaultDecl GhcRn
decl of
      DefaultDecl XCDefaultDecl GhcRn
_ HsContext GhcRn
typs ->
        [ HsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsContext GhcRn
typs
        ]
      XDefaultDecl XXDefaultDecl GhcRn
_ -> []

instance ToHie (LForeignDecl GhcRn) where
  toHie :: LForeignDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span ForeignDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ForeignDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode ForeignDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ForeignDecl GhcRn
decl of
      ForeignImport {fd_name :: forall pass. ForeignDecl pass -> Located (IdP pass)
fd_name = Located (IdP GhcRn)
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fi :: forall pass. ForeignDecl pass -> ForeignImport
fd_fi = ForeignImport
fi} ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
ModuleScope (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdP GhcRn)
Located Name
name
        , TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
sig
        , ForeignImport -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignImport
fi
        ]
      ForeignExport {fd_name :: forall pass. ForeignDecl pass -> Located (IdP pass)
fd_name = Located (IdP GhcRn)
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport
fd_fe = ForeignExport
fe} ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdP GhcRn)
Located Name
name
        , TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigType GhcRn -> TScoped (LHsSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
sig
        , ForeignExport -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignExport
fe
        ]
      XForeignDecl XXForeignDecl GhcRn
_ -> []

instance ToHie ForeignImport where
  toHie :: ForeignImport -> HieM [HieAST Type]
toHie (CImport (L SrcSpan
a CCallConv
_) (L SrcSpan
b Safety
_) Maybe Header
_ CImportSpec
_ (L SrcSpan
c SourceText
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [[HieAST Type]] -> [HieAST Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[HieAST Type]] -> [HieAST Type])
-> [[HieAST Type]] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
a
    , SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
b
    , SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
c
    ]

instance ToHie ForeignExport where
  toHie :: ForeignExport -> HieM [HieAST Type]
toHie (CExport (L SrcSpan
a CExportSpec
_) (L SrcSpan
b SourceText
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [[HieAST Type]] -> [HieAST Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[HieAST Type]] -> [HieAST Type])
-> [[HieAST Type]] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
a
    , SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
b
    ]

instance ToHie (LWarnDecls GhcRn) where
  toHie :: LWarnDecls GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span WarnDecls GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ WarnDecls GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode WarnDecls GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecls GhcRn
decl of
      Warnings XWarnings GhcRn
_ SourceText
_ [LWarnDecl GhcRn]
warnings ->
        [ [LWarnDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LWarnDecl GhcRn]
warnings
        ]
      XWarnDecls XXWarnDecls GhcRn
_ -> []

instance ToHie (LWarnDecl GhcRn) where
  toHie :: LWarnDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span WarnDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ WarnDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode WarnDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecl GhcRn
decl of
      Warning XWarning GhcRn
_ [Located (IdP GhcRn)]
vars WarningTxt
_ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP GhcRn)]
[Located Name]
vars
        ]
      XWarnDecl XXWarnDecl GhcRn
_ -> []

instance ToHie (LAnnDecl GhcRn) where
  toHie :: LAnnDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span AnnDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ AnnDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode AnnDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case AnnDecl GhcRn
decl of
      HsAnnotation XHsAnnotation GhcRn
_ SourceText
_ AnnProvenance (IdP GhcRn)
prov LHsExpr GhcRn
expr ->
        [ AnnProvenance Name -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie AnnProvenance (IdP GhcRn)
AnnProvenance Name
prov
        , LHsExpr GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
expr
        ]
      XAnnDecl XXAnnDecl GhcRn
_ -> []

instance ToHie (Context (Located a)) => ToHie (AnnProvenance a) where
  toHie :: AnnProvenance a -> HieM [HieAST Type]
toHie (ValueAnnProvenance Located a
a) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located a) -> HieM [HieAST Type])
-> Context (Located a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located a
a
  toHie (TypeAnnProvenance Located a
a) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located a) -> HieM [HieAST Type])
-> Context (Located a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located a
a
  toHie AnnProvenance a
ModuleAnnProvenance = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LRuleDecls GhcRn) where
  toHie :: LRuleDecls GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span RuleDecls GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RuleDecls GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode RuleDecls GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleDecls GhcRn
decl of
      HsRules XCRuleDecls GhcRn
_ SourceText
_ [LRuleDecl GhcRn]
rules ->
        [ [LRuleDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRuleDecl GhcRn]
rules
        ]
      XRuleDecls XXRuleDecls GhcRn
_ -> []

instance ToHie (LRuleDecl GhcRn) where
  toHie :: LRuleDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
_ (XRuleDecl XXRuleDecl GhcRn
_)) = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  toHie (L SrcSpan
span r :: RuleDecl GhcRn
r@(HsRule XHsRule GhcRn
_ Located (SourceText, FastString)
rname Activation
_ Maybe [LHsTyVarBndr (NoGhcTc GhcRn)]
tybndrs [LRuleBndr GhcRn]
bndrs LHsExpr GhcRn
exprA LHsExpr GhcRn
exprB)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
        [ RuleDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode RuleDecl GhcRn
r SrcSpan
span
        , [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly (SrcSpan -> [HieAST Type]) -> SrcSpan -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Located (SourceText, FastString) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc Located (SourceText, FastString)
rname
        , Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type])
-> Maybe [TVScoped (LHsTyVarBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)])
-> Maybe [LHsTyVarBndr GhcRn]
-> Maybe [TVScoped (LHsTyVarBndr GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TyVarScope
-> Scope -> [LHsTyVarBndr GhcRn] -> [TVScoped (LHsTyVarBndr GhcRn)]
forall a.
TyVarScope
-> Scope -> [LHsTyVarBndr a] -> [TVScoped (LHsTyVarBndr a)]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope) Maybe [LHsTyVarBndr GhcRn]
Maybe [LHsTyVarBndr (NoGhcTc GhcRn)]
tybndrs
        , [RScoped (LRuleBndr GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (LRuleBndr GhcRn)] -> HieM [HieAST Type])
-> [RScoped (LRuleBndr GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LRuleBndr GhcRn -> RScoped (LRuleBndr GhcRn))
-> [LRuleBndr GhcRn] -> [RScoped (LRuleBndr GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (Scope -> LRuleBndr GhcRn -> RScoped (LRuleBndr GhcRn)
forall a. Scope -> a -> RScoped a
RS (Scope -> LRuleBndr GhcRn -> RScoped (LRuleBndr GhcRn))
-> Scope -> LRuleBndr GhcRn -> RScoped (LRuleBndr GhcRn)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
mkScope SrcSpan
span) [LRuleBndr GhcRn]
bndrs
        , LHsExpr GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
exprA
        , LHsExpr GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
exprB
        ]
    where scope :: Scope
scope = Scope
bndrs_sc Scope -> Scope -> Scope
`combineScopes` Scope
exprA_sc Scope -> Scope -> Scope
`combineScopes` Scope
exprB_sc
          bndrs_sc :: Scope
bndrs_sc = Scope
-> (LRuleBndr GhcRn -> Scope) -> Maybe (LRuleBndr GhcRn) -> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope LRuleBndr GhcRn -> Scope
forall a. Located a -> Scope
mkLScope ([LRuleBndr GhcRn] -> Maybe (LRuleBndr GhcRn)
forall a. [a] -> Maybe a
listToMaybe [LRuleBndr GhcRn]
bndrs)
          exprA_sc :: Scope
exprA_sc = LHsExpr GhcRn -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr GhcRn
exprA
          exprB_sc :: Scope
exprB_sc = LHsExpr GhcRn -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr GhcRn
exprB

instance ToHie (RScoped (LRuleBndr GhcRn)) where
  toHie :: RScoped (LRuleBndr GhcRn) -> HieM [HieAST Type]
toHie (RS Scope
sc (L SrcSpan
span RuleBndr GhcRn
bndr)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RuleBndr GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode RuleBndr GhcRn
bndr SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleBndr GhcRn
bndr of
      RuleBndr XCRuleBndr GhcRn
_ Located (IdP GhcRn)
var ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe RealSrcSpan
forall a. Maybe a
Nothing) Located (IdP GhcRn)
Located Name
var
        ]
      RuleBndrSig XRuleBndrSig GhcRn
_ Located (IdP GhcRn)
var LHsSigWcType GhcRn
typ ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe RealSrcSpan
forall a. Maybe a
Nothing) Located (IdP GhcRn)
Located Name
var
        , TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsSigWcType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsSigWcType GhcRn -> TScoped (LHsSigWcType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) LHsSigWcType GhcRn
typ
        ]
      XRuleBndr XXRuleBndr GhcRn
_ -> []

instance ToHie (LImportDecl GhcRn) where
  toHie :: LImportDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span ImportDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ImportDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode ImportDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ImportDecl GhcRn
decl of
      ImportDecl { ideclName :: forall pass. ImportDecl pass -> Located ModuleName
ideclName = Located ModuleName
name, ideclAs :: forall pass. ImportDecl pass -> Maybe (Located ModuleName)
ideclAs = Maybe (Located ModuleName)
as, ideclHiding :: forall pass. ImportDecl pass -> Maybe (Bool, Located [LIE pass])
ideclHiding = Maybe (Bool, Located [LIE GhcRn])
hidden } ->
        [ IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (Located ModuleName) -> HieM [HieAST Type])
-> IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Import Located ModuleName
name
        , Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type])
-> Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located ModuleName -> IEContext (Located ModuleName))
-> Maybe (Located ModuleName)
-> Maybe (IEContext (Located ModuleName))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
ImportAs) Maybe (Located ModuleName)
as
        , HieM [HieAST Type]
-> ((Bool, Located [LIE GhcRn]) -> HieM [HieAST Type])
-> Maybe (Bool, Located [LIE GhcRn])
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (Bool, Located [LIE GhcRn]) -> HieM [HieAST Type]
forall a.
ToHie (IEContext a) =>
(Bool, GenLocated SrcSpan [a]) -> HieM [HieAST Type]
goIE Maybe (Bool, Located [LIE GhcRn])
hidden
        ]
      XImportDecl XXImportDecl GhcRn
_ -> []
    where
      goIE :: (Bool, GenLocated SrcSpan [a]) -> HieM [HieAST Type]
goIE (Bool
hiding, (L SrcSpan
sp [a]
liens)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
        [ [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> [HieAST Type]
forall a. SrcSpan -> [HieAST a]
locOnly SrcSpan
sp
        , [IEContext a] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext a] -> HieM [HieAST Type])
-> [IEContext a] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (a -> IEContext a) -> [a] -> [IEContext a]
forall a b. (a -> b) -> [a] -> [b]
map (IEType -> a -> IEContext a
forall a. IEType -> a -> IEContext a
IEC IEType
c) [a]
liens
        ]
        where
         c :: IEType
c = if Bool
hiding then IEType
ImportHiding else IEType
Import

instance ToHie (IEContext (LIE GhcRn)) where
  toHie :: IEContext (LIE GhcRn) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span IE GhcRn
ie)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IE GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode IE GhcRn
ie SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IE GhcRn
ie of
      IEVar XIEVar GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (IdP GhcRn)
LIEWrappedName Name
n
        ]
      IEThingAbs XIEThingAbs GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (IdP GhcRn)
LIEWrappedName Name
n
        ]
      IEThingAll XIEThingAll GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (IdP GhcRn)
LIEWrappedName Name
n
        ]
      IEThingWith XIEThingWith GhcRn
_ LIEWrappedName (IdP GhcRn)
n IEWildcard
_ [LIEWrappedName (IdP GhcRn)]
ns [Located (FieldLbl (IdP GhcRn))]
flds ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (IdP GhcRn)
LIEWrappedName Name
n
        , [IEContext (LIEWrappedName Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext (LIEWrappedName Name)] -> HieM [HieAST Type])
-> [IEContext (LIEWrappedName Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LIEWrappedName Name -> IEContext (LIEWrappedName Name))
-> [LIEWrappedName Name] -> [IEContext (LIEWrappedName Name)]
forall a b. (a -> b) -> [a] -> [b]
map (IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c) [LIEWrappedName (IdP GhcRn)]
[LIEWrappedName Name]
ns
        , [IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type])
-> [IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (FieldLbl Name) -> IEContext (Located (FieldLbl Name)))
-> [Located (FieldLbl Name)]
-> [IEContext (Located (FieldLbl Name))]
forall a b. (a -> b) -> [a] -> [b]
map (IEType
-> Located (FieldLbl Name) -> IEContext (Located (FieldLbl Name))
forall a. IEType -> a -> IEContext a
IEC IEType
c) [Located (FieldLbl (IdP GhcRn))]
[Located (FieldLbl Name)]
flds
        ]
      IEModuleContents XIEModuleContents GhcRn
_ Located ModuleName
n ->
        [ IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (Located ModuleName) -> HieM [HieAST Type])
-> IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
c Located ModuleName
n
        ]
      IEGroup XIEGroup GhcRn
_ Int
_ HsDocString
_ -> []
      IEDoc XIEDoc GhcRn
_ HsDocString
_ -> []
      IEDocNamed XIEDocNamed GhcRn
_ String
_ -> []
      XIE XXIE GhcRn
_ -> []

instance ToHie (IEContext (LIEWrappedName Name)) where
  toHie :: IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span IEWrappedName Name
iewn)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEWrappedName Name -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode IEWrappedName Name
iewn SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IEWrappedName Name
iewn of
      IEName Located Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
n
        ]
      IEPattern Located Name
p ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
p
        ]
      IEType Located Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
n
        ]

instance ToHie (IEContext (Located (FieldLbl Name))) where
  toHie :: IEContext (Located (FieldLbl Name)) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span FieldLbl Name
lbl)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FieldLbl Name -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Applicative m, Data a) =>
a -> SrcSpan -> m [HieAST b]
makeNode FieldLbl Name
lbl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FieldLbl Name
lbl of
      FieldLabel FastString
_ Bool
_ Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
span Name
n
        ]