{-# LANGUAGE AllowAmbiguousTypes     #-}
{-# LANGUAGE CPP                     #-}
{-# LANGUAGE ConstraintKinds         #-}
{-# LANGUAGE DataKinds               #-}
{-# LANGUAGE DeriveDataTypeable      #-}
{-# LANGUAGE FlexibleContexts        #-}
{-# LANGUAGE FlexibleInstances       #-}
{-# LANGUAGE GADTs                   #-}
{-# LANGUAGE OverloadedStrings       #-}
{-# LANGUAGE ScopedTypeVariables     #-}
{-# LANGUAGE TypeApplications        #-}
{-# LANGUAGE TypeFamilies            #-}
{-# LANGUAGE UndecidableInstances    #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE RankNTypes #-}

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-orphans #-} -- For the HasLoc instances

{-
Main functions for .hie file generation
-}

module GHC.Iface.Ext.Ast ( mkHieFile, mkHieFileWithSource, getCompressedAsts, enrichHie) where

import GHC.Utils.Outputable(ppr)

import GHC.Prelude hiding ( head, init, last, tail )

import GHC.Types.Avail            ( Avails )
import GHC.Data.Bag               ( Bag, bagToList )
import GHC.Types.Basic
import GHC.Data.BooleanFormula
import GHC.Core.Class             ( className, classSCSelIds )
import GHC.Core.ConLike           ( conLikeName )
import GHC.Core.TyCon             ( TyCon, tyConClass_maybe )
import GHC.Core.FVs
import GHC.Core.DataCon           ( dataConNonlinearType )
import GHC.Types.FieldLabel
import GHC.Hs
import GHC.Hs.Syn.Type
import GHC.Utils.Monad            ( concatMapM, MonadIO(liftIO) )
import GHC.Types.Id               ( isDataConId_maybe )
import GHC.Types.Name             ( Name, nameSrcSpan, nameUnique )
import GHC.Types.Name.Env         ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
import GHC.Types.Name.Reader      ( RecFieldInfo(..) )
import GHC.Types.SrcLoc
import GHC.Core.Type              ( Type )
import GHC.Core.Predicate
import GHC.Core.InstEnv
import GHC.Tc.Types
import GHC.Tc.Types.Evidence
import GHC.Types.Var              ( Id, Var, EvId, varName, varType, varUnique )
import GHC.Types.Var.Env
import GHC.Builtin.Uniques
import GHC.Iface.Make             ( mkIfaceExports )
import GHC.Utils.Panic
import GHC.Utils.Misc
import GHC.Data.Maybe
import GHC.Data.FastString
import qualified GHC.Data.Strict as Strict

import GHC.Iface.Ext.Types
import GHC.Iface.Ext.Utils

import GHC.Unit.Module            ( ml_hs_file )
import GHC.Unit.Module.ModSummary

import qualified Data.Array as A
import qualified Data.ByteString as BS
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Data                  ( Data, Typeable )
import Data.Foldable              ( toList )
import Data.Functor.Identity      ( Identity(..) )
import Data.List.NonEmpty         ( NonEmpty(..), nonEmpty )
import qualified Data.List.NonEmpty as NE
import Data.Void                  ( Void, absurd )
import Control.Monad              ( forM_ )
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Class  ( lift )
import Control.Applicative        ( (<|>) )

{- 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 `GHC.Iface.Ext.Types`, 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 GHC.Iface.Ext.Ast.

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 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
        ]
      ...
      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 compiler/GHC.hs
type RenamedSource     = ( HsGroup GhcRn, [LImportDecl GhcRn]
                         , Maybe [(LIE GhcRn, Avails)]
                         , Maybe (LHsDoc GhcRn)
                         , Maybe (XRec GhcRn ModuleName) )
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.
-}
type VarMap a = DVarEnv (Var,a)
data HieState = HieState
  { HieState -> NameEnv Id
name_remapping :: NameEnv Id
  , HieState -> VarMap (Set ContextInfo)
unlocated_ev_binds :: VarMap (S.Set ContextInfo)
  -- These contain evidence bindings that we don't have a location for
  -- These are placed at the top level Node in the HieAST after everything
  -- else has been generated
  -- This includes things like top level evidence bindings.
  }

addUnlocatedEvBind :: Var -> ContextInfo -> HieM ()
addUnlocatedEvBind :: Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
var ContextInfo
ci = do
  let go :: (a, Set a) -> (a, Set a) -> (a, Set a)
go (a
a,Set a
b) (a
_,Set a
c) = (a
a,Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
S.union Set a
b Set a
c)
  State HieState () -> HieM ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState () -> HieM ()) -> State HieState () -> HieM ()
forall a b. (a -> b) -> a -> b
$ (HieState -> HieState) -> State HieState ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' ((HieState -> HieState) -> State HieState ())
-> (HieState -> HieState) -> State HieState ()
forall a b. (a -> b) -> a -> b
$ \HieState
s ->
    HieState
s { unlocated_ev_binds =
          extendDVarEnv_C go (unlocated_ev_binds s)
                          var (var,S.singleton ci)
      }

getUnlocatedEvBinds :: FastString -> HieM (NodeIdentifiers Type,[HieAST Type])
getUnlocatedEvBinds :: FastString -> HieM (NodeIdentifiers Type, [HieAST Type])
getUnlocatedEvBinds FastString
file = do
  binds <- State HieState (VarMap (Set ContextInfo))
-> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo))
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (VarMap (Set ContextInfo))
 -> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo)))
-> State HieState (VarMap (Set ContextInfo))
-> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo))
forall a b. (a -> b) -> a -> b
$ (HieState -> VarMap (Set ContextInfo))
-> State HieState (VarMap (Set ContextInfo))
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> VarMap (Set ContextInfo)
unlocated_ev_binds
  org <- ask
  let elts = VarMap (Set ContextInfo) -> [(Id, Set ContextInfo)]
forall a. DVarEnv a -> [a]
dVarEnvElts VarMap (Set ContextInfo)
binds

      mkNodeInfo (Id
n,Set ContextInfo
ci) = (Name -> Either a Name
forall a b. b -> Either a b
Right (Id -> Name
varName Id
n), 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
n) Set ContextInfo
ci)

      go e :: (Id, Set ContextInfo)
e@(Id
v,Set ContextInfo
_) ([(Identifier, IdentifierDetails Type)]
xs,[HieAST Type]
ys) = case Name -> SrcSpan
nameSrcSpan (Name -> SrcSpan) -> Name -> SrcSpan
forall a b. (a -> b) -> a -> b
$ Id -> Name
varName Id
v of
        RealSrcSpan Span
spn Maybe BufSpan
_
          | Span -> FastString
srcSpanFile Span
spn FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
== FastString
file ->
            let node :: HieAST Type
node = SourcedNodeInfo Type -> Span -> [HieAST Type] -> HieAST Type
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo Type -> SourcedNodeInfo Type
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo Type
ni) Span
spn []
                ni :: NodeInfo Type
ni = Set NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Monoid a => a
mempty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$ [(Identifier, IdentifierDetails Type)] -> NodeIdentifiers Type
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Id, Set ContextInfo) -> (Identifier, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e]
              in ([(Identifier, IdentifierDetails Type)]
xs,HieAST Type
nodeHieAST Type -> [HieAST Type] -> [HieAST Type]
forall a. a -> [a] -> [a]
:[HieAST Type]
ys)
        SrcSpan
_ -> ((Id, Set ContextInfo) -> (Identifier, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e (Identifier, IdentifierDetails Type)
-> [(Identifier, IdentifierDetails Type)]
-> [(Identifier, IdentifierDetails Type)]
forall a. a -> [a] -> [a]
: [(Identifier, IdentifierDetails Type)]
xs,[HieAST Type]
ys)

      (nis,asts) = foldr go ([],[]) elts

  pure $ (M.fromList nis, asts)

initState :: HieState
initState :: HieState
initState = NameEnv Id -> VarMap (Set ContextInfo) -> HieState
HieState NameEnv Id
forall a. NameEnv a
emptyNameEnv VarMap (Set ContextInfo)
forall a. DVarEnv a
emptyDVarEnv

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 = extendNameEnv (name_remapping hs) (varName mono) poly}

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

type HieM = ReaderT NodeOrigin (State HieState)

-- | Construct an 'HieFile' from the outputs of the typechecker.
mkHieFile :: MonadIO m
          => ModSummary
          -> TcGblEnv
          -> RenamedSource -> m HieFile
mkHieFile :: forall (m :: * -> *).
MonadIO m =>
ModSummary -> TcGblEnv -> RenamedSource -> m HieFile
mkHieFile ModSummary
ms TcGblEnv
ts RenamedSource
rs = do
  let src_file :: FilePath
src_file = FilePath -> Maybe FilePath -> FilePath
forall a. HasCallStack => FilePath -> Maybe a -> a
expectJust FilePath
"mkHieFile" (ModLocation -> Maybe FilePath
ml_hs_file (ModLocation -> Maybe FilePath) -> ModLocation -> Maybe FilePath
forall a b. (a -> b) -> a -> b
$ ModSummary -> ModLocation
ms_location ModSummary
ms)
  src <- IO ByteString -> m ByteString
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString) -> IO ByteString -> m ByteString
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ByteString
BS.readFile FilePath
src_file
  pure $ mkHieFileWithSource src_file src ms ts rs

-- | Construct an 'HieFile' from the outputs of the typechecker but don't
-- read the source file again from disk.
mkHieFileWithSource :: FilePath
                    -> BS.ByteString
                    -> ModSummary
                    -> TcGblEnv
                    -> RenamedSource -> HieFile
mkHieFileWithSource :: FilePath
-> ByteString -> ModSummary -> TcGblEnv -> RenamedSource -> HieFile
mkHieFileWithSource FilePath
src_file ByteString
src ModSummary
ms TcGblEnv
ts RenamedSource
rs =
  let tc_binds :: LHsBinds GhcTc
tc_binds = TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
ts
      top_ev_binds :: Bag EvBind
top_ev_binds = TcGblEnv -> Bag EvBind
tcg_ev_binds TcGblEnv
ts
      insts :: [ClsInst]
insts = TcGblEnv -> [ClsInst]
tcg_insts TcGblEnv
ts
      tcs :: [TyCon]
tcs = TcGblEnv -> [TyCon]
tcg_tcs TcGblEnv
ts
      (HieASTs TypeIndex
asts',Array TypeIndex HieTypeFlat
arr) = LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
getCompressedAsts LHsBinds GhcTc
tc_binds RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs in
  HieFile
      { hie_hs_file :: FilePath
hie_hs_file = FilePath
src_file
      , hie_module :: Module
hie_module = ModSummary -> Module
ms_mod ModSummary
ms
      , hie_types :: Array TypeIndex HieTypeFlat
hie_types = Array TypeIndex HieTypeFlat
arr
      , hie_asts :: HieASTs TypeIndex
hie_asts = HieASTs TypeIndex
asts'
      -- mkIfaceExports sorts the AvailInfos for stability
      , hie_exports :: [AvailInfo]
hie_exports = [AvailInfo] -> [AvailInfo]
mkIfaceExports (TcGblEnv -> [AvailInfo]
tcg_exports TcGblEnv
ts)
      , hie_hs_src :: ByteString
hie_hs_src = ByteString
src
      }

getCompressedAsts :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon]
  -> (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
getCompressedAsts :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
getCompressedAsts LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs =
  let asts :: HieASTs Type
asts = LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> HieASTs Type
enrichHie LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs in
  HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
compressTypes HieASTs Type
asts

enrichHie :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon]
  -> HieASTs Type
enrichHie :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> HieASTs Type
enrichHie LHsBinds GhcTc
ts (HsGroup GhcRn
hsGrp, [LImportDecl GhcRn]
imports, Maybe [(LIE GhcRn, [AvailInfo])]
exports, Maybe (LHsDoc GhcRn)
docs, Maybe (XRec GhcRn ModuleName)
modName) Bag EvBind
ev_bs [ClsInst]
insts [TyCon]
tcs =
  Identity (HieASTs Type) -> HieASTs Type
forall a. Identity a -> a
runIdentity (Identity (HieASTs Type) -> HieASTs Type)
-> Identity (HieASTs Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ (StateT HieState Identity (HieASTs Type)
 -> HieState -> Identity (HieASTs Type))
-> HieState
-> StateT HieState Identity (HieASTs Type)
-> Identity (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT HieState Identity (HieASTs Type)
-> HieState -> Identity (HieASTs Type)
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT HieState
initState (StateT HieState Identity (HieASTs Type)
 -> Identity (HieASTs Type))
-> StateT HieState Identity (HieASTs Type)
-> Identity (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ (ReaderT NodeOrigin (State HieState) (HieASTs Type)
 -> NodeOrigin -> StateT HieState Identity (HieASTs Type))
-> NodeOrigin
-> ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> StateT HieState Identity (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> NodeOrigin -> StateT HieState Identity (HieASTs Type)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT NodeOrigin
SourceInfo (ReaderT NodeOrigin (State HieState) (HieASTs Type)
 -> StateT HieState Identity (HieASTs Type))
-> ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> StateT HieState Identity (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ do
    modName <- Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Export (GenLocated SrcSpanAnnA ModuleName
 -> IEContext (GenLocated SrcSpanAnnA ModuleName))
-> Maybe (GenLocated SrcSpanAnnA ModuleName)
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (XRec GhcRn ModuleName)
Maybe (GenLocated SrcSpanAnnA ModuleName)
modName)
    tasts <- toHie $ fmap (BC RegularBind ModuleScope) ts
    rasts <- processGrp hsGrp
    imps <- toHie $ filter (not . ideclImplicit . ideclExt . unLoc) imports
    exps <- toHie $ fmap (map $ IEC Export . fst) exports
    docs <- toHie docs
    -- Add Instance bindings
    forM_ insts $ \ClsInst
i ->
      Id -> ContextInfo -> HieM ()
addUnlocatedEvBind (ClsInst -> Id
is_dfun ClsInst
i) (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
False (ClsInst -> Name
is_cls_nm ClsInst
i)) Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing)
    -- Add class parent bindings
    forM_ tcs $ \TyCon
tc ->
      case TyCon -> Maybe Class
tyConClass_maybe TyCon
tc of
        Maybe Class
Nothing -> () -> HieM ()
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        Just Class
c -> [Id] -> (Id -> HieM ()) -> HieM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Class -> [Id]
classSCSelIds Class
c) ((Id -> HieM ()) -> HieM ()) -> (Id -> HieM ()) -> HieM ()
forall a b. (a -> b) -> a -> b
$ \Id
v ->
          Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
v (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
True (Class -> Name
className Class
c)) Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing)
    let spanFile FastString
file [HieAST a]
children = case [HieAST a] -> Maybe (NonEmpty (HieAST a))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [HieAST a]
children of
          Maybe (NonEmpty (HieAST a))
Nothing -> RealSrcLoc -> Span
realSrcLocSpan (FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1)
          Just NonEmpty (HieAST a)
children -> RealSrcLoc -> RealSrcLoc -> Span
mkRealSrcSpan
              (Span -> RealSrcLoc
realSrcSpanStart (Span -> RealSrcLoc) -> Span -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> Span
forall a. HieAST a -> Span
nodeSpan (NonEmpty (HieAST a) -> HieAST a
forall a. NonEmpty a -> a
NE.head NonEmpty (HieAST a)
children))
              (Span -> RealSrcLoc
realSrcSpanEnd   (Span -> RealSrcLoc) -> Span -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> Span
forall a. HieAST a -> Span
nodeSpan (NonEmpty (HieAST a) -> HieAST a
forall a. NonEmpty a -> a
NE.last NonEmpty (HieAST a)
children))

        flat_asts = [[HieAST Type]] -> [HieAST Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
          [ [HieAST Type]
modName
          , [HieAST Type]
tasts
          , [HieAST Type]
rasts
          , [HieAST Type]
imps
          , [HieAST Type]
exps
          , [HieAST Type]
docs
          ]

        modulify (HiePath FastString
file) [HieAST Type]
xs' = do

          top_ev_asts :: [HieAST Type] <- do
            let
              l :: SrcSpanAnnA
              l :: SrcSpanAnnA
l = SrcSpan -> SrcSpanAnnA
forall e. HasAnnotation e => SrcSpan -> e
noAnnSrcSpan (Span -> Maybe BufSpan -> SrcSpan
RealSrcSpan (RealSrcLoc -> Span
realSrcLocSpan (RealSrcLoc -> Span) -> RealSrcLoc -> Span
forall a b. (a -> b) -> a -> b
$ FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1) Maybe BufSpan
forall a. Maybe a
Strict.Nothing)
            EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing
                  (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (Bag EvBind -> TcEvBinds
EvBinds Bag EvBind
ev_bs)

          (uloc_evs,more_ev_asts) <- getUnlocatedEvBinds file

          let xs = [HieAST Type] -> [HieAST Type]
mergeSortAsts ([HieAST Type] -> [HieAST Type]) -> [HieAST Type] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieAST Type]
xs' [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
++ [HieAST Type]
top_ev_asts [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
++ [HieAST Type]
more_ev_asts
              span = FastString -> [HieAST Type] -> Span
forall {a}. FastString -> [HieAST a] -> Span
spanFile FastString
file [HieAST Type]
xs

              moduleInfo = Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type
forall a. Map NodeOrigin (NodeInfo a) -> SourcedNodeInfo a
SourcedNodeInfo
                             (Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type)
-> Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type
forall a b. (a -> b) -> a -> b
$ NodeOrigin -> NodeInfo Type -> Map NodeOrigin (NodeInfo Type)
forall k a. k -> a -> Map k a
M.singleton NodeOrigin
SourceInfo
                               (NodeInfo Type -> Map NodeOrigin (NodeInfo Type))
-> NodeInfo Type -> Map NodeOrigin (NodeInfo Type)
forall a b. (a -> b) -> a -> b
$ (FastString -> FastString -> NodeInfo Type
forall a. FastString -> FastString -> NodeInfo a
simpleNodeInfo FastString
"Module" FastString
"Module")
                                  {nodeIdentifiers = uloc_evs}

              moduleNode = SourcedNodeInfo Type -> Span -> [HieAST Type] -> HieAST Type
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node SourcedNodeInfo Type
moduleInfo Span
span []

          case mergeSortAsts $ moduleNode : xs of
            [HieAST Type
x] -> HieAST Type -> ReaderT NodeOrigin (State HieState) (HieAST Type)
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (m :: * -> *) a. Monad m => a -> m a
return HieAST Type
x
            [HieAST Type]
xs -> FilePath
-> SDoc -> ReaderT NodeOrigin (State HieState) (HieAST Type)
forall a. FilePath -> SDoc -> a
panicDoc FilePath
"enrichHie: mergeSortAsts retur:ed more than one result" ([Span] -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([Span] -> SDoc) -> [Span] -> SDoc
forall a b. (a -> b) -> a -> b
$ (HieAST Type -> Span) -> [HieAST Type] -> [Span]
forall a b. (a -> b) -> [a] -> [b]
map HieAST Type -> Span
forall a. HieAST a -> Span
nodeSpan [HieAST Type]
xs)

    asts' <- sequence
          $ M.mapWithKey modulify
          $ M.fromListWith (++)
          $ map (\HieAST Type
x -> (FastString -> HiePath
HiePath (Span -> FastString
srcSpanFile (HieAST Type -> Span
forall a. HieAST a -> Span
nodeSpan HieAST Type
x)),[HieAST Type
x])) flat_asts

    let asts = Map HiePath (HieAST Type) -> HieASTs Type
forall a. Map HiePath (HieAST a) -> HieASTs a
HieASTs (Map HiePath (HieAST Type) -> HieASTs Type)
-> Map HiePath (HieAST Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ Map HiePath (HieAST Type) -> Map HiePath (HieAST Type)
forall a. Map HiePath (HieAST a) -> Map HiePath (HieAST a)
resolveTyVarScopes Map HiePath (HieAST Type)
asts'
    return asts

processGrp :: HsGroup GhcRn -> HieM [HieAST Type]
processGrp :: HsGroup GhcRn -> HieM [HieAST Type]
processGrp HsGroup GhcRn
grp = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RScoped (HsValBinds GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBinds GhcRn) -> HieM [HieAST Type])
-> RScoped (HsValBinds GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsValBinds GhcRn -> RScoped (HsValBinds GhcRn))
-> (HsGroup GhcRn -> HsValBinds GhcRn)
-> HsGroup GhcRn
-> RScoped (HsValBinds GhcRn)
forall a b. (a -> b) -> (HsGroup GhcRn -> a) -> HsGroup GhcRn -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Scope -> HsValBinds GhcRn -> RScoped (HsValBinds GhcRn)
forall a. Scope -> a -> RScoped a
RS Scope
ModuleScope ) HsGroup GhcRn -> HsValBinds GhcRn
forall p. HsGroup p -> HsValBinds p
hs_valds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (SpliceDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (SpliceDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (SpliceDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LSpliceDecl GhcRn]
forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds HsGroup GhcRn
grp
      , [TyClGroup GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TyClGroup GhcRn] -> HieM [HieAST Type])
-> [TyClGroup GhcRn] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [TyClGroup GhcRn]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (DerivDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DerivDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DerivDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LDerivDecl GhcRn]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (FixitySig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (FixitySig GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (FixitySig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LFixitySig GhcRn]
forall p. HsGroup p -> [LFixitySig p]
hs_fixds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (DefaultDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DefaultDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DefaultDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LDefaultDecl GhcRn]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (ForeignDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (ForeignDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (ForeignDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LForeignDecl GhcRn]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (WarnDecls GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (WarnDecls GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (WarnDecls GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LWarnDecls GhcRn]
forall p. HsGroup p -> [LWarnDecls p]
hs_warnds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (AnnDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (AnnDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (AnnDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LAnnDecl GhcRn]
forall p. HsGroup p -> [LAnnDecl p]
hs_annds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (RuleDecls GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (RuleDecls GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (RuleDecls GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LRuleDecls GhcRn]
forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds HsGroup GhcRn
grp
      , [GenLocated SrcSpanAnnA (DocDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DocDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DocDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup GhcRn -> [LDocDecl GhcRn]
forall p. HsGroup p -> [LDocDecl p]
hs_docs HsGroup GhcRn
grp
      ]

getRealSpanA :: EpAnn ann -> Maybe Span
getRealSpanA :: forall ann. EpAnn ann -> Maybe Span
getRealSpanA EpAnn ann
la = SrcSpan -> Maybe Span
getRealSpan (EpAnn ann -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA EpAnn ann
la)

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

grhss_span :: (Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p)))) ~ EpAnn NoEpAnns)
           => GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span :: forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span (GRHSs XCGRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
_ [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
xs HsLocalBinds (GhcPass p)
bs) = (SrcSpan -> SrcSpan -> SrcSpan) -> SrcSpan -> [SrcSpan] -> SrcSpan
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
bs) ((GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 -> SrcSpan)
-> [GenLocated
      (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
-> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated
  (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
[GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
xs)

bindingsOnly :: [Context Name] -> HieM [HieAST a]
bindingsOnly :: forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [] = [HieAST a] -> ReaderT NodeOrigin (State HieState) [HieAST a]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
bindingsOnly (C ContextInfo
c Name
n : [Context Name]
xs) = do
  org <- ReaderT NodeOrigin (State HieState) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
  rest <- bindingsOnly xs
  pure $ case nameSrcSpan n of
    RealSrcSpan Span
span Maybe BufSpan
_ -> SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo a
nodeinfo) Span
span [] HieAST a -> [HieAST a] -> [HieAST a]
forall a. a -> [a] -> [a]
: [HieAST a]
rest
      where nodeinfo :: NodeInfo a
nodeinfo = Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Set a
S.empty [] (Identifier -> IdentifierDetails a -> NodeIdentifiers a
forall k a. k -> a -> Map k a
M.singleton (Name -> Identifier
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 = S.singleton c}
    SrcSpan
_ -> [HieAST a]
rest

concatM :: Monad m => [m [a]] -> m [a]
concatM :: forall (m :: * -> *) a. Monad m => [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)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [m [a]]
xs

{- Note [Capturing Scopes and other non local information]
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toHie is a local transformation, 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 EvBindContext a = EvBindContext Scope (Maybe Span) a

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)
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.
    TypeIndex -> (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 -> Constr
PScoped a -> DataType
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall a. Data a => Typeable (PScoped a)
forall a. Data a => PScoped a -> Constr
forall a. Data a => PScoped a -> DataType
forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall a u.
Data a =>
TypeIndex -> (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. TypeIndex -> (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.
TypeIndex -> (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))
$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)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> 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)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
$ctoConstr :: forall a. Data a => PScoped a -> Constr
toConstr :: PScoped a -> Constr
$cdataTypeOf :: forall a. Data a => PScoped a -> DataType
dataTypeOf :: PScoped a -> DataType
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> 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))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
gmapT :: (forall b. Data b => b -> b) -> PScoped a -> PScoped a
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapQl :: forall r r'.
(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
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PScoped a -> [u]
$cgmapQi :: forall a u.
Data a =>
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
gmapQi :: forall u.
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapM :: forall (m :: * -> *).
Monad m =>
(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)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(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)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (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 -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes :: forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
_ [] = []
listScopes Scope
rhsScope [LocatedA a
pat] = [Scope -> LocatedA a -> RScoped (LocatedA a)
forall a. Scope -> a -> RScoped a
RS Scope
rhsScope LocatedA a
pat]
listScopes Scope
rhsScope (LocatedA a
pat : [LocatedA a]
pats) = Scope -> LocatedA a -> RScoped (LocatedA a)
forall a. Scope -> a -> RScoped a
RS Scope
sc LocatedA a
pat RScoped (LocatedA a)
-> [RScoped (LocatedA a)] -> [RScoped (LocatedA a)]
forall a. a -> [a] -> [a]
: [RScoped (LocatedA a)]
pats'
  where
    pats' :: [RScoped (LocatedA a)]
pats'@((RS Scope
scope LocatedA a
p):[RScoped (LocatedA a)]
_) = Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope [LocatedA a]
pats
    sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LocatedA a -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LocatedA a
p

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

-- | 'listScopes' specialised to 'HsConPatTyArg'
taScopes
  :: Scope
  -> Scope
  -> [HsConPatTyArg (GhcPass a)]
  -> [TScoped (HsTyPat (GhcPass a))]
taScopes :: forall (a :: Pass).
Scope
-> Scope
-> [HsConPatTyArg (GhcPass a)]
-> [TScoped (HsTyPat (GhcPass a))]
taScopes Scope
scope Scope
rhsScope [HsConPatTyArg (GhcPass a)]
xs =
  (RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))
 -> TScoped (HsTyPat (GhcPass a)))
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
-> [TScoped (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
a) -> TyVarScope -> HsTyPat (GhcPass a) -> TScoped (HsTyPat (GhcPass a))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
sc]) (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)) -> HsTyPat (GhcPass a)
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
a)) ([RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
 -> [TScoped (HsTyPat (GhcPass a))])
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
-> [TScoped (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> a -> b
$
    Scope
-> [GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))]
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope ((HsConPatTyArg (GhcPass a)
 -> GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))
-> [HsConPatTyArg (GhcPass a)]
-> [GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(HsConPatTyArg XConPatTyArg (GhcPass a)
_ HsTyPat (GhcPass a)
hstp) -> SrcSpanAnnA
-> HsTyPat (GhcPass a)
-> GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
forall l e. l -> e -> GenLocated l e
L (GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc (GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA
forall a b. (a -> b) -> a -> b
$ HsTyPat (GhcPass a) -> LHsType (GhcPass a)
forall pass. HsTyPat pass -> LHsType pass
hstp_body HsTyPat (GhcPass a)
hstp) HsTyPat (GhcPass a)
hstp) [HsConPatTyArg (GhcPass a)]
xs)
  -- We make the HsTyPat into a Located one by using the location of the underlying LHsType.
  -- We then strip off the redundant location information afterward, and take the union of the given scope and those to the right when forming the TS.

-- | 'listScopes' specialised to 'TVScoped' things
tvScopes
  :: TyVarScope
  -> Scope
  -> [LHsTyVarBndr flag (GhcPass a)]
  -> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes :: forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tvScope Scope
rhsScope [LHsTyVarBndr flag (GhcPass a)]
xs =
  (RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))
 -> TVScoped (LHsTyVarBndr flag (GhcPass a)))
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc LocatedA (HsTyVarBndr flag (GhcPass a))
a)-> TyVarScope
-> Scope
-> LocatedA (HsTyVarBndr flag (GhcPass a))
-> TVScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tvScope Scope
sc LocatedA (HsTyVarBndr flag (GhcPass a))
a) ([RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
 -> [TVScoped (LHsTyVarBndr flag (GhcPass a))])
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA (HsTyVarBndr flag (GhcPass a))]
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope [LHsTyVarBndr flag (GhcPass a)]
[LocatedA (HsTyVarBndr flag (GhcPass 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

This case in handled in the instance for HsPatSigType
-}

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

instance HasLoc a => HasLoc (DataDefnCons a) where
  getHasLoc :: DataDefnCons a -> SrcSpan
getHasLoc = [a] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList ([a] -> SrcSpan)
-> (DataDefnCons a -> [a]) -> DataDefnCons a -> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDefnCons a -> [a]
forall a. DataDefnCons a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

instance (HasLoc a, HiePass p) => HasLoc (FamEqn (GhcPass p) a) where
  getHasLoc :: FamEqn (GhcPass p) a -> SrcSpan
getHasLoc (FamEqn XCFamEqn (GhcPass p) a
_ LIdP (GhcPass p)
a HsOuterFamEqnTyVarBndrs (GhcPass p)
outer_bndrs HsFamEqnPats (GhcPass p)
b LexicalFixity
_ a
c) = case HsOuterFamEqnTyVarBndrs (GhcPass p)
outer_bndrs of
    HsOuterImplicit{} ->
      (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [GenLocated SrcSpanAnnN (IdGhcP p) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
a, [HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats (GhcPass p)
[HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc a
c]
    HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
tvs} ->
      (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [GenLocated SrcSpanAnnN (IdGhcP p) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
a, [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
tvs, [HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats (GhcPass p)
[HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc a
c]

instance (HasLoc tm, HasLoc ty) => HasLoc (HsArg (GhcPass p) tm ty) where
  getHasLoc :: HsArg (GhcPass p) tm ty -> SrcSpan
getHasLoc (HsValArg XValArg (GhcPass p)
_ tm
tm) = tm -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc tm
tm
  getHasLoc (HsTypeArg XTypeArg (GhcPass p)
_ ty
ty) = ty -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc ty
ty
  getHasLoc (HsArgPar XArgPar (GhcPass p)
sp)  = SrcSpan
XArgPar (GhcPass p)
sp

instance HasLoc (HsDataDefn GhcRn) where
  getHasLoc :: HsDataDefn GhcRn -> SrcSpan
getHasLoc def :: HsDataDefn GhcRn
def@(HsDataDefn{}) = DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn)) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn)) -> SrcSpan)
-> DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn)) -> SrcSpan
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> DataDefnCons (LConDecl GhcRn)
forall pass. HsDataDefn pass -> DataDefnCons (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

-- | 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 HasType a where
  getTypeNode :: a -> HieM [HieAST Type]

instance ToHie Void where
  toHie :: Void -> HieM [HieAST Type]
toHie Void
v = Void -> HieM [HieAST Type]
forall a. Void -> a
absurd Void
v

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

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

instance (ToHie a) => ToHie (DataDefnCons a) where
  toHie :: DataDefnCons a -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> DataDefnCons a -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f 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 a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance ToHie (IEContext (LocatedA ModuleName)) where
  toHie :: IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
toHie (IEC IEType
c (L (EpAnn (EpaSpan (RealSrcSpan Span
span Maybe BufSpan
_)) AnnListItem
_ EpAnnComments
_) ModuleName
mname)) = do
      org <- ReaderT NodeOrigin (State HieState) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
      pure $ [Node (mkSourcedNodeInfo org $ NodeInfo S.empty [] idents) span []]
    where details :: IdentifierDetails Type
details = IdentifierDetails Type
forall a. Monoid a => a
mempty{identInfo = S.singleton (IEThing c)}
          idents :: NodeIdentifiers Type
idents = Identifier -> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (ModuleName -> Identifier
forall a b. a -> Either a b
Left ModuleName
mname) IdentifierDetails Type
details
  toHie IEContext (GenLocated SrcSpanAnnA ModuleName)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located a)) => ToHie (Context (LocatedN a)) where
  toHie :: Context (LocatedN a) -> HieM [HieAST Type]
toHie (C ContextInfo
c (L SrcSpanAnnN
l a
a)) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpan -> a -> Located a
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnN -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnN
l) a
a))

instance ToHie (Context (Located a)) => ToHie (Context (LocatedA a)) where
  toHie :: Context (LocatedA a) -> HieM [HieAST Type]
toHie (C ContextInfo
c (L SrcSpanAnnA
l a
a)) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpan -> a -> Located a
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
l) a
a))

instance ToHie (Context (Located Var)) where
  toHie :: Context (Located Id) -> HieM [HieAST Type]
toHie Context (Located Id)
c = case Context (Located Id)
c of
      C ContextInfo
context (L (RealSrcSpan Span
span Maybe BufSpan
_) Id
name')
        | Id -> Unique
varUnique Id
name' Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== TypeIndex -> Unique
mkBuiltinUnique TypeIndex
1 -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          m <- State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (NameEnv Id)
 -> ReaderT NodeOrigin (State HieState) (NameEnv Id))
-> State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> State HieState (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          org <- ask
          let 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'
              ty = case Id -> Maybe DataCon
isDataConId_maybe Id
name' of
                      Maybe DataCon
Nothing -> Id -> Type
varType Id
name'
                      Just DataCon
dc -> DataCon -> Type
dataConNonlinearType DataCon
dc
          pure
            [Node
              (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
                M.singleton (Right $ varName name)
                            (IdentifierDetails (Just ty)
                                               (S.singleton context)))
              span
              []]
      C (EvidenceVarBind EvVarSource
i Scope
_ Maybe Span
sp)  (L SrcSpan
_ Id
name) -> do
        Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
name (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
i Scope
ModuleScope Maybe Span
sp)
        [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
      Context (Located Id)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
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 Span
span Maybe BufSpan
_) Name
name')
        | Name -> Unique
nameUnique Name
name' Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== TypeIndex -> Unique
mkBuiltinUnique TypeIndex
1 -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          m <- State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (NameEnv Id)
 -> ReaderT NodeOrigin (State HieState) (NameEnv Id))
-> State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> State HieState (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          org <- ask
          let 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'
          pure
            [Node
              (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
                M.singleton (Right name)
                            (IdentifierDetails Nothing
                                               (S.singleton context)))
              span
              []]
      Context (Located Name)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

evVarsOfTermList :: EvTerm -> [EvId]
evVarsOfTermList :: EvTerm -> [Id]
evVarsOfTermList (EvExpr EvExpr
e)         = InterestingVarFun -> EvExpr -> [Id]
exprSomeFreeVarsList InterestingVarFun
isEvVar EvExpr
e
evVarsOfTermList (EvTypeable Type
_ EvTypeable
ev)  =
  case EvTypeable
ev of
    EvTypeableTyCon TyCon
_ [EvTerm]
e   -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm]
e
    EvTypeableTyApp EvTerm
e1 EvTerm
e2 -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm
e1,EvTerm
e2]
    EvTypeableTrFun EvTerm
e1 EvTerm
e2 EvTerm
e3 -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm
e1,EvTerm
e2,EvTerm
e3]
    EvTypeableTyLit EvTerm
e     -> EvTerm -> [Id]
evVarsOfTermList EvTerm
e
evVarsOfTermList (EvFun{}) = []

instance ToHie (EvBindContext (LocatedA TcEvBinds)) where
  toHie :: EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
toHie (EvBindContext Scope
sc Maybe Span
sp (L SrcSpanAnnA
span (EvBinds Bag EvBind
bs)))
    = (EvBind -> HieM [HieAST Type]) -> [EvBind] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM EvBind -> HieM [HieAST Type]
go ([EvBind] -> HieM [HieAST Type]) -> [EvBind] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Bag EvBind -> [EvBind]
forall a. Bag a -> [a]
bagToList Bag EvBind
bs
    where
      go :: EvBind -> HieM [HieAST Type]
go EvBind
evbind = do
          let evDeps :: [Id]
evDeps = EvTerm -> [Id]
evVarsOfTermList (EvTerm -> [Id]) -> EvTerm -> [Id]
forall a b. (a -> b) -> a -> b
$ EvBind -> EvTerm
eb_rhs EvBind
evbind
              depNames :: EvBindDeps
depNames = [Name] -> EvBindDeps
EvBindDeps ([Name] -> EvBindDeps) -> [Name] -> EvBindDeps
forall a b. (a -> b) -> a -> b
$ (Id -> Name) -> [Id] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Id -> Name
varName [Id]
evDeps
          [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 (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (EvBindDeps -> EvVarSource
EvLetBind EvBindDeps
depNames) (Scope -> Scope -> Scope
combineScopes Scope
sc (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span)) Maybe Span
sp)
                                        (SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (Id -> GenLocated SrcSpanAnnA Id)
-> Id -> GenLocated SrcSpanAnnA Id
forall a b. (a -> b) -> a -> b
$ EvBind -> Id
eb_lhs EvBind
evbind))
            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) ([Id] -> [Context (GenLocated SrcSpanAnnA Id)])
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> a -> b
$ [Id]
evDeps
            ]
  toHie EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA HsWrapper) where
  toHie :: LocatedA HsWrapper -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
osp HsWrapper
wrap)
    = case HsWrapper
wrap of
        (WpLet TcEvBinds
bs)      -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
osp) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
osp) (SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp TcEvBinds
bs)
        (WpCompose HsWrapper
a HsWrapper
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
$
          [LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
a), LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
b)]
        (WpFun HsWrapper
a HsWrapper
b Scaled Type
_)   -> [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
$
          [LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
a), LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
b)]
        (WpEvLam Id
a) ->
          Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvWrapperBind (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
osp) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
osp))
                (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp Id
a
        (WpEvApp EvTerm
a) ->
          (Id -> HieM [HieAST Type]) -> [Id] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> (Id -> Context (GenLocated SrcSpanAnnA Id))
-> Id
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp) ([Id] -> HieM [HieAST Type]) -> [Id] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ EvTerm -> [Id]
evVarsOfTermList EvTerm
a
        HsWrapper
_               -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => HasType (LocatedA (HsBind (GhcPass p))) where
  getTypeNode :: LocatedA (HsBind (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn HsBind (GhcPass p)
bind) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn)
      HiePassEv p
HieTc ->  case HsBind (GhcPass p)
bind of
        FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name} -> HsBind (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn) (Id -> Type
varType (Id -> Type) -> Id -> Type
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnN Id -> Id
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN Id
name)
        HsBind (GhcPass p)
_ -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn)

instance HiePass p => HasType (LocatedA (Pat (GhcPass p))) where
  getTypeNode :: LocatedA (Pat (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn Pat (GhcPass p)
pat) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> Pat (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Pat (GhcPass p)
pat SrcSpanAnnA
spn
      HiePassEv p
HieTc -> Pat (GhcPass p) -> SrcSpanAnnA -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpanAnnA -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNodeA Pat (GhcPass p)
pat SrcSpanAnnA
spn (Pat GhcTc -> Type
hsPatType Pat (GhcPass p)
Pat GhcTc
pat)

-- | 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.
--
-- See Note [Computing the type of every node in the tree]
instance HiePass p => HasType (LocatedA (HsExpr (GhcPass p))) where
  getTypeNode :: LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn HsExpr (GhcPass p)
e) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HieM [HieAST Type]
fallback
      HiePassEv p
HieTc -> case HsExpr GhcTc -> Maybe Type
computeType HsExpr (GhcPass p)
HsExpr GhcTc
e of
          Just Type
ty -> HsExpr (GhcPass p) -> SrcSpanAnnA -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpanAnnA -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNodeA HsExpr (GhcPass p)
e SrcSpanAnnA
spn Type
ty
          Maybe Type
Nothing -> HieM [HieAST Type]
fallback
    where
      fallback :: HieM [HieAST Type]
      fallback :: HieM [HieAST Type]
fallback = HsExpr (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsExpr (GhcPass p)
e SrcSpanAnnA
spn

      -- Skip computing the type of some expressions for performance reasons.
      --
      -- See impact on Haddock output (esp. missing type annotations or links)
      -- before skipping more kinds of expressions. See impact on Haddock
      -- performance before computing the types of more expressions.
      --
      -- See Note [Computing the type of every node in the tree]
      computeType :: HsExpr GhcTc -> Maybe Type
      computeType :: HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e = case HsExpr GhcTc
e of
        HsApp{} -> Maybe Type
forall a. Maybe a
Nothing
        HsAppType{} -> Maybe Type
forall a. Maybe a
Nothing
        NegApp{} -> Maybe Type
forall a. Maybe a
Nothing
        HsPar XPar GhcTc
_ LHsExpr GhcTc
e -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        ExplicitTuple{} -> Maybe Type
forall a. Maybe a
Nothing
        HsIf XIf GhcTc
_ LHsExpr GhcTc
_ LHsExpr GhcTc
t LHsExpr GhcTc
f -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
t Maybe Type -> Maybe Type -> Maybe Type
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
f
        HsLet XLet GhcTc
_ HsLocalBinds GhcTc
_ LHsExpr GhcTc
body -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
body
        RecordCon XRecordCon GhcTc
con_expr XRec GhcTc (ConLikeP GhcTc)
_ HsRecordBinds GhcTc
_ -> HsExpr GhcTc -> Maybe Type
computeType XRecordCon GhcTc
HsExpr GhcTc
con_expr
        ExprWithTySig XExprWithTySig GhcTc
_ LHsExpr GhcTc
e LHsSigWcType (NoGhcTc GhcTc)
_ -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        HsPragE XPragE GhcTc
_ HsPragE GhcTc
_ LHsExpr GhcTc
e -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        XExpr (ExpandedThingTc HsThingRn
thing HsExpr GhcTc
e)
          | OrigExpr (HsGetField{}) <- HsThingRn
thing -- for record-dot-syntax
          -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsExpr GhcTc -> Type
hsExprType HsExpr GhcTc
e)
          | Bool
otherwise -> HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e
        XExpr (HsTick CoreTickish
_ LHsExpr GhcTc
e) -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        XExpr (HsBinTick TypeIndex
_ TypeIndex
_ LHsExpr GhcTc
e) -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        HsExpr GhcTc
e -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsExpr GhcTc -> Type
hsExprType HsExpr GhcTc
e)

      computeLType :: LHsExpr GhcTc -> Maybe Type
      computeLType :: LHsExpr GhcTc -> Maybe Type
computeLType (L SrcSpanAnnA
_ HsExpr GhcTc
e) = HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e

{- Note [Computing the type of every node in the tree]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In GHC.Iface.Ext.Ast we decorate every node in the AST with its
type, computed by `hsExprType` applied to that node.  So it's
important that `hsExprType` takes roughly constant time per node.
There are three cases to consider:

1. For many nodes (e.g. HsVar, HsDo, HsCase) it is easy to get their
   type -- e.g. it is stored in the node, or in sub-node thereof.

2. For some nodes (e.g. HsPar, HsTick, HsIf) the type of the node is
   the type of a child, so we can recurse, fast.  We don't expect the
   nesting to be very deep, so while this is theoretically non-linear,
   we don't expect it to be a problem in practice.

3. A very few nodes (e.g. HsApp) are more troublesome because we need to
   take the type of a child, and then do some non-trivial processing.
   To be conservative on computation, we decline to decorate these
   nodes, using `fallback` instead.

The function `computeType e` returns `Just t` if we can find the type
of `e` cheaply, and `Nothing` otherwise.  The base `Nothing` cases
are the troublesome ones in (3) above. Hopefully we can ultimately
get rid of them all.

See #16233

-}

data HiePassEv p where
  HieRn :: HiePassEv 'Renamed
  HieTc :: HiePassEv 'Typechecked

class ( HiePass (NoGhcTcPass p)
      , NoGhcTcPass p ~ 'Renamed
      , ModifyState (IdGhcP p)
      , Data (GRHS  (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Match (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Match (GhcPass p) (LocatedA (HsCmd  (GhcPass p))))
      , Data (Stmt  (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Stmt  (GhcPass p) (LocatedA (HsCmd  (GhcPass p))))
      , Data (HsExpr (GhcPass p))
      , Data (HsCmd  (GhcPass p))
      , Data (AmbiguousFieldOcc (GhcPass p))
      , Data (HsCmdTop (GhcPass p))
      , Data (GRHS (GhcPass p) (LocatedA (HsCmd (GhcPass p))))
      , Data (HsUntypedSplice (GhcPass p))
      , Data (HsLocalBinds (GhcPass p))
      , Data (FieldOcc (GhcPass p))
      , Data (HsTupArg (GhcPass p))
      , Data (IPBind (GhcPass p))
      , ToHie (Context (Located (IdGhcP p)))
      , Anno (IdGhcP p) ~ SrcSpanAnnN
      )
      => HiePass p where
  hiePass :: HiePassEv p

instance HiePass 'Renamed where
  hiePass :: HiePassEv 'Renamed
hiePass = HiePassEv 'Renamed
HieRn
instance HiePass 'Typechecked where
  hiePass :: HiePassEv 'Typechecked
hiePass = HiePassEv 'Typechecked
HieTc

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

type AnnoBody p body
  = ( Anno (Match (GhcPass p) (LocatedA (body (GhcPass p))))
                   ~ SrcSpanAnnA
    , Anno [LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
                   ~ SrcSpanAnnL
    , Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
                   ~ EpAnn NoEpAnns
    , Anno (StmtLR (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))) ~ SrcSpanAnnA

    , Data (body (GhcPass p))
    , Data (Match (GhcPass p) (LocatedA (body (GhcPass p))))
    , Data (GRHS  (GhcPass p) (LocatedA (body (GhcPass p))))
    , Data (Stmt  (GhcPass p) (LocatedA (body (GhcPass p))))
    )

instance HiePass p => ToHie (BindContext (LocatedA (HsBind (GhcPass p)))) where
  toHie :: BindContext (LocatedA (HsBind (GhcPass p))) -> HieM [HieAST Type]
toHie (BC BindType
context Scope
scope b :: LocatedA (HsBind (GhcPass p))
b@(L SrcSpanAnnA
span HsBind (GhcPass p)
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
$ LocatedA (HsBind (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (HsBind (GhcPass p))
b HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsBind (GhcPass p)
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches, fun_ext :: forall idL idR. HsBindLR idL idR -> XFunBind idL idR
fun_ext = XFunBind (GhcPass p) (GhcPass p)
ext} ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
context Scope
scope (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
name
        , MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
matches
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc | (HsWrapper
wrap, [CoreTickish]
_) <- XFunBind (GhcPass p) (GhcPass p)
ext -> LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsWrapper
wrap
            HiePassEv p
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
      PatBind{pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat (GhcPass p)
lhs, pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs (GhcPass p) (LHsExpr (GhcPass p))
rhs} ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe Span
getRealSpan (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) Scope
scope Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
lhs
        , GRHSs (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LHsExpr (GhcPass p))
GRHSs (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
rhs
        ]
      VarBind{var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr (GhcPass p)
expr} ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        ]
      XHsBindsLR XXHsBindsLR (GhcPass p) (GhcPass p)
ext -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc
          | AbsBinds{ abs_exports :: AbsBinds -> [ABExport]
abs_exports = [ABExport]
xs, abs_binds :: AbsBinds -> LHsBinds GhcTc
abs_binds = LHsBinds GhcTc
binds
                    , abs_ev_binds :: AbsBinds -> [TcEvBinds]
abs_ev_binds = [TcEvBinds]
ev_binds
                    , abs_ev_vars :: AbsBinds -> [Id]
abs_ev_vars = [Id]
ev_vars } <- XXHsBindsLR (GhcPass p) (GhcPass p)
ext
          ->
            [  State HieState () -> HieM ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((HieState -> HieState) -> State HieState ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify ([ABExport] -> HieState -> HieState
modifyState [ABExport]
xs)) HieM () -> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b.
ReaderT NodeOrigin (State HieState) a
-> ReaderT NodeOrigin (State HieState) b
-> ReaderT NodeOrigin (State HieState) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> -- Note [Name Remapping]
                    (Bag (BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
 -> HieM [HieAST Type])
-> Bag
     (BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)
 -> BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
-> Bag
     (BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
forall a b. (a -> b) -> Bag a -> Bag b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)
-> BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
context Scope
scope) LHsBinds GhcTc
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
binds)
            , [LocatedA HsWrapper] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([LocatedA HsWrapper] -> HieM [HieAST Type])
-> [LocatedA HsWrapper] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ABExport -> LocatedA HsWrapper)
-> [ABExport] -> [LocatedA HsWrapper]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (HsWrapper -> LocatedA HsWrapper)
-> (ABExport -> HsWrapper) -> ABExport -> LocatedA HsWrapper
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ABExport -> HsWrapper
abe_wrap) [ABExport]
xs
            , [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
 -> HieM [HieAST Type])
-> [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (TcEvBinds -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> [TcEvBinds]
-> [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span)
                    (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> (TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds)
-> TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [TcEvBinds]
ev_binds
            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvSigBind
                                        (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span)
                                        (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span))
                    (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [Id]
ev_vars
            ]
      PatSynBind XPatSynBind (GhcPass p) (GhcPass p)
_ PatSynBind (GhcPass p) (GhcPass p)
psb ->
        [ GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> PatSynBind (GhcPass p) (GhcPass p)
-> GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) PatSynBind (GhcPass p) (GhcPass p)
psb -- PatSynBinds only occur at the top level
        ]

instance ( HiePass p
         , AnnoBody p body
         , ToHie (LocatedA (body (GhcPass p)))
         ) => ToHie (MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))) where
  toHie :: MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg = case MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg of
    MG{ mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = (L SrcSpanAnnL
span [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
alts) } ->
      (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (Origin -> NodeOrigin -> NodeOrigin
setOrigin Origin
origin) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
span)
        , [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
alts
        ]
    where origin :: Origin
origin = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
             HiePassEv p
HieRn -> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> XMG (GhcPass p) (LocatedA (body (GhcPass p)))
forall p body. MatchGroup p body -> XMG p body
mg_ext MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg
             HiePassEv p
HieTc -> MatchGroupTc -> Origin
mg_origin (MatchGroupTc -> Origin) -> MatchGroupTc -> Origin
forall a b. (a -> b) -> a -> b
$ MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> XMG (GhcPass p) (LocatedA (body (GhcPass p)))
forall p body. MatchGroup p body -> XMG p body
mg_ext MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg

setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin Origin
FromSource NodeOrigin
_ = NodeOrigin
SourceInfo
setOrigin (Generated {}) NodeOrigin
_ = NodeOrigin
GeneratedInfo

instance HiePass p => ToHie (Located (PatSynBind (GhcPass p) (GhcPass p))) where
    toHie :: Located (PatSynBind (GhcPass p) (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpan
sp PatSynBind (GhcPass p) (GhcPass p)
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 (GhcPass p) (GhcPass p)
psb of
      PSB{psb_id :: forall idL idR. PatSynBind idL idR -> LIdP idL
psb_id=XRec (GhcPass p) (IdP (GhcPass p))
var, psb_args :: forall idL idR. PatSynBind idL idR -> HsPatSynDetails idR
psb_args=HsPatSynDetails (GhcPass p)
dets, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def=LPat (GhcPass p)
pat, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir=HsPatSynDir (GhcPass p)
dir} ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
PatSynDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
sp) XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdGhcP p)
var
        , HsConDetails
  Void
  (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
  [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   Void
   (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
   [PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HieM [HieAST Type])
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
toBind HsPatSynDetails (GhcPass p)
HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
dets
        , PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
lhsScope Scope
patScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , HsPatSynDir (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsPatSynDir (GhcPass p)
dir
        ]
        where
          lhsScope :: Scope
lhsScope = Scope -> Scope -> Scope
combineScopes Scope
varScope Scope
detScope
          varScope :: Scope
varScope = GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdGhcP p)
var
          patScope :: Scope
patScope = SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope) -> SrcSpanAnnA -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (Pat (GhcPass p)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
          detScope :: Scope
detScope = case HsPatSynDetails (GhcPass p)
dets of
            (PrefixCon [Void]
_ [XRec (GhcPass p) (IdP (GhcPass p))]
args) -> (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
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
$ (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope)
-> [GenLocated SrcSpanAnnN (IdGhcP p)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope [XRec (GhcPass p) (IdP (GhcPass p))]
[GenLocated SrcSpanAnnN (IdGhcP p)]
args
            (InfixCon XRec (GhcPass p) (IdP (GhcPass p))
a XRec (GhcPass p) (IdP (GhcPass p))
b) -> Scope -> Scope -> Scope
combineScopes (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdGhcP p)
a) (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdGhcP p)
b)
            (RecCon [RecordPatSynField (GhcPass p)]
r) -> (RecordPatSynField (GhcPass p) -> Scope -> Scope)
-> Scope -> [RecordPatSynField (GhcPass p)] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RecordPatSynField (GhcPass p) -> Scope -> Scope
forall {pass}.
(HasLoc (XRec pass (IdP pass)), HasLoc (XRec pass RdrName)) =>
RecordPatSynField pass -> Scope -> Scope
go Scope
NoScope [RecordPatSynField (GhcPass p)]
r
          go :: RecordPatSynField pass -> Scope -> Scope
go (RecordPatSynField FieldOcc pass
a XRec pass (IdP pass)
b) Scope
c = Scope -> Scope -> Scope
combineScopes Scope
c
            (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes (XRec pass RdrName -> Scope
forall a. HasLoc a => a -> Scope
mkScope (FieldOcc pass -> XRec pass RdrName
forall pass. FieldOcc pass -> XRec pass RdrName
foLabel FieldOcc pass
a)) (XRec pass (IdP pass) -> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec pass (IdP pass)
b)
          detSpan :: Maybe Span
detSpan = case Scope
detScope of
            LocalScope Span
a -> Span -> Maybe Span
forall a. a -> Maybe a
Just Span
a
            Scope
_ -> Maybe Span
forall a. Maybe a
Nothing
          toBind :: HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
toBind (PrefixCon [Void]
ts [GenLocated SrcSpanAnnN (IdGhcP p)]
args) = Bool
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a. HasCallStack => Bool -> a -> a
assert ([Void] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Void]
ts) (HsConDetails
   Void
   (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
   [PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ [Void]
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [Void]
ts ([Context (GenLocated SrcSpanAnnN (IdGhcP p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnN (IdGhcP p)
 -> Context (GenLocated SrcSpanAnnN (IdGhcP p)))
-> [GenLocated SrcSpanAnnN (IdGhcP p)]
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [GenLocated SrcSpanAnnN (IdGhcP p)]
args
          toBind (InfixCon GenLocated SrcSpanAnnN (IdGhcP p)
a GenLocated SrcSpanAnnN (IdGhcP p)
b) = Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use GenLocated SrcSpanAnnN (IdGhcP p)
a) (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use GenLocated SrcSpanAnnN (IdGhcP p)
b)
          toBind (RecCon [RecordPatSynField (GhcPass p)]
r) = [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon ([PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ (RecordPatSynField (GhcPass p)
 -> PatSynFieldContext (RecordPatSynField (GhcPass p)))
-> [RecordPatSynField (GhcPass p)]
-> [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Span
-> RecordPatSynField (GhcPass p)
-> PatSynFieldContext (RecordPatSynField (GhcPass p))
forall a. Maybe Span -> a -> PatSynFieldContext a
PSC Maybe Span
detSpan) [RecordPatSynField (GhcPass p)]
r

instance HiePass p => ToHie (HsPatSynDir (GhcPass p)) where
  toHie :: HsPatSynDir (GhcPass p) -> HieM [HieAST Type]
toHie HsPatSynDir (GhcPass p)
dir = case HsPatSynDir (GhcPass p)
dir of
    ExplicitBidirectional MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg -> MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
mg
    HsPatSynDir (GhcPass p)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( HiePass p
         , Data (body (GhcPass p))
         , AnnoBody p body
         , ToHie (LocatedA (body (GhcPass p)))
         ) => ToHie (LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))) where
  toHie :: LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span Match (GhcPass p) (LocatedA (body (GhcPass p)))
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) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Match (GhcPass p) (LocatedA (body (GhcPass p)))
m SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Match (GhcPass p) (LocatedA (body (GhcPass p)))
m of
    Match{m_ctxt :: forall p body. Match p body -> HsMatchContext (LIdP (NoGhcTc p))
m_ctxt=HsMatchContext (LIdP (NoGhcTc (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) (LocatedA (body (GhcPass p)))
grhss } ->
      [ forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext @p HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
mctx
      , let rhsScope :: Scope
rhsScope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhss
          in [PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
 -> HieM [HieAST Type])
-> [PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
forall a. Maybe a
Nothing Scope
rhsScope Scope
NoScope [LPat (GhcPass p)]
pats
      , GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhss
      ]

toHieHsMatchContext :: forall p. HiePass p => HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
                                           -> HieM [HieAST Type]
toHieHsMatchContext :: forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
ctxt
  = case HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
ctxt of
      FunRhs{mc_fun :: forall fn. HsMatchContext fn -> fn
mc_fun=LIdP (NoGhcTc (GhcPass p))
name} -> Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
MatchBind (LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
get_name LIdP (NoGhcTc (GhcPass p))
name)
      StmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a          -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
_                   -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  where
      -- See a paragraph about Haddock in #20415.
    get_name :: LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
    get_name :: LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
get_name LIdP (NoGhcTc (GhcPass p))
name = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
                      HiePassEv p
HieRn -> LIdP (NoGhcTc (GhcPass p))
LocatedN Name
name
                      HiePassEv p
HieTc -> LIdP (NoGhcTc (GhcPass p))
LocatedN Name
name

toHieHsStmtContext :: forall p. HiePass p => HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
                                          -> HieM [HieAST Type]
toHieHsStmtContext :: forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
ctxt
  = case HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
ctxt of
      PatGuard HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
a      -> forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext @p HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
a
      ParStmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a   -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext  @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      TransStmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext  @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
_               -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => ToHie (PScoped (LocatedA (Pat (GhcPass p)))) where
  toHie :: PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
toHie (PS Maybe Span
rsp Scope
scope Scope
pscope lpat :: LocatedA (Pat (GhcPass p))
lpat@(L SrcSpanAnnA
ospan 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
$ LocatedA (Pat (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (Pat (GhcPass p))
lpat HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Pat (GhcPass p)
opat of
      WildPat XWildPat (GhcPass p)
_ ->
        []
      VarPat XVarPat (GhcPass p)
_ LIdP (GhcPass p)
lname ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
lname
        ]
      LazyPat XLazyPat (GhcPass p)
_ LPat (GhcPass p)
p ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
p
        ]
      AsPat XAsPat (GhcPass p)
_ LIdP (GhcPass p)
lname LPat (GhcPass p)
pat ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope
                                 (Scope -> Scope -> Scope
combineScopes (LocatedA (Pat (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat) Scope
pscope)
                                 Maybe Span
rsp)
                    LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
lname
        , PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ParPat XParPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      BangPat XBangPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ListPat XListPat (GhcPass p)
_ [LPat (GhcPass p)]
pats ->
        [ [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      TuplePat XTuplePat (GhcPass p)
_ [LPat (GhcPass p)]
pats Boxity
_ ->
        [ [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      SumPat XSumPat (GhcPass p)
_ LPat (GhcPass p)
pat TypeIndex
_ TypeIndex
_ ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ConPat {pat_con :: forall p. Pat p -> XRec p (ConLikeP p)
pat_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = HsConPatDetails (GhcPass p)
dets, pat_con_ext :: forall p. Pat p -> XConPat p
pat_con_ext = XConPat (GhcPass p)
ext} ->
        case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieTc ->
            [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (LocatedN Name -> Context (LocatedN Name))
-> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ (ConLike -> Name)
-> GenLocated SrcSpanAnnN ConLike -> LocatedN Name
forall a b.
(a -> b) -> GenLocated SrcSpanAnnN a -> GenLocated SrcSpanAnnN b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName XRec (GhcPass p) (ConLikeP (GhcPass p))
GenLocated SrcSpanAnnN ConLike
con
            , HsConDetails
  (TScoped (HsTyPat GhcRn))
  (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
  (RContext
     (HsRecFields
        (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (TScoped (HsTyPat GhcRn))
   (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
   (RContext
      (HsRecFields
         (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
 -> HieM [HieAST Type])
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (HsConPatTyArg GhcRn)
  (GenLocated SrcSpanAnnA (Pat GhcTc))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcTc)))
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails (HsConPatTyArg GhcRn) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (HsConPatTyArg GhcRn)
  (GenLocated SrcSpanAnnA (Pat GhcTc))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcTc)))
dets
            , let ev_binds :: TcEvBinds
ev_binds = ConPatTc -> TcEvBinds
cpt_binds XConPat (GhcPass p)
ConPatTc
ext
                  ev_vars :: [Id]
ev_vars = ConPatTc -> [Id]
cpt_dicts XConPat (GhcPass p)
ConPatTc
ext
                  wrap :: HsWrapper
wrap = ConPatTc -> HsWrapper
cpt_wrap XConPat (GhcPass p)
ConPatTc
ext
                  evscope :: Scope
evscope = SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
ospan Scope -> Scope -> Scope
`combineScopes` Scope
scope Scope -> Scope -> Scope
`combineScopes` Scope
pscope
                 in [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
scope Maybe Span
rsp (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan TcEvBinds
ev_binds
                            , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsWrapper
wrap
                            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvPatternBind Scope
evscope Maybe Span
rsp)
                                          (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan) [Id]
ev_vars
                            ]
            ]
          HiePassEv p
HieRn ->
            [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use XRec (GhcPass p) (ConLikeP (GhcPass p))
LocatedN Name
con
            , HsConDetails
  (TScoped (HsTyPat GhcRn))
  (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))
  (RContext
     (HsRecFields
        (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (TScoped (HsTyPat GhcRn))
   (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))
   (RContext
      (HsRecFields
         (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))))
 -> HieM [HieAST Type])
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (HsConPatTyArg GhcRn)
  (GenLocated SrcSpanAnnA (Pat GhcRn))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcRn)))
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails (HsConPatTyArg GhcRn) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (HsConPatTyArg GhcRn)
  (GenLocated SrcSpanAnnA (Pat GhcRn))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcRn)))
dets
            ]
      ViewPat XViewPat (GhcPass p)
_ LHsExpr (GhcPass p)
expr LPat (GhcPass p)
pat ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        , PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      SplicePat XSplicePat (GhcPass p)
_ HsUntypedSplice (GhcPass p)
sp ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice (GhcPass p)
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsUntypedSplice (GhcPass p)
sp
        ]
      LitPat XLitPat (GhcPass p)
_ HsLit (GhcPass p)
_ ->
        []
      NPat XNPat (GhcPass p)
_ (L EpAnn NoEpAnns
loc HsOverLit (GhcPass p)
lit) Maybe (SyntaxExpr (GhcPass p))
_ SyntaxExpr (GhcPass p)
eq ->
        [ GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (EpAnn NoEpAnns -> SrcSpanAnnA
forall a b. (HasLoc a, HasAnnotation b) => a -> b
l2l EpAnn NoEpAnns
loc :: SrcSpanAnnA) HsOverLit (GhcPass p)
lit
        , LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan SyntaxExpr (GhcPass p)
SyntaxExprGhc p
eq)
        ]
      NPlusKPat XNPlusKPat (GhcPass p)
_ LIdP (GhcPass p)
n (L EpAnn NoEpAnns
loc HsOverLit (GhcPass p)
lit) HsOverLit (GhcPass p)
_ SyntaxExpr (GhcPass p)
ord SyntaxExpr (GhcPass p)
_ ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
n
        , GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (EpAnn NoEpAnns -> SrcSpanAnnA
forall a b. (HasLoc a, HasAnnotation b) => a -> b
l2l EpAnn NoEpAnns
loc :: SrcSpanAnnA) HsOverLit (GhcPass p)
lit
        , LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan SyntaxExpr (GhcPass p)
SyntaxExprGhc p
ord)
        ]
      SigPat XSigPat (GhcPass p)
_ LPat (GhcPass p)
pat HsPatSigType (NoGhcTc (GhcPass p))
sig ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc ->
              let cscope :: Scope
cscope = GenLocated SrcSpanAnnA (Pat GhcTc) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat GhcTc)
pat in
                TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> HsPatSigType GhcRn -> TScoped (HsPatSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
cscope, Scope
scope, Scope
pscope])
                           HsPatSigType (NoGhcTc (GhcPass p))
HsPatSigType GhcRn
sig
            HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
      EmbTyPat XEmbTyPat (GhcPass p)
_ HsTyPat (NoGhcTc (GhcPass p))
tp ->
        [ TScoped (HsTyPat GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsTyPat GhcRn) -> HieM [HieAST Type])
-> TScoped (HsTyPat GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> HsTyPat GhcRn -> TScoped (HsTyPat GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
pscope]) HsTyPat (NoGhcTc (GhcPass p))
HsTyPat GhcRn
tp
        ]
      InvisPat XInvisPat (GhcPass p)
_ HsTyPat (NoGhcTc (GhcPass p))
tp ->
        [ TScoped (HsTyPat GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsTyPat GhcRn) -> HieM [HieAST Type])
-> TScoped (HsTyPat GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> HsTyPat GhcRn -> TScoped (HsTyPat GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
pscope]) HsTyPat (NoGhcTc (GhcPass p))
HsTyPat GhcRn
tp
        ]
      XPat XXPat (GhcPass p)
e ->
        case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieRn -> case XXPat (GhcPass p)
e of
            HsPatExpanded Pat GhcRn
_ Pat GhcRn
p -> [ PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat GhcRn))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcRn)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcRn))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (SrcSpanAnnA -> Pat GhcRn -> GenLocated SrcSpanAnnA (Pat GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat GhcRn
p) ]
          HiePassEv p
HieTc -> case XXPat (GhcPass p)
e of
            CoPat HsWrapper
wrap Pat GhcTc
pat Type
_ ->
              [ LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsWrapper
wrap
              , PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (GenLocated SrcSpanAnnA (Pat GhcTc)
 -> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a b. (a -> b) -> a -> b
$ (SrcSpanAnnA -> Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat GhcTc
pat)
              ]
            ExpansionPat Pat GhcRn
_ Pat GhcTc
p -> [ PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (SrcSpanAnnA -> Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat GhcTc
p) ]
    where
      contextify :: a ~ LPat (GhcPass p) => HsConDetails (HsConPatTyArg GhcRn) a (HsRecFields (GhcPass p) a)
                 -> HsConDetails (TScoped (HsTyPat GhcRn)) (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
      contextify :: forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails (HsConPatTyArg GhcRn) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify (PrefixCon [HsConPatTyArg GhcRn]
tyargs [a]
args) =
        [TScoped (HsTyPat GhcRn)]
-> [PScoped a]
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon (Scope
-> Scope -> [HsConPatTyArg GhcRn] -> [TScoped (HsTyPat GhcRn)]
forall (a :: Pass).
Scope
-> Scope
-> [HsConPatTyArg (GhcPass a)]
-> [TScoped (HsTyPat (GhcPass a))]
taScopes Scope
scope Scope
argscope [HsConPatTyArg GhcRn]
tyargs)
                  (Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [a]
[LPat (GhcPass p)]
args)
        where argscope :: Scope
argscope = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
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
$ (a -> Scope) -> [a] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map a -> Scope
forall a. HasLoc a => a -> Scope
mkScope [a]
args
      contextify (InfixCon a
a a
b) = PScoped a
-> PScoped a
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon PScoped a
PScoped (LPat (GhcPass p))
a' PScoped a
PScoped (LPat (GhcPass p))
b'
        where [PScoped (LPat (GhcPass p))
a', PScoped (LPat (GhcPass p))
b'] = Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [a
LPat (GhcPass p)
a,a
LPat (GhcPass p)
b]
      contextify (RecCon HsRecFields (GhcPass p) a
r) = RContext (HsRecFields (GhcPass p) (PScoped a))
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon (RContext (HsRecFields (GhcPass p) (PScoped a))
 -> HsConDetails
      (TScoped (HsTyPat GhcRn))
      (PScoped a)
      (RContext (HsRecFields (GhcPass p) (PScoped a))))
-> RContext (HsRecFields (GhcPass p) (PScoped a))
-> HsConDetails
     (TScoped (HsTyPat GhcRn))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldMatch (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
 -> RContext
      (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
contextify_rec HsRecFields (GhcPass p) a
HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
r
      contextify_rec :: HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
contextify_rec (HsRecFields [LHsRecField (GhcPass p) (LocatedA (Pat (GhcPass p)))]
fds Maybe (XRec (GhcPass p) RecFieldsDotDot)
a) = [LHsRecField (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))]
-> Maybe (XRec (GhcPass p) RecFieldsDotDot)
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
forall p arg.
[LHsRecField p arg]
-> Maybe (XRec p RecFieldsDotDot) -> HsRecFields p arg
HsRecFields ((RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))
 -> LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (PScoped (LocatedA (Pat (GhcPass p))))))
-> [RScoped
      (LocatedA
         (HsFieldBind
            (XRec (GhcPass p) (FieldOcc (GhcPass p)))
            (LocatedA (Pat (GhcPass p)))))]
-> [LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (PScoped (LocatedA (Pat (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map RScoped
  (LocatedA
     (HsFieldBind
        (XRec (GhcPass p) (FieldOcc (GhcPass p)))
        (LocatedA (Pat (GhcPass p)))))
-> LocatedA
     (HsFieldBind
        (XRec (GhcPass p) (FieldOcc (GhcPass p)))
        (PScoped (LocatedA (Pat (GhcPass p)))))
forall id a1.
RScoped (LocatedA (HsFieldBind id a1))
-> LocatedA (HsFieldBind id (PScoped a1))
go [RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))]
scoped_fds) Maybe (XRec (GhcPass p) RecFieldsDotDot)
a
        where
          go :: RScoped (LocatedA (HsFieldBind id a1))
                      -> LocatedA (HsFieldBind id (PScoped a1)) -- AZ
          go :: forall id a1.
RScoped (LocatedA (HsFieldBind id a1))
-> LocatedA (HsFieldBind id (PScoped a1))
go (RS Scope
fscope (L SrcSpanAnnA
spn (HsFieldBind XHsFieldBind id
x id
lbl a1
pat Bool
pun))) =
            SrcSpanAnnA
-> HsFieldBind id (PScoped a1)
-> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
spn (HsFieldBind id (PScoped a1)
 -> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1)))
-> HsFieldBind id (PScoped a1)
-> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1))
forall a b. (a -> b) -> a -> b
$ XHsFieldBind id
-> id -> PScoped a1 -> Bool -> HsFieldBind id (PScoped a1)
forall lhs rhs.
XHsFieldBind lhs -> lhs -> rhs -> Bool -> HsFieldBind lhs rhs
HsFieldBind XHsFieldBind id
x id
lbl (Maybe Span -> Scope -> Scope -> a1 -> PScoped a1
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
fscope a1
pat) Bool
pun
          scoped_fds :: [RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))]
scoped_fds = Scope
-> [LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p))))]
-> [RScoped
      (LocatedA
         (HsFieldBind
            (XRec (GhcPass p) (FieldOcc (GhcPass p)))
            (LocatedA (Pat (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
pscope [LHsRecField (GhcPass p) (LocatedA (Pat (GhcPass p)))]
[LocatedA
   (HsFieldBind
      (XRec (GhcPass p) (FieldOcc (GhcPass p)))
      (LocatedA (Pat (GhcPass p))))]
fds

toHieSyntax :: forall p. HiePass p => LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax :: forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax LocatedA (SyntaxExpr (GhcPass p))
s = (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (NodeOrigin -> NodeOrigin -> NodeOrigin
forall a b. a -> b -> a
const NodeOrigin
GeneratedInfo) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
  HiePassEv p
HieRn -> LocatedA SyntaxExprRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (SyntaxExpr (GhcPass p))
LocatedA SyntaxExprRn
s
  HiePassEv p
HieTc -> LocatedA SyntaxExprTc -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (SyntaxExpr (GhcPass p))
LocatedA SyntaxExprTc
s

instance ToHie (LocatedA SyntaxExprRn) where
  toHie :: LocatedA SyntaxExprRn -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
mspan (SyntaxExprRn HsExpr GhcRn
expr)) = LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsExpr GhcRn -> LocatedA (HsExpr GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcRn
expr)
  toHie (L SrcSpanAnnA
_ SyntaxExprRn
NoSyntaxExprRn) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA SyntaxExprTc) where
  toHie :: LocatedA SyntaxExprTc -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
mspan (SyntaxExprTc HsExpr GhcTc
expr [HsWrapper]
w1 HsWrapper
w2)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
expr)
      , (HsWrapper -> HieM [HieAST Type])
-> [HsWrapper] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> (HsWrapper -> LocatedA HsWrapper)
-> HsWrapper
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan) [HsWrapper]
w1
      , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsWrapper
w2)
      ]
  toHie (L SrcSpanAnnA
_ SyntaxExprTc
NoSyntaxExprTc) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (TScoped (HsPatSigType GhcRn)) where
  toHie :: TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsPS (HsPSRn [Name]
wcs [Name]
tvs) body :: LHsType GhcRn
body@(L SrcSpanAnnA
span HsType GhcRn
_))) = [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 Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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 (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) TyVarScope
sc) ([Name]
wcs[Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++[Name]
tvs)
      , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body
      ]
  -- See Note [Scoping Rules for SigPat]

instance ToHie (TScoped (HsTyPat GhcRn)) where
  toHie :: TScoped (HsTyPat GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsTP (HsTPRn [Name]
wcs [Name]
imp_tvs [Name]
exp_tvs) body :: LHsType GhcRn
body@(L SrcSpanAnnA
span HsType GhcRn
_))) = [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 Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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 (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) TyVarScope
sc) ([Name]
wcs [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
imp_tvs [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
exp_tvs)
      , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body
      ]

instance ( ToHie (LocatedA (body (GhcPass p)))
         , HiePass p
         , AnnoBody p body
         ) => ToHie (GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))) where
  toHie :: GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
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 (GhcPass p) (LocatedA (body (GhcPass p)))
grhs of
    GRHSs XCGRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
_ [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
grhss HsLocalBinds (GhcPass p)
binds ->
     [ [GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
[GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
grhss
     , RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhs) HsLocalBinds (GhcPass p)
binds
     ]

instance ( ToHie (LocatedA (body (GhcPass p)))
         , HiePass p
         , AnnoBody p body
         ) => ToHie (LocatedAn NoEpAnns (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))) where
  toHie :: LocatedAn NoEpAnns (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
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 (GhcPass p) (LocatedA (body (GhcPass p)))
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
g EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
g of
    GRHS XCGRHS (GhcPass p) (LocatedA (body (GhcPass p)))
_ [GuardLStmt (GhcPass p)]
guards LocatedA (body (GhcPass p))
body ->
      [ [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes (LocatedA (body (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LocatedA (body (GhcPass p))
body) [GuardLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
guards
      , LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
      ]

{-
Note [Source locations for implicit function calls]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While calls to e.g. 'fromString' with -XOverloadedStrings do not actually
appear in the source code, giving their HsWrapper the location of the
overloaded bit of syntax that triggered them is useful for assigning
their type class evidence uses to the right location in the HIE AST.
Without this, we only get type class instance information under the
expected top-level node if the type had to be inferred. (#23540)

We currently handle the following constructors with this in mind,
all largely in the renamer as their locations are normally inherited by
the typechecker:

  * HsOverLit, where we assign the SrcSpan of the overloaded literal
    to ol_from_fun.
  * HsDo, where we give the SrcSpan of the entire do block to each
    ApplicativeStmt.
  * Expanded (via ExpandedThingRn) ExplicitList{}, where we give the SrcSpan of the original
    list expression to the 'fromListN' call.

In order for the implicit function calls to not be confused for actual
occurrences of functions in the source code, most of this extra information
is put under 'GeneratedInfo'.
-}

whenPostTc :: forall p t m. (HiePass p, Applicative t, Monoid m) => ((p ~ 'Typechecked) => t m) -> t m
whenPostTc :: forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc (p ~ 'Typechecked) => t m
a = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
  HiePassEv p
HieTc -> t m
(p ~ 'Typechecked) => t m
a
  HiePassEv p
HieRn -> m -> t m
forall a. a -> t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure m
forall a. Monoid a => a
mempty

-- | Helper function for a common pattern where we are only interested in
-- implicit evidence information: runs only post-typecheck and marks the
-- current 'NodeOrigin' as generated.
whenPostTcGen :: forall p. HiePass p => ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen :: forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen (p ~ 'Typechecked) => HieM [HieAST Type]
a = (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (NodeOrigin -> NodeOrigin -> NodeOrigin
forall a b. a -> b -> a
const NodeOrigin
GeneratedInfo) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc @p HieM [HieAST Type]
(p ~ 'Typechecked) => HieM [HieAST Type]
a

instance HiePass p => ToHie (LocatedA (HsOverLit (GhcPass p))) where
  toHie :: LocatedA (HsOverLit (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span (OverLit XOverLit (GhcPass p)
x OverLitVal
_)) = forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> 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
$ case XOverLit (GhcPass p)
x of
      OverLitTc Bool
_ HsExpr GhcTc
witness Type
_ ->
        [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsExpr GhcTc
witness)
        ]
      -- See Note [Source locations for implicit function calls]

instance HiePass p => ToHie (LocatedA (HsExpr (GhcPass p))) where
  toHie :: LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
toHie e :: LocatedA (HsExpr (GhcPass p))
e@(L SrcSpanAnnA
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
$ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (HsExpr (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 SrcSpanAnnN
_ IdGhcP p
var) ->
        [ Context (GenLocated SrcSpanAnnA (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA (IdGhcP p)
-> Context (GenLocated SrcSpanAnnA (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (SrcSpanAnnA -> IdGhcP p -> GenLocated SrcSpanAnnA (IdGhcP p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan IdGhcP p
var)
             -- Patch up var location since typechecker removes it
        ]
      HsUnboundVar XUnboundVar (GhcPass p)
_ RdrName
_ -> []  -- there is an unbound name here, but that causes trouble
      HsRecSel XRecSel (GhcPass p)
_ FieldOcc (GhcPass p)
fld ->
        [ RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p)))
 -> HieM [HieAST Type])
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe Span
-> GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p)))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe Span
forall a. Maybe a
Nothing (SrcSpanAnnA
-> FieldOcc (GhcPass p)
-> GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan FieldOcc (GhcPass p)
fld)
        ]
      HsOverLabel {} -> []
      HsIPVar XIPVar (GhcPass p)
_ HsIPName
_ -> []
      HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
o ->
        [ GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsOverLit (GhcPass p)
o)
        ]
      HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
_ -> []
      HsLam XLam (GhcPass p)
_ HsLamVariant
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
mg
        ]
      HsApp XApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      HsAppType XAppTypeE (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsWcType (NoGhcTc (GhcPass p))
sig ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
sig
        ]
      OpApp XOpApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
c
        ]
      NegApp XNegApp (GhcPass p)
_ LHsExpr (GhcPass p)
a SyntaxExpr (GhcPass p)
_ ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        ]
      HsPar XPar (GhcPass p)
_ LHsExpr (GhcPass p)
a ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        ]
      SectionL XSectionL (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      SectionR XSectionR (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      ExplicitTuple XExplicitTuple (GhcPass p)
_ [HsTupArg (GhcPass p)]
args Boxity
_ ->
        [ [HsTupArg (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsTupArg (GhcPass p)]
args
        ]
      ExplicitSum XExplicitSum (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsCase XCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
matches
        ]
      HsIf XIf (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
c
        ]
      HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss ->
        [ [GenLocated
   (EpAnn NoEpAnns)
   (GRHS (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
[GenLocated
   (EpAnn NoEpAnns)
   (GRHS (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
grhss
        ]
      HsLet XLet (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsExpr (GhcPass p)
expr ->
        [ RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LocatedA (HsExpr (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr) HsLocalBinds (GhcPass p)
binds
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsDo XDo (GhcPass p)
_ HsDoFlavour
_ (L SrcSpanAnnL
ispan [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
ispan)
        , [RScoped
   (LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
stmts
        ]
      ExplicitList XExplicitList (GhcPass p)
_ [LHsExpr (GhcPass p)]
exprs ->
        [ [LocatedA (HsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsExpr (GhcPass p)]
[LocatedA (HsExpr (GhcPass p))]
exprs
        ]
      RecordCon { rcon_con :: forall p. HsExpr p -> XRec p (ConLikeP p)
rcon_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds (GhcPass p)
binds} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (LocatedN Name -> Context (LocatedN Name))
-> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ LocatedN Name
con_name
        , RContext (HsRecFields (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RContext (HsRecFields (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
 -> HieM [HieAST Type])
-> RContext
     (HsRecFields (GhcPass p) (LocatedA (HsExpr (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
        ]
        where
          con_name :: LocatedN Name
          con_name :: LocatedN Name
con_name = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of       -- Like ConPat
                       HiePassEv p
HieRn -> XRec (GhcPass p) (ConLikeP (GhcPass p))
LocatedN Name
con
                       HiePassEv p
HieTc -> (ConLike -> Name)
-> GenLocated SrcSpanAnnN ConLike -> LocatedN Name
forall a b.
(a -> b) -> GenLocated SrcSpanAnnN a -> GenLocated SrcSpanAnnN b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName XRec (GhcPass p) (ConLikeP (GhcPass p))
GenLocated SrcSpanAnnN ConLike
con
      RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr
                , rupd_flds :: forall p. HsExpr p -> LHsRecUpdFields p
rupd_flds = RegularRecUpdFields { recUpdFields :: forall p. LHsRecUpdFields p -> [LHsRecUpdField p p]
recUpdFields = [LHsRecUpdField (GhcPass p) (GhcPass p)]
upds } }->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , [RContext
   (GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
         (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (GenLocated
       SrcSpanAnnA
       (HsFieldBind
          (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
          (LocatedA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
            (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
      (LocatedA (HsExpr (GhcPass p))))
 -> RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
            (LocatedA (HsExpr (GhcPass p))))))
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
         (LocatedA (HsExpr (GhcPass p))))]
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
            (LocatedA (HsExpr (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> GenLocated
     SrcSpanAnnA
     (HsFieldBind
        (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
        (LocatedA (HsExpr (GhcPass p))))
-> RContext
     (GenLocated
        SrcSpanAnnA
        (HsFieldBind
           (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
           (LocatedA (HsExpr (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [LHsRecUpdField (GhcPass p) (GhcPass p)]
[GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (AmbiguousFieldOcc (GhcPass p)))
      (LocatedA (HsExpr (GhcPass p))))]
upds
        ]
      RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr
                , rupd_flds :: forall p. HsExpr p -> LHsRecUpdFields p
rupd_flds = OverloadedRecUpdFields {} }->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      ExprWithTySig XExprWithTySig (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [LocatedA (HsExpr (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr]) LHsSigWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
sig
        ]
      ArithSeq XArithSeq (GhcPass p)
enum 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
        , forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan XArithSeq (GhcPass p)
HsExpr GhcTc
enum)
        ]
      HsPragE XPragE (GhcPass p)
_ HsPragE (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat LHsCmdTop (GhcPass p)
cmdtop ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing (GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsCmdTop (GhcPass p)
GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
cmdtop) Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmdTop (GhcPass p)
GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
cmdtop
        ]
      HsStatic XStatic (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsEmbTy XEmbTy (GhcPass p)
_ LHsWcType (NoGhcTc (GhcPass p))
ty ->
        [ TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
ty
        ]
      HsTypedBracket XTypedBracket (GhcPass p)
xbracket LHsExpr (GhcPass p)
b -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
          [ LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr GhcRn)
b
          ]
        HiePassEv p
HieTc | HsBracketTc HsQuote GhcRn
_ Type
_ Maybe QuoteWrapper
_ [PendingTcSplice]
p <- XTypedBracket (GhcPass p)
xbracket ->
          [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr GhcTc)
b
          , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
          ]
      HsUntypedBracket XUntypedBracket (GhcPass p)
xbracket HsQuote (GhcPass p)
b -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
            [ HsQuote (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsQuote (GhcPass p)
b
            , [PendingRnSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingRnSplice]
XUntypedBracket (GhcPass p)
xbracket
            ]
        HiePassEv p
HieTc | HsBracketTc HsQuote GhcRn
q Type
_ Maybe QuoteWrapper
_ [PendingTcSplice]
p <- XUntypedBracket (GhcPass p)
xbracket ->
          [ HsQuote GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsQuote GhcRn
q
          , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
          ]
      HsTypedSplice XTypedSplice (GhcPass p)
_ LHsExpr (GhcPass p)
x ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
x
        ]
      HsUntypedSplice XUntypedSplice (GhcPass p)
_ HsUntypedSplice (GhcPass p)
x ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice (GhcPass p)
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsUntypedSplice (GhcPass p)
x
        ]
      HsGetField {} -> []
      HsProjection {} -> []
      XExpr XXExpr (GhcPass p)
x
        | HiePassEv p
HieTc <- forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p
        -> case XXExpr (GhcPass p)
x of
             WrapExpr (HsWrap HsWrapper
w HsExpr GhcTc
a)
               -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
a
                  , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsWrapper
w) ]
             ExpandedThingTc HsThingRn
_ HsExpr GhcTc
e
               -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
e) ]
             ConLikeTc ConLike
con [Id]
_ [Scaled Type]
_
               -> [ Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Name
-> Context (GenLocated SrcSpanAnnA Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (GenLocated SrcSpanAnnA Name
 -> Context (GenLocated SrcSpanAnnA Name))
-> GenLocated SrcSpanAnnA Name
-> Context (GenLocated SrcSpanAnnA Name)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Name -> GenLocated SrcSpanAnnA Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan (Name -> GenLocated SrcSpanAnnA Name)
-> Name -> GenLocated SrcSpanAnnA Name
forall a b. (a -> b) -> a -> b
$ ConLike -> Name
conLikeName ConLike
con ]
             HsTick CoreTickish
_ LHsExpr GhcTc
expr
               -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
                  ]
             HsBinTick TypeIndex
_ TypeIndex
_ LHsExpr GhcTc
expr
               -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
                  ]
        | Bool
otherwise -> []

-- NOTE: no longer have the location
instance HiePass p => ToHie (HsTupArg (GhcPass p)) where
  toHie :: HsTupArg (GhcPass p) -> HieM [HieAST Type]
toHie 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
$ case HsTupArg (GhcPass p)
arg of
    Present XPresent (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
      [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
      ]
    Missing XMissing (GhcPass p)
_ -> []

instance ( ToHie (LocatedA (body (GhcPass p)))
         , AnnoBody p body
         , HiePass p
         ) => ToHie (RScoped (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))) where
  toHie :: RScoped (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
-> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpanAnnA
span Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
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
$ HieM [HieAST Type]
node HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt of
      LastStmt XLastStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ LocatedA (body (GhcPass p))
body Maybe Bool
_ SyntaxExpr (GhcPass p)
_ ->
        [ LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        ]
      BindStmt XBindStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
monad LPat (GhcPass p)
pat LocatedA (body (GhcPass p))
body ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ LocatedA (body (GhcPass p)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LocatedA (body (GhcPass p))
body) Scope
scope Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        , forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type])
-> LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> SyntaxExprGhc 'Typechecked
-> GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (XBindStmtTc -> SyntaxExpr GhcTc
xbstc_bindOp XBindStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
XBindStmtTc
monad)
        ]
      ApplicativeStmt XApplicativeStmt
  (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
stmts Maybe (SyntaxExpr (GhcPass p))
_ ->
        [ ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
 -> HieM [HieAST Type])
-> [(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f 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])
-> ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
    -> RScoped (ApplicativeArg (GhcPass p)))
-> (SyntaxExprGhc 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)))
-> ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
    -> ApplicativeArg (GhcPass p))
-> (SyntaxExprGhc p, ApplicativeArg (GhcPass p))
-> RScoped (ApplicativeArg (GhcPass p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SyntaxExprGhc p, ApplicativeArg (GhcPass p))
-> ApplicativeArg (GhcPass p)
forall a b. (a, b) -> b
snd) [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
[(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
stmts
        , let applicative_or_functor :: [SyntaxExprGhc p]
applicative_or_functor = ((SyntaxExprGhc p, ApplicativeArg (GhcPass p)) -> SyntaxExprGhc p)
-> [(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
-> [SyntaxExprGhc p]
forall a b. (a -> b) -> [a] -> [b]
map (SyntaxExprGhc p, ApplicativeArg (GhcPass p)) -> SyntaxExprGhc p
forall a b. (a, b) -> a
fst [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
[(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
stmts
           in forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (SyntaxExprGhc p -> HieM [HieAST Type])
-> [SyntaxExprGhc p] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
GenLocated SrcSpanAnnA (SyntaxExprGhc p) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (GenLocated SrcSpanAnnA (SyntaxExprGhc p) -> HieM [HieAST Type])
-> (SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p))
-> SyntaxExprGhc p
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [SyntaxExprGhc p]
applicative_or_functor
        ]
      BodyStmt XBodyStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ LocatedA (body (GhcPass p))
body SyntaxExpr (GhcPass p)
monad SyntaxExpr (GhcPass p)
alternative ->
        [ LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        , forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            (SyntaxExprGhc 'Typechecked -> HieM [HieAST Type])
-> [SyntaxExprGhc 'Typechecked] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
-> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
 -> HieM [HieAST Type])
-> (SyntaxExprGhc 'Typechecked
    -> GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked))
-> SyntaxExprGhc 'Typechecked
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA
-> SyntaxExprGhc 'Typechecked
-> GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [SyntaxExpr (GhcPass p)
SyntaxExprGhc 'Typechecked
monad, SyntaxExpr (GhcPass p)
SyntaxExprGhc 'Typechecked
alternative]
        ]
      LetStmt XLetStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ HsLocalBindsLR (GhcPass p) (GhcPass p)
binds ->
        [ RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBindsLR (GhcPass p) (GhcPass p)
-> RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope HsLocalBindsLR (GhcPass p) (GhcPass p)
binds
        ]
      ParStmt XParStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ [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 :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (\(ParStmtBlock XParStmtBlock (GhcPass p) (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts [IdP (GhcPass p)]
_ SyntaxExpr (GhcPass p)
_) ->
                          [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (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
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
scope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
using
        , Maybe (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsExpr (GhcPass p))
Maybe (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
by
        ]
      RecStmt {recS_stmts :: forall idL idR body.
StmtLR idL idR body -> XRec idR [LStmtLR idL idR body]
recS_stmts = L SrcSpanAnnL
_ [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
stmts} ->
        [ [RScoped
   (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
 -> RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))))
-> [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
-> [RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
-> RScoped
     (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
 -> RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))))
-> Scope
-> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
-> RScoped
     (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes Scope
scope (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span))) [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
stmts
        ]
    where
      node :: HieM [HieAST Type]
node = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt SrcSpanAnnA
span
        HiePassEv p
HieRn -> Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt SrcSpanAnnA
span

instance HiePass p => ToHie (RScoped (HsLocalBinds (GhcPass p))) where
  toHie :: RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
scope HsLocalBinds (GhcPass p)
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 (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsLocalBinds (GhcPass p)
binds (HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
binds) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsLocalBinds (GhcPass p)
binds of
      EmptyLocalBinds XEmptyLocalBinds (GhcPass p) (GhcPass p)
_ -> []
      HsIPBinds XHsIPBinds (GhcPass p) (GhcPass p)
_ HsIPBinds (GhcPass p)
ipbinds -> case HsIPBinds (GhcPass p)
ipbinds of
        IPBinds XIPBinds (GhcPass p)
evbinds [LIPBind (GhcPass p)]
xs -> let sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ HsLocalBinds (GhcPass p) -> Scope
forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds HsLocalBinds (GhcPass p)
binds
                                  sp :: SrcSpanAnnA
                                  sp :: SrcSpanAnnA
sp = SrcSpan -> SrcSpanAnnA
forall e. HasAnnotation e => SrcSpan -> e
noAnnSrcSpan (SrcSpan -> SrcSpanAnnA) -> SrcSpan -> SrcSpanAnnA
forall a b. (a -> b) -> a -> b
$ HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
binds in
          [
            case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
              HiePassEv p
HieTc -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
sc (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
sp) (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp XIPBinds (GhcPass p)
TcEvBinds
evbinds
              HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          , [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
 -> HieM [HieAST Type])
-> [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (IPBind (GhcPass p))
 -> RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p))))
-> [GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
-> [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> GenLocated SrcSpanAnnA (IPBind (GhcPass p))
-> RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS Scope
sc) [LIPBind (GhcPass p)]
[GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
xs
          ]
      HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ HsValBindsLR (GhcPass p) (GhcPass p)
valBinds ->
        [
          RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsValBindsLR (GhcPass p) (GhcPass p)
-> RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (Scope -> Scope -> Scope
combineScopes Scope
scope (HsLocalBinds (GhcPass p) -> Scope
forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds HsLocalBinds (GhcPass p)
binds))
                      HsValBindsLR (GhcPass p) (GhcPass p)
valBinds
        ]

scopeHsLocaLBinds :: HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds :: forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds (HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ (ValBinds XValBinds (GhcPass p) (GhcPass p)
_ LHsBindsLR (GhcPass p) (GhcPass p)
bs [LSig (GhcPass p)]
sigs))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope]
bsScope [Scope] -> [Scope] -> [Scope]
forall a. [a] -> [a] -> [a]
++ [Scope]
sigsScope)
  where
    bsScope :: [Scope]
    bsScope :: [Scope]
bsScope = (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> Scope)
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
    -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) ([GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
 -> [Scope])
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> a -> b
$ Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall a. Bag a -> [a]
bagToList LHsBindsLR (GhcPass p) (GhcPass p)
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
bs
    sigsScope :: [Scope]
    sigsScope :: [Scope]
sigsScope = (GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> Scope)
-> [GenLocated SrcSpanAnnA (Sig (GhcPass p))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> SrcSpan)
-> GenLocated SrcSpanAnnA (Sig (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs
scopeHsLocaLBinds (HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ (XValBindsLR (NValBinds [(RecFlag, LHsBindsLR (GhcPass p) (GhcPass p))]
bs [LSig GhcRn]
sigs)))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope]
bsScope [Scope] -> [Scope] -> [Scope]
forall a. [a] -> [a] -> [a]
++ [Scope]
sigsScope)
  where
    bsScope :: [Scope]
    bsScope :: [Scope]
bsScope = (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> Scope)
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
    -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) ([GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
 -> [Scope])
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> a -> b
$ ((RecFlag,
  Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
 -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> [(RecFlag,
     Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))]
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall a. Bag a -> [a]
bagToList (Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
 -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> ((RecFlag,
     Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
    -> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> (RecFlag,
    Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag,
 Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a b. (a, b) -> b
snd) [(RecFlag, LHsBindsLR (GhcPass p) (GhcPass p))]
[(RecFlag,
  Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))]
bs
    sigsScope :: [Scope]
    sigsScope :: [Scope]
sigsScope = (GenLocated SrcSpanAnnA (Sig GhcRn) -> Scope)
-> [GenLocated SrcSpanAnnA (Sig GhcRn)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated SrcSpanAnnA (Sig GhcRn) -> SrcSpan)
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Sig GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LSig GhcRn]
[GenLocated SrcSpanAnnA (Sig GhcRn)]
sigs

scopeHsLocaLBinds (HsIPBinds XHsIPBinds (GhcPass p) (GhcPass p)
_ (IPBinds XIPBinds (GhcPass p)
_ [LIPBind (GhcPass p)]
bs))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ((GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> Scope)
-> [GenLocated SrcSpanAnnA (IPBind (GhcPass p))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (IPBind (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) [LIPBind (GhcPass p)]
[GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
bs)
scopeHsLocaLBinds (EmptyLocalBinds XEmptyLocalBinds (GhcPass p) (GhcPass p)
_) = Scope
NoScope

instance HiePass p => ToHie (RScoped (LocatedA (IPBind (GhcPass p)))) where
  toHie :: RScoped (LocatedA (IPBind (GhcPass p))) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpanAnnA
sp bind :: IPBind (GhcPass p)
bind@(IPBind XCIPBind (GhcPass p)
v XRec (GhcPass p) HsIPName
_ LHsExpr (GhcPass p)
expr))) = [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
$ IPBind (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA IPBind (GhcPass p)
bind SrcSpanAnnA
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
    HiePassEv p
HieRn -> [LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr GhcRn)
expr]
    HiePassEv p
HieTc -> [ Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvImplicitBind Scope
scope (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
sp))
                       (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp XCIPBind (GhcPass p)
Id
v
             , GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
             ]

instance HiePass p => ToHie (RScoped (HsValBindsLR (GhcPass p) (GhcPass p))) where
  toHie :: RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
toHie (RS Scope
sc HsValBindsLR (GhcPass p) (GhcPass p)
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 (GhcPass p) (GhcPass p)
v of
    ValBinds XValBinds (GhcPass p) (GhcPass p)
_ LHsBindsLR (GhcPass p) (GhcPass p)
binds [LSig (GhcPass p)]
sigs ->
      [ Bag
  (BindContext
     (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag
   (BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
 -> HieM [HieAST Type])
-> Bag
     (BindContext
        (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> Bag
     (BindContext
        (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
forall a b. (a -> b) -> Bag a -> Bag b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext
     (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) LHsBindsLR (GhcPass p) (GhcPass p)
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
binds
      , [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig (GhcPass p))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p))))
-> [GenLocated SrcSpanAnnA (Sig (GhcPass p))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass p))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe Span -> SigInfo
SI SigType
BindSig Maybe Span
forall a. Maybe a
Nothing)) [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs
      ]
    XValBindsLR XXValBindsLR (GhcPass p) (GhcPass p)
x -> [ RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> NHsValBindsLR (GhcPass p) -> RScoped (NHsValBindsLR (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
sc XXValBindsLR (GhcPass p) (GhcPass p)
NHsValBindsLR (GhcPass p)
x ]

instance HiePass p => ToHie (RScoped (NHsValBindsLR (GhcPass p))) where
  toHie :: RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
sc (NValBinds [(RecFlag, LHsBinds (GhcPass p))]
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
   (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag,
  Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
 -> [BindContext
       (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))])
-> [(RecFlag,
     Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext
     (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
 -> [BindContext
       (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))])
-> ((RecFlag,
     Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
    -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> (RecFlag,
    Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall a. Bag a -> [a]
bagToList (Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
 -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> ((RecFlag,
     Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
    -> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> (RecFlag,
    Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag,
 Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a b. (a, b) -> b
snd) [(RecFlag, LHsBinds (GhcPass p))]
[(RecFlag,
  Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))]
binds)
    , [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig GhcRn)
 -> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn)))
-> [GenLocated SrcSpanAnnA (Sig GhcRn)]
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe Span -> SigInfo
SI SigType
BindSig Maybe Span
forall a. Maybe a
Nothing)) [LSig GhcRn]
[GenLocated SrcSpanAnnA (Sig GhcRn)]
sigs
    ]

instance ( ToHie arg , HasLoc arg , Data arg
         , HiePass p ) => ToHie (RContext (HsRecFields (GhcPass p) arg)) where
  toHie :: RContext (HsRecFields (GhcPass p) arg) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (HsRecFields [LHsRecField (GhcPass p) arg]
fields Maybe (XRec (GhcPass p) RecFieldsDotDot)
_)) = [RContext
   (GenLocated
      SrcSpanAnnA
      (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (GenLocated
       SrcSpanAnnA
       (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
 -> HieM [HieAST Type])
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)
 -> RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)))
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)]
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> GenLocated
     SrcSpanAnnA
     (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)
-> RContext
     (GenLocated
        SrcSpanAnnA
        (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
c) [LHsRecField (GhcPass p) arg]
[GenLocated
   SrcSpanAnnA
   (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)]
fields

instance ( ToHie (RFContext label)
         , ToHie arg, HasLoc arg, Data arg
         , Data label
         ) => ToHie (RContext (LocatedA (HsFieldBind label arg))) where
  toHie :: RContext (LocatedA (HsFieldBind label arg)) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (L SrcSpanAnnA
span HsFieldBind 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
$ HsFieldBind label arg -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsFieldBind label arg
recfld (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsFieldBind label arg
recfld of
    HsFieldBind XHsFieldBind label
_ label
label arg
expr Bool
_ ->
      [ RFContext label -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext label -> HieM [HieAST Type])
-> RFContext label -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext -> Maybe Span -> label -> RFContext label
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
c (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ arg -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc arg
expr) label
label
      , arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
expr
      ]

instance HiePass p => ToHie (RFContext (LocatedA (FieldOcc (GhcPass p)))) where
  toHie :: RFContext (LocatedA (FieldOcc (GhcPass p))) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpanAnnA
nspan FieldOcc (GhcPass p)
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 (GhcPass p)
f of
    FieldOcc XCFieldOcc (GhcPass p)
fld XRec (GhcPass p) RdrName
_ ->
      case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn -> [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 Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) XCFieldOcc (GhcPass p)
Name
fld)]
        HiePassEv p
HieTc -> [Context (Located Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Id) -> HieM [HieAST Type])
-> Context (Located Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Id -> Context (Located Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> Located Id
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) XCFieldOcc (GhcPass p)
Id
fld)]

instance HiePass p => ToHie (RFContext (LocatedA (AmbiguousFieldOcc (GhcPass p)))) where

  toHie :: RFContext (LocatedA (AmbiguousFieldOcc (GhcPass p)))
-> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpanAnnA
nspan AmbiguousFieldOcc (GhcPass p)
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 (GhcPass p)
afo of
    Unambiguous XUnambiguous (GhcPass p)
fld XRec (GhcPass p) RdrName
_ ->
      case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn -> [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 Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
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 (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) XUnambiguous (GhcPass p)
Name
fld]
        HiePassEv p
HieTc -> [Context (Located Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Id) -> HieM [HieAST Type])
-> Context (Located Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Id -> Context (Located Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (Located Id -> Context (Located Id))
-> Located Id -> Context (Located Id)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Id -> Located Id
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) XUnambiguous (GhcPass p)
Id
fld]
    Ambiguous XAmbiguous (GhcPass p)
fld XRec (GhcPass p) RdrName
_ ->
      case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn -> []
        HiePassEv p
HieTc -> [ Context (Located Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Id) -> HieM [HieAST Type])
-> Context (Located Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Id -> Context (Located Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> Located Id
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) XAmbiguous (GhcPass p)
Id
fld) ]

instance HiePass p => 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
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
    , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
    ]
  toHie (RS Scope
sc (ApplicativeArgMany XApplicativeArgMany (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts HsExpr (GhcPass p)
_ LPat (GhcPass p)
pat HsDoFlavour
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts
    , PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
    ]

instance (ToHie tyarg, ToHie arg, ToHie rec) => ToHie (HsConDetails tyarg arg rec) where
  toHie :: HsConDetails tyarg arg rec -> HieM [HieAST Type]
toHie (PrefixCon [tyarg]
tyargs [arg]
args) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ [tyarg] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [tyarg]
tyargs, [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 (HsConDeclGADTDetails GhcRn) where
  toHie :: HsConDeclGADTDetails GhcRn -> HieM [HieAST Type]
toHie (PrefixConGADT XPrefixConGADT GhcRn
_ [HsScaled GhcRn (LHsType GhcRn)]
args) = [HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsScaled GhcRn (LHsType GhcRn)]
[HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))]
args
  toHie (RecConGADT XRecConGADT GhcRn
_ XRec GhcRn [LConDeclField GhcRn]
rec) = GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec GhcRn [LConDeclField GhcRn]
GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
rec

instance HiePass p => ToHie (LocatedAn NoEpAnns (HsCmdTop (GhcPass p))) where
  toHie :: LocatedAn NoEpAnns (HsCmdTop (GhcPass p)) -> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span HsCmdTop (GhcPass p)
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 (GhcPass p) -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsCmdTop (GhcPass p)
top EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsCmdTop (GhcPass p)
top of
    HsCmdTop XCmdTop (GhcPass p)
_ LHsCmd (GhcPass p)
cmd ->
      [ GenLocated SrcSpanAnnA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
GenLocated SrcSpanAnnA (HsCmd (GhcPass p))
cmd
      ]

instance HiePass p => ToHie (LocatedA (HsCmd (GhcPass p))) where
  toHie :: LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsCmd (GhcPass p)
cmd SrcSpanAnnA
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
_ ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
b
        ]
      HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
a LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop (GhcPass p)]
cmdtops ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , [GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsCmdTop (GhcPass p)]
[GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))]
cmdtops
        ]
      HsCmdApp XCmdApp (GhcPass p)
_ LHsCmd (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
a
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
b
        ]
      HsCmdPar XCmdPar (GhcPass p)
_ LHsCmd (GhcPass p)
a ->
        [ LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
a
        ]
      HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        , MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
alts
        ]
      HsCmdLam XCmdLamCase (GhcPass p)
_ HsLamVariant
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
alts
        ]
      HsCmdIf XCmdIf (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsCmd (GhcPass p)
b LHsCmd (GhcPass p)
c ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
b
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
c
        ]
      HsCmdLet XCmdLet (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsCmd (GhcPass p)
cmd' ->
        [ RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LocatedA (HsCmd (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
cmd') HsLocalBinds (GhcPass p)
binds
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
cmd'
        ]
      HsCmdDo XCmdDo (GhcPass p)
_ (L SrcSpanAnnL
ispan [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
ispan)
        , [RScoped
   (LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
stmts
        ]
      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
    [ [GenLocated SrcSpanAnnA (TyClDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyClDecl GhcRn]
[GenLocated SrcSpanAnnA (TyClDecl GhcRn)]
classes
    , [GenLocated SrcSpanAnnA (StandaloneKindSig GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LStandaloneKindSig GhcRn]
[GenLocated SrcSpanAnnA (StandaloneKindSig GhcRn)]
sigs
    , [GenLocated SrcSpanAnnA (RoleAnnotDecl GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRoleAnnotDecl GhcRn]
[GenLocated SrcSpanAnnA (RoleAnnotDecl GhcRn)]
roles
    , [GenLocated SrcSpanAnnA (InstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LInstDecl GhcRn]
[GenLocated SrcSpanAnnA (InstDecl GhcRn)]
instances
    ]

instance ToHie (LocatedA (TyClDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (TyClDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA TyClDecl GhcRn
decl SrcSpanAnnA
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 SrcSpanAnnA (FamilyDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ((SrcSpanAnnA
-> FamilyDecl GhcRn -> GenLocated SrcSpanAnnA (FamilyDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span FamilyDecl GhcRn
fdecl) :: LFamilyDecl GhcRn)
        ]
      SynDecl {tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP 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 (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
SynDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP GhcRn
LocatedN 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
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ]) LHsQTyVars GhcRn
vars
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ
        ]
      DataDecl {tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP 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 (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
DataDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP GhcRn
LocatedN 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 = GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
 -> Scope)
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Maybe
     (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall a. a -> Maybe a -> a
fromMaybe ([GenLocated SrcSpanAnnA (HsType GhcRn)]
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA []) (Maybe
   (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
 -> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> Maybe
     (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Maybe (LHsContext GhcRn)
forall pass. HsDataDefn pass -> Maybe (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
-> (GenLocated SrcSpanAnnA (HsType GhcRn) -> Scope)
-> Maybe (GenLocated SrcSpanAnnA (HsType GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated SrcSpanAnnA (HsType GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (Maybe (GenLocated SrcSpanAnnA (HsType GhcRn)) -> Scope)
-> Maybe (GenLocated SrcSpanAnnA (HsType 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 -> DataDefnCons Scope -> Scope
forall a b. (a -> b -> b) -> b -> DataDefnCons a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope (DataDefnCons Scope -> Scope) -> DataDefnCons Scope -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (ConDecl GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnA (ConDecl GhcRn) -> Scope)
-> DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn))
-> DataDefnCons Scope
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsDataDefn GhcRn -> DataDefnCons (LConDecl GhcRn)
forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons HsDataDefn GhcRn
defn
          deriv_sc :: Scope
deriv_sc = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
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
$ GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn) -> Scope)
-> [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
-> [Scope]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsDataDefn GhcRn -> HsDeriving GhcRn
forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs HsDataDefn GhcRn
defn
      ClassDecl { tcdCtxt :: forall pass. TyClDecl pass -> Maybe (LHsContext pass)
tcdCtxt = Maybe (LHsContext GhcRn)
context
                , tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP 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 = [XRec GhcRn (FamilyDecl GhcRn)]
typs
                , tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl GhcRn]
deftyps
                } ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ClassDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP GhcRn
LocatedN Name
name
        , Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType 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
        , [GenLocated SrcSpanAnnA (FunDep GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsFunDep GhcRn]
[GenLocated SrcSpanAnnA (FunDep GhcRn)]
deps
        , [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig GhcRn)
 -> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn)))
-> [GenLocated SrcSpanAnnA (Sig GhcRn)]
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> GenLocated SrcSpanAnnA (Sig GhcRn)
 -> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn)))
-> SigInfo
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe Span -> SigInfo
SI SigType
ClassSig (Maybe Span -> SigInfo) -> Maybe Span -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) [LSig GhcRn]
[GenLocated SrcSpanAnnA (Sig GhcRn)]
sigs
        , Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
 -> HieM [HieAST Type])
-> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBind GhcRn)
 -> BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
-> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
forall a b. (a -> b) -> Bag a -> Bag b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBind GhcRn)
-> BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) LHsBinds GhcRn
Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
meths
        , [GenLocated SrcSpanAnnA (FamilyDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [XRec GhcRn (FamilyDecl GhcRn)]
[GenLocated SrcSpanAnnA (FamilyDecl GhcRn)]
typs
        , (GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LTyFamDefltDecl GhcRn]
[GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
deftyps
        , [GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyFamDefltDecl GhcRn]
[GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
deftyps
        ]
        where
          context_scope :: Scope
context_scope = GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
 -> Scope)
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Maybe
     (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall a. a -> Maybe a -> a
fromMaybe ([GenLocated SrcSpanAnnA (HsType GhcRn)]
-> GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA []) Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
context
          rhs_scope :: Scope
rhs_scope = (Scope -> Scope -> Scope) -> [Scope] -> Scope
forall a. HasCallStack => (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
forall a. HasLoc a => a -> Scope
mkScope
            [ [GenLocated SrcSpanAnnA (FunDep GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsFunDep GhcRn]
[GenLocated SrcSpanAnnA (FunDep GhcRn)]
deps, [GenLocated SrcSpanAnnA (Sig GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LSig GhcRn]
[GenLocated SrcSpanAnnA (Sig GhcRn)]
sigs, [GenLocated SrcSpanAnnA (HsBind GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList (Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
-> [GenLocated SrcSpanAnnA (HsBind GhcRn)]
forall a. Bag a -> [a]
bagToList LHsBinds GhcRn
Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
meths), [GenLocated SrcSpanAnnA (FamilyDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [XRec GhcRn (FamilyDecl GhcRn)]
[GenLocated SrcSpanAnnA (FamilyDecl GhcRn)]
typs, [GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LTyFamDefltDecl GhcRn]
[GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
deftyps]

instance ToHie (LocatedA (FamilyDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FamilyDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FamilyDecl GhcRn
decl SrcSpanAnnA
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 TopLevelFlag
_ LIdP GhcRn
name LHsQTyVars GhcRn
vars LexicalFixity
_ LFamilyResultSig GhcRn
sig Maybe (LInjectivityAnn GhcRn)
inj ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
FamDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP GhcRn
LocatedN 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 (GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn))
 -> HieM [HieAST Type])
-> RScoped (GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn)
-> RScoped (GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn))
forall a. Scope -> a -> RScoped a
RS Scope
injSpan LFamilyResultSig GhcRn
GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn)
sig
        , Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LInjectivityAnn GhcRn)
Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn))
inj
        ]
        where
          rhsSpan :: Scope
rhsSpan = Scope
sigSpan Scope -> Scope -> Scope
`combineScopes` Scope
injSpan
          sigSpan :: Scope
sigSpan = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LFamilyResultSig GhcRn
GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn)
sig
          injSpan :: Scope
injSpan = Scope
-> (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn) -> Scope)
-> Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn) -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn)
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) Maybe (LInjectivityAnn GhcRn)
Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn))
inj

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
$
    [ (GenLocated
   SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> HieM [HieAST Type])
-> [GenLocated
      SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated
      SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
    -> SrcSpan)
-> GenLocated
     SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated
  SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LTyFamInstEqn GhcRn]
[GenLocated
   SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
eqns
    , [TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
 -> HieM [HieAST Type])
-> [TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))))
-> [GenLocated
      SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> [TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated
  SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
forall {a} {a}. HasLoc a => GenLocated a a -> TScoped a
go [LTyFamInstEqn GhcRn]
[GenLocated
   SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
eqns
    ]
    where
      go :: GenLocated a a -> TScoped a
go (L a
l a
ib) = TyVarScope -> a -> TScoped a
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [a -> Scope
forall a. HasLoc a => a -> Scope
mkScope a
l]) a
ib
  toHie FamilyInfo GhcRn
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (RScoped (LocatedAn NoEpAnns (FamilyResultSig GhcRn))) where
  toHie :: RScoped (GenLocated (EpAnn NoEpAnns) (FamilyResultSig GhcRn))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
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 -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FamilyResultSig GhcRn
sig EpAnn NoEpAnns
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 ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
k
        ]
      TyVarSig XTyVarSig GhcRn
_ LHsTyVarBndr () GhcRn
bndr ->
        [ TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))
 -> HieM [HieAST Type])
-> TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
-> TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) Scope
NoScope LHsTyVarBndr () GhcRn
GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
bndr
        ]

instance ToHie (LocatedA (FunDep GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FunDep GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span fd :: FunDep GhcRn
fd@(FunDep XCFunDep GhcRn
_ [LIdP GhcRn]
lhs [LIdP GhcRn]
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 GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode FunDep GhcRn
fd (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)
    , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP GhcRn]
[LocatedN Name]
lhs
    , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP GhcRn]
[LocatedN Name]
rhs
    ]


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

instance ToHie (TScoped (FamEqn GhcRn (LocatedA (HsType GhcRn)))) where
  toHie :: TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
toHie (TS TyVarScope
_ FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
f) = FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
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
_ LIdP GhcRn
var HsOuterFamEqnTyVarBndrs GhcRn
outer_bndrs HsFamEqnPats 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 (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
InstDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ FamEqn GhcRn rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc FamEqn GhcRn rhs
fe) LIdP GhcRn
LocatedN Name
var
    , TVScoped (HsOuterFamEqnTyVarBndrs GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TVScoped (HsOuterFamEqnTyVarBndrs GhcRn) -> HieM [HieAST Type])
-> TVScoped (HsOuterFamEqnTyVarBndrs GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> HsOuterFamEqnTyVarBndrs GhcRn
-> TVScoped (HsOuterFamEqnTyVarBndrs GhcRn)
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope HsOuterFamEqnTyVarBndrs GhcRn
outer_bndrs
    , [HsArg
   GhcRn
   (GenLocated SrcSpanAnnA (HsType GhcRn))
   (GenLocated SrcSpanAnnA (HsType GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsFamEqnPats GhcRn
[HsArg
   GhcRn
   (GenLocated SrcSpanAnnA (HsType GhcRn))
   (GenLocated SrcSpanAnnA (HsType 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
forall a. HasLoc a => a -> Scope
mkScope ([HsArg
   GhcRn
   (GenLocated SrcSpanAnnA (HsType GhcRn))
   (GenLocated SrcSpanAnnA (HsType GhcRn))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats GhcRn
[HsArg
   GhcRn
   (GenLocated SrcSpanAnnA (HsType GhcRn))
   (GenLocated SrcSpanAnnA (HsType GhcRn))]
pats)
          rhsScope :: Scope
rhsScope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc rhs
rhs)

instance ToHie (LocatedAn NoEpAnns (InjectivityAnn GhcRn)) where
  toHie :: GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn)
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
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 -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA InjectivityAnn GhcRn
ann EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InjectivityAnn GhcRn
ann of
      InjectivityAnn XCInjectivityAnn GhcRn
_ LIdP GhcRn
lhs [LIdP GhcRn]
rhs ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
lhs
        , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP GhcRn]
[LocatedN Name]
rhs
        ]

instance ToHie (HsDataDefn GhcRn) where
  toHie :: HsDataDefn GhcRn -> HieM [HieAST Type]
toHie (HsDataDefn XCHsDataDefn GhcRn
_ Maybe (LHsContext GhcRn)
ctx Maybe (XRec GhcRn CType)
_ Maybe (LHsType GhcRn)
mkind DataDefnCons (LConDecl GhcRn)
cons HsDeriving GhcRn
derivs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
ctx
    , Maybe (GenLocated SrcSpanAnnA (HsType GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsType GhcRn)
Maybe (GenLocated SrcSpanAnnA (HsType GhcRn))
mkind
    , DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie DataDefnCons (LConDecl GhcRn)
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcRn))
cons
    , [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsDeriving GhcRn
[GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
derivs
    ]

instance ToHie (Located [LocatedAn NoEpAnns (HsDerivingClause GhcRn)]) where
  toHie :: Located [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
-> HieM [HieAST Type]
toHie (L SrcSpan
span [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
clauses) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
span
    , [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)]
clauses
    ]

instance ToHie (LocatedAn NoEpAnns (HsDerivingClause GhcRn)) where
  toHie :: GenLocated (EpAnn NoEpAnns) (HsDerivingClause GhcRn)
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
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 -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsDerivingClause GhcRn
cl EpAnn NoEpAnns
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 LDerivClauseTys GhcRn
dct ->
        [ Maybe (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Scope
-> GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)
-> RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
forall a. Scope -> a -> RScoped a
RS (GenLocated SrcSpanAnnC (DerivClauseTys GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LDerivClauseTys GhcRn
GenLocated SrcSpanAnnC (DerivClauseTys GhcRn)
dct) (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)
 -> RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
-> Maybe (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
-> Maybe
     (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LDerivStrategy GhcRn)
Maybe (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
strat)
        , GenLocated SrcSpanAnnC (DerivClauseTys GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LDerivClauseTys GhcRn
GenLocated SrcSpanAnnC (DerivClauseTys GhcRn)
dct
        ]

instance ToHie (LocatedC (DerivClauseTys GhcRn)) where
  toHie :: GenLocated SrcSpanAnnC (DerivClauseTys GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnC
span DerivClauseTys GhcRn
dct) = [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
$ DerivClauseTys GhcRn -> SrcSpanAnnC -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivClauseTys GhcRn
dct SrcSpanAnnC
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivClauseTys GhcRn
dct of
      DctSingle XDctSingle GhcRn
_ LHsSigType GhcRn
ty -> [ TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
ty ]
      DctMulti XDctMulti GhcRn
_ [LHsSigType GhcRn]
tys -> [ [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
 -> HieM [HieAST Type])
-> [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsSigType GhcRn)
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> [GenLocated SrcSpanAnnA (HsSigType GhcRn)]
-> [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType GhcRn]
[GenLocated SrcSpanAnnA (HsSigType GhcRn)]
tys ]

instance ToHie (RScoped (LocatedAn NoEpAnns (DerivStrategy GhcRn))) where
  toHie :: RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
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 -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivStrategy GhcRn
strat EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivStrategy GhcRn
strat of
      StockStrategy XStockStrategy GhcRn
_ -> []
      AnyclassStrategy XAnyClassStrategy GhcRn
_ -> []
      NewtypeStrategy XNewtypeStrategy GhcRn
_ -> []
      ViaStrategy XViaStrategy GhcRn
s -> [ TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) XViaStrategy GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
s) ]

instance ToHie (LocatedP OverlapMode) where
  toHie :: LocatedP OverlapMode -> HieM [HieAST Type]
toHie (L SrcSpanAnnP
span OverlapMode
_) = SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnP -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnP
span)

instance ToHie a => ToHie (HsScaled GhcRn a) where
  toHie :: HsScaled GhcRn a -> HieM [HieAST Type]
toHie (HsScaled HsArrow GhcRn
w a
t) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrow GhcRn -> LHsType GhcRn
arrowToHsType HsArrow GhcRn
w), a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie a
t]

instance ToHie (LocatedA (ConDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ConDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDecl GhcRn
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
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 -> NonEmpty (LIdP pass)
con_names = NonEmpty (LIdP GhcRn)
names, con_bndrs :: forall pass. ConDecl pass -> XRec pass (HsOuterSigTyVarBndrs pass)
con_bndrs = L SrcSpanAnnA
outer_bndrs_loc HsOuterSigTyVarBndrs GhcRn
outer_bndrs
                  , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
ctx, con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails GhcRn
args, con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType GhcRn
typ
                  , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc GhcRn)
doc} ->
        [ NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type])
-> NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ConDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) (LocatedN Name -> Context (LocatedN Name))
-> NonEmpty (LocatedN Name) -> NonEmpty (Context (LocatedN Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty (LIdP GhcRn)
NonEmpty (LocatedN Name)
names
        , case HsOuterSigTyVarBndrs GhcRn
outer_bndrs of
            HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcRn
imp_vars} ->
              [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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 (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
outer_bndrs_loc) TyVarScope
resScope)
                             [Name]
XHsOuterImplicit GhcRn
imp_vars
            HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr Specificity (NoGhcTc GhcRn)]
exp_bndrs} ->
              [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
resScope Scope
NoScope [LHsTyVarBndr Specificity (NoGhcTc GhcRn)]
[LHsTyVarBndr Specificity GhcRn]
exp_bndrs
        , Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
ctx
        , HsConDeclGADTDetails GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclGADTDetails GhcRn
args
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ
        , Maybe (LHsDoc GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc GhcRn)
doc
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
argsScope Scope
tyScope
          ctxScope :: Scope
ctxScope = Scope
-> (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
    -> Scope)
-> Maybe
     (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
ctx
          argsScope :: Scope
argsScope = case HsConDeclGADTDetails GhcRn
args of
            PrefixConGADT XPrefixConGADT GhcRn
_ [HsScaled GhcRn (LHsType GhcRn)]
xs -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)]
xs
            RecConGADT XRecConGADT GhcRn
_ XRec GhcRn [LConDeclField GhcRn]
x     -> GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec GhcRn [LConDeclField GhcRn]
GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
x
          tyScope :: Scope
tyScope = GenLocated SrcSpanAnnA (HsType GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ
          resScope :: TyVarScope
resScope = [Scope] -> TyVarScope
ResolvedScopes [Scope
ctxScope, Scope
rhsScope]
      ConDeclH98 { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = LIdP GhcRn
name, con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_ex_tvs = [LHsTyVarBndr Specificity GhcRn]
qvars
                 , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
ctx, con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details GhcRn
dets
                 , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc GhcRn)
doc} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ConDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) LIdP GhcRn
LocatedN Name
name
        , [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
rhsScope [LHsTyVarBndr Specificity GhcRn]
qvars
        , Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
ctx
        , HsConDetails
  Void
  (HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
  (GenLocated
     SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclH98Details GhcRn
HsConDetails
  Void
  (HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
  (GenLocated
     SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
dets
        , Maybe (LHsDoc GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc GhcRn)
doc
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
ctxScope Scope
argsScope
          ctxScope :: Scope
ctxScope = Scope
-> (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
    -> Scope)
-> Maybe
     (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope Maybe (LHsContext GhcRn)
Maybe
  (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
ctx
          argsScope :: Scope
argsScope = case HsConDeclH98Details GhcRn
dets of
            PrefixCon [Void]
_ [HsScaled GhcRn (LHsType GhcRn)]
xs -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)]
xs
            InfixCon HsScaled GhcRn (LHsType GhcRn)
a HsScaled GhcRn (LHsType GhcRn)
b   -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)
a, HsScaled GhcRn (LHsType GhcRn)
b]
            RecCon XRec GhcRn [LConDeclField GhcRn]
x       -> GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec GhcRn [LConDeclField GhcRn]
GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
x
    where scaled_args_scope :: [HsScaled GhcRn (LHsType GhcRn)] -> Scope
          scaled_args_scope :: [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope)
-> ([HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))]
    -> [Scope])
-> [HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))]
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)) -> Scope)
-> [HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated SrcSpanAnnA (HsType GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnA (HsType GhcRn) -> Scope)
-> (HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
    -> GenLocated SrcSpanAnnA (HsType GhcRn))
-> HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsScaled GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
forall pass a. HsScaled pass a -> a
hsScaledThing)

instance ToHie (LocatedL [LocatedA (ConDeclField GhcRn)]) where
  toHie :: GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> HieM [HieAST Type]
toHie (L SrcSpanAnnL
span [GenLocated SrcSpanAnnA (ConDeclField 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
$
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
span)
    , [GenLocated SrcSpanAnnA (ConDeclField GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
decls
    ]

instance ToHie (TScoped (HsWildCardBndrs GhcRn (LocatedA (HsSigType GhcRn)))) where
  toHie :: TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsWC XHsWC GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
names GenLocated SrcSpanAnnA (HsSigType GhcRn)
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
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsWC GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
names
      , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS TyVarScope
sc GenLocated SrcSpanAnnA (HsSigType GhcRn)
a
      ]
    where span :: SrcSpan
span = GenLocated SrcSpanAnnA (HsSigType GhcRn) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc GenLocated SrcSpanAnnA (HsSigType GhcRn)
a

instance ToHie (TScoped (HsWildCardBndrs GhcRn (LocatedA (HsType GhcRn)))) where
  toHie :: TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsWC XHsWC GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
names GenLocated SrcSpanAnnA (HsType GhcRn)
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
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsWC GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
names
      , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpanAnnA (HsType GhcRn)
a
      ]
    where span :: SrcSpan
span = GenLocated SrcSpanAnnA (HsType GhcRn) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc GenLocated SrcSpanAnnA (HsType GhcRn)
a

instance ToHie (LocatedA (StandaloneKindSig GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (StandaloneKindSig GhcRn)
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
sp StandaloneKindSig GhcRn
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [StandaloneKindSig GhcRn -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA StandaloneKindSig GhcRn
sig SrcSpanAnnA
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
_ LIdP GhcRn
name LHsSigType GhcRn
typ ->
      [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl LIdP GhcRn
LocatedN Name
name
      , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
typ
      ]

instance HiePass p => ToHie (SigContext (LocatedA (Sig (GhcPass p)))) where
  toHie :: SigContext (LocatedA (Sig (GhcPass p))) -> HieM [HieAST Type]
toHie (SC (SI SigType
styp Maybe Span
msp) (L SrcSpanAnnA
sp Sig (GhcPass p)
sig)) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieTc -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
      HiePassEv p
HieRn -> [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 (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Sig (GhcPass p)
sig SrcSpanAnnA
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Sig (GhcPass p)
sig of
        TypeSig XTypeSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigWcType (GhcPass p)
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
forall a. Maybe a
Nothing) LHsSigWcType (GhcPass p)
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
typ
          ]
        PatSynSig XPatSynSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
forall a. Maybe a
Nothing) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType GhcRn)
typ
          ]
        ClassOpSig XClassOpSig (GhcPass p)
_ Bool
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
typ ->
          [ case SigType
styp of
              SigType
ClassSig -> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> LocatedN Name -> Context (LocatedN Name))
-> ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ Maybe Span -> ContextInfo
ClassTyDecl (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
sp) [LIdP (GhcPass p)]
[LocatedN Name]
names
              SigType
_  -> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> LocatedN Name -> Context (LocatedN Name))
-> ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
msp) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType GhcRn)
typ
          ]
        FixSig XFixSig (GhcPass p)
_ FixitySig (GhcPass p)
fsig ->
          [ GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> FixitySig (GhcPass p)
-> GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp FixitySig (GhcPass p)
fsig
          ]
        InlineSig XInlineSig (GhcPass p)
_ LIdP (GhcPass p)
name InlinePragma
_ ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          ]
        SpecSig XSpecSig (GhcPass p)
_ LIdP (GhcPass p)
name [LHsSigType (GhcPass p)]
typs InlinePragma
_ ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          , [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
 -> HieM [HieAST Type])
-> [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsSigType GhcRn)
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> [GenLocated SrcSpanAnnA (HsSigType GhcRn)]
-> [TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType (GhcPass p)]
[GenLocated SrcSpanAnnA (HsSigType GhcRn)]
typs
          ]
        SpecInstSig XSpecInstSig (GhcPass p)
_ LHsSigType (GhcPass p)
typ ->
          [ TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType GhcRn)
typ
          ]
        MinimalSig XMinimalSig (GhcPass p)
_ LBooleanFormula (LIdP (GhcPass p))
form ->
          [ LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (LIdP (GhcPass p))
LBooleanFormula (LocatedN Name)
form
          ]
        SCCFunSig XSCCFunSig (GhcPass p)
_ LIdP (GhcPass p)
name Maybe (XRec (GhcPass p) StringLiteral)
mtxt ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          , HieM [HieAST Type]
-> (GenLocated (EpAnn NoEpAnns) StringLiteral
    -> HieM [HieAST Type])
-> Maybe (GenLocated (EpAnn NoEpAnns) StringLiteral)
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated (EpAnn NoEpAnns) StringLiteral -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) StringLiteral
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) StringLiteral -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) Maybe (XRec (GhcPass p) StringLiteral)
Maybe (GenLocated (EpAnn NoEpAnns) StringLiteral)
mtxt
          ]
        CompleteMatchSig XCompleteMatchSig (GhcPass p)
_ [LIdP (GhcPass p)]
names Maybe (LIdP (GhcPass p))
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , Maybe (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Context (LocatedN Name)) -> HieM [HieAST Type])
-> Maybe (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> Maybe (LocatedN Name) -> Maybe (Context (LocatedN Name))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Maybe (LIdP (GhcPass p))
Maybe (LocatedN Name)
typ
          ]
        XSig XXSig (GhcPass p)
_ -> []

instance ToHie (TScoped (LocatedA (HsSigType GhcRn))) where
  toHie :: TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
toHie (TS TyVarScope
tsc (L SrcSpanAnnA
span t :: HsSigType GhcRn
t@HsSig{sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs=HsOuterSigTyVarBndrs GhcRn
bndrs,sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body=LHsType GhcRn
body})) = [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
$ HsSigType GhcRn -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsSigType GhcRn
t SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
:
      [ TVScoped (HsOuterSigTyVarBndrs GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TyVarScope
-> Scope
-> HsOuterSigTyVarBndrs GhcRn
-> TVScoped (HsOuterSigTyVarBndrs GhcRn)
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tsc (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) HsOuterSigTyVarBndrs GhcRn
bndrs)
      , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body
      ]

-- Check this
instance Data flag => ToHie (TVScoped (HsOuterTyVarBndrs flag GhcRn)) where
  toHie :: TVScoped (HsOuterTyVarBndrs flag GhcRn) -> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc HsOuterTyVarBndrs flag GhcRn
bndrs) = case HsOuterTyVarBndrs flag GhcRn
bndrs of
    HsOuterImplicit XHsOuterImplicit GhcRn
xs -> [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [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 Scope
sc TyVarScope
tsc) [Name]
XHsOuterImplicit GhcRn
xs
    HsOuterExplicit XHsOuterExplicit GhcRn flag
_ [LHsTyVarBndr flag (NoGhcTc GhcRn)]
xs -> [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr flag GhcRn]
-> [TVScoped (LHsTyVarBndr flag GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tsc Scope
sc [LHsTyVarBndr flag (NoGhcTc GhcRn)]
[LHsTyVarBndr flag GhcRn]
xs

instance ToHie (LocatedA (HsType GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsType GhcRn
t (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsType GhcRn
t of
      HsForAllTy XForAllTy GhcRn
_ HsForAllTelescope GhcRn
tele LHsType GhcRn
body ->
        let scope :: Scope
scope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body in
        [ case HsForAllTelescope GhcRn
tele of
            HsForAllVis { hsf_vis_bndrs :: forall pass. HsForAllTelescope pass -> [LHsTyVarBndr () pass]
hsf_vis_bndrs = [LHsTyVarBndr () GhcRn]
bndrs } ->
              [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr () GhcRn]
-> [TVScoped (LHsTyVarBndr () GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope [LHsTyVarBndr () GhcRn]
bndrs
            HsForAllInvis { hsf_invis_bndrs :: forall pass.
HsForAllTelescope pass -> [LHsTyVarBndr Specificity pass]
hsf_invis_bndrs = [LHsTyVarBndr Specificity GhcRn]
bndrs } ->
              [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope [LHsTyVarBndr Specificity GhcRn]
bndrs
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body
        ]
      HsQualTy XQualTy GhcRn
_ LHsContext GhcRn
ctx LHsType GhcRn
body ->
        [ GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsContext GhcRn
GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
ctx
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
body
        ]
      HsTyVar XTyVar GhcRn
_ PromotionFlag
_ LIdP GhcRn
var ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
var
        ]
      HsAppTy XAppTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
b
        ]
      HsAppKindTy XAppKindTy GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
ki ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ki
        ]
      HsFunTy XFunTy GhcRn
_ HsArrow GhcRn
w LHsType GhcRn
a LHsType GhcRn
b ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrow GhcRn -> LHsType GhcRn
arrowToHsType HsArrow GhcRn
w)
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
b
        ]
      HsListTy XListTy GhcRn
_ LHsType GhcRn
a ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        ]
      HsTupleTy XTupleTy GhcRn
_ HsTupleSort
_ [LHsType GhcRn]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
        ]
      HsSumTy XSumTy GhcRn
_ [LHsType GhcRn]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
        ]
      HsOpTy XOpTy GhcRn
_ PromotionFlag
_prom LHsType GhcRn
a LIdP GhcRn
op LHsType GhcRn
b ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        , Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
op
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
b
        ]
      HsParTy XParTy GhcRn
_ LHsType GhcRn
a ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        ]
      HsIParamTy XIParamTy GhcRn
_ XRec GhcRn HsIPName
ip LHsType GhcRn
ty ->
        [ GenLocated (EpAnn NoEpAnns) HsIPName -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec GhcRn HsIPName
GenLocated (EpAnn NoEpAnns) HsIPName
ip
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty
        ]
      HsKindSig XKindSig GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
b
        ]
      HsSpliceTy XSpliceTy GhcRn
_ HsUntypedSplice GhcRn
a ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice GhcRn
-> GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsUntypedSplice GhcRn
a
        ]
      HsDocTy XDocTy GhcRn
_ LHsType GhcRn
a LHsDoc GhcRn
doc ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a
        , LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
doc
        ]
      HsBangTy XBangTy GhcRn
_ HsSrcBang
_ LHsType GhcRn
ty ->
        [ GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty
        ]
      HsRecTy XRecTy GhcRn
_ [LConDeclField GhcRn]
fields ->
        [ [GenLocated SrcSpanAnnA (ConDeclField GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LConDeclField GhcRn]
[GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
fields
        ]
      HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ [LHsType GhcRn]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
        ]
      HsExplicitTupleTy XExplicitTupleTy GhcRn
_ [LHsType GhcRn]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
        ]
      HsTyLit XTyLit GhcRn
_ HsTyLit GhcRn
_ -> []
      HsWildCardTy XWildCardTy GhcRn
_ -> []
      HsStarTy XStarTy GhcRn
_ Bool
_ -> []
      XHsType XXType GhcRn
_ -> []

instance (ToHie tm, ToHie ty) => ToHie (HsArg (GhcPass p) tm ty) where
  toHie :: HsArg (GhcPass p) tm ty -> HieM [HieAST Type]
toHie (HsValArg XValArg (GhcPass p)
_ tm
tm) = tm -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie tm
tm
  toHie (HsTypeArg XTypeArg (GhcPass p)
_ ty
ty) = ty -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ty
ty
  toHie (HsArgPar XArgPar (GhcPass p)
sp) = SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
XArgPar (GhcPass p)
sp

instance Data flag => ToHie (TVScoped (LocatedA (HsTyVarBndr flag GhcRn))) where
  toHie :: TVScoped (LocatedA (HsTyVarBndr flag GhcRn)) -> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc (L SrcSpanAnnA
span HsTyVarBndr flag 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 flag GhcRn -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsTyVarBndr flag GhcRn
bndr SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsTyVarBndr flag GhcRn
bndr of
      UserTyVar XUserTyVar GhcRn
_ flag
_ LIdP GhcRn
var ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) LIdP GhcRn
LocatedN Name
var
        ]
      KindedTyVar XKindedTyVar GhcRn
_ flag
_ LIdP GhcRn
var LHsType GhcRn
kind ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) LIdP GhcRn
LocatedN Name
var
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
kind
        ]

instance ToHie (TScoped (LHsQTyVars GhcRn)) where
  toHie :: TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsQTvs XHsQTvs GhcRn
implicits [LHsTyVarBndr (HsBndrVis GhcRn) 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
$
    [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [Context Name]
bindings
    , [TVScoped
   (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
-> [TVScoped (LHsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
sc Scope
NoScope [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
vars
    ]
    where
      varLoc :: SrcSpan
varLoc = [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) 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
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
varLoc) TyVarScope
sc) [Name]
XHsQTvs GhcRn
implicits

instance ToHie (LocatedC [LocatedA (HsType GhcRn)]) where
  toHie :: GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> HieM [HieAST Type]
toHie (L SrcSpanAnnC
span [GenLocated SrcSpanAnnA (HsType 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
$
      [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnC -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnC
span)
      , [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
      ]

instance ToHie (LocatedA (ConDeclField GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ConDeclField GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDeclField GhcRn
field (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
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 (LHsDoc GhcRn)
doc ->
        [ [RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn))]
 -> HieM [HieAST Type])
-> [RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (FieldOcc GhcRn)
 -> RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn)))
-> [GenLocated SrcSpanAnnA (FieldOcc GhcRn)]
-> [RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> Maybe Span
-> GenLocated SrcSpanAnnA (FieldOcc GhcRn)
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcRn))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldDecl (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType GhcRn) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ)) [LFieldOcc GhcRn]
[GenLocated SrcSpanAnnA (FieldOcc GhcRn)]
fields
        , GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ
        , Maybe (LHsDoc GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc GhcRn)
doc
        ]

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 (LocatedA (SpliceDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (SpliceDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA SpliceDecl GhcRn
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case SpliceDecl GhcRn
decl of
      SpliceDecl XSpliceDecl GhcRn
_ XRec GhcRn (HsUntypedSplice GhcRn)
splice SpliceDecoration
_ ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec GhcRn (HsUntypedSplice GhcRn)
GenLocated SrcSpanAnnA (HsUntypedSplice GhcRn)
splice
        ]

instance ToHie (HsQuote GhcRn) where
  toHie :: HsQuote GhcRn -> HieM [HieAST Type]
toHie (ExpBr XExpBr GhcRn
_ LHsExpr GhcRn
e)  = LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
e
  toHie (PatBr XPatBr GhcRn
_ LPat GhcRn
b)  = PScoped (GenLocated SrcSpanAnnA (Pat GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcRn)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcRn))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
NoScope Scope
NoScope LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
b)
  toHie (DecBrL {} ) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  toHie (DecBrG XDecBrG GhcRn
_ HsGroup GhcRn
decls) = HsGroup GhcRn -> HieM [HieAST Type]
processGrp HsGroup GhcRn
decls
  toHie (TypBr XTypBr GhcRn
_ LHsType GhcRn
ty) = GenLocated SrcSpanAnnA (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty
  toHie (VarBr {} )  = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingRnSplice where
  toHie :: PendingRnSplice -> HieM [HieAST Type]
toHie (PendingRnSplice UntypedSpliceFlavour
_ Name
_ LHsExpr GhcRn
e) = LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
e

instance ToHie PendingTcSplice where
  toHie :: PendingTcSplice -> HieM [HieAST Type]
toHie (PendingTcSplice Name
_ LHsExpr GhcTc
e) = GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
e

instance ToHie (LBooleanFormula (LocatedN Name)) where
  toHie :: LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
toHie (L SrcSpanAnnL
span BooleanFormula (LocatedN 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 (LocatedN Name) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode BooleanFormula (LocatedN Name)
form (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case BooleanFormula (LocatedN Name)
form of
      Var LocatedN Name
a ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LocatedN Name
a
        ]
      And [LBooleanFormula (LocatedN Name)]
forms ->
        [ [LBooleanFormula (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (LocatedN Name)]
forms
        ]
      Or [LBooleanFormula (LocatedN Name)]
forms ->
        [ [LBooleanFormula (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (LocatedN Name)]
forms
        ]
      Parens LBooleanFormula (LocatedN Name)
f ->
        [ LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (LocatedN Name)
f
        ]

instance ToHie (LocatedAn NoEpAnns HsIPName) where
  toHie :: GenLocated (EpAnn NoEpAnns) HsIPName -> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span HsIPName
e) = HsIPName -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsIPName
e EpAnn NoEpAnns
span

instance HiePass p => ToHie (LocatedA (HsUntypedSplice (GhcPass p))) where
  toHie :: LocatedA (HsUntypedSplice (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span HsUntypedSplice (GhcPass p)
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
$ HsUntypedSplice (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsUntypedSplice (GhcPass p)
sp SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsUntypedSplice (GhcPass p)
sp of
      HsUntypedSpliceExpr XUntypedSpliceExpr (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        ]
      HsQuasiQuote XQuasiQuote (GhcPass p)
_ IdP (GhcPass p)
_ XRec (GhcPass p) FastString
ispanFs ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (GenLocated (EpAnn NoEpAnns) FastString -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA XRec (GhcPass p) FastString
GenLocated (EpAnn NoEpAnns) FastString
ispanFs)
        ]

instance ToHie (LocatedA (RoleAnnotDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RoleAnnotDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RoleAnnotDecl GhcRn
annot SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RoleAnnotDecl GhcRn
annot of
      RoleAnnotDecl XCRoleAnnotDecl GhcRn
_ LIdP GhcRn
var [XRec GhcRn (Maybe Role)]
roles ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
var
        , (GenLocated (EpAnn NoEpAnns) (Maybe Role) -> HieM [HieAST Type])
-> [GenLocated (EpAnn NoEpAnns) (Maybe Role)] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated (EpAnn NoEpAnns) (Maybe Role) -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) (Maybe Role)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) (Maybe Role) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [XRec GhcRn (Maybe Role)]
[GenLocated (EpAnn NoEpAnns) (Maybe Role)]
roles
        ]

instance ToHie (LocatedA (InstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (InstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA InstDecl GhcRn
decl SrcSpanAnnA
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 SrcSpanAnnA (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (ClsInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> ClsInstDecl GhcRn -> GenLocated SrcSpanAnnA (ClsInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span ClsInstDecl GhcRn
d
        ]
      DataFamInstD XDataFamInstD GhcRn
_ DataFamInstDecl GhcRn
d ->
        [ GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> DataFamInstDecl GhcRn
-> GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span DataFamInstDecl GhcRn
d
        ]
      TyFamInstD XTyFamInstD GhcRn
_ TyFamInstDecl GhcRn
d ->
        [ GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> TyFamInstDecl GhcRn
-> GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span TyFamInstDecl GhcRn
d
        ]

instance ToHie (LocatedA (ClsInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ClsInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ClsInstDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span]) (GenLocated SrcSpanAnnA (HsSigType GhcRn)
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType 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 (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
 -> HieM [HieAST Type])
-> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBind GhcRn)
 -> BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
-> Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
-> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
forall a b. (a -> b) -> Bag a -> Bag b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBind GhcRn)
-> BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) (Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
 -> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn))))
-> Bag (GenLocated SrcSpanAnnA (HsBind GhcRn))
-> Bag (BindContext (GenLocated SrcSpanAnnA (HsBind GhcRn)))
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> LHsBinds GhcRn
forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds ClsInstDecl GhcRn
decl
    , [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig GhcRn)
 -> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn)))
-> [GenLocated SrcSpanAnnA (Sig GhcRn)]
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> GenLocated SrcSpanAnnA (Sig GhcRn)
 -> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn)))
-> SigInfo
-> GenLocated SrcSpanAnnA (Sig GhcRn)
-> SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe Span -> SigInfo
SI SigType
InstSig (Maybe Span -> SigInfo) -> Maybe Span -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) ([GenLocated SrcSpanAnnA (Sig GhcRn)]
 -> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))])
-> [GenLocated SrcSpanAnnA (Sig GhcRn)]
-> [SigContext (GenLocated SrcSpanAnnA (Sig GhcRn))]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LSig GhcRn]
forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs ClsInstDecl GhcRn
decl
    , (GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) ([GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl 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
    , [GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl 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
    , (GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) ([GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LDataFamInstDecl GhcRn]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , [GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LDataFamInstDecl GhcRn]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (LocatedP OverlapMode) -> HieM [HieAST Type])
-> Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> Maybe (XRec GhcRn OverlapMode)
forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
cid_overlap_mode ClsInstDecl GhcRn
decl
    ]

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

instance ToHie (LocatedA (TyFamInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (TyFamInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
sp (TyFamInstDecl XCTyFamInstDecl GhcRn
_ TyFamInstEqn GhcRn
d)) = TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> TScoped (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
sp]) TyFamInstEqn GhcRn
FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
d

instance HiePass p => ToHie (Context (FieldOcc (GhcPass p))) where
  toHie :: Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
toHie (C ContextInfo
c (FieldOcc XCFieldOcc (GhcPass p)
n (L SrcSpanAnnN
l RdrName
_))) = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
    HiePassEv p
HieTc -> Context (GenLocated SrcSpanAnnN Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo
-> GenLocated SrcSpanAnnN Id -> Context (GenLocated SrcSpanAnnN Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpanAnnN -> Id -> GenLocated SrcSpanAnnN Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l XCFieldOcc (GhcPass p)
Id
n))
    HiePassEv p
HieRn -> Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l XCFieldOcc (GhcPass p)
Name
n))

instance HiePass p => ToHie (PatSynFieldContext (RecordPatSynField (GhcPass p))) where
  toHie :: PatSynFieldContext (RecordPatSynField (GhcPass p))
-> HieM [HieAST Type]
toHie (PSC Maybe Span
sp (RecordPatSynField FieldOcc (GhcPass p)
a LIdP (GhcPass p)
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 (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type])
-> Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> FieldOcc (GhcPass p) -> Context (FieldOcc (GhcPass p))
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
RecFieldDecl Maybe Span
sp) FieldOcc (GhcPass p)
a
    , Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
b
    ]

instance ToHie (LocatedA (DerivDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DerivDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivDecl GhcRn
decl SrcSpanAnnA
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 (XRec GhcRn OverlapMode)
overlap ->
        [ TScoped
  (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> TScoped
     (HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigWcType GhcRn
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
typ
        , Maybe (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe
   (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
 -> HieM [HieAST Type])
-> Maybe
     (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Scope
-> GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)
-> RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
forall a. Scope -> a -> RScoped a
RS (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)
 -> RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
-> Maybe (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
-> Maybe
     (RScoped (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LDerivStrategy GhcRn)
Maybe (GenLocated (EpAnn NoEpAnns) (DerivStrategy GhcRn))
strat)
        , Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (XRec GhcRn OverlapMode)
Maybe (LocatedP OverlapMode)
overlap
        ]

instance ToHie (LocatedA (FixitySig GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FixitySig GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FixitySig GhcRn
sig SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FixitySig GhcRn
sig of
      FixitySig XFixitySig GhcRn
_ [LIdP GhcRn]
vars Fixity
_ ->
        [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP GhcRn]
[LocatedN Name]
vars
        ]

instance ToHie (LocatedA (DefaultDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DefaultDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DefaultDecl GhcRn
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DefaultDecl GhcRn
decl of
      DefaultDecl XCDefaultDecl GhcRn
_ [LHsType GhcRn]
typs ->
        [ [GenLocated SrcSpanAnnA (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
typs
        ]

instance ToHie (LocatedA (ForeignDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ForeignDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA ForeignDecl GhcRn
decl SrcSpanAnnA
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 -> LIdP pass
fd_name = LIdP GhcRn
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fi :: forall pass. ForeignDecl pass -> ForeignImport pass
fd_fi = ForeignImport GhcRn
fi} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
ModuleScope (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP GhcRn
LocatedN Name
name
        , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig
        , ForeignImport GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignImport GhcRn
fi
        ]
      ForeignExport {fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP GhcRn
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport pass
fd_fe = ForeignExport GhcRn
fe} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
name
        , TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TScoped (GenLocated SrcSpanAnnA (HsSigType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig
        , ForeignExport GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignExport GhcRn
fe
        ]

instance ToHie (ForeignImport GhcRn) where
  toHie :: ForeignImport GhcRn -> HieM [HieAST Type]
toHie (CImport (L EpaLocation' [LEpaComment]
c SourceText
_) (L EpaLocation' [LEpaComment]
a CCallConv
_) (L EpaLocation' [LEpaComment]
b Safety
_) Maybe Header
_ CImportSpec
_) = [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
$
    [ EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
a
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
b
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
c
    ]

instance ToHie (ForeignExport GhcRn) where
  toHie :: ForeignExport GhcRn -> HieM [HieAST Type]
toHie (CExport (L EpaLocation' [LEpaComment]
b SourceText
_) (L EpaLocation' [LEpaComment]
a CExportSpec
_)) = [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
$
    [ EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
a
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
b
    ]

instance ToHie (LocatedA (WarnDecls GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (WarnDecls GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA WarnDecls GhcRn
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecls GhcRn
decl of
      Warnings XWarnings GhcRn
_ [LWarnDecl GhcRn]
warnings ->
        [ [GenLocated SrcSpanAnnA (WarnDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LWarnDecl GhcRn]
[GenLocated SrcSpanAnnA (WarnDecl GhcRn)]
warnings
        ]

instance ToHie (LocatedA (WarnDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (WarnDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode WarnDecl GhcRn
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecl GhcRn
decl of
      Warning XWarning GhcRn
_ [LIdP GhcRn]
vars WarningTxt GhcRn
_ ->
        [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP GhcRn]
[LocatedN Name]
vars
        ]

instance ToHie (LocatedA (AnnDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (AnnDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA AnnDecl GhcRn
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case AnnDecl GhcRn
decl of
      HsAnnotation XHsAnnotation GhcRn
_ AnnProvenance GhcRn
prov LHsExpr GhcRn
expr ->
        [ AnnProvenance GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie AnnProvenance GhcRn
prov
        , LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
expr
        ]

instance ToHie (AnnProvenance GhcRn) where
  toHie :: AnnProvenance GhcRn -> HieM [HieAST Type]
toHie (ValueAnnProvenance LIdP GhcRn
a) = Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
a
  toHie (TypeAnnProvenance LIdP GhcRn
a) = Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP GhcRn
LocatedN Name
a
  toHie AnnProvenance GhcRn
ModuleAnnProvenance = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA (RuleDecls GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RuleDecls GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleDecls GhcRn
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleDecls GhcRn
decl of
      HsRules XCRuleDecls GhcRn
_ [LRuleDecl GhcRn]
rules ->
        [ [GenLocated SrcSpanAnnA (RuleDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRuleDecl GhcRn]
[GenLocated SrcSpanAnnA (RuleDecl GhcRn)]
rules
        ]

instance ToHie (LocatedA (RuleDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RuleDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span r :: RuleDecl GhcRn
r@(HsRule XHsRule GhcRn
_ XRec GhcRn 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 -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleDecl GhcRn
r SrcSpanAnnA
span
        , SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type]) -> SrcSpan -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GenLocated (EpAnn NoEpAnns) FastString -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA XRec GhcRn FastString
GenLocated (EpAnn NoEpAnns) FastString
rname
        , Maybe [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
 -> HieM [HieAST Type])
-> Maybe [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
 -> [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))])
-> Maybe [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> Maybe [TVScoped (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TyVarScope
-> Scope
-> [LHsTyVarBndr () GhcRn]
-> [TVScoped (LHsTyVarBndr () GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope) Maybe [LHsTyVarBndr () (NoGhcTc GhcRn)]
Maybe [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
tybndrs
        , [RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))]
 -> HieM [HieAST Type])
-> [RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)
 -> RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)))
-> [GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)]
-> [RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)
-> RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)
 -> RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)))
-> Scope
-> GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)
-> RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) [LRuleBndr GhcRn]
[GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)]
bndrs
        , LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
exprA
        , LocatedA (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcRn
LocatedA (HsExpr 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
-> (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn) -> Scope)
-> Maybe (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope ([GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)]
-> Maybe (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))
forall a. [a] -> Maybe a
listToMaybe [LRuleBndr GhcRn]
[GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn)]
bndrs)
          exprA_sc :: Scope
exprA_sc = LocatedA (HsExpr GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
exprA
          exprB_sc :: Scope
exprB_sc = LocatedA (HsExpr GhcRn) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr GhcRn
LocatedA (HsExpr GhcRn)
exprB

instance ToHie (RScoped (LocatedAn NoEpAnns (RuleBndr GhcRn))) where
  toHie :: RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr GhcRn))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
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 -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleBndr GhcRn
bndr EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleBndr GhcRn
bndr of
      RuleBndr XCRuleBndr GhcRn
_ LIdP GhcRn
var ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe Span
forall a. Maybe a
Nothing) LIdP GhcRn
LocatedN Name
var
        ]
      RuleBndrSig XRuleBndrSig GhcRn
_ LIdP GhcRn
var HsPatSigType GhcRn
typ ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe Span
forall a. Maybe a
Nothing) LIdP GhcRn
LocatedN Name
var
        , TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> HsPatSigType GhcRn -> TScoped (HsPatSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) HsPatSigType GhcRn
typ
        ]

instance ToHie (LocatedA (ImportDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ImportDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ImportDecl GhcRn
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
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 -> XRec pass ModuleName
ideclName = XRec GhcRn ModuleName
name, ideclAs :: forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs = Maybe (XRec GhcRn ModuleName)
as, ideclImportList :: forall pass.
ImportDecl pass
-> Maybe (ImportListInterpretation, XRec pass [LIE pass])
ideclImportList = Maybe (ImportListInterpretation, XRec GhcRn [LIE GhcRn])
hidden } ->
        [ IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA ModuleName)
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Import XRec GhcRn ModuleName
GenLocated SrcSpanAnnA ModuleName
name
        , Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
 -> HieM [HieAST Type])
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA ModuleName
 -> IEContext (GenLocated SrcSpanAnnA ModuleName))
-> Maybe (GenLocated SrcSpanAnnA ModuleName)
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
ImportAs) Maybe (XRec GhcRn ModuleName)
Maybe (GenLocated SrcSpanAnnA ModuleName)
as
        , HieM [HieAST Type]
-> ((ImportListInterpretation,
     GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE GhcRn)])
    -> HieM [HieAST Type])
-> Maybe
     (ImportListInterpretation,
      GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE GhcRn)])
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (ImportListInterpretation,
 GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE GhcRn)])
-> HieM [HieAST Type]
forall {a} {a}.
(HasLoc a, ToHie (IEContext a)) =>
(ImportListInterpretation, GenLocated a [a]) -> HieM [HieAST Type]
goIE Maybe (ImportListInterpretation, XRec GhcRn [LIE GhcRn])
Maybe
  (ImportListInterpretation,
   GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE GhcRn)])
hidden
        ]
    where
      goIE :: (ImportListInterpretation, GenLocated a [a]) -> HieM [HieAST Type]
goIE (ImportListInterpretation
hiding, (L a
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
$
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA a
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
         -- ROMES:TODO: I notice some overlap here with Iface types, eventually
         -- we could join these
         c :: IEType
c = case ImportListInterpretation
hiding of
               ImportListInterpretation
Exactly -> IEType
Import
               ImportListInterpretation
EverythingBut -> IEType
ImportHiding


instance ToHie (IEContext (LocatedA (IE GhcRn))) where
  toHie :: IEContext (GenLocated SrcSpanAnnA (IE GhcRn)) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpanAnnA
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.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode IE GhcRn
ie (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IE GhcRn
ie of
      IEVar XIEVar GhcRn
_ LIEWrappedName GhcRn
n Maybe (LHsDoc GhcRn)
_ ->
        [ IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName GhcRn
GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
n
        ]
      IEThingAbs XIEThingAbs GhcRn
_ LIEWrappedName GhcRn
n Maybe (LHsDoc GhcRn)
_ ->
        [ IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName GhcRn
GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
n
        ]
      IEThingAll XIEThingAll GhcRn
_ LIEWrappedName GhcRn
n Maybe (LHsDoc GhcRn)
_ ->
        [ IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName GhcRn
GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
n
        ]
      IEThingWith XIEThingWith GhcRn
_ LIEWrappedName GhcRn
n IEWildcard
_ [LIEWrappedName GhcRn]
ns Maybe (LHsDoc GhcRn)
_ ->
        [ IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName GhcRn
GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
n
        , [IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))]
 -> HieM [HieAST Type])
-> [IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
 -> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn)))
-> [GenLocated SrcSpanAnnA (IEWrappedName GhcRn)]
-> [IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (IEType
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
-> IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
c) [LIEWrappedName GhcRn]
[GenLocated SrcSpanAnnA (IEWrappedName GhcRn)]
ns
        ]
      IEModuleContents XIEModuleContents GhcRn
_ XRec GhcRn ModuleName
n ->
        [ IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA ModuleName)
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
c XRec GhcRn ModuleName
GenLocated SrcSpanAnnA ModuleName
n
        ]
      IEGroup XIEGroup GhcRn
_ TypeIndex
_ LHsDoc GhcRn
d -> [LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d]
      IEDoc XIEDoc GhcRn
_ LHsDoc GhcRn
d -> [LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d]
      IEDocNamed XIEDocNamed GhcRn
_ FilePath
_ -> []

instance ToHie (IEContext (LocatedA (IEWrappedName GhcRn))) where
  toHie :: IEContext (GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpanAnnA
span IEWrappedName GhcRn
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 GhcRn -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA IEWrappedName GhcRn
iewn SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IEWrappedName GhcRn
iewn of
      IEName XIEName GhcRn
_ (L SrcSpanAnnN
l Name
n) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
n)
        ]
      IEPattern XIEPattern GhcRn
_ (L SrcSpanAnnN
l Name
p) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
p)
        ]
      IEType XIEType GhcRn
_ (L SrcSpanAnnN
l Name
n) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
n)
        ]

instance ToHie (IEContext (Located RecFieldInfo)) where
  toHie :: IEContext (Located RecFieldInfo) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span RecFieldInfo
info)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RecFieldInfo -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode RecFieldInfo
info 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
$ 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 (FieldLabel -> Name
flSelector (FieldLabel -> Name) -> FieldLabel -> Name
forall a b. (a -> b) -> a -> b
$ RecFieldInfo -> FieldLabel
recFieldLabel RecFieldInfo
info)
      ]

instance ToHie (LocatedA (DocDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DocDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span DocDecl GhcRn
d) = [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
$ DocDecl GhcRn -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DocDecl GhcRn
d SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DocDecl GhcRn
d of
    DocCommentNext LHsDoc GhcRn
d -> [ LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d ]
    DocCommentPrev LHsDoc GhcRn
d -> [ LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d ]
    DocCommentNamed FilePath
_ LHsDoc GhcRn
d -> [ LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d ]
    DocGroup TypeIndex
_ LHsDoc GhcRn
d -> [ LHsDoc GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc GhcRn
d ]

instance ToHie (LHsDoc GhcRn) where
  toHie :: LHsDoc GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span d :: HsDoc GhcRn
d@(WithHsDocIdentifiers HsDocString
_ [Located (IdP GhcRn)]
ids)) =
    [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
$ HsDoc GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsDoc GhcRn
d SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [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
$ (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]
ids]