{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE ViewPatterns      #-}


-- | 'annotate' is a function which given a GHC AST fragment, constructs
-- a syntax tree which indicates which annotations belong to each specific
-- part of the fragment.
--
-- "Delta" and "Print" provide two interpreters for this structure. You
-- should probably use those unless you know what you're doing!
--
-- The functor 'AnnotationF' has a number of constructors which correspond
-- to different sitations which annotations can arise. It is hoped that in
-- future versions of GHC these can be simplified by making suitable
-- modifications to the AST.

module Language.Haskell.GHC.ExactPrint.Annotater
       (
         annotate
       , AnnotationF(..)
       , Annotated
       , Annotate(..)
       , withSortKeyContextsHelper
       ) where


import Language.Haskell.GHC.ExactPrint.AnnotateTypes
import Language.Haskell.GHC.ExactPrint.Types
import Language.Haskell.GHC.ExactPrint.Utils

import qualified GHC                     as GHC
import qualified GHC.Core.Class          as GHC
import qualified GHC.Core.Coercion.Axiom as GHC
import qualified GHC.Data.Bag            as GHC
import qualified GHC.Data.BooleanFormula as GHC
import qualified GHC.Data.FastString     as GHC
import qualified GHC.Parser.Annotation   as GHC
import qualified GHC.Types.Basic         as GHC
import qualified GHC.Types.ForeignCall   as GHC
import qualified GHC.Types.Name          as GHC
import qualified GHC.Types.Name.Reader   as GHC
import qualified GHC.Types.SrcLoc        as GHC
import qualified GHC.Types.Var           as GHC
import qualified GHC.Utils.Outputable    as GHC

import Control.Monad.Identity
import Data.Data
import Data.Maybe

import qualified Data.Set as Set

import Debug.Trace


{-# ANN module "HLint: ignore Eta reduce" #-}
{-# ANN module "HLint: ignore Redundant do" #-}
{-# ANN module "HLint: ignore Reduce duplication" #-}
-- ---------------------------------------------------------------------

class Data ast => Annotate ast where
  markAST :: GHC.SrcSpan -> ast -> Annotated ()

-- ---------------------------------------------------------------------

-- | Construct a syntax tree which represent which KeywordIds must appear
-- where.
-- annotate :: (Annotate ast, Data (GHC.SrcSpanLess ast), GHC.HasSrcSpan ast) => ast -> Annotated ()
annotate :: (Annotate ast) => GHC.Located ast -> Annotated ()
annotate :: forall ast. Annotate ast => Located ast -> Annotated ()
annotate = Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated

-- instance Annotate (GHC.SrcSpanLess ast) where
--   markAST s ast = undefined
instance (Data ast, Annotate ast) => Annotate (GHC.Located ast) where
  markAST :: SrcSpan -> Located ast -> Annotated ()
markAST SrcSpan
l (GHC.L SrcSpan
_ ast
ast) = SrcSpan -> ast -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l ast
ast

-- ---------------------------------------------------------------------

-- | Constructs a syntax tree which contains information about which
-- annotations are required by each element.
markLocated :: (Annotate ast) => GHC.Located ast -> Annotated ()
markLocated :: forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
ast =
  case Located ast -> Maybe (LHsDecl GhcPs)
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast Located ast
ast :: Maybe (GHC.LHsDecl GHC.GhcPs) of
    Just LHsDecl GhcPs
d  -> LHsDecl GhcPs -> Annotated ()
markLHsDecl LHsDecl GhcPs
d
    Maybe (LHsDecl GhcPs)
Nothing -> Located ast -> (SrcSpan -> ast -> Annotated ()) -> Annotated ()
forall a.
Data a =>
Located a -> (SrcSpan -> a -> Annotated ()) -> Annotated ()
withLocated Located ast
ast SrcSpan -> ast -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST

-- ---------------------------------------------------------------------

-- |When adding missing annotations, do not put a preceding space in front of a list
markListNoPrecedingSpace :: Annotate ast => Bool -> [GHC.Located ast] -> Annotated ()
markListNoPrecedingSpace :: forall ast. Annotate ast => Bool -> [Located ast] -> Annotated ()
markListNoPrecedingSpace Bool
intercal [Located ast]
ls =
    case [Located ast]
ls of
      [] -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      (Located ast
l:[Located ast]
ls') -> do
        if Bool
intercal
        then do
          if [Located ast] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Located ast]
ls'
            then Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
NoPrecedingSpace            ]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
l
            else Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
NoPrecedingSpace,AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
l
          [Located ast] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located ast]
ls'
        else do
          Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
NoPrecedingSpace) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
l
          (Located ast -> Annotated ()) -> [Located ast] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located ast]
ls'

-- ---------------------------------------------------------------------


-- |Mark a list, with the given keyword as a list item separator
markListIntercalate :: Annotate ast => [GHC.Located ast] -> Annotated ()
markListIntercalate :: forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located ast]
ls = (Located ast -> Annotated ()) -> [Located ast] -> Annotated ()
forall t. (t -> Annotated ()) -> [t] -> Annotated ()
markListIntercalateWithFun Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located ast]
ls

-- ---------------------------------------------------------------------

markListWithContexts :: Annotate ast
  => Set.Set AstContext -> Set.Set AstContext -> [GHC.Located ast] -> Annotated ()
markListWithContexts :: forall ast.
Annotate ast =>
Set AstContext -> Set AstContext -> [Located ast] -> Annotated ()
markListWithContexts Set AstContext
ctxInitial Set AstContext
ctxRest [Located ast]
ls =
  case [Located ast]
ls of
    [] -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    [Located ast
x] -> Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxInitial PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
    (Located ast
x:[Located ast]
xs) -> do
      Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxInitial PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
      Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxRest    PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (Located ast -> Annotated ()) -> [Located ast] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located ast]
xs

-- ---------------------------------------------------------------------

-- Context for only if just one, else first item, middle ones, and last one
markListWithContexts' :: Annotate ast
                      => ListContexts
                      -> [GHC.Located ast] -> Annotated ()
markListWithContexts' :: forall ast.
Annotate ast =>
ListContexts -> [Located ast] -> Annotated ()
markListWithContexts' (LC Set AstContext
ctxOnly Set AstContext
ctxInitial Set AstContext
ctxMiddle Set AstContext
ctxLast) [Located ast]
ls =
  case [Located ast]
ls of
    [] -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    [Located ast
x] -> Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxOnly PhaseNum
level (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
    (Located ast
x:[Located ast]
xs) -> do
      Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxInitial PhaseNum
level (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
      [Located ast] -> Annotated ()
go [Located ast]
xs
  where
    level :: PhaseNum
level = PhaseNum
2
    go :: [Located ast] -> Annotated ()
go []  = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    go [Located ast
x] = Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxLast PhaseNum
level (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
    go (Located ast
x:[Located ast]
xs) = do
      Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel Set AstContext
ctxMiddle PhaseNum
level (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
x
      [Located ast] -> Annotated ()
go [Located ast]
xs


-- ---------------------------------------------------------------------

markListWithLayout :: Annotate ast => [GHC.Located ast] -> Annotated ()
markListWithLayout :: forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [Located ast]
ls =
  Annotated () -> Annotated ()
setLayoutFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located ast] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markList [Located ast]
ls

-- ---------------------------------------------------------------------

markList :: Annotate ast => [GHC.Located ast] -> Annotated ()
markList :: forall ast. Annotate ast => [Located ast] -> Annotated ()
markList [Located ast]
ls =
  Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
NoPrecedingSpace)
   (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ ListContexts -> [Located ast] -> Annotated ()
forall ast.
Annotate ast =>
ListContexts -> [Located ast] -> Annotated ()
markListWithContexts' ListContexts
listContexts' [Located ast]
ls

markLocalBindsWithLayout :: GHC.HsLocalBinds GHC.GhcPs -> Annotated ()
markLocalBindsWithLayout :: HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
binds = HsLocalBinds GhcPs -> Annotated ()
markHsLocalBinds HsLocalBinds GhcPs
binds

-- ---------------------------------------------------------------------

-- |This function is used to get around shortcomings in the GHC AST for 7.10.1
markLocatedFromKw :: (Annotate ast) => GHC.AnnKeywordId -> GHC.Located ast -> Annotated ()
markLocatedFromKw :: forall ast.
Annotate ast =>
AnnKeywordId -> Located ast -> Annotated ()
markLocatedFromKw AnnKeywordId
kw (GHC.L SrcSpan
l ast
a) = do
  -- Note: l is needed so that the pretty printer can make something up
  SrcSpan
ss <- SrcSpan -> AnnKeywordId -> FreeT AnnotationF Identity SrcSpan
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> m SrcSpan
getSrcSpanForKw SrcSpan
l AnnKeywordId
kw
  AnnKey AnnSpan
ss' AnnConName
_ <- SrcSpan -> AnnKey -> FreeT AnnotationF Identity AnnKey
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKey -> m AnnKey
storeOriginalSrcSpan SrcSpan
l (GenLocated SrcSpan ast -> AnnKey
forall a. Data a => Located a -> AnnKey
mkAnnKey (SrcSpan -> ast -> GenLocated SrcSpan ast
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
ss ast
a))
  GenLocated SrcSpan ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> ast -> GenLocated SrcSpan ast
forall l e. l -> e -> GenLocated l e
GHC.L (AnnSpan -> Maybe BufSpan -> SrcSpan
GHC.RealSrcSpan AnnSpan
ss' Maybe BufSpan
forall a. Maybe a
Nothing) ast
a)

-- ---------------------------------------------------------------------

markMaybe :: (Annotate ast) => Maybe (GHC.Located ast) -> Annotated ()
markMaybe :: forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located ast)
Nothing    = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
markMaybe (Just Located ast
ast) = Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
ast

-- ---------------------------------------------------------------------

markTightPrefix :: Annotated () -> Annotated ()
markTightPrefix :: Annotated () -> Annotated ()
markTightPrefix Annotated ()
action = Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InTypeApp) Annotated ()
action

-- ---------------------------------------------------------------------
-- Managing lists which have been separated, e.g. Sigs and Binds

prepareListAnnotation :: Annotate a => [GHC.Located a] -> [(GHC.RealSrcSpan,Annotated ())]
prepareListAnnotation :: forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located a]
ls = (Located a -> (AnnSpan, Annotated ()))
-> [Located a] -> [(AnnSpan, Annotated ())]
forall a b. (a -> b) -> [a] -> [b]
map (\Located a
b -> (SrcSpan -> AnnSpan
rs (SrcSpan -> AnnSpan) -> SrcSpan -> AnnSpan
forall a b. (a -> b) -> a -> b
$ Located a -> SrcSpan
forall l e. GenLocated l e -> l
GHC.getLoc Located a
b,Located a -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located a
b)) [Located a]
ls

-- ---------------------------------------------------------------------

instance Annotate GHC.HsModule where
  markAST :: SrcSpan -> HsModule -> Annotated ()
markAST SrcSpan
_ (GHC.HsModule LayoutInfo
_lo Maybe (Located ModuleName)
mmn Maybe (Located [LIE GhcPs])
mexp [LImportDecl GhcPs]
imps [LHsDecl GhcPs]
decs Maybe (Located WarningTxt)
mdepr Maybe LHsDocString
_haddock) = do

    case Maybe (Located ModuleName)
mmn of
      Maybe (Located ModuleName)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just (GHC.L SrcSpan
ln ModuleName
mn) -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnModule
        SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
ln AnnKeywordId
GHC.AnnVal (ModuleName -> String
GHC.moduleNameString ModuleName
mn)

        Maybe (Located WarningTxt)
-> (Located WarningTxt -> Annotated ()) -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (Located WarningTxt)
mdepr Located WarningTxt -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated
        Maybe (Located [LIE GhcPs])
-> (Located [LIE GhcPs] -> Annotated ()) -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (Located [LIE GhcPs])
mexp Located [LIE GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated

        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere

    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- Possible '{'
    AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
GHC.AnnSemi -- possible leading semis
    Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
TopLevel) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [LImportDecl GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LImportDecl GhcPs]
imps

    Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
TopLevel) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [LHsDecl GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LHsDecl GhcPs]
decs

    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- Possible '}'

    Annotated ()
forall (m :: * -> *). MonadFree AnnotationF m => m ()
markEOF

-- ---------------------------------------------------------------------

instance Annotate GHC.WarningTxt where
  markAST :: SrcSpan -> WarningTxt -> Annotated ()
markAST SrcSpan
_ (GHC.WarningTxt (GHC.L SrcSpan
_ SourceText
txt) [Located StringLiteral]
lss) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
txt String
"{-# WARNING"
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS
    [Located StringLiteral] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located StringLiteral]
lss
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

  markAST SrcSpan
_ (GHC.DeprecatedTxt (GHC.L SrcSpan
_ SourceText
txt) [Located StringLiteral]
lss) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
txt String
"{-# DEPRECATED"
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS
    [Located StringLiteral] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located StringLiteral]
lss
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

-- ---------------------------------------------------------------------

instance Annotate GHC.StringLiteral where
  markAST :: SrcSpan -> StringLiteral -> Annotated ()
markAST SrcSpan
l (GHC.StringLiteral SourceText
src FastString
fs) = do
    SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
l SourceText
src (String -> String
forall a. Show a => a -> String
show (FastString -> String
GHC.unpackFS FastString
fs))
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate (GHC.SourceText,GHC.FastString) where
  markAST :: SrcSpan -> (SourceText, FastString) -> Annotated ()
markAST SrcSpan
l (SourceText
src,FastString
fs) = do
    SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
l SourceText
src (String -> String
forall a. Show a => a -> String
show (FastString -> String
GHC.unpackFS FastString
fs))

-- ---------------------------------------------------------------------

instance Annotate [GHC.LIE GHC.GhcPs] where
   markAST :: SrcSpan -> [LIE GhcPs] -> Annotated ()
markAST SrcSpan
_ [LIE GhcPs]
ls = do
     Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
HasHiding) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnHiding -- in an import decl
     AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
     -- Can't use markListIntercalate, there can be trailing commas, but only in imports.
     (LIE GhcPs -> Annotated ())
-> PhaseNum -> [LIE GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LIE GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LIE GhcPs]
ls

     AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnComma
     AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'

instance Annotate (GHC.IE GHC.GhcPs) where
  markAST :: SrcSpan -> IE GhcPs -> Annotated ()
markAST SrcSpan
_ IE GhcPs
ie = do

    case IE GhcPs
ie of
        GHC.IEVar XIEVar GhcPs
_ LIEWrappedName (IdP GhcPs)
ln -> Located (IEWrappedName RdrName) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIEWrappedName (IdP GhcPs)
Located (IEWrappedName RdrName)
ln

        GHC.IEThingAbs XIEThingAbs GhcPs
_ LIEWrappedName (IdP GhcPs)
ln -> do
          Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (IEWrappedName RdrName) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIEWrappedName (IdP GhcPs)
Located (IEWrappedName RdrName)
ln

        GHC.IEThingWith XIEThingWith GhcPs
_ LIEWrappedName (IdP GhcPs)
ln IEWildcard
wc [LIEWrappedName (IdP GhcPs)]
ns [Located (FieldLbl (IdP GhcPs))]
_lfs -> do
          Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (IEWrappedName RdrName) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIEWrappedName (IdP GhcPs)
Located (IEWrappedName RdrName)
ln
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
          case IEWildcard
wc of
            IEWildcard
GHC.NoIEWildcard ->
              AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp])
                (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located (IEWrappedName RdrName)] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LIEWrappedName (IdP GhcPs)]
[Located (IEWrappedName RdrName)]
ns
            GHC.IEWildcard PhaseNum
n -> do
              Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp,AstContext
Intercalate])
                (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (Located (IEWrappedName RdrName) -> Annotated ())
-> [Located (IEWrappedName RdrName)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (IEWrappedName RdrName) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (PhaseNum
-> [Located (IEWrappedName RdrName)]
-> [Located (IEWrappedName RdrName)]
forall a. PhaseNum -> [a] -> [a]
take PhaseNum
n [LIEWrappedName (IdP GhcPs)]
[Located (IEWrappedName RdrName)]
ns)
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
              case PhaseNum
-> [Located (IEWrappedName RdrName)]
-> [Located (IEWrappedName RdrName)]
forall a. PhaseNum -> [a] -> [a]
drop PhaseNum
n [LIEWrappedName (IdP GhcPs)]
[Located (IEWrappedName RdrName)]
ns of
                [] -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                [Located (IEWrappedName RdrName)]
ns' -> do
                  AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
                  AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp])
                    (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located (IEWrappedName RdrName)] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IEWrappedName RdrName)]
ns'
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP

        (GHC.IEThingAll XIEThingAll GhcPs
_ LIEWrappedName (IdP GhcPs)
ln) -> do
          Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (IEWrappedName RdrName) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIEWrappedName (IdP GhcPs)
Located (IEWrappedName RdrName)
ln
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP

        (GHC.IEModuleContents XIEModuleContents GhcPs
_ (GHC.L SrcSpan
lm ModuleName
mn)) -> do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnModule
          SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
lm AnnKeywordId
GHC.AnnVal (ModuleName -> String
GHC.moduleNameString ModuleName
mn)

        -- Only used in Haddock mode so we can ignore them.
        (GHC.IEGroup {})    -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

        (GHC.IEDoc {})      -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

        (GHC.IEDocNamed {}) -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate])
      (AnnKeywordId -> Annotated ()
mark         AnnKeywordId
GHC.AnnComma)
      (AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnComma)

-- ---------------------------------------------------------------------

instance Annotate (GHC.IEWrappedName GHC.RdrName) where
  markAST :: SrcSpan -> IEWrappedName RdrName -> Annotated ()
markAST SrcSpan
_ (GHC.IEName Located RdrName
ln) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp])
      (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
  markAST SrcSpan
_ (GHC.IEPattern Located RdrName
ln) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnPattern
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
  markAST SrcSpan
_ (GHC.IEType Located RdrName
ln) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

isSymRdr :: GHC.RdrName -> Bool
isSymRdr :: RdrName -> Bool
isSymRdr RdrName
n = OccName -> Bool
GHC.isSymOcc (RdrName -> OccName
GHC.rdrNameOcc RdrName
n) Bool -> Bool -> Bool
|| RdrName -> String
rdrName2String RdrName
n String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"."

instance Annotate GHC.RdrName where
  markAST :: SrcSpan -> RdrName -> Annotated ()
markAST SrcSpan
l RdrName
n = do
    let
      str :: String
str = RdrName -> String
rdrName2String RdrName
n
      isSym :: Bool
isSym = RdrName -> Bool
isSymRdr RdrName
n
      doNormalRdrName :: Annotated ()
doNormalRdrName = do
        let str' :: String
str' = case String
str of
              -- TODO: unicode support?
                        String
"forall" -> if SrcSpan -> PhaseNum
spanLength SrcSpan
l PhaseNum -> PhaseNum -> Bool
forall a. Eq a => a -> a -> Bool
== PhaseNum
1 then String
"∀" else String
str
                        String
_ -> String
str

        let
          markParen :: GHC.AnnKeywordId -> Annotated ()
          markParen :: AnnKeywordId -> Annotated ()
markParen AnnKeywordId
pa = do
            if Bool
isSym
              then Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
PrefixOp,AstContext
PrefixOpDollar])
                                       (AnnKeywordId -> Annotated ()
mark         AnnKeywordId
pa) -- '('
                                       (AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
pa)
              else AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
pa

        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnSimpleQuote
        AnnKeywordId -> Annotated ()
markParen AnnKeywordId
GHC.AnnOpenP
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
isSym (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InfixOp]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnBackquote PhaseNum
0
        PhaseNum
cnt  <- AnnKeywordId -> FreeT AnnotationF Identity PhaseNum
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m PhaseNum
countAnns AnnKeywordId
GHC.AnnVal
        case PhaseNum
cnt of
          PhaseNum
0 -> SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
str'
          PhaseNum
1 -> AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnVal String
str'
          PhaseNum
_ -> String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM (String -> Annotated ()) -> String -> Annotated ()
forall a b. (a -> b) -> a -> b
$ String
"Printing RdrName, more than 1 AnnVal:" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (SrcSpan, RdrName) -> String
forall a. Outputable a => a -> String
showGhc (SrcSpan
l,RdrName
n)
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
isSym (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InfixOp]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnBackquote PhaseNum
1
        AnnKeywordId -> Annotated ()
markParen AnnKeywordId
GHC.AnnCloseP

    case RdrName
n of
      GHC.Unqual OccName
_ -> Annotated ()
doNormalRdrName
      GHC.Qual ModuleName
_ OccName
_ -> Annotated ()
doNormalRdrName
      GHC.Orig Module
_ OccName
_ -> if String
str String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"~"
                        then Annotated ()
doNormalRdrName
                        -- then error $ "GHC.orig:(isSym,canParen)=" ++ show (isSym,canParen)
                        else SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
str
      GHC.Exact Name
n'  -> do
       case String
str of
         -- Special handling for Exact RdrNames, which are built-in Names
         String
"[]" -> do
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS  -- '['
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'
         String
"()" -> do
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP  -- '('
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
         (Char
'(':Char
'#':String
_) -> do
           AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen  String
"(#" -- '(#'
           let cnt :: PhaseNum
cnt = String -> PhaseNum
forall (t :: * -> *) a. Foldable t => t a -> PhaseNum
length (String -> PhaseNum) -> String -> PhaseNum
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
',') String
str
           PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ PhaseNum
cnt (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCommaTuple)
           AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose  String
"#)"-- '#)'
         String
"[::]" -> do
           AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen  String
"[:" -- '[:'
           AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
":]" -- ':]'
         String
"->" -> do
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
         String
"~"  -> do
           Annotated ()
doNormalRdrName
         String
"*"  -> do
           SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
str
         String
"★"  -> do -- Note: unicode star
           SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
str
         String
":"  -> do
           -- Note: The OccName for ":" has the following attributes (via occAttributes)
           -- (d, Data DataSym Sym Val )
           -- consDataConName   = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon
           Annotated ()
doNormalRdrName
           -- trace ("RdrName.checking :" ++ (occAttributes $ GHC.occName n)) doNormalRdrName
         (Char
'(':Char
',':String
_) -> do
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
           let cnt :: PhaseNum
cnt = String -> PhaseNum
forall (t :: * -> *) a. Foldable t => t a -> PhaseNum
length (String -> PhaseNum) -> String -> PhaseNum
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
',') String
str
           PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ PhaseNum
cnt (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCommaTuple)
           AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
         String
_ -> do
            let isSym' :: Bool
isSym' = RdrName -> Bool
isSymRdr  (Name -> RdrName
GHC.nameRdrName Name
n')
            Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isSym' (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
            AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnVal String
str
            Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isSym (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma Annotated () -> String -> Annotated ()
forall c. c -> String -> c
`debug` (String
"AnnComma in RdrName")

-- ---------------------------------------------------------------------

instance Annotate (GHC.ImportDecl GHC.GhcPs) where
 markAST :: SrcSpan -> ImportDecl GhcPs -> Annotated ()
markAST SrcSpan
_ imp :: ImportDecl GhcPs
imp@(GHC.ImportDecl XCImportDecl GhcPs
_ SourceText
msrc Located ModuleName
modname Maybe StringLiteral
mpkg IsBootInterface
_src Bool
safeflag ImportDeclQualifiedStyle
qualFlag Bool
_impl Maybe (Located ModuleName)
_as Maybe (Bool, Located [LIE GhcPs])
hiding) = do

   -- 'import' maybe_src maybe_safe optqualified maybe_pkg modid maybeas maybeimpspec
   AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnImport

   -- "{-# SOURCE" and "#-}"
   case SourceText
msrc of
     GHC.SourceText String
_txt -> do
       SourceText -> String -> Annotated ()
markAnnOpen SourceText
msrc String
"{-# SOURCE"
       AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
     SourceText
GHC.NoSourceText -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
   Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
safeflag (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSafe)
   case ImportDeclQualifiedStyle
qualFlag of
     ImportDeclQualifiedStyle
GHC.QualifiedPre  -- 'qualified' appears in prepositive position.
       -> (AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
TopLevel (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnQualified)
     ImportDeclQualifiedStyle
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
   case Maybe StringLiteral
mpkg of
    Just (GHC.StringLiteral (GHC.SourceText String
srcPkg) FastString
_) ->
      AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnPackageName String
srcPkg
    Maybe StringLiteral
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

   Located ModuleName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ModuleName
modname

   case ImportDeclQualifiedStyle
qualFlag of
     ImportDeclQualifiedStyle
GHC.QualifiedPost -- 'qualified' appears in postpositive position.
       -> (AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
TopLevel (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnQualified)
     ImportDeclQualifiedStyle
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

   case ImportDecl GhcPs -> Maybe (Located ModuleName)
forall pass. ImportDecl pass -> Maybe (Located ModuleName)
GHC.ideclAs ImportDecl GhcPs
imp of
      Maybe (Located ModuleName)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just Located ModuleName
mn -> do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnAs
          Located ModuleName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ModuleName
mn

   case Maybe (Bool, Located [LIE GhcPs])
hiding of
     Maybe (Bool, Located [LIE GhcPs])
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     Just (Bool
isHiding,Located [LIE GhcPs]
lie) -> do
       if Bool
isHiding
         then Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
HasHiding) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
                Located [LIE GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LIE GhcPs]
lie
         else Located [LIE GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LIE GhcPs]
lie
   Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate GHC.ModuleName where
   markAST :: SrcSpan -> ModuleName -> Annotated ()
markAST SrcSpan
l ModuleName
mname =
    SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (ModuleName -> String
GHC.moduleNameString ModuleName
mname)

-- ---------------------------------------------------------------------

markLHsDecl :: GHC.LHsDecl GHC.GhcPs -> Annotated ()
markLHsDecl :: LHsDecl GhcPs -> Annotated ()
markLHsDecl (GHC.L SrcSpan
l HsDecl GhcPs
decl) =
    case HsDecl GhcPs
decl of
      GHC.TyClD XTyClD GhcPs
_ TyClDecl GhcPs
d       -> Located (TyClDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> TyClDecl GhcPs -> Located (TyClDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l TyClDecl GhcPs
d)
      GHC.InstD XInstD GhcPs
_ InstDecl GhcPs
d       -> Located (InstDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> InstDecl GhcPs -> Located (InstDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l InstDecl GhcPs
d)
      GHC.DerivD XDerivD GhcPs
_ DerivDecl GhcPs
d      -> Located (DerivDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> DerivDecl GhcPs -> Located (DerivDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l DerivDecl GhcPs
d)
      GHC.ValD XValD GhcPs
_ HsBind GhcPs
d        -> Located (HsBind GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> HsBind GhcPs -> Located (HsBind GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l HsBind GhcPs
d)
      GHC.SigD XSigD GhcPs
_ Sig GhcPs
d        -> Located (Sig GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> Sig GhcPs -> Located (Sig GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l Sig GhcPs
d)
      GHC.KindSigD XKindSigD GhcPs
_ StandaloneKindSig GhcPs
d    -> Located (StandaloneKindSig GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan
-> StandaloneKindSig GhcPs -> Located (StandaloneKindSig GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l StandaloneKindSig GhcPs
d)
      GHC.DefD XDefD GhcPs
_ DefaultDecl GhcPs
d        -> Located (DefaultDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> DefaultDecl GhcPs -> Located (DefaultDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l DefaultDecl GhcPs
d)
      GHC.ForD XForD GhcPs
_ ForeignDecl GhcPs
d        -> Located (ForeignDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> ForeignDecl GhcPs -> Located (ForeignDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l ForeignDecl GhcPs
d)
      GHC.WarningD XWarningD GhcPs
_ WarnDecls GhcPs
d    -> Located (WarnDecls GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> WarnDecls GhcPs -> Located (WarnDecls GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l WarnDecls GhcPs
d)
      GHC.AnnD XAnnD GhcPs
_ AnnDecl GhcPs
d        -> Located (AnnDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> AnnDecl GhcPs -> Located (AnnDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l AnnDecl GhcPs
d)
      GHC.RuleD XRuleD GhcPs
_ RuleDecls GhcPs
d       -> Located (RuleDecls GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> RuleDecls GhcPs -> Located (RuleDecls GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l RuleDecls GhcPs
d)
      GHC.SpliceD XSpliceD GhcPs
_ SpliceDecl GhcPs
d     -> Located (SpliceDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> SpliceDecl GhcPs -> Located (SpliceDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l SpliceDecl GhcPs
d)
      GHC.DocD XDocD GhcPs
_ DocDecl
d        -> Located DocDecl -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> DocDecl -> Located DocDecl
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l DocDecl
d)
      GHC.RoleAnnotD XRoleAnnotD GhcPs
_ RoleAnnotDecl GhcPs
d  -> Located (RoleAnnotDecl GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> RoleAnnotDecl GhcPs -> Located (RoleAnnotDecl GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l RoleAnnotDecl GhcPs
d)

instance Annotate (GHC.HsDecl GHC.GhcPs) where
  markAST :: SrcSpan -> HsDecl GhcPs -> Annotated ()
markAST SrcSpan
l HsDecl GhcPs
d = LHsDecl GhcPs -> Annotated ()
markLHsDecl (SrcSpan -> HsDecl GhcPs -> LHsDecl GhcPs
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l HsDecl GhcPs
d)

-- ---------------------------------------------------------------------

instance Annotate (GHC.RoleAnnotDecl GHC.GhcPs) where
  markAST :: SrcSpan -> RoleAnnotDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.RoleAnnotDecl XCRoleAnnotDecl GhcPs
_ Located (IdP GhcPs)
ln [Located (Maybe Role)]
mr) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRole
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    (Located (Maybe Role) -> Annotated ())
-> [Located (Maybe Role)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (Maybe Role) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (Maybe Role)]
mr

instance Annotate (Maybe GHC.Role) where
  markAST :: SrcSpan -> Maybe Role -> Annotated ()
markAST SrcSpan
l Maybe Role
Nothing  = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"_"
  markAST SrcSpan
l (Just Role
r) = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (FastString -> String
GHC.unpackFS (FastString -> String) -> FastString -> String
forall a b. (a -> b) -> a -> b
$ Role -> FastString
GHC.fsFromRole Role
r)

-- ---------------------------------------------------------------------

instance Annotate (GHC.SpliceDecl GHC.GhcPs) where
  markAST :: SrcSpan -> SpliceDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.SpliceDecl XSpliceDecl GhcPs
_ e :: Located (HsSplice GhcPs)
e@(GHC.L SrcSpan
_ (GHC.HsQuasiQuote{})) SpliceExplicitFlag
_flag) = do
    Located (HsSplice GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsSplice GhcPs)
e
    Annotated ()
markTrailingSemi
  markAST SrcSpan
_ (GHC.SpliceDecl XSpliceDecl GhcPs
_ Located (HsSplice GhcPs)
e SpliceExplicitFlag
_flag) = do
    Located (HsSplice GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsSplice GhcPs)
e
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.RuleDecls GHC.GhcPs) where
  markAST :: SrcSpan -> RuleDecls GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsRules XCRuleDecls GhcPs
_ SourceText
src [LRuleDecl GhcPs]
rules) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# RULES"
    Annotated () -> Annotated ()
setLayoutFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (LRuleDecl GhcPs -> Annotated ())
-> PhaseNum -> [LRuleDecl GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LRuleDecl GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LRuleDecl GhcPs]
rules
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.RuleDecl GHC.GhcPs) where
  markAST :: SrcSpan -> RuleDecl GhcPs -> Annotated ()
markAST SrcSpan
l (GHC.HsRule XHsRule GhcPs
_ Located (SourceText, FastString)
ln Activation
act Maybe [LHsTyVarBndr () (NoGhcTc GhcPs)]
mtybndrs [LRuleBndr GhcPs]
termbndrs Located (HsExpr GhcPs)
lhs Located (HsExpr GhcPs)
rhs) = do
    Located (SourceText, FastString) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (SourceText, FastString)
ln
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
ExplicitNeverActive) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Activation -> Annotated ()
markActivation SrcSpan
l Activation
act

    case Maybe [LHsTyVarBndr () (NoGhcTc GhcPs)]
mtybndrs of
      Maybe [LHsTyVarBndr () (NoGhcTc GhcPs)]
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just [LHsTyVarBndr () (NoGhcTc GhcPs)]
bndrs -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
        (Located (HsTyVarBndr () GhcPs) -> Annotated ())
-> [Located (HsTyVarBndr () GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (HsTyVarBndr () GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsTyVarBndr () (NoGhcTc GhcPs)]
[Located (HsTyVarBndr () GhcPs)]
bndrs
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot

    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
    (LRuleBndr GhcPs -> Annotated ())
-> [LRuleBndr GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LRuleBndr GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LRuleBndr GhcPs]
termbndrs
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot

    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
lhs
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
rhs
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSemi
    Annotated ()
markTrailingSemi
{-
  = HsRule -- Source rule
       { rd_ext  :: XHsRule pass
           -- ^ After renamer, free-vars from the LHS and RHS
       , rd_name :: Located (SourceText,RuleName)
           -- ^ Note [Pragma source text] in BasicTypes
       , rd_act  :: Activation
       , rd_tyvs :: Maybe [LHsTyVarBndr (NoGhcTc pass)]
           -- ^ Forall'd type vars
       , rd_tmvs :: [LRuleBndr pass]
           -- ^ Forall'd term vars, before typechecking; after typechecking
           --    this includes all forall'd vars
       , rd_lhs  :: Located (HsExpr pass)
       , rd_rhs  :: Located (HsExpr pass)
       }

-}

-- ---------------------------------------------------------------------

markActivation :: GHC.SrcSpan -> GHC.Activation -> Annotated ()
markActivation :: SrcSpan -> Activation -> Annotated ()
markActivation SrcSpan
_ Activation
act = do
  case Activation
act of
    GHC.ActiveBefore SourceText
src PhaseNum
phase -> do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS --  '['
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnTilde -- ~
      SourceText -> String -> Annotated ()
markSourceText SourceText
src (PhaseNum -> String
forall a. Show a => a -> String
show PhaseNum
phase)
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'
    GHC.ActiveAfter SourceText
src PhaseNum
phase -> do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS --  '['
      SourceText -> String -> Annotated ()
markSourceText SourceText
src (PhaseNum -> String
forall a. Show a => a -> String
show PhaseNum
phase)
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'
    Activation
GHC.NeverActive -> do
      Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
ExplicitNeverActive) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS --  '['
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnTilde -- ~
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'
    Activation
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- ---------------------------------------------------------------------

instance Annotate (GHC.RuleBndr GHC.GhcPs) where
{-
  = RuleBndr (XCRuleBndr pass)  (Located (IdP pass))
  | RuleBndrSig (XRuleBndrSig pass) (Located (IdP pass)) (HsPatSigType pass)
-}
  markAST :: SrcSpan -> RuleBndr GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.RuleBndr XCRuleBndr GhcPs
_ Located (IdP GhcPs)
ln) = Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
  markAST SrcSpan
_ (GHC.RuleBndrSig XRuleBndrSig GhcPs
_ Located (IdP GhcPs)
ln (GHC.HsPS XHsPS GhcPs
_ LBangType GhcPs
ty)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- "("
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ")"

-- ---------------------------------------------------------------------

markLHsSigWcType :: GHC.LHsSigWcType GHC.GhcPs -> Annotated ()
markLHsSigWcType :: LHsSigWcType GhcPs -> Annotated ()
markLHsSigWcType (GHC.HsWC XHsWC GhcPs (LHsSigType GhcPs)
_ (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
ty)) = do
  LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty

-- ---------------------------------------------------------------------

instance Annotate (GHC.AnnDecl GHC.GhcPs) where
   markAST :: SrcSpan -> AnnDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsAnnotation XHsAnnotation GhcPs
_ SourceText
src AnnProvenance (IdP GhcPs)
prov Located (HsExpr GhcPs)
e) = do
     SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# ANN"
     case AnnProvenance (IdP GhcPs)
prov of
       (GHC.ValueAnnProvenance Located (IdP GhcPs)
n) -> Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n
       (GHC.TypeAnnProvenance Located (IdP GhcPs)
n) -> do
         AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType
         Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n
       AnnProvenance (IdP GhcPs)
GHC.ModuleAnnProvenance -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnModule

     Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
     AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
     Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.WarnDecls GHC.GhcPs) where
   markAST :: SrcSpan -> WarnDecls GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.Warnings XWarnings GhcPs
_ SourceText
src [LWarnDecl GhcPs]
warns) = do
     SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# WARNING" -- Note: might be {-# DEPRECATED
     (LWarnDecl GhcPs -> Annotated ())
-> [LWarnDecl GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LWarnDecl GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LWarnDecl GhcPs]
warns
     AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

-- ---------------------------------------------------------------------

instance Annotate (GHC.WarnDecl GHC.GhcPs) where
   markAST :: SrcSpan -> WarnDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.Warning XWarning GhcPs
_ [Located (IdP GhcPs)]
lns WarningTxt
txt) = do
     [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
lns
     AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS -- "["
     case WarningTxt
txt of
       GHC.WarningTxt    GenLocated SrcSpan SourceText
_src [Located StringLiteral]
ls -> [Located StringLiteral] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located StringLiteral]
ls
       GHC.DeprecatedTxt GenLocated SrcSpan SourceText
_src [Located StringLiteral]
ls -> [Located StringLiteral] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located StringLiteral]
ls
     AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- "]"

instance Annotate GHC.FastString where
  -- TODO: https://ghc.haskell.org/trac/ghc/ticket/10313 applies.
  markAST :: SrcSpan -> FastString -> Annotated ()
markAST SrcSpan
l FastString
fs = do
    SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (String -> String
forall a. Show a => a -> String
show (FastString -> String
GHC.unpackFS FastString
fs))
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate (GHC.ForeignDecl GHC.GhcPs) where
  markAST :: SrcSpan -> ForeignDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.ForeignImport XForeignImport GhcPs
_ Located (IdP GhcPs)
ln (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ)
               (GHC.CImport Located CCallConv
cconv safety :: Located Safety
safety@(GHC.L SrcSpan
ll Safety
_) Maybe Header
_mh CImportSpec
_imp (GHC.L SrcSpan
ls SourceText
src))) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForeign
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnImport
    Located CCallConv -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located CCallConv
cconv
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (SrcSpan
ll SrcSpan -> SrcSpan -> Bool
forall a. Eq a => a -> a -> Bool
== SrcSpan
GHC.noSrcSpan) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located Safety -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located Safety
safety
    SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
ls SourceText
src String
""
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_l (GHC.ForeignExport XForeignExport GhcPs
_ Located (IdP GhcPs)
ln (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ) (GHC.CExport Located CExportSpec
spec (GHC.L SrcSpan
ls SourceText
src))) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForeign
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnExport
    Located CExportSpec -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located CExportSpec
spec
    SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
ls AnnKeywordId
GHC.AnnVal (SourceText -> String -> String
sourceTextToString SourceText
src String
"")
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ

-- ---------------------------------------------------------------------

instance (Annotate GHC.CExportSpec) where
  markAST :: SrcSpan -> CExportSpec -> Annotated ()
markAST SrcSpan
l (GHC.CExportStatic SourceText
_src FastString
_ CCallConv
cconv) = SrcSpan -> CCallConv -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l CCallConv
cconv

-- ---------------------------------------------------------------------

instance (Annotate GHC.CCallConv) where
  markAST :: SrcSpan -> CCallConv -> Annotated ()
markAST SrcSpan
l CCallConv
GHC.StdCallConv        =  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"stdcall"
  markAST SrcSpan
l CCallConv
GHC.CCallConv          =  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"ccall"
  markAST SrcSpan
l CCallConv
GHC.CApiConv           =  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"capi"
  markAST SrcSpan
l CCallConv
GHC.PrimCallConv       =  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"prim"
  markAST SrcSpan
l CCallConv
GHC.JavaScriptCallConv =  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"javascript"

-- ---------------------------------------------------------------------

instance (Annotate GHC.Safety) where
  markAST :: SrcSpan -> Safety -> Annotated ()
markAST SrcSpan
l Safety
GHC.PlayRisky         = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"unsafe"
  markAST SrcSpan
l Safety
GHC.PlaySafe          = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"safe"
  markAST SrcSpan
l Safety
GHC.PlayInterruptible = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"interruptible"

-- ---------------------------------------------------------------------

instance Annotate (GHC.DerivDecl GHC.GhcPs) where

  markAST :: SrcSpan -> DerivDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.DerivDecl XCDerivDecl GhcPs
_ (GHC.HsWC XHsWC GhcPs (LHsSigType GhcPs)
_ (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ)) Maybe (LDerivStrategy GhcPs)
ms Maybe (Located OverlapMode)
mov) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDeriving
    Maybe (LDerivStrategy GhcPs) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (LDerivStrategy GhcPs)
ms
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnInstance
    Maybe (Located OverlapMode) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located OverlapMode)
mov
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    Annotated ()
markTrailingSemi

{-
data DerivDecl pass = DerivDecl
        { deriv_ext          :: XCDerivDecl pass
        , deriv_type         :: LHsSigWcType pass
          -- ^ The instance type to derive.
          --
          -- It uses an 'LHsSigWcType' because the context is allowed to be a
          -- single wildcard:
          --
          -- > deriving instance _ => Eq (Foo a)
          --
          -- Which signifies that the context should be inferred.

          -- See Note [Inferring the instance context] in TcDerivInfer.

        , deriv_strategy     :: Maybe (LDerivStrategy pass)
        , deriv_overlap_mode :: Maybe (Located OverlapMode)

type LHsSigWcType pass = HsWildCardBndrs pass (LHsSigType pass) -- Both

data HsWildCardBndrs pass thing
    -- See Note [HsType binders]
    -- See Note [The wildcard story for types]
  = HsWC { hswc_ext :: XHsWC pass thing
                -- after the renamer
                -- Wild cards, both named and anonymous

         , hswc_body :: thing
                -- Main payload (type or list of types)
                -- If there is an extra-constraints wildcard,
                -- it's still there in the hsc_body.
    }


-}

-- ---------------------------------------------------------------------

instance Annotate (GHC.DerivStrategy GHC.GhcPs) where

  markAST :: SrcSpan -> DerivStrategy GhcPs -> Annotated ()
markAST SrcSpan
_ DerivStrategy GhcPs
GHC.StockStrategy    = AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnStock
  markAST SrcSpan
_ DerivStrategy GhcPs
GHC.AnyclassStrategy = AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnAnyclass
  markAST SrcSpan
_ DerivStrategy GhcPs
GHC.NewtypeStrategy  = AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnNewtype
  markAST SrcSpan
_ (GHC.ViaStrategy (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
ty)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVia
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty

-- ---------------------------------------------------------------------

instance Annotate (GHC.DefaultDecl GHC.GhcPs) where

  markAST :: SrcSpan -> DefaultDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.DefaultDecl XCDefaultDecl GhcPs
_ HsContext GhcPs
typs) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDefault
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
    HsContext GhcPs -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate HsContext GhcPs
typs
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.InstDecl GHC.GhcPs) where

  markAST :: SrcSpan -> InstDecl GhcPs -> Annotated ()
markAST SrcSpan
l (GHC.ClsInstD     XClsInstD GhcPs
_  ClsInstDecl GhcPs
cid) = SrcSpan -> ClsInstDecl GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l  ClsInstDecl GhcPs
cid
  markAST SrcSpan
l (GHC.DataFamInstD XDataFamInstD GhcPs
_ DataFamInstDecl GhcPs
dfid) = SrcSpan -> DataFamInstDecl GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l DataFamInstDecl GhcPs
dfid
  markAST SrcSpan
l (GHC.TyFamInstD   XTyFamInstD GhcPs
_ TyFamInstDecl GhcPs
tfid) = SrcSpan -> TyFamInstDecl GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l TyFamInstDecl GhcPs
tfid

-- ---------------------------------------------------------------------

instance Annotate GHC.OverlapMode where

  -- NOTE: NoOverlap is only used in the typechecker
  markAST :: SrcSpan -> OverlapMode -> Annotated ()
markAST SrcSpan
_ (GHC.NoOverlap SourceText
src) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# NO_OVERLAP"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

  markAST SrcSpan
_ (GHC.Overlappable SourceText
src) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# OVERLAPPABLE"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

  markAST SrcSpan
_ (GHC.Overlapping SourceText
src) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# OVERLAPPING"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

  markAST SrcSpan
_ (GHC.Overlaps SourceText
src) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# OVERLAPS"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

  markAST SrcSpan
_ (GHC.Incoherent SourceText
src) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# INCOHERENT"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

-- ---------------------------------------------------------------------

instance Annotate (GHC.ClsInstDecl GHC.GhcPs) where

  markAST :: SrcSpan -> ClsInstDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.ClsInstDecl XCClsInstDecl GhcPs
_ (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
poly) LHsBinds GhcPs
binds [Located (Sig GhcPs)]
sigs [LTyFamInstDecl GhcPs]
tyfams [LDataFamInstDecl GhcPs]
datafams Maybe (Located OverlapMode)
mov) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnInstance
    Maybe (Located OverlapMode) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located OverlapMode)
mov
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
poly
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
    AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi

    [(AnnSpan, Annotated ())] -> Annotated ()
applyListAnnotationsLayout ([Located (HsBind GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation (LHsBinds GhcPs -> [Located (HsBind GhcPs)]
forall a. Bag a -> [a]
GHC.bagToList LHsBinds GhcPs
binds)
                             [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [Located (Sig GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located (Sig GhcPs)]
sigs
                             [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [LTyFamInstDecl GhcPs] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [LTyFamInstDecl GhcPs]
tyfams
                             [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [LDataFamInstDecl GhcPs] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [LDataFamInstDecl GhcPs]
datafams
                               )

    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- '}'
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.TyFamInstDecl GHC.GhcPs) where
{-
newtype TyFamInstDecl pass = TyFamInstDecl { tfid_eqn :: TyFamInstEqn pass }

type TyFamInstEqn pass = FamInstEqn pass (LHsType pass)

type FamInstEqn pass rhs
  = HsImplicitBndrs pass (FamEqn pass (HsTyPats pass) rhs)


-}
  markAST :: SrcSpan -> TyFamInstDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.TyFamInstDecl (GHC.HsIB XHsIB GhcPs (FamEqn GhcPs (LBangType GhcPs))
_ FamEqn GhcPs (LBangType GhcPs)
eqn)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnInstance -- Note: this keyword is optional
    FamEqn GhcPs (LBangType GhcPs) -> Annotated ()
markFamEqn FamEqn GhcPs (LBangType GhcPs)
eqn
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

-- markFamEqn :: (GHC.HasOccName (GHC.IdP pass),
--                Annotate (GHC.IdP pass), Annotate ast1, Annotate ast2)
--            => GHC.FamEqn pass [GHC.Located ast1] (GHC.Located ast2)
--                     -> Annotated ()
-- markFamEqn :: GHC.FamEqn GhcPs [GHC.LHsTypeArg GhcPs] (GHC.LHsType GHC.GhcPs)
markFamEqn :: GHC.FamEqn GhcPs (GHC.LHsType GHC.GhcPs)
           -> Annotated ()
markFamEqn :: FamEqn GhcPs (LBangType GhcPs) -> Annotated ()
markFamEqn (GHC.FamEqn XCFamEqn GhcPs (LBangType GhcPs)
_ Located (IdP GhcPs)
ln Maybe [Located (HsTyVarBndr () GhcPs)]
bndrs HsTyPats GhcPs
pats LexicalFixity
fixity LBangType GhcPs
rhs) = do
  Maybe [Located (HsTyVarBndr () GhcPs)]
-> LexicalFixity
-> Located RdrName
-> HsTyPats GhcPs
-> Annotated ()
forall a flag.
(Annotate a, Data flag) =>
Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity -> Located a -> HsTyPats GhcPs -> Annotated ()
markTyClassArgs Maybe [Located (HsTyVarBndr () GhcPs)]
bndrs LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln HsTyPats GhcPs
pats
  AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
  LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
rhs
{-
data FamEqn pass pats rhs
  = FamEqn
       { feqn_ext    :: XCFamEqn pass pats rhs
       , feqn_tycon  :: Located (IdP pass)
       , feqn_bndrs  :: Maybe [LHsTyVarBndr pass] -- ^ Optional quantified type vars
       , feqn_pats   :: pats
       , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration
       , feqn_rhs    :: rhs
       }
-}

-- ---------------------------------------------------------------------

instance Annotate (GHC.DataFamInstDecl GHC.GhcPs) where

  markAST :: SrcSpan -> DataFamInstDecl GhcPs -> Annotated ()
markAST SrcSpan
l (GHC.DataFamInstDecl (GHC.HsIB XHsIB GhcPs (FamEqn GhcPs (HsDataDefn GhcPs))
_ (GHC.FamEqn XCFamEqn GhcPs (HsDataDefn GhcPs)
_ Located (IdP GhcPs)
ln Maybe [Located (HsTyVarBndr () GhcPs)]
bndrs HsTyPats GhcPs
pats LexicalFixity
fixity
             defn :: HsDataDefn GhcPs
defn@(GHC.HsDataDefn XCHsDataDefn GhcPs
_ NewOrData
nd LHsContext GhcPs
ctx Maybe (Located CType)
typ Maybe (LBangType GhcPs)
_mk [LConDecl GhcPs]
cons HsDeriving GhcPs
mderivs) ))) = do
    case HsDataDefn GhcPs -> NewOrData
forall pass. HsDataDefn pass -> NewOrData
GHC.dd_ND HsDataDefn GhcPs
defn of
      NewOrData
GHC.NewType  -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnNewtype
      NewOrData
GHC.DataType -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnData
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnInstance

    LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
ctx

    Maybe [Located (HsTyVarBndr () GhcPs)]
-> LexicalFixity
-> Located RdrName
-> HsTyPats GhcPs
-> Annotated ()
forall a flag.
(Annotate a, Data flag) =>
Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity -> Located a -> HsTyPats GhcPs -> Annotated ()
markTyClassArgs Maybe [Located (HsTyVarBndr () GhcPs)]
bndrs LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln HsTyPats GhcPs
pats

    case (HsDataDefn GhcPs -> Maybe (LBangType GhcPs)
forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
GHC.dd_kindSig HsDataDefn GhcPs
defn) of
      Just LBangType GhcPs
s -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
s
      Maybe (LBangType GhcPs)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    if [LConDecl GhcPs] -> Bool
forall name. [LConDecl name] -> Bool
isGadt ([LConDecl GhcPs] -> Bool) -> [LConDecl GhcPs] -> Bool
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcPs -> [LConDecl GhcPs]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons HsDataDefn GhcPs
defn
      then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
      else Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([LConDecl GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LConDecl GhcPs]
cons) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
    SrcSpan -> HsDataDefn GhcPs -> Annotated ()
markDataDefn SrcSpan
l (XCHsDataDefn GhcPs
-> NewOrData
-> LHsContext GhcPs
-> Maybe (Located CType)
-> Maybe (LBangType GhcPs)
-> [LConDecl GhcPs]
-> HsDeriving GhcPs
-> HsDataDefn GhcPs
forall pass.
XCHsDataDefn pass
-> NewOrData
-> LHsContext pass
-> Maybe (Located CType)
-> Maybe (LHsKind pass)
-> [LConDecl pass]
-> HsDeriving pass
-> HsDataDefn pass
GHC.HsDataDefn XCHsDataDefn GhcPs
NoExtField
GHC.NoExtField NewOrData
nd (HsContext GhcPs -> LHsContext GhcPs
forall e. e -> Located e
GHC.noLoc []) Maybe (Located CType)
typ Maybe (LBangType GhcPs)
_mk [LConDecl GhcPs]
cons HsDeriving GhcPs
mderivs)
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnWhere
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsBind GHC.GhcPs) where
  markAST :: SrcSpan -> HsBind GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.FunBind XFunBind GhcPs GhcPs
_ Located (IdP GhcPs)
_ (GHC.MG XMG GhcPs (Located (HsExpr GhcPs))
_ (GHC.L SrcSpan
_ [LMatch GhcPs (Located (HsExpr GhcPs))]
matches) Origin
_) [Tickish Id]
_) = do
    -- Note: from a layout perspective a FunBind should not exist, so the
    -- current context is passed through unchanged to the matches.
    -- TODO: perhaps bring the edp from the first match up to the annotation for
    -- the FunBind.
    let
      tlFun :: Annotated ()
tlFun =
        Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
CtxOnly,AstContext
CtxFirst])
          (ListContexts
-> [LMatch GhcPs (Located (HsExpr GhcPs))] -> Annotated ()
forall ast.
Annotate ast =>
ListContexts -> [Located ast] -> Annotated ()
markListWithContexts' ListContexts
listContexts [LMatch GhcPs (Located (HsExpr GhcPs))]
matches)
          (Set AstContext
-> Set AstContext
-> [LMatch GhcPs (Located (HsExpr GhcPs))]
-> Annotated ()
forall ast.
Annotate ast =>
Set AstContext -> Set AstContext -> [Located ast] -> Annotated ()
markListWithContexts (ListContexts -> Set AstContext
lcMiddle ListContexts
listContexts) (ListContexts -> Set AstContext
lcLast ListContexts
listContexts) [LMatch GhcPs (Located (HsExpr GhcPs))]
matches)
    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
TopLevel)
      (Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
TopLevel) PhaseNum
2 Annotated ()
tlFun)
      Annotated ()
tlFun

  -- -----------------------------------

  markAST SrcSpan
_ (GHC.PatBind XPatBind GhcPs GhcPs
_ LPat GhcPs
lhs (GHC.GRHSs XCGRHSs GhcPs (Located (HsExpr GhcPs))
_ [LGRHS GhcPs (Located (HsExpr GhcPs))]
grhs (GHC.L SrcSpan
_ HsLocalBinds GhcPs
lb)) ([Tickish Id], [[Tickish Id]])
_ticks) = do
    Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
lhs
    case [LGRHS GhcPs (Located (HsExpr GhcPs))]
grhs of
      (GHC.L SrcSpan
_ (GHC.GRHS XCGRHS GhcPs (Located (HsExpr GhcPs))
_ [] Located (HsExpr GhcPs)
_):[LGRHS GhcPs (Located (HsExpr GhcPs))]
_) -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual -- empty guards
      [LGRHS GhcPs (Located (HsExpr GhcPs))]
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    (LGRHS GhcPs (Located (HsExpr GhcPs)) -> Annotated ())
-> PhaseNum
-> [LGRHS GhcPs (Located (HsExpr GhcPs))]
-> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LGRHS GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LGRHS GhcPs (Located (HsExpr GhcPs))]
grhs

    -- TODO: extract this common code
    case HsLocalBinds GhcPs
lb of
      GHC.EmptyLocalBinds{} -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      HsLocalBinds GhcPs
_ -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
        HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
lb
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- '}'
    Annotated ()
markTrailingSemi

  -- -----------------------------------

  markAST SrcSpan
_ (GHC.VarBind XVarBind GhcPs GhcPs
_ IdP GhcPs
_n Located (HsExpr GhcPs)
rhse) =
    -- Note: this bind is introduced by the typechecker
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
rhse

  -- -----------------------------------

  -- Introduced after renaming.
  markAST SrcSpan
_ (GHC.AbsBinds {}) =
    String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: AbsBinds introduced after renaming"

  -- -----------------------------------

  markAST SrcSpan
l (GHC.PatSynBind XPatSynBind GhcPs GhcPs
_ (GHC.PSB XPSB GhcPs GhcPs
_ Located (IdP GhcPs)
ln HsPatSynDetails (Located (IdP GhcPs))
args LPat GhcPs
def HsPatSynDir GhcPs
dir)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnPattern
    case HsPatSynDetails (Located (IdP GhcPs))
args of
      GHC.InfixCon Located (IdP GhcPs)
la Located (IdP GhcPs)
lb -> do
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
la
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
lb
      GHC.PrefixCon [Located (IdP GhcPs)]
ns -> do
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
        (Located RdrName -> Annotated ())
-> [Located RdrName] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (IdP GhcPs)]
[Located RdrName]
ns
      GHC.RecCon [RecordPatSynField (Located (IdP GhcPs))]
fs -> do
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC  -- '{'
        (RecordPatSynField (Located RdrName) -> Annotated ())
-> [RecordPatSynField (Located RdrName)] -> Annotated ()
forall t. (t -> Annotated ()) -> [t] -> Annotated ()
markListIntercalateWithFun (Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (Located RdrName -> Annotated ())
-> (RecordPatSynField (Located RdrName) -> Located RdrName)
-> RecordPatSynField (Located RdrName)
-> Annotated ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (Located RdrName) -> Located RdrName
forall a. RecordPatSynField a -> a
GHC.recordPatSynSelectorId) [RecordPatSynField (Located (IdP GhcPs))]
[RecordPatSynField (Located RdrName)]
fs
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- '}'
    case HsPatSynDir GhcPs
dir of
      HsPatSynDir GhcPs
GHC.ImplicitBidirectional -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
      HsPatSynDir GhcPs
_                         -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLarrow

    Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
def
    case HsPatSynDir GhcPs
dir of
      HsPatSynDir GhcPs
GHC.Unidirectional           -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      HsPatSynDir GhcPs
GHC.ImplicitBidirectional    -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      GHC.ExplicitBidirectional MatchGroup GhcPs (Located (HsExpr GhcPs))
mg -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC  -- '{'
        SrcSpan
-> MatchGroup GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (Located (HsExpr GhcPs))
mg
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- '}'

    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.IPBind GHC.GhcPs) where
  markAST :: SrcSpan -> IPBind GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.IPBind XCIPBind GhcPs
_ Either (Located HsIPName) (IdP GhcPs)
en Located (HsExpr GhcPs)
e) = do
    case Either (Located HsIPName) (IdP GhcPs)
en of
      Left Located HsIPName
n   -> Located HsIPName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located HsIPName
n
      Right IdP GhcPs
_i -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate GHC.HsIPName where
  markAST :: SrcSpan -> HsIPName -> Annotated ()
markAST SrcSpan
l (GHC.HsIPName FastString
n) = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (String
"?" String -> String -> String
forall a. [a] -> [a] -> [a]
++ FastString -> String
GHC.unpackFS FastString
n)

-- ---------------------------------------------------------------------

instance (Annotate body)
  => Annotate (GHC.Match GHC.GhcPs (GHC.Located body)) where

  markAST :: SrcSpan -> Match GhcPs (Located body) -> Annotated ()
markAST SrcSpan
l (GHC.Match XCMatch GhcPs (Located body)
_ HsMatchContext (NoGhcTc GhcPs)
mln [LPat GhcPs]
pats (GHC.GRHSs XCGRHSs GhcPs (Located body)
_ [LGRHS GhcPs (Located body)]
grhs (GHC.L SrcSpan
_ HsLocalBinds GhcPs
lb))) = do
    let
      get_infix :: HsMatchContext p -> LexicalFixity
get_infix (GHC.FunRhs LIdP p
_ LexicalFixity
f SrcStrictness
_) = LexicalFixity
f
      get_infix HsMatchContext p
_                  = LexicalFixity
GHC.Prefix

      isFunBind :: HsMatchContext p -> Bool
isFunBind GHC.FunRhs{} = Bool
True
      isFunBind HsMatchContext p
_            = Bool
False
    case (HsMatchContext GhcPs -> LexicalFixity
forall {p}. HsMatchContext p -> LexicalFixity
get_infix HsMatchContext (NoGhcTc GhcPs)
HsMatchContext GhcPs
mln,[LPat GhcPs]
[Located (Pat GhcPs)]
pats) of
      (LexicalFixity
GHC.Infix, Located (Pat GhcPs)
a:Located (Pat GhcPs)
b:[Located (Pat GhcPs)]
xs) -> do
        if [Located (Pat GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Located (Pat GhcPs)]
xs
          then AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenP
          else AnnKeywordId -> Annotated ()
mark         AnnKeywordId
GHC.AnnOpenP
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (Pat GhcPs)
a
        case HsMatchContext (NoGhcTc GhcPs)
mln of
          GHC.FunRhs LIdP (NoGhcTc GhcPs)
n LexicalFixity
_ SrcStrictness
_ -> Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIdP (NoGhcTc GhcPs)
Located RdrName
n
          HsMatchContext (NoGhcTc GhcPs)
_              -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (Pat GhcPs)
b
        if [Located (Pat GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Located (Pat GhcPs)]
xs
         then AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseP
         else AnnKeywordId -> Annotated ()
mark         AnnKeywordId
GHC.AnnCloseP
        (Located (Pat GhcPs) -> Annotated ())
-> [Located (Pat GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (Pat GhcPs)]
xs
      (LexicalFixity, [Located (Pat GhcPs)])
_ -> do
        [AnnKeywordId] -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
[AnnKeywordId] -> m ()
annotationsToComments [AnnKeywordId
GHC.AnnOpenP,AnnKeywordId
GHC.AnnCloseP]
        Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LambdaExpr]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLam -- For HsLam
        case HsMatchContext (NoGhcTc GhcPs)
mln of
          GHC.FunRhs LIdP (NoGhcTc GhcPs)
n LexicalFixity
_ SrcStrictness
s -> do
            Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
NoPrecedingSpace,AstContext
PrefixOp]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
              if (SrcStrictness
s SrcStrictness -> SrcStrictness -> Bool
forall a. Eq a => a -> a -> Bool
== SrcStrictness
GHC.SrcStrict)
                then do
                  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal (SrcSpan -> SrcSpan
GHC.srcSpanFirstCharacter SrcSpan
l) AnnKeywordId
GHC.AnnBang String
"!"
                  Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIdP (NoGhcTc GhcPs)
Located RdrName
n
                else Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LIdP (NoGhcTc GhcPs)
Located RdrName
n
            (Located (Pat GhcPs) -> Annotated ())
-> [Located (Pat GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LPat GhcPs]
[Located (Pat GhcPs)]
pats
          HsMatchContext (NoGhcTc GhcPs)
_  -> Bool -> [Located (Pat GhcPs)] -> Annotated ()
forall ast. Annotate ast => Bool -> [Located ast] -> Annotated ()
markListNoPrecedingSpace Bool
False [LPat GhcPs]
[Located (Pat GhcPs)]
pats

    -- TODO: The AnnEqual annotation actually belongs in the first GRHS value
    case [LGRHS GhcPs (Located body)]
grhs of
      (GHC.L SrcSpan
_ (GHC.GRHS XCGRHS GhcPs (Located body)
_ [] Located body
_):[LGRHS GhcPs (Located body)]
_) -> Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HsMatchContext GhcPs -> Bool
forall {p}. HsMatchContext p -> Bool
isFunBind HsMatchContext (NoGhcTc GhcPs)
HsMatchContext GhcPs
mln) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual -- empty guards
      [LGRHS GhcPs (Located body)]
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LambdaExpr]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow -- For HsLam
    (LGRHS GhcPs (Located body) -> Annotated ())
-> [LGRHS GhcPs (Located body)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LGRHS GhcPs (Located body) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LGRHS GhcPs (Located body)]
grhs

    case HsLocalBinds GhcPs
lb of
      GHC.EmptyLocalBinds{} -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      HsLocalBinds GhcPs
_ -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
        HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
lb
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- '}'
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance (Annotate body)
  => Annotate (GHC.GRHS GHC.GhcPs (GHC.Located body)) where
  markAST :: SrcSpan -> GRHS GhcPs (Located body) -> Annotated ()
markAST SrcSpan
_ (GHC.GRHS XCGRHS GhcPs (Located body)
_ [GuardLStmt GhcPs]
guards Located body
expr) = do
    case [GuardLStmt GhcPs]
guards of
      [] -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      (GuardLStmt GhcPs
_:[GuardLStmt GhcPs]
_) -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LeftMost,AstContext
PrefixOp])
          (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [GuardLStmt GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [GuardLStmt GhcPs]
guards
        Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
CaseAlt])
          (() -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
          (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual)

    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnEqual -- For apply-refact Structure8.hs test

    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
CaseAlt]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow -- For HsLam
    Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LeftMost,AstContext
PrefixOp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located body -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located body
expr

-- ---------------------------------------------------------------------

instance Annotate (GHC.Sig GHC.GhcPs) where

  markAST :: SrcSpan -> Sig GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.TypeSig XTypeSig GhcPs
_ [Located (IdP GhcPs)]
lns LHsSigWcType GhcPs
st)  = do
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Bool -> [Located RdrName] -> Annotated ()
forall ast. Annotate ast => Bool -> [Located ast] -> Annotated ()
markListNoPrecedingSpace Bool
True [Located (IdP GhcPs)]
[Located RdrName]
lns
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LHsSigWcType GhcPs -> Annotated ()
markLHsSigWcType LHsSigWcType GhcPs
st
    Annotated ()
markTrailingSemi
    Set AstContext -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> m ()
tellContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
FollowingLine)

  markAST SrcSpan
_ (GHC.PatSynSig XPatSynSig GhcPs
_ [Located (IdP GhcPs)]
lns (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnPattern
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
lns
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.ClassOpSig XClassOpSig GhcPs
_ Bool
isDefault [Located (IdP GhcPs)]
ns (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ)) = do
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isDefault (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDefault
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
ns
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.IdSig {}) =
    String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: Introduced after renaming"

  markAST SrcSpan
_ (GHC.FixSig XFixSig GhcPs
_ (GHC.FixitySig XFixitySig GhcPs
_ [Located (IdP GhcPs)]
lns (GHC.Fixity SourceText
src PhaseNum
v FixityDirection
fdir))) = do
    let fixstr :: String
fixstr = case FixityDirection
fdir of
         FixityDirection
GHC.InfixL -> String
"infixl"
         FixityDirection
GHC.InfixR -> String
"infixr"
         FixityDirection
GHC.InfixN -> String
"infix"
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnInfix String
fixstr
    SourceText -> String -> Annotated ()
markSourceText SourceText
src (PhaseNum -> String
forall a. Show a => a -> String
show PhaseNum
v)
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
lns
    Annotated ()
markTrailingSemi

  markAST SrcSpan
l (GHC.InlineSig XInlineSig GhcPs
_ Located (IdP GhcPs)
ln InlinePragma
inl) = do
    SourceText -> String -> Annotated ()
markAnnOpen (InlinePragma -> SourceText
GHC.inl_src InlinePragma
inl) String
"{-# INLINE"
    SrcSpan -> Activation -> Annotated ()
markActivation SrcSpan
l (InlinePragma -> Activation
GHC.inl_act InlinePragma
inl)
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}" -- '#-}'
    Annotated ()
markTrailingSemi

  markAST SrcSpan
l (GHC.SpecSig XSpecSig GhcPs
_ Located (IdP GhcPs)
ln [LHsSigType GhcPs]
typs InlinePragma
inl) = do
    SourceText -> String -> Annotated ()
markAnnOpen (InlinePragma -> SourceText
GHC.inl_src InlinePragma
inl) String
"{-# SPECIALISE" -- Note: may be {-# SPECIALISE_INLINE
    SrcSpan -> Activation -> Annotated ()
markActivation SrcSpan
l (InlinePragma -> Activation
GHC.inl_act InlinePragma
inl)
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon -- '::'
    (LHsSigType GhcPs -> Annotated ())
-> PhaseNum -> [LHsSigType GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LHsSigType GhcPs -> Annotated ()
markLHsSigType PhaseNum
2 [LHsSigType GhcPs]
typs
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}" -- '#-}'
    Annotated ()
markTrailingSemi


  markAST SrcSpan
_ (GHC.SpecInstSig XSpecInstSig GhcPs
_ SourceText
src LHsSigType GhcPs
typ) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# SPECIALISE"
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnInstance
    LHsSigType GhcPs -> Annotated ()
markLHsSigType LHsSigType GhcPs
typ
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}" -- '#-}'
    Annotated ()
markTrailingSemi


  markAST SrcSpan
_ (GHC.MinimalSig XMinimalSig GhcPs
_ SourceText
src LBooleanFormula (Located (IdP GhcPs))
formula) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# MINIMAL"
    Located (BooleanFormula (Located RdrName)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBooleanFormula (Located (IdP GhcPs))
Located (BooleanFormula (Located RdrName))
formula
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.SCCFunSig XSCCFunSig GhcPs
_ SourceText
src Located (IdP GhcPs)
ln Maybe (Located StringLiteral)
ml) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# SCC"
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    Maybe (Located StringLiteral) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located StringLiteral)
ml
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.CompleteMatchSig XCompleteMatchSig GhcPs
_ SourceText
src (GHC.L SrcSpan
_ [Located (IdP GhcPs)]
ns) Maybe (Located (IdP GhcPs))
mlns) = do
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# COMPLETE"
    [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
ns
    case Maybe (Located (IdP GhcPs))
mlns of
      Maybe (Located (IdP GhcPs))
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just Located (IdP GhcPs)
_ -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        Maybe (Located RdrName) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located (IdP GhcPs))
Maybe (Located RdrName)
mlns
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}" -- '#-}'
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.StandaloneKindSig GHC.GhcPs) where

  markAST :: SrcSpan -> StandaloneKindSig GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.StandaloneKindSig XStandaloneKindSig GhcPs
_ Located (IdP GhcPs)
ln LHsSigType GhcPs
st)  = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    LHsSigType GhcPs -> Annotated ()
markLHsSigType LHsSigType GhcPs
st
    Annotated ()
markTrailingSemi
    Set AstContext -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> m ()
tellContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
FollowingLine)

-- --------------------------------------------------------------------

markLHsSigType :: GHC.LHsSigType GHC.GhcPs -> Annotated ()
markLHsSigType :: LHsSigType GhcPs -> Annotated ()
markLHsSigType (GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
typ) = LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ

instance Annotate [GHC.LHsSigType GHC.GhcPs] where
  markAST :: SrcSpan -> [LHsSigType GhcPs] -> Annotated ()
markAST SrcSpan
_ [LHsSigType GhcPs]
ls = do
    -- mark GHC.AnnDeriving
    -- Mote: a single item in parens is parsed as a HsAppsTy. Without parens it
    -- is a HsTyVar. So for round trip pretty printing we need to take this into
    -- account.
    let marker :: AnnKeywordId -> Annotated ()
marker = case [LHsSigType GhcPs]
ls of
          []  -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional
          [GHC.HsIB XHsIB GhcPs (LBangType GhcPs)
_ LBangType GhcPs
t] -> if PprPrec -> HsType GhcPs -> Bool
forall (p :: Pass). PprPrec -> HsType (GhcPass p) -> Bool
GHC.hsTypeNeedsParens PprPrec
GHC.appPrec (LBangType GhcPs -> HsType GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LBangType GhcPs
t)
                           then AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany
                           else AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional
          [LHsSigType GhcPs]
_   -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany -- Need parens if more than one entry
    AnnKeywordId -> Annotated ()
marker AnnKeywordId
GHC.AnnOpenP
    (LHsSigType GhcPs -> Annotated ())
-> [LHsSigType GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> [t] -> Annotated ()
markListIntercalateWithFun LHsSigType GhcPs -> Annotated ()
markLHsSigType [LHsSigType GhcPs]
ls
    AnnKeywordId -> Annotated ()
marker AnnKeywordId
GHC.AnnCloseP

-- --------------------------------------------------------------------

instance  (Annotate name) => Annotate (GHC.BooleanFormula (GHC.Located name)) where
  markAST :: SrcSpan -> BooleanFormula (Located name) -> Annotated ()
markAST SrcSpan
_ (GHC.Var Located name
x)  = do
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located name -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located name
x
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
AddVbar]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
  markAST SrcSpan
_ (GHC.Or [LBooleanFormula (Located name)]
ls)  = (LBooleanFormula (Located name) -> Annotated ())
-> PhaseNum
-> AstContext
-> [LBooleanFormula (Located name)]
-> Annotated ()
forall t.
(t -> Annotated ())
-> PhaseNum -> AstContext -> [t] -> Annotated ()
markListIntercalateWithFunLevelCtx LBooleanFormula (Located name) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 AstContext
AddVbar [LBooleanFormula (Located name)]
ls
  markAST SrcSpan
_ (GHC.And [LBooleanFormula (Located name)]
ls) = do
    (LBooleanFormula (Located name) -> Annotated ())
-> PhaseNum -> [LBooleanFormula (Located name)] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LBooleanFormula (Located name) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LBooleanFormula (Located name)]
ls
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
AddVbar]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
  markAST SrcSpan
_ (GHC.Parens LBooleanFormula (Located name)
x)  = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
    LBooleanFormula (Located name) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBooleanFormula (Located name)
x
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
AddVbar]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance (Data flag) => Annotate (GHC.HsTyVarBndr flag GHC.GhcPs) where
  markAST :: SrcSpan -> HsTyVarBndr flag GhcPs -> Annotated ()
markAST SrcSpan
_l (GHC.UserTyVar XUserTyVar GhcPs
_ flag
f Located (IdP GhcPs)
n) = do
    flag -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
forall a.
Typeable a =>
a -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
markInferred flag
f AnnKeywordId
GHC.AnnOpenC  Maybe AnnKeywordId
forall a. Maybe a
Nothing -- '{'
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n
    flag -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
forall a.
Typeable a =>
a -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
markInferred flag
f AnnKeywordId
GHC.AnnCloseC Maybe AnnKeywordId
forall a. Maybe a
Nothing -- '}'

  markAST SrcSpan
_ (GHC.KindedTyVar XKindedTyVar GhcPs
_ flag
f Located (IdP GhcPs)
n LBangType GhcPs
ty) = do
    flag -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
forall a.
Typeable a =>
a -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
markInferred flag
f AnnKeywordId
GHC.AnnOpenC (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnOpenP)
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon -- '::'
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty
    flag -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
forall a.
Typeable a =>
a -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
markInferred flag
f AnnKeywordId
GHC.AnnCloseC (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnCloseP)

markInferred :: Typeable a
             => a -> GHC.AnnKeywordId -> (Maybe GHC.AnnKeywordId) -> Annotated ()
markInferred :: forall a.
Typeable a =>
a -> AnnKeywordId -> Maybe AnnKeywordId -> Annotated ()
markInferred a
flag AnnKeywordId
kw Maybe AnnKeywordId
kw2 =
  case (a -> Maybe Specificity
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast a
flag :: Maybe GHC.Specificity) of
    (Just Specificity
GHC.InferredSpec) -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
kw
    Maybe Specificity
_ -> (AnnKeywordId -> Annotated ())
-> Maybe AnnKeywordId -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ AnnKeywordId -> Annotated ()
mark Maybe AnnKeywordId
kw2

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsType GHC.GhcPs) where
  markAST :: SrcSpan -> HsType GhcPs -> Annotated ()
markAST SrcSpan
loc HsType GhcPs
ty = do
    SrcSpan -> HsType GhcPs -> Annotated ()
markType SrcSpan
loc HsType GhcPs
ty
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
    (Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar)
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InGadt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
      -- markOptional GHC.AnnLolly
   where

    -- markType :: GHC.SrcSpan -> ast -> Annotated ()
    markType :: GHC.SrcSpan -> (GHC.HsType GHC.GhcPs) -> Annotated ()
    markType :: SrcSpan -> HsType GhcPs -> Annotated ()
markType SrcSpan
_ (GHC.HsForAllTy XForAllTy GhcPs
_ HsForAllTelescope GhcPs
tele LBangType GhcPs
typ) = do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
      case HsForAllTelescope GhcPs
tele of
        (GHC.HsForAllVis   XHsForAllVis GhcPs
_ [Located (HsTyVarBndr () GhcPs)]
qtvs) -> do
          (Located (HsTyVarBndr () GhcPs) -> Annotated ())
-> [Located (HsTyVarBndr () GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (HsTyVarBndr () GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (HsTyVarBndr () GhcPs)]
qtvs
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
        (GHC.HsForAllInvis XHsForAllInvis GhcPs
_ [LHsTyVarBndr Specificity GhcPs]
qtvs) -> do
          (LHsTyVarBndr Specificity GhcPs -> Annotated ())
-> [LHsTyVarBndr Specificity GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsTyVarBndr Specificity GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsTyVarBndr Specificity GhcPs]
qtvs
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ

    markType SrcSpan
_ (GHC.HsQualTy XQualTy GhcPs
_ LHsContext GhcPs
cxt LBangType GhcPs
typ) = do
      LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
cxt
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ

    markType SrcSpan
_ (GHC.HsTyVar XTyVar GhcPs
_ PromotionFlag
promoted Located (IdP GhcPs)
name) = do
      Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PromotionFlag
promoted PromotionFlag -> PromotionFlag -> Bool
forall a. Eq a => a -> a -> Bool
== PromotionFlag
GHC.IsPromoted) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSimpleQuote
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
InfixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
name

    markType SrcSpan
_ (GHC.HsAppTy XAppTy GhcPs
_ LBangType GhcPs
t1 LBangType GhcPs
t2) = do
      Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t1
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t2

    markType SrcSpan
_ (GHC.HsAppKindTy XAppKindTy GhcPs
l LBangType GhcPs
t LBangType GhcPs
k) = do
      Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp)  (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      SrcSpan -> Annotated ()
markTypeApp XAppKindTy GhcPs
SrcSpan
l
      Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
k

    markType SrcSpan
_ (GHC.HsFunTy XFunTy GhcPs
_ HsArrow GhcPs
arrow LBangType GhcPs
t1 LBangType GhcPs
t2) = do
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t1
      HsArrow GhcPs -> Annotated ()
markArrow HsArrow GhcPs
arrow
      -- case arrow of
      --   GHC.HsLinearArrow       -> do
      --     case u of
      --       GHC.NormalSyntax -> do
      --         mark GHC.AnnMult -- "%1"
      --         mark GHC.AnnRarrow
      --       GHC.UnicodeSyntax -> mark GHC.AnnLollyU
      --   GHC.HsUnrestrictedArrow -> mark GHC.AnnRarrow -- a -> b
      --   GHC.HsExplicitMult _    -> do
      --     mark GHC.AnnMult -- "%1"
      --     mark GHC.AnnRarrow
        -- arr = case mult of
        --   HsLinearArrow -> lollipop
        --   HsUnrestrictedArrow -> arrow
        --   HsExplicitMult p -> mulArrow (ppr p)
-- lollipop   = unicodeSyntax (char '⊸') (docToSDoc $ Pretty.text "%1 ->")
-- mulArrow d = text "%" <> d <+> arrow


      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t2

    markType SrcSpan
_ (GHC.HsListTy XListTy GhcPs
_ LBangType GhcPs
t) = do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS -- '['
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'

    markType SrcSpan
_ (GHC.HsTupleTy XTupleTy GhcPs
_ HsTupleSort
tt HsContext GhcPs
ts) = do
      case HsTupleSort
tt  of
        HsTupleSort
GHC.HsBoxedOrConstraintTuple -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP  -- '('
        HsTupleSort
_                            -> AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#" -- '(#'
      (LBangType GhcPs -> Annotated ())
-> PhaseNum -> HsContext GhcPs -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 HsContext GhcPs
ts
      case HsTupleSort
tt  of
        HsTupleSort
GHC.HsBoxedOrConstraintTuple -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP  -- ')'
        HsTupleSort
_                            -> AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)" -- '#)'

    markType SrcSpan
_ (GHC.HsSumTy XSumTy GhcPs
_ HsContext GhcPs
tys) = do
      AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#"
      (LBangType GhcPs -> Annotated ())
-> PhaseNum -> AstContext -> HsContext GhcPs -> Annotated ()
forall t.
(t -> Annotated ())
-> PhaseNum -> AstContext -> [t] -> Annotated ()
markListIntercalateWithFunLevelCtx LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 AstContext
AddVbar HsContext GhcPs
tys
      AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)"

    markType SrcSpan
_ (GHC.HsOpTy XOpTy GhcPs
_ LBangType GhcPs
t1 Located (IdP GhcPs)
lo LBangType GhcPs
t2) = do
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t1
      if (OccName -> Bool
GHC.isTcOcc (OccName -> Bool) -> OccName -> Bool
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
forall name. HasOccName name => name -> OccName
GHC.occName (RdrName -> OccName) -> RdrName -> OccName
forall a b. (a -> b) -> a -> b
$ Located RdrName -> RdrName
forall l e. GenLocated l e -> e
GHC.unLoc Located (IdP GhcPs)
Located RdrName
lo)
        then do
          AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnSimpleQuote
        else do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSimpleQuote
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
PrefixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
lo
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t2

    markType SrcSpan
_ (GHC.HsParTy XParTy GhcPs
_ LBangType GhcPs
t) = do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP  -- '('
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'

    markType SrcSpan
_ (GHC.HsIParamTy XIParamTy GhcPs
_ Located HsIPName
n LBangType GhcPs
t) = do
      Located HsIPName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located HsIPName
n
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t

    markType SrcSpan
l (GHC.HsStarTy XStarTy GhcPs
_ Bool
isUnicode) = do
      if Bool
isUnicode
        then SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"\x2605" -- Unicode star
        else SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"*"

    markType SrcSpan
_ (GHC.HsKindSig XKindSig GhcPs
_ LBangType GhcPs
t LBangType GhcPs
k) = do
      AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenP  -- '('
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon -- '::'
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
k
      AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseP -- ')'

    markType SrcSpan
l (GHC.HsSpliceTy XSpliceTy GhcPs
_ HsSplice GhcPs
s) = do
      SrcSpan -> HsSplice GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsSplice GhcPs
s

    markType SrcSpan
_ (GHC.HsDocTy XDocTy GhcPs
_ LBangType GhcPs
t LHsDocString
ds) = do
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      LHsDocString -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsDocString
ds

    markType SrcSpan
_ (GHC.HsBangTy XBangTy GhcPs
_ (GHC.HsSrcBang SourceText
mt SrcUnpackedness
_up SrcStrictness
str) LBangType GhcPs
t) = do
      case SourceText
mt of
        SourceText
GHC.NoSourceText -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        GHC.SourceText String
src -> do
          AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
src
          AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
      case SrcStrictness
str of
        SrcStrictness
GHC.SrcLazy     -> do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnTilde
          Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
        SrcStrictness
GHC.SrcStrict   -> do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBang
          Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
        SrcStrictness
GHC.NoSrcStrict -> LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t


    markType SrcSpan
_ (GHC.HsRecTy XRecTy GhcPs
_ [LConDeclField GhcPs]
cons) = do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC  -- '{'
      [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LConDeclField GhcPs]
cons
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- '}'

    markType SrcSpan
_ (GHC.HsExplicitListTy XExplicitListTy GhcPs
_ PromotionFlag
promoted HsContext GhcPs
ts) = do
      Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PromotionFlag
promoted PromotionFlag -> PromotionFlag -> Bool
forall a. Eq a => a -> a -> Bool
== PromotionFlag
GHC.IsPromoted) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSimpleQuote
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS  -- "["
      HsContext GhcPs -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate HsContext GhcPs
ts
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'

    markType SrcSpan
_ (GHC.HsExplicitTupleTy XExplicitTupleTy GhcPs
_ HsContext GhcPs
ts) = do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSimpleQuote
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
      HsContext GhcPs -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate HsContext GhcPs
ts
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP

    markType SrcSpan
l (GHC.HsTyLit XTyLit GhcPs
_ HsTyLit
lit) = do
      case HsTyLit
lit of
        (GHC.HsNumTy SourceText
s Integer
v) ->
          SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
l SourceText
s (Integer -> String
forall a. Show a => a -> String
show Integer
v)
        (GHC.HsStrTy SourceText
s FastString
v) ->
          SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
l SourceText
s (FastString -> String
forall a. Show a => a -> String
show FastString
v)

    markType SrcSpan
l (GHC.HsWildCardTy XWildCardTy GhcPs
_) = do
      SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"_"

    markType SrcSpan
_ (GHC.XHsType XXType GhcPs
x) = String -> Annotated ()
forall a. HasCallStack => String -> a
error (String -> Annotated ()) -> String -> Annotated ()
forall a b. (a -> b) -> a -> b
$ String
"got XHsType for:" String -> String -> String
forall a. [a] -> [a] -> [a]
++ NewHsTypeX -> String
forall a. Outputable a => a -> String
showGhc NewHsTypeX
XXType GhcPs
x


-- ---------------------------------------------------------------------

-- instance Annotate (GHC.HsAppType GHC.GhcPs) where
--   markAST _ (GHC.HsAppInfix _ n)  = do
--     when (GHC.isDataOcc $ GHC.occName $ GHC.unLoc n) $ mark GHC.AnnSimpleQuote
--     setContext (Set.singleton InfixOp) $ markLocated n
--   markAST _ (GHC.HsAppPrefix _ t) = do
--     markOptional GHC.AnnTilde
--     setContext (Set.singleton PrefixOp) $ markLocated t

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsSplice GHC.GhcPs) where
  markAST :: SrcSpan -> HsSplice GhcPs -> Annotated ()
markAST SrcSpan
l HsSplice GhcPs
c =
    case HsSplice GhcPs
c of
      GHC.HsQuasiQuote XQuasiQuote GhcPs
_ IdP GhcPs
_ IdP GhcPs
n SrcSpan
_pos FastString
fs -> do
        SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal
              -- Note: Lexer.x does not provide unicode alternative. 2017-02-26
              (String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (RdrName -> String
forall a. Outputable a => a -> String
showGhc IdP GhcPs
RdrName
n) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (FastString -> String
GHC.unpackFS FastString
fs) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|]")

      GHC.HsTypedSplice XTypedSplice GhcPs
_ SpliceDecoration
decoration IdP GhcPs
_n Located (HsExpr GhcPs)
b  -> do
        if (SpliceDecoration
decoration SpliceDecoration -> SpliceDecoration -> Bool
forall a. Eq a => a -> a -> Bool
== SpliceDecoration
GHC.DollarSplice)
          then do
            AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDollarDollar
            Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b
          else Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b

      GHC.HsUntypedSplice XUntypedSplice GhcPs
_ SpliceDecoration
decoration IdP GhcPs
_n Located (HsExpr GhcPs)
b  -> do
        if (SpliceDecoration
decoration SpliceDecoration -> SpliceDecoration -> Bool
forall a. Eq a => a -> a -> Bool
== SpliceDecoration
GHC.DollarSplice)
          then do
            AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDollar
            Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b
          else Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b

      GHC.HsSpliced{}  -> String -> Annotated ()
forall a. HasCallStack => String -> a
error String
"HsSpliced only exists between renamer and typechecker in GHC"

-- ---------------------------------------------------------------------

instance Annotate (GHC.ConDeclField GHC.GhcPs) where
  markAST :: SrcSpan -> ConDeclField GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.ConDeclField XConDeclField GhcPs
_ [LFieldOcc GhcPs]
ns LBangType GhcPs
ty Maybe LHsDocString
mdoc) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      [LFieldOcc GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LFieldOcc GhcPs]
ns
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
      LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty
      Maybe LHsDocString -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe LHsDocString
mdoc
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate (GHC.FieldOcc GHC.GhcPs) where
  markAST :: SrcSpan -> FieldOcc GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.FieldOcc XCFieldOcc GhcPs
_ Located RdrName
rn) = do
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
rn
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate GHC.HsDocString where
  markAST :: SrcSpan -> HsDocString -> Annotated ()
markAST SrcSpan
l HsDocString
s = do
    SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (HsDocString -> String
GHC.unpackHDS HsDocString
s)

-- ---------------------------------------------------------------------

instance Annotate (GHC.Pat GHC.GhcPs) where
  markAST :: SrcSpan -> Pat GhcPs -> Annotated ()
markAST SrcSpan
loc Pat GhcPs
typ = do
    SrcSpan -> Pat GhcPs -> Annotated ()
markPat SrcSpan
loc Pat GhcPs
typ
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma Annotated () -> String -> Annotated ()
forall c. c -> String -> c
`debug` (String
"AnnComma in Pat")
    where
      markPat :: SrcSpan -> Pat GhcPs -> Annotated ()
markPat SrcSpan
l (GHC.WildPat XWildPat GhcPs
_) = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"_"
      markPat SrcSpan
l (GHC.VarPat XVarPat GhcPs
_ Located (IdP GhcPs)
n) = do
        -- The parser inserts a placeholder value for a record pun rhs. This must be
        -- filtered out until https://ghc.haskell.org/trac/ghc/ticket/12224 is
        -- resolved, particularly for pretty printing where annotations are added.
        let pun_RDR :: String
pun_RDR = String
"pun-right-hand-side"
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Located RdrName -> String
forall a. Outputable a => a -> String
showGhc Located (IdP GhcPs)
Located RdrName
n String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
pun_RDR) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
          AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ SrcSpan -> RdrName -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l (Located RdrName -> RdrName
forall l e. GenLocated l e -> e
GHC.unLoc Located (IdP GhcPs)
Located RdrName
n)
          -- unsetContext Intercalate $ setContext (Set.singleton PrefixOp) $ markLocated n
      markPat SrcSpan
_ (GHC.LazyPat XLazyPat GhcPs
_ LPat GhcPs
p) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnTilde
        Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
p

      markPat SrcSpan
_ (GHC.AsPat XAsPat GhcPs
_ Located (IdP GhcPs)
ln LPat GhcPs
p) = do
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnAt
        Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
p

      markPat SrcSpan
_ (GHC.ParPat XParPat GhcPs
_ LPat GhcPs
p) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
p
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP

      markPat SrcSpan
_ (GHC.BangPat XBangPat GhcPs
_ LPat GhcPs
p) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBang
        Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
p

      markPat SrcSpan
_ (GHC.ListPat XListPat GhcPs
_ [LPat GhcPs]
ps) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS
        (Located (Pat GhcPs) -> Annotated ())
-> PhaseNum -> [Located (Pat GhcPs)] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LPat GhcPs]
[Located (Pat GhcPs)]
ps
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS

      markPat SrcSpan
_ (GHC.TuplePat XTuplePat GhcPs
_ [LPat GhcPs]
pats Boxity
b) = do
        if Boxity
b Boxity -> Boxity -> Bool
forall a. Eq a => a -> a -> Bool
== Boxity
GHC.Boxed then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
                          else AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#"
        (Located (Pat GhcPs) -> Annotated ())
-> PhaseNum -> [Located (Pat GhcPs)] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LPat GhcPs]
[Located (Pat GhcPs)]
pats
        if Boxity
b Boxity -> Boxity -> Bool
forall a. Eq a => a -> a -> Bool
== Boxity
GHC.Boxed then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP
                          else AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)"

      markPat SrcSpan
_ (GHC.SumPat XSumPat GhcPs
_ LPat GhcPs
pat PhaseNum
alt PhaseNum
arity) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#"
        PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ (PhaseNum
alt PhaseNum -> PhaseNum -> PhaseNum
forall a. Num a => a -> a -> a
- PhaseNum
1) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
pat
        PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ (PhaseNum
arity PhaseNum -> PhaseNum -> PhaseNum
forall a. Num a => a -> a -> a
- PhaseNum
alt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)"

      markPat SrcSpan
_ (GHC.ConPat XConPat GhcPs
_ Located (ConLikeP GhcPs)
n HsConPatDetails GhcPs
dets) = do
        Located RdrName -> HsConPatDetails GhcPs -> Annotated ()
markHsConPatDetails Located (ConLikeP GhcPs)
Located RdrName
n HsConPatDetails GhcPs
dets

      markPat SrcSpan
_ (GHC.ViewPat XViewPat GhcPs
_ Located (HsExpr GhcPs)
e LPat GhcPs
pat) = do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
pat

      markPat SrcSpan
l (GHC.SplicePat XSplicePat GhcPs
_ HsSplice GhcPs
s) = do
        SrcSpan -> HsSplice GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsSplice GhcPs
s

      markPat SrcSpan
l (GHC.LitPat XLitPat GhcPs
_ HsLit GhcPs
lp) = SrcSpan -> HsLit GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsLit GhcPs
lp

      markPat SrcSpan
_ (GHC.NPat XNPat GhcPs
_ Located (HsOverLit GhcPs)
ol Maybe (SyntaxExpr GhcPs)
mn SyntaxExpr GhcPs
_) = do
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe NoExtField -> Bool
forall a. Maybe a -> Bool
isJust Maybe (SyntaxExpr GhcPs)
Maybe NoExtField
mn) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnMinus
        Located (HsOverLit GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsOverLit GhcPs)
ol

      markPat SrcSpan
_ (GHC.NPlusKPat XNPlusKPat GhcPs
_ Located (IdP GhcPs)
ln Located (HsOverLit GhcPs)
ol HsOverLit GhcPs
_ SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_) = do
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnVal String
"+"  -- "+"
        Located (HsOverLit GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsOverLit GhcPs)
ol

      markPat SrcSpan
_ (GHC.SigPat XSigPat GhcPs
_ LPat GhcPs
pat (GHC.HsPS XHsPS (NoGhcTc GhcPs)
_ LHsType (NoGhcTc GhcPs)
ty)) = do
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
pat
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsType (NoGhcTc GhcPs)
LBangType GhcPs
ty

-- ---------------------------------------------------------------------

hsLit2String :: GHC.HsLit GHC.GhcPs -> String
hsLit2String :: HsLit GhcPs -> String
hsLit2String HsLit GhcPs
lit =
  case HsLit GhcPs
lit of
    GHC.HsChar       XHsChar GhcPs
src Char
v   -> SourceText -> Char -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsChar GhcPs
SourceText
src Char
v String
""
    -- It should be included here
    -- https://github.com/ghc/ghc/blob/master/compiler/parser/Lexer.x#L1471
    GHC.HsCharPrim   XHsCharPrim GhcPs
src Char
p   -> SourceText -> Char -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsCharPrim GhcPs
SourceText
src Char
p String
"#"
    GHC.HsString     XHsString GhcPs
src FastString
v   -> SourceText -> FastString -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsString GhcPs
SourceText
src FastString
v String
""
    GHC.HsStringPrim XHsStringPrim GhcPs
src ByteString
v   -> SourceText -> ByteString -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsStringPrim GhcPs
SourceText
src ByteString
v String
""
    GHC.HsInt        XHsInt GhcPs
_ (GHC.IL SourceText
src Bool
_ Integer
v)   -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix SourceText
src Integer
v String
""
    GHC.HsIntPrim    XHsIntPrim GhcPs
src Integer
v   -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsIntPrim GhcPs
SourceText
src Integer
v String
""
    GHC.HsWordPrim   XHsWordPrim GhcPs
src Integer
v   -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsWordPrim GhcPs
SourceText
src Integer
v String
""
    GHC.HsInt64Prim  XHsInt64Prim GhcPs
src Integer
v   -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsInt64Prim GhcPs
SourceText
src Integer
v String
""
    GHC.HsWord64Prim XHsWord64Prim GhcPs
src Integer
v   -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsWord64Prim GhcPs
SourceText
src Integer
v String
""
    GHC.HsInteger    XHsInteger GhcPs
src Integer
v Type
_ -> SourceText -> Integer -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix XHsInteger GhcPs
SourceText
src Integer
v String
""
    GHC.HsRat        XHsRat GhcPs
_ (GHC.FL SourceText
src Bool
_ Rational
v) Type
_ -> SourceText -> Rational -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix SourceText
src Rational
v String
""
    GHC.HsFloatPrim  XHsFloatPrim GhcPs
_ (GHC.FL SourceText
src Bool
_ Rational
v)   -> SourceText -> Rational -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix SourceText
src Rational
v String
"#"
    GHC.HsDoublePrim XHsDoublePrim GhcPs
_ (GHC.FL SourceText
src Bool
_ Rational
v)   -> SourceText -> Rational -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix SourceText
src Rational
v String
"##"

toSourceTextWithSuffix :: (Show a) => GHC.SourceText -> a -> String -> String
toSourceTextWithSuffix :: forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix (SourceText
GHC.NoSourceText)    a
alt String
suffix = a -> String
forall a. Show a => a -> String
show a
alt String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suffix
toSourceTextWithSuffix (GHC.SourceText String
txt) a
_alt String
suffix = String
txt String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suffix

-- --------------------------------------------------------------------

markHsConPatDetails :: GHC.Located GHC.RdrName -> GHC.HsConPatDetails GHC.GhcPs -> Annotated ()
markHsConPatDetails :: Located RdrName -> HsConPatDetails GhcPs -> Annotated ()
markHsConPatDetails Located RdrName
ln HsConPatDetails GhcPs
dets = do
  case HsConPatDetails GhcPs
dets of
    GHC.PrefixCon [LPat GhcPs]
args -> do
      Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
      (Located (Pat GhcPs) -> Annotated ())
-> [Located (Pat GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LPat GhcPs]
[Located (Pat GhcPs)]
args
    GHC.RecCon (GHC.HsRecFields [LHsRecField GhcPs (LPat GhcPs)]
fs Maybe (Located PhaseNum)
dd) -> do
      Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC -- '{'
      case Maybe (Located PhaseNum)
dd of
        Maybe (Located PhaseNum)
Nothing ->  (Located (HsRecField GhcPs (Located (Pat GhcPs))) -> Annotated ())
-> PhaseNum
-> [Located (HsRecField GhcPs (Located (Pat GhcPs)))]
-> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel Located (HsRecField GhcPs (Located (Pat GhcPs))) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LHsRecField GhcPs (LPat GhcPs)]
[Located (HsRecField GhcPs (Located (Pat GhcPs)))]
fs
        Just Located PhaseNum
_ -> do
          Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (Located (HsRecField GhcPs (Located (Pat GhcPs))) -> Annotated ())
-> [Located (HsRecField GhcPs (Located (Pat GhcPs)))]
-> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (HsRecField GhcPs (Located (Pat GhcPs))) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsRecField GhcPs (LPat GhcPs)]
[Located (HsRecField GhcPs (Located (Pat GhcPs)))]
fs
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- '}'
    GHC.InfixCon LPat GhcPs
a1 LPat GhcPs
a2 -> do
      Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
a1
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
PrefixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
ln
      Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
a2

{-
type HsConDeclDetails pass
   = HsConDetails (HsScaled pass (LBangType pass)) (Located [LConDeclField pass])
-}
markHsConDeclDetails ::
  Bool -> Bool -> [GHC.Located GHC.RdrName] -> GHC.HsConDeclDetails GHC.GhcPs -> Annotated ()
markHsConDeclDetails :: Bool
-> Bool
-> [Located RdrName]
-> HsConDeclDetails GhcPs
-> Annotated ()
markHsConDeclDetails Bool
isDeprecated Bool
inGadt [Located RdrName]
lns HsConDeclDetails GhcPs
dets = do
  case HsConDeclDetails GhcPs
dets of
    GHC.PrefixCon [HsScaled GhcPs (LBangType GhcPs)]
args ->
      if Bool
inGadt
        then Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InGadt,AstContext
PrefixOp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
             (HsScaled GhcPs (LBangType GhcPs) -> Annotated ())
-> [HsScaled GhcPs (LBangType GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markScaled [HsScaled GhcPs (LBangType GhcPs)]
args
        else Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp        ) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
             (HsScaled GhcPs (LBangType GhcPs) -> Annotated ())
-> [HsScaled GhcPs (LBangType GhcPs)] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markScaled [HsScaled GhcPs (LBangType GhcPs)]
args
    GHC.RecCon Located [LConDeclField GhcPs]
fs -> do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC
      if Bool
inGadt
        then do
          if Bool
isDeprecated
            then Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InGadt]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LConDeclField GhcPs]
fs
            else Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InGadt,AstContext
InRecCon]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LConDeclField GhcPs]
fs
        else do
          if Bool
isDeprecated
            then Located [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LConDeclField GhcPs]
fs
            else Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InRecCon]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LConDeclField GhcPs]
fs
    GHC.InfixCon HsScaled GhcPs (LBangType GhcPs)
a1 HsScaled GhcPs (LBangType GhcPs)
a2 -> do
      HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markScaled HsScaled GhcPs (LBangType GhcPs)
a1
      Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> Annotated ())
-> [Located RdrName] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located RdrName]
lns
      HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markScaled HsScaled GhcPs (LBangType GhcPs)
a2

-- ---------------------------------------------------------------------

-- markScaled :: (GHC.HsScaled GHC.GhcPs (GHC.Located a)) -> Annotated ()
markScaled :: (GHC.HsScaled GHC.GhcPs (GHC.LBangType GHC.GhcPs)) -> Annotated ()
markScaled :: HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markScaled a :: HsScaled GhcPs (LBangType GhcPs)
a@(GHC.HsScaled HsArrow GhcPs
_rr (GHC.L SrcSpan
l HsType GhcPs
_)) = Located (HsScaled GhcPs (LBangType GhcPs)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan
-> HsScaled GhcPs (LBangType GhcPs)
-> Located (HsScaled GhcPs (LBangType GhcPs))
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l HsScaled GhcPs (LBangType GhcPs)
a)

instance Annotate (GHC.HsScaled GHC.GhcPs (GHC.LBangType GHC.GhcPs)) where
  markAST :: SrcSpan -> HsScaled GhcPs (LBangType GhcPs) -> Annotated ()
markAST SrcSpan
_  (GHC.HsScaled HsArrow GhcPs
arrow LBangType GhcPs
a) = do
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
a
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InGadt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      HsArrow GhcPs -> Annotated ()
markArrow HsArrow GhcPs
arrow
      -- -- AZ:TODO: fix this, with the new syntax
      -- case arrow of
      --   GHC.HsUnrestrictedArrow -> mark GHC.AnnRarrow -- a -> b
      --   GHC.HsLinearArrow       -> mark GHC.AnnLollyU  -- a #-> b
      --   GHC.HsExplicitMult _    -> mark GHC.AnnLollyU  -- a #-> b
      -- markOptional GHC.AnnRarrow -- See https://gitlab.haskell.org/ghc/ghc/-/commit/7f418acf61e#note_304011
-- ---------------------------------------------------------------------

markArrow :: GHC.HsArrow GhcPs -> Annotated ()
markArrow :: HsArrow GhcPs -> Annotated ()
markArrow HsArrow GhcPs
arrow = do
  case HsArrow GhcPs
arrow of
    GHC.HsLinearArrow IsUnicodeSyntax
u     -> do
      case IsUnicodeSyntax
u of
        IsUnicodeSyntax
GHC.NormalSyntax -> do
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnPercentOne -- "%1"
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
        IsUnicodeSyntax
GHC.UnicodeSyntax -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLollyU
    GHC.HsUnrestrictedArrow IsUnicodeSyntax
u ->
      case IsUnicodeSyntax
u of
        IsUnicodeSyntax
GHC.NormalSyntax  -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow  -- a -> b
        IsUnicodeSyntax
GHC.UnicodeSyntax -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrowU -- a ⊸ b
    GHC.HsExplicitMult IsUnicodeSyntax
u LBangType GhcPs
t  -> do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnPercent
      Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
NoPrecedingSpace, AstContext
InTypeApp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
t
      case IsUnicodeSyntax
u of
        IsUnicodeSyntax
GHC.NormalSyntax  -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow  -- ->
        IsUnicodeSyntax
GHC.UnicodeSyntax -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrowU -- ⊸

-- data HsArrow pass
--   = HsUnrestrictedArrow IsUnicodeSyntax
--     -- ^ a -> b or a → b
--   | HsLinearArrow IsUnicodeSyntax
--     -- ^ a %1 -> b or a %1 → b, or a ⊸ b
--   | HsExplicitMult IsUnicodeSyntax (LHsType pass)
--     -- ^ a %m -> b or a %m → b (very much including `a %Many -> b`!


-- ---------------------------------------------------------------------

instance Annotate [GHC.LConDeclField GHC.GhcPs] where
  markAST :: SrcSpan -> [LConDeclField GhcPs] -> Annotated ()
markAST SrcSpan
_ [LConDeclField GhcPs]
fs = do
       AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
       [LConDeclField GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LConDeclField GhcPs]
fs
       AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnDotdot
       Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InRecCon) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- '}'
       -- inContext (Set.singleton InRecCon) $ do
       --   mark GHC.AnnRarrow
       Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InGadt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
         AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsOverLit GHC.GhcPs) where
  markAST :: SrcSpan -> HsOverLit GhcPs -> Annotated ()
markAST SrcSpan
l HsOverLit GhcPs
ol =
    let str :: SourceText
str = case HsOverLit GhcPs -> OverLitVal
forall p. HsOverLit p -> OverLitVal
GHC.ol_val HsOverLit GhcPs
ol of
                GHC.HsIntegral   (GHC.IL SourceText
src Bool
_ Integer
_) -> SourceText
src
                GHC.HsFractional (GHC.FL SourceText
src Bool
_ Rational
_) -> SourceText
src
                GHC.HsIsString SourceText
src FastString
_ -> SourceText
src
    in
    SrcSpan -> SourceText -> String -> Annotated ()
markExternalSourceText SrcSpan
l SourceText
str String
""

-- ---------------------------------------------------------------------

instance (Annotate arg)
    => Annotate (GHC.HsImplicitBndrs GHC.GhcPs (GHC.Located arg)) where
  markAST :: SrcSpan -> HsImplicitBndrs GhcPs (Located arg) -> Annotated ()
markAST SrcSpan
_ (GHC.HsIB XHsIB GhcPs (Located arg)
_ Located arg
thing) = do
    Located arg -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located arg
thing

-- ---------------------------------------------------------------------

instance (Annotate body) => Annotate (GHC.Stmt GHC.GhcPs (GHC.Located body)) where

  markAST :: SrcSpan -> Stmt GhcPs (Located body) -> Annotated ()
markAST SrcSpan
_ (GHC.LastStmt XLastStmt GhcPs GhcPs (Located body)
_ Located body
body Maybe Bool
_ SyntaxExpr GhcPs
_)
    = Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LeftMost,AstContext
PrefixOp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located body -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located body
body

  markAST SrcSpan
_ (GHC.BindStmt XBindStmt GhcPs GhcPs (Located body)
_ LPat GhcPs
pat Located body
body) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
pat
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLarrow
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LeftMost,AstContext
PrefixOp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located body -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located body
body

    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate)
      (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma)
      (Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar)
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ GHC.ApplicativeStmt{}
    = String -> Annotated ()
forall a. HasCallStack => String -> a
error String
"ApplicativeStmt should not appear in ParsedSource"

  markAST SrcSpan
_ (GHC.BodyStmt XBodyStmt GhcPs GhcPs (Located body)
_ Located body
body SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located body -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located body
body
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar)     (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.LetStmt XLetStmt GhcPs GhcPs (Located body)
_ (GHC.L SrcSpan
_ HsLocalBinds GhcPs
lb)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLet
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
    AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
    HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
lb
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- '}'
    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate)
      (AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma)
      (Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar)     (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar)
    Annotated ()
markTrailingSemi

  markAST SrcSpan
l (GHC.ParStmt XParStmt GhcPs GhcPs (Located body)
_ [ParStmtBlock GhcPs GhcPs]
pbs HsExpr GhcPs
_ SyntaxExpr GhcPs
_) = do
    -- Within a given parallel list comprehension,one of the sections to be done
    -- in parallel. It is a normal list comprehension, so has a list of
    -- ParStmtBlock, one for each part of the sub- list comprehension


    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate)
      (

      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
        ListContexts
-> (ParStmtBlock GhcPs GhcPs -> Annotated ())
-> [ParStmtBlock GhcPs GhcPs]
-> Annotated ()
forall t.
ListContexts -> (t -> Annotated ()) -> [t] -> Annotated ()
markListWithContextsFunction
          (Set AstContext
-> Set AstContext
-> Set AstContext
-> Set AstContext
-> ListContexts
LC (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate)  -- only
              Set AstContext
forall a. Set a
Set.empty -- first
              Set AstContext
forall a. Set a
Set.empty -- middle
              (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) -- last
          ) (SrcSpan -> ParStmtBlock GhcPs GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l) [ParStmtBlock GhcPs GhcPs]
pbs
         )
      (
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
        ListContexts
-> (ParStmtBlock GhcPs GhcPs -> Annotated ())
-> [ParStmtBlock GhcPs GhcPs]
-> Annotated ()
forall t.
ListContexts -> (t -> Annotated ()) -> [t] -> Annotated ()
markListWithContextsFunction
          (Set AstContext
-> Set AstContext
-> Set AstContext
-> Set AstContext
-> ListContexts
LC Set AstContext
forall a. Set a
Set.empty -- only
              ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
AddVbar]) -- first
              ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
AddVbar]) -- middle
              Set AstContext
forall a. Set a
Set.empty                -- last
          ) (SrcSpan -> ParStmtBlock GhcPs GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l) [ParStmtBlock GhcPs GhcPs]
pbs
       )
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.TransStmt XTransStmt GhcPs GhcPs (Located body)
_ TransForm
form [GuardLStmt GhcPs]
stmts [(IdP GhcPs, IdP GhcPs)]
_b Located (HsExpr GhcPs)
using Maybe (Located (HsExpr GhcPs))
by SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_ HsExpr GhcPs
_) = do
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (GuardLStmt GhcPs -> Annotated ())
-> [GuardLStmt GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ GuardLStmt GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [GuardLStmt GhcPs]
stmts
    case TransForm
form of
      TransForm
GHC.ThenForm -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnThen
        AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
using
        case Maybe (Located (HsExpr GhcPs))
by of
          Just Located (HsExpr GhcPs)
b -> do
            AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBy
            AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b
          Maybe (Located (HsExpr GhcPs))
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TransForm
GHC.GroupForm -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnThen
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnGroup
        case Maybe (Located (HsExpr GhcPs))
by of
          Just Located (HsExpr GhcPs)
b -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBy Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
b
          Maybe (Located (HsExpr GhcPs))
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnUsing
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
using
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar)     (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.RecStmt XRecStmt GhcPs GhcPs (Located body)
_ [LStmtLR GhcPs GhcPs (Located body)]
stmts [IdP GhcPs]
_ [IdP GhcPs]
_ SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRec
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
    [LStmtLR GhcPs GhcPs (Located body)] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LStmtLR GhcPs GhcPs (Located body)]
stmts
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar)     (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

-- Note: We never have a located ParStmtBlock, so have nothing to hang the
-- annotation on. This means there is no pushing of context from the parent ParStmt.
instance Annotate (GHC.ParStmtBlock GHC.GhcPs GHC.GhcPs) where
  markAST :: SrcSpan -> ParStmtBlock GhcPs GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.ParStmtBlock XParStmtBlock GhcPs GhcPs
_ [GuardLStmt GhcPs]
stmts [IdP GhcPs]
_ns SyntaxExpr GhcPs
_) = do
    [GuardLStmt GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [GuardLStmt GhcPs]
stmts

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsLocalBinds GHC.GhcPs) where
  markAST :: SrcSpan -> HsLocalBinds GhcPs -> Annotated ()
markAST SrcSpan
_ HsLocalBinds GhcPs
lb = HsLocalBinds GhcPs -> Annotated ()
markHsLocalBinds HsLocalBinds GhcPs
lb

-- ---------------------------------------------------------------------

markHsLocalBinds :: GHC.HsLocalBinds GHC.GhcPs -> Annotated ()
markHsLocalBinds :: HsLocalBinds GhcPs -> Annotated ()
markHsLocalBinds (GHC.HsValBinds XHsValBinds GhcPs GhcPs
_ (GHC.ValBinds XValBinds GhcPs GhcPs
_ LHsBinds GhcPs
binds [Located (Sig GhcPs)]
sigs)) =
    [(AnnSpan, Annotated ())] -> Annotated ()
applyListAnnotationsLayout
       ([Located (HsBind GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation (LHsBinds GhcPs -> [Located (HsBind GhcPs)]
forall a. Bag a -> [a]
GHC.bagToList LHsBinds GhcPs
binds)
     [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [Located (Sig GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located (Sig GhcPs)]
sigs
       )
markHsLocalBinds (GHC.HsIPBinds XHsIPBinds GhcPs GhcPs
_ (GHC.IPBinds XIPBinds GhcPs
_ [LIPBind GhcPs]
binds)) = [LIPBind GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LIPBind GhcPs]
binds
markHsLocalBinds GHC.EmptyLocalBinds{}                   = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

markHsLocalBinds (GHC.HsValBinds XHsValBinds GhcPs GhcPs
_ (GHC.XValBindsLR XXValBindsLR GhcPs GhcPs
_)) = String -> Annotated ()
forall a. HasCallStack => String -> a
error String
"markHsLocalBinds:got extension"

-- ---------------------------------------------------------------------

markMatchGroup :: (Annotate body)
                   => GHC.SrcSpan -> GHC.MatchGroup GHC.GhcPs (GHC.Located body)
                   -> Annotated ()
markMatchGroup :: forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
_ (GHC.MG XMG GhcPs (Located body)
_ (GHC.L SrcSpan
_ [LMatch GhcPs (Located body)]
matches) Origin
_)
  = Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AdvanceLine) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [LMatch GhcPs (Located body)] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LMatch GhcPs (Located body)]
matches

-- ---------------------------------------------------------------------

instance (Annotate body)
  => Annotate [GHC.Located (GHC.Match GHC.GhcPs (GHC.Located body))] where
  markAST :: SrcSpan -> [Located (Match GhcPs (Located body))] -> Annotated ()
markAST SrcSpan
_ [Located (Match GhcPs (Located body))]
ls = (Located (Match GhcPs (Located body)) -> Annotated ())
-> [Located (Match GhcPs (Located body))] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located (Match GhcPs (Located body)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (Match GhcPs (Located body))]
ls

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsExpr GHC.GhcPs) where
  markAST :: SrcSpan -> HsExpr GhcPs -> Annotated ()
markAST SrcSpan
loc HsExpr GhcPs
expr = do
    SrcSpan -> HsExpr GhcPs -> Annotated ()
markExpr SrcSpan
loc HsExpr GhcPs
expr
    Set AstContext -> Annotated () -> Annotated ()
inContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
AddVbar) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    -- TODO: If the AnnComma is not needed, revert to markAST
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
   where
      markExpr :: SrcSpan -> HsExpr GhcPs -> Annotated ()
markExpr SrcSpan
_ (GHC.HsVar XVar GhcPs
_ Located (IdP GhcPs)
n) = AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp)
          (Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n)
          (Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp)
            (Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n)
            (Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n)
            )

      markExpr SrcSpan
l (GHC.HsUnboundVar {}) = do
        Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
InfixOp])
          (do  AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBackquote
               AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnVal String
"_"
               AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnBackquote)
          (SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"_")

      markExpr SrcSpan
l (GHC.HsRecFld XRecFld GhcPs
_ AmbiguousFieldOcc GhcPs
f) = SrcSpan -> AmbiguousFieldOcc GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l AmbiguousFieldOcc GhcPs
f

      markExpr SrcSpan
l (GHC.HsOverLabel XOverLabel GhcPs
_ Maybe (IdP GhcPs)
_ FastString
fs)
        = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (String
"#" String -> String -> String
forall a. [a] -> [a] -> [a]
++ FastString -> String
GHC.unpackFS FastString
fs)


      markExpr SrcSpan
l (GHC.HsIPVar XIPVar GhcPs
_ n :: HsIPName
n@(GHC.HsIPName FastString
_v))         =
        SrcSpan -> HsIPName -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsIPName
n
      markExpr SrcSpan
l (GHC.HsOverLit XOverLitE GhcPs
_ HsOverLit GhcPs
ov)     = SrcSpan -> HsOverLit GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsOverLit GhcPs
ov
      markExpr SrcSpan
l (GHC.HsLit XLitE GhcPs
_ HsLit GhcPs
lit)        = SrcSpan -> HsLit GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsLit GhcPs
lit

      markExpr SrcSpan
_ (GHC.HsLam XLam GhcPs
_ (GHC.MG XMG GhcPs (Located (HsExpr GhcPs))
_ (GHC.L SrcSpan
_ [LMatch GhcPs (Located (HsExpr GhcPs))
match]) Origin
_)) = do
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
LambdaExpr) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        -- TODO: Change this, HsLam binds do not need obey layout rules.
        --       And will only ever have a single match
          LMatch GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LMatch GhcPs (Located (HsExpr GhcPs))
match
      markExpr SrcSpan
_ (GHC.HsLam XLam GhcPs
_ MatchGroup GhcPs (Located (HsExpr GhcPs))
_) = String -> Annotated ()
forall a. HasCallStack => String -> a
error (String -> Annotated ()) -> String -> Annotated ()
forall a b. (a -> b) -> a -> b
$ String
"HsLam with other than one match"

      markExpr SrcSpan
l (GHC.HsLamCase XLamCase GhcPs
_ MatchGroup GhcPs (Located (HsExpr GhcPs))
match) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLam
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCase
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnSemi
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
CaseAlt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
          SrcSpan
-> MatchGroup GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (Located (HsExpr GhcPs))
match
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

      markExpr SrcSpan
_ (GHC.HsApp XApp GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2) = do
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2

      -- -------------------------------

      markExpr SrcSpan
_ (GHC.OpApp XOpApp GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 Located (HsExpr GhcPs)
e3) = do
        let
          isInfix :: Bool
isInfix = case Located (HsExpr GhcPs)
e2 of
            -- TODO: generalise this. Is it a fixity thing?
            GHC.L SrcSpan
_ (GHC.HsVar{}) -> Bool
True
            Located (HsExpr GhcPs)
_                     -> Bool
False

          normal :: Annotated ()
normal =
            -- When it is the leftmost item in a GRHS, e1 needs to have PrefixOp context
            Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
LeftMost)
              (Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
LeftMost,AstContext
PrefixOp]) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1)
              (Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1)

        if Bool
isInfix
            then Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
            else Annotated ()
normal

        AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
PrefixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2

        if Bool
isInfix
          then Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e3
          else Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e3

      -- -------------------------------

      markExpr SrcSpan
_ (GHC.NegApp XNegApp GhcPs
_ Located (HsExpr GhcPs)
e SyntaxExpr GhcPs
_) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnMinus
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e

      markExpr SrcSpan
_ (GHC.HsPar XPar GhcPs
_ Located (HsExpr GhcPs)
e) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP -- '('
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'

      markExpr SrcSpan
_ (GHC.SectionL XSectionL GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2) = do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2

      markExpr SrcSpan
_ (GHC.SectionR XSectionR GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2) = do
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2

      markExpr SrcSpan
_ (GHC.ExplicitTuple XExplicitTuple GhcPs
_ [LHsTupArg GhcPs]
args Boxity
b) = do
        if Boxity
b Boxity -> Boxity -> Bool
forall a. Eq a => a -> a -> Bool
== Boxity
GHC.Boxed then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
                          else AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#"

        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (LHsTupArg GhcPs -> Annotated ())
-> PhaseNum -> [LHsTupArg GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LHsTupArg GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LHsTupArg GhcPs]
args

        if Boxity
b Boxity -> Boxity -> Bool
forall a. Eq a => a -> a -> Bool
== Boxity
GHC.Boxed then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP
                          else AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)"

      markExpr SrcSpan
_ (GHC.ExplicitSum XExplicitSum GhcPs
_ PhaseNum
alt PhaseNum
arity Located (HsExpr GhcPs)
e) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"(#"
        PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ (PhaseNum
alt PhaseNum -> PhaseNum -> PhaseNum
forall a. Num a => a -> a -> a
- PhaseNum
1) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *) a. Applicative m => PhaseNum -> m a -> m ()
replicateM_ (PhaseNum
arity PhaseNum -> PhaseNum -> PhaseNum
forall a. Num a => a -> a -> a
- PhaseNum
alt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#)"

      markExpr SrcSpan
l (GHC.HsCase XCase GhcPs
_ Located (HsExpr GhcPs)
e1 MatchGroup GhcPs (Located (HsExpr GhcPs))
matches) = Annotated () -> Annotated ()
setRigidFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCase
        Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOf
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
CaseAlt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> MatchGroup GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (Located (HsExpr GhcPs))
matches
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

      -- We set the layout for HsIf even though it need not obey layout rules as
      -- when moving these expressions it's useful that they maintain "internal
      -- integrity", that is to say the subparts remain indented relative to each
      -- other.
      markExpr SrcSpan
_ (GHC.HsIf XIf GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 Located (HsExpr GhcPs)
e3) = Annotated () -> Annotated ()
setLayoutFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnIf
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        AnnKeywordId -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> AnnKeywordId -> m ()
markAnnBeforeAnn AnnKeywordId
GHC.AnnSemi AnnKeywordId
GHC.AnnThen
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnThen
        Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
ListStart) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
        AnnKeywordId -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> AnnKeywordId -> m ()
markAnnBeforeAnn AnnKeywordId
GHC.AnnSemi AnnKeywordId
GHC.AnnElse
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnElse
        Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
ListStart) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e3

      markExpr SrcSpan
_ (GHC.HsMultiIf XMultiIf GhcPs
_ [LGRHS GhcPs (Located (HsExpr GhcPs))]
rhs) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnIf
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
CaseAlt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
          -- mapM_ markLocated rhs
          [LGRHS GhcPs (Located (HsExpr GhcPs))] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LGRHS GhcPs (Located (HsExpr GhcPs))]
rhs
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

      markExpr SrcSpan
_ (GHC.HsLet XLet GhcPs
_ (GHC.L SrcSpan
_ HsLocalBinds GhcPs
binds) Located (HsExpr GhcPs)
e) = do
        Annotated () -> Annotated ()
setLayoutFlag (do -- Make sure the 'in' gets indented too
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLet
          AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
          AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
          HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
binds
          AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
          AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnIn
          Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e)

      -- -------------------------------

      markExpr SrcSpan
_ (GHC.HsDo XDo GhcPs
_ HsStmtContext GhcRn
cts (GHC.L SrcSpan
_ [GuardLStmt GhcPs]
es)) = do
        case HsStmtContext GhcRn
cts of
          GHC.DoExpr  Maybe ModuleName
Nothing   -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDo
          GHC.DoExpr  (Just ModuleName
mn) ->
            AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnDo ((ModuleName -> String
GHC.moduleNameString ModuleName
mn) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".do")
          GHC.MDoExpr Maybe ModuleName
Nothing -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnMdo
          GHC.MDoExpr (Just ModuleName
mn) ->
            AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnMdo ((ModuleName -> String
GHC.moduleNameString ModuleName
mn) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".mdo")
          HsStmtContext GhcRn
_             -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        let (String
ostr,String
cstr) =
              if HsStmtContext GhcRn -> Bool
forall name. HsStmtContext name -> Bool
isListComp HsStmtContext GhcRn
cts
                then (String
"[", String
"]")
                else (String
"{", String
"}")

        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HsStmtContext GhcRn -> Bool
forall name. HsStmtContext name -> Bool
isListComp HsStmtContext GhcRn
cts) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
ostr
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenS
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
        if HsStmtContext GhcRn -> Bool
forall name. HsStmtContext name -> Bool
isListComp HsStmtContext GhcRn
cts
          then do
            GuardLStmt GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated ([GuardLStmt GhcPs] -> GuardLStmt GhcPs
forall a. [a] -> a
last [GuardLStmt GhcPs]
es)
            AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
            Annotated () -> Annotated ()
setLayoutFlag ([GuardLStmt GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate ([GuardLStmt GhcPs] -> [GuardLStmt GhcPs]
forall a. [a] -> [a]
init [GuardLStmt GhcPs]
es))
          else do
           [GuardLStmt GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [GuardLStmt GhcPs]
es
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseS
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HsStmtContext GhcRn -> Bool
forall name. HsStmtContext name -> Bool
isListComp HsStmtContext GhcRn
cts) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
cstr

      -- -------------------------------

      markExpr SrcSpan
_ (GHC.ExplicitList XExplicitList GhcPs
_ Maybe (SyntaxExpr GhcPs)
_ [Located (HsExpr GhcPs)]
es) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (Located (HsExpr GhcPs) -> Annotated ())
-> PhaseNum -> [Located (HsExpr GhcPs)] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [Located (HsExpr GhcPs)]
es
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS

      markExpr SrcSpan
_ (GHC.RecordCon XRecordCon GhcPs
_ Located (IdP GhcPs)
n (GHC.HsRecFields [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs Maybe (Located PhaseNum)
dd)) = do
        Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
n
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC
        case Maybe (Located PhaseNum)
dd of
          Maybe (Located PhaseNum)
Nothing -> [LHsRecField GhcPs (Located (HsExpr GhcPs))] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs
          Just Located PhaseNum
_ -> do
            Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Intercalate) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (LHsRecField GhcPs (Located (HsExpr GhcPs)) -> Annotated ())
-> [LHsRecField GhcPs (Located (HsExpr GhcPs))] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsRecField GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs
            AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC

      markExpr SrcSpan
_ (GHC.RecordUpd XRecordUpd GhcPs
_ Located (HsExpr GhcPs)
e [LHsRecUpdField GhcPs]
fs) = do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC
        [LHsRecUpdField GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [LHsRecUpdField GhcPs]
fs
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC

      markExpr SrcSpan
_ (GHC.ExprWithTySig XExprWithTySig GhcPs
_ Located (HsExpr GhcPs)
e LHsSigWcType (NoGhcTc GhcPs)
typ) = do
        Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        LHsSigWcType GhcPs -> Annotated ()
markLHsSigWcType LHsSigWcType (NoGhcTc GhcPs)
LHsSigWcType GhcPs
typ

      markExpr SrcSpan
_ (GHC.ArithSeq XArithSeq GhcPs
_ Maybe (SyntaxExpr GhcPs)
_ ArithSeqInfo GhcPs
seqInfo) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenS -- '['
        case ArithSeqInfo GhcPs
seqInfo of
            GHC.From Located (HsExpr GhcPs)
e -> do
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
            GHC.FromTo Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 -> do
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
            GHC.FromThen Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 -> do
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
            GHC.FromThenTo Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 Located (HsExpr GhcPs)
e3 -> do
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
              Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e3
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseS -- ']'


      -- markExpr _ (GHC.HsCoreAnn _ src csFStr e) = do
      --   -- markWithString GHC.AnnOpen src -- "{-# CORE"
      --   markAnnOpen src "{-# CORE"
      --   -- markWithString GHC.AnnVal (GHC.sl_st csFStr)
      --   markSourceText (GHC.sl_st csFStr) (GHC.unpackFS $ GHC.sl_fs csFStr)
      --   markWithString GHC.AnnClose "#-}"
      --   markLocated e
      -- TODO: make monomorphic
      markExpr SrcSpan
l (GHC.HsBracket XBracket GhcPs
_ (GHC.VarBr XVarBr GhcPs
_ Bool
True IdP GhcPs
v)) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnSimpleQuote
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOpDollar) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Located RdrName -> Annotated ()
forall ast.
Annotate ast =>
AnnKeywordId -> Located ast -> Annotated ()
markLocatedFromKw AnnKeywordId
GHC.AnnName (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l IdP GhcPs
RdrName
v)
      markExpr SrcSpan
l (GHC.HsBracket XBracket GhcPs
_ (GHC.VarBr XVarBr GhcPs
_ Bool
False IdP GhcPs
v)) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnThTyQuote
        AnnKeywordId -> Located RdrName -> Annotated ()
forall ast.
Annotate ast =>
AnnKeywordId -> Located ast -> Annotated ()
markLocatedFromKw AnnKeywordId
GHC.AnnName (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l IdP GhcPs
RdrName
v)
      markExpr SrcSpan
_ (GHC.HsBracket XBracket GhcPs
_ (GHC.DecBrL XDecBrL GhcPs
_ [LHsDecl GhcPs]
ds)) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"[d|"
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
NoAdvanceLine)
             (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> PhaseNum -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> PhaseNum -> Annotated () -> m ()
setContextLevel (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
TopLevel) PhaseNum
2 (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [LHsDecl GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LHsDecl GhcPs]
ds
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseQ -- "|]"
      -- Introduced after the renamer
      markExpr SrcSpan
_ (GHC.HsBracket XBracket GhcPs
_ (GHC.DecBrG XDecBrG GhcPs
_ HsGroup GhcPs
_)) =
        String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: DecBrG introduced after renamer"
      markExpr SrcSpan
_l (GHC.HsBracket XBracket GhcPs
_ (GHC.ExpBr XExpBr GhcPs
_ Located (HsExpr GhcPs)
e)) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenEQ -- "[|"
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenE  -- "[e|"
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseQ -- "|]"
      markExpr SrcSpan
_l (GHC.HsBracket XBracket GhcPs
_ (GHC.TExpBr XTExpBr GhcPs
_ Located (HsExpr GhcPs)
e)) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen  String
"[||"
        AnnKeywordId -> String -> Annotated ()
markWithStringOptional AnnKeywordId
GHC.AnnOpenE String
"[e||"
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"||]"
      markExpr SrcSpan
_ (GHC.HsBracket XBracket GhcPs
_ (GHC.TypBr XTypBr GhcPs
_ LBangType GhcPs
e)) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen String
"[t|"
        LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseQ -- "|]"
      markExpr SrcSpan
_ (GHC.HsBracket XBracket GhcPs
_ (GHC.PatBr XPatBr GhcPs
_ LPat GhcPs
e)) = do
        AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnOpen  String
"[p|"
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
e
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseQ -- "|]"

      markExpr SrcSpan
_ (GHC.HsRnBracketOut {}) =
        String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: HsRnBracketOut introduced after renamer"
      markExpr SrcSpan
_ (GHC.HsTcBracketOut {}) =
        String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: HsTcBracketOut introduced after renamer"

      markExpr SrcSpan
l (GHC.HsSpliceE XSpliceE GhcPs
_ HsSplice GhcPs
e) = SrcSpan -> HsSplice GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l HsSplice GhcPs
e

      markExpr SrcSpan
_ (GHC.HsProc XProc GhcPs
_ LPat GhcPs
p LHsCmdTop GhcPs
c) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnProc
        Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LPat GhcPs
Located (Pat GhcPs)
p
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
        LHsCmdTop GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmdTop GhcPs
c

      markExpr SrcSpan
_ (GHC.HsStatic XStatic GhcPs
_ Located (HsExpr GhcPs)
e) = do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnStatic
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e

      markExpr SrcSpan
_ (GHC.HsTick {}) = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      markExpr SrcSpan
_ (GHC.HsBinTick {}) = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      markExpr SrcSpan
_ (GHC.HsPragE XPragE GhcPs
_ HsPragE GhcPs
prag Located (HsExpr GhcPs)
e) = do
        case HsPragE GhcPs
prag of
          (GHC.HsPragSCC XSCC GhcPs
_ SourceText
src StringLiteral
csFStr) -> do
            SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
"{-# SCC"
            let txt :: String
txt = SourceText -> String -> String
sourceTextToString (StringLiteral -> SourceText
GHC.sl_st StringLiteral
csFStr) (FastString -> String
GHC.unpackFS (FastString -> String) -> FastString -> String
forall a b. (a -> b) -> a -> b
$ StringLiteral -> FastString
GHC.sl_fs StringLiteral
csFStr)
            AnnKeywordId -> String -> Annotated ()
markWithStringOptional AnnKeywordId
GHC.AnnVal    String
txt
            AnnKeywordId -> String -> Annotated ()
markWithString         AnnKeywordId
GHC.AnnValStr String
txt
            AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"
            Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e

          (GHC.HsPragTick XTickPragma GhcPs
_ SourceText
src (StringLiteral
str,(PhaseNum
v1,PhaseNum
v2),(PhaseNum
v3,PhaseNum
v4)) ((SourceText
s1,SourceText
s2),(SourceText
s3,SourceText
s4))) -> do
            -- '{-# GENERATED' STRING INTEGER ':' INTEGER '-' INTEGER ':' INTEGER '#-}'
            SourceText -> String -> Annotated ()
markAnnOpen SourceText
src  String
"{-# GENERATED"
            AnnKeywordId -> PhaseNum -> String -> Annotated ()
markOffsetWithString AnnKeywordId
GHC.AnnVal PhaseNum
0 (StringLiteral -> String
stringLiteralToString StringLiteral
str) -- STRING

            let
              markOne :: PhaseNum -> a -> SourceText -> Annotated ()
markOne PhaseNum
n  a
v SourceText
GHC.NoSourceText   = AnnKeywordId -> PhaseNum -> String -> Annotated ()
markOffsetWithString AnnKeywordId
GHC.AnnVal PhaseNum
n (a -> String
forall a. Show a => a -> String
show a
v)
              markOne PhaseNum
n a
_v (GHC.SourceText String
s) = AnnKeywordId -> PhaseNum -> String -> Annotated ()
markOffsetWithString AnnKeywordId
GHC.AnnVal PhaseNum
n String
s

            PhaseNum -> PhaseNum -> SourceText -> Annotated ()
forall {a}. Show a => PhaseNum -> a -> SourceText -> Annotated ()
markOne  PhaseNum
1 PhaseNum
v1 SourceText
s1 -- INTEGER
            AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnColon PhaseNum
0 -- ':'
            PhaseNum -> PhaseNum -> SourceText -> Annotated ()
forall {a}. Show a => PhaseNum -> a -> SourceText -> Annotated ()
markOne  PhaseNum
2 PhaseNum
v2 SourceText
s2 -- INTEGER
            AnnKeywordId -> Annotated ()
mark   AnnKeywordId
GHC.AnnMinus   -- '-'
            PhaseNum -> PhaseNum -> SourceText -> Annotated ()
forall {a}. Show a => PhaseNum -> a -> SourceText -> Annotated ()
markOne  PhaseNum
3 PhaseNum
v3 SourceText
s3 -- INTEGER
            AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnColon PhaseNum
1 -- ':'
            PhaseNum -> PhaseNum -> SourceText -> Annotated ()
forall {a}. Show a => PhaseNum -> a -> SourceText -> Annotated ()
markOne  PhaseNum
4 PhaseNum
v4 SourceText
s4 -- INTEGER
            AnnKeywordId -> String -> Annotated ()
markWithString   AnnKeywordId
GHC.AnnClose  String
"#-}"
            Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e

      markExpr SrcSpan
_ (GHC.HsAppType XAppTypeE GhcPs
_ Located (HsExpr GhcPs)
e LHsWcType (NoGhcTc GhcPs)
ty) = do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
        AnnKeywordId -> KeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> KeywordId -> m ()
markInstead AnnKeywordId
GHC.AnnAt KeywordId
AnnTypeApp
        Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LHsWcType GhcPs -> Annotated ()
markLHsWcType LHsWcType (NoGhcTc GhcPs)
LHsWcType GhcPs
ty

      -- markExpr _ (GHC.HsWrap {}) =
      --   traceM "warning: HsWrap introduced after renaming"

      markExpr SrcSpan
_ (GHC.HsConLikeOut{}) =
        String -> Annotated ()
forall (f :: * -> *). Applicative f => String -> f ()
traceM String
"warning: HsConLikeOut introduced after type checking"

      -- markExpr _ x =
      --   error $ "markExpr: not matched for " ++ showAnnData mempty 0 x

-- ---------------------------------------------------------------------

markLHsWcType :: GHC.LHsWcType GHC.GhcPs -> Annotated ()
markLHsWcType :: LHsWcType GhcPs -> Annotated ()
markLHsWcType (GHC.HsWC XHsWC GhcPs (LBangType GhcPs)
_ LBangType GhcPs
ty) = do
  LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
ty

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsLit GHC.GhcPs) where
  markAST :: SrcSpan -> HsLit GhcPs -> Annotated ()
markAST SrcSpan
l HsLit GhcPs
lit = SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal (HsLit GhcPs -> String
hsLit2String HsLit GhcPs
lit)

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsRecUpdField GHC.GhcPs) where
  markAST :: SrcSpan -> HsRecUpdField GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsRecField Located (AmbiguousFieldOcc GhcPs)
lbl Located (HsExpr GhcPs)
expr Bool
punFlag) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (AmbiguousFieldOcc GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (AmbiguousFieldOcc GhcPs)
lbl
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
punFlag Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
False) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
expr
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

instance Annotate (GHC.AmbiguousFieldOcc GHC.GhcPs) where
  markAST :: SrcSpan -> AmbiguousFieldOcc GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.Unambiguous XUnambiguous GhcPs
_ Located RdrName
n) = Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
n
  markAST SrcSpan
_ (GHC.Ambiguous   XAmbiguous GhcPs
_ Located RdrName
n) = Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located RdrName
n

-- ---------------------------------------------------------------------

-- |Used for declarations that need to be aligned together, e.g. in a
-- do or let .. in statement/expr
instance Annotate [GHC.ExprLStmt GHC.GhcPs] where
  markAST :: SrcSpan -> [GuardLStmt GhcPs] -> Annotated ()
markAST SrcSpan
_ [GuardLStmt GhcPs]
ls = (GuardLStmt GhcPs -> Annotated ())
-> [GuardLStmt GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ GuardLStmt GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [GuardLStmt GhcPs]
ls

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsTupArg GHC.GhcPs) where
  markAST :: SrcSpan -> HsTupArg GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.Present XPresent GhcPs
_ (GHC.L SrcSpan
l HsExpr GhcPs
e)) = do
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> HsExpr GhcPs -> Located (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l HsExpr GhcPs
e)
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> KeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> KeywordId -> m ()
markOutside AnnKeywordId
GHC.AnnComma (AnnKeywordId -> KeywordId
G AnnKeywordId
GHC.AnnComma)

  markAST SrcSpan
_ (GHC.Missing XMissing GhcPs
_) = do
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsCmdTop GHC.GhcPs) where
  markAST :: SrcSpan -> HsCmdTop GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsCmdTop XCmdTop GhcPs
_ LHsCmd GhcPs
cmd) = LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
cmd

instance Annotate (GHC.HsCmd GHC.GhcPs) where
  markAST :: SrcSpan -> HsCmd GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsCmdArrApp XCmdArrApp GhcPs
_ Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 HsArrAppType
o Bool
isRightToLeft) = do
        -- isRightToLeft True  => right-to-left (f -< arg)
        --               False => left-to-right (arg >- f)
    if Bool
isRightToLeft
      then do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
        case HsArrAppType
o of
          HsArrAppType
GHC.HsFirstOrderApp  -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.Annlarrowtail
          HsArrAppType
GHC.HsHigherOrderApp -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLarrowtail
      else do
        Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
        case HsArrAppType
o of
          HsArrAppType
GHC.HsFirstOrderApp  -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.Annrarrowtail
          HsArrAppType
GHC.HsHigherOrderApp -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrowtail

    if Bool
isRightToLeft
      then Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2
      else Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1

  markAST SrcSpan
_ (GHC.HsCmdArrForm XCmdArrForm GhcPs
_ Located (HsExpr GhcPs)
e LexicalFixity
fixity Maybe Fixity
_mf [LHsCmdTop GhcPs]
cs) = do
    -- The AnnOpen should be marked for a prefix usage, not for a postfix one,
    -- due to the way checkCmd maps both HsArrForm and OpApp to HsCmdArrForm

    let isPrefixOp :: Bool
isPrefixOp = case LexicalFixity
fixity of
          LexicalFixity
GHC.Infix  -> Bool
False
          LexicalFixity
GHC.Prefix -> Bool
True
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isPrefixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenB -- "(|"

    -- This may be an infix operation
    ListContexts -> [(AnnSpan, Annotated ())] -> Annotated ()
applyListAnnotationsContexts (Set AstContext
-> Set AstContext
-> Set AstContext
-> Set AstContext
-> ListContexts
LC (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp)
                                     (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp))
                       ([Located (HsExpr GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located (HsExpr GhcPs)
e]
                         [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [LHsCmdTop GhcPs] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [LHsCmdTop GhcPs]
cs)
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isPrefixOp (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseB -- "|)"

  markAST SrcSpan
_ (GHC.HsCmdApp XCmdApp GhcPs
_ LHsCmd GhcPs
e1 Located (HsExpr GhcPs)
e2) = do
    LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
e1
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e2

  markAST SrcSpan
l (GHC.HsCmdLam XCmdLam GhcPs
_ MatchGroup GhcPs (LHsCmd GhcPs)
match) = do
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
LambdaExpr) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do SrcSpan -> MatchGroup GhcPs (LHsCmd GhcPs) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (LHsCmd GhcPs)
match

  markAST SrcSpan
_ (GHC.HsCmdPar XCmdPar GhcPs
_ LHsCmd GhcPs
e) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
    LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
e
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP -- ')'

  markAST SrcSpan
l (GHC.HsCmdCase XCmdCase GhcPs
_ Located (HsExpr GhcPs)
e1 MatchGroup GhcPs (LHsCmd GhcPs)
matches) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCase
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOf
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
CaseAlt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      SrcSpan -> MatchGroup GhcPs (LHsCmd GhcPs) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (LHsCmd GhcPs)
matches
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

  markAST SrcSpan
l (GHC.HsCmdLamCase XCmdLamCase GhcPs
_ MatchGroup GhcPs (LHsCmd GhcPs)
matches) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLam
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCase
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
CaseAlt) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      SrcSpan -> MatchGroup GhcPs (LHsCmd GhcPs) -> Annotated ()
forall body.
Annotate body =>
SrcSpan -> MatchGroup GhcPs (Located body) -> Annotated ()
markMatchGroup SrcSpan
l MatchGroup GhcPs (LHsCmd GhcPs)
matches
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

  markAST SrcSpan
_ (GHC.HsCmdIf XCmdIf GhcPs
_ SyntaxExpr GhcPs
_ Located (HsExpr GhcPs)
e1 LHsCmd GhcPs
e2 LHsCmd GhcPs
e3) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnIf
    Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e1
    AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnSemi PhaseNum
0
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnThen
    LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
e2
    AnnKeywordId -> PhaseNum -> Annotated ()
markOffset AnnKeywordId
GHC.AnnSemi PhaseNum
1
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnElse
    LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
e3

  markAST SrcSpan
_ (GHC.HsCmdLet XCmdLet GhcPs
_ (GHC.L SrcSpan
_ HsLocalBinds GhcPs
binds) LHsCmd GhcPs
e) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnLet
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    HsLocalBinds GhcPs -> Annotated ()
markLocalBindsWithLayout HsLocalBinds GhcPs
binds
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnIn
    LHsCmd GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsCmd GhcPs
e

  markAST SrcSpan
_ (GHC.HsCmdDo XCmdDo GhcPs
_ (GHC.L SrcSpan
_ [CmdLStmt GhcPs]
es)) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDo
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    [CmdLStmt GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [CmdLStmt GhcPs]
es
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC

  -- markAST _ (GHC.HsCmdWrap {}) =
  --   traceM "warning: HsCmdWrap introduced after renaming"

  -- markAST _ x = error $ "got HsCmd for:" ++ showAnnData mempty 0 x

-- ---------------------------------------------------------------------

instance Annotate [GHC.Located (GHC.StmtLR GHC.GhcPs GHC.GhcPs (GHC.LHsCmd GHC.GhcPs))] where
  markAST :: SrcSpan -> [CmdLStmt GhcPs] -> Annotated ()
markAST SrcSpan
_ [CmdLStmt GhcPs]
ls = (CmdLStmt GhcPs -> Annotated ())
-> [CmdLStmt GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ CmdLStmt GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [CmdLStmt GhcPs]
ls

-- ---------------------------------------------------------------------

instance Annotate (GHC.TyClDecl GHC.GhcPs) where

  markAST :: SrcSpan -> TyClDecl GhcPs -> Annotated ()
markAST SrcSpan
l (GHC.FamDecl XFamDecl GhcPs
_ FamilyDecl GhcPs
famdecl) = SrcSpan -> FamilyDecl GhcPs -> Annotated ()
forall ast. Annotate ast => SrcSpan -> ast -> Annotated ()
markAST SrcSpan
l FamilyDecl GhcPs
famdecl Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Annotated ()
markTrailingSemi
{-
    SynDecl { tcdSExt   :: XSynDecl pass          -- ^ Post renameer, FVs
            , tcdLName  :: Located (IdP pass)     -- ^ Type constructor
            , tcdTyVars :: LHsQTyVars pass        -- ^ Type variables; for an
                                                  -- associated type these
                                                  -- include outer binders
            , tcdFixity :: LexicalFixity          -- ^ Fixity used in the declaration
            , tcdRhs    :: LHsType pass }         -- ^ RHS of type declaration

-}
  markAST SrcSpan
_ (GHC.SynDecl XSynDecl GhcPs
_ Located (IdP GhcPs)
ln (GHC.HsQTvs XHsQTvs GhcPs
_ [Located (HsTyVarBndr () GhcPs)]
tyvars) LexicalFixity
fixity LBangType GhcPs
typ) = do
    -- There may be arbitrary parens around parts of the constructor that are
    -- infix.
    -- Turn these into comments so that they feed into the right place automatically
    -- annotationsToComments [GHC.AnnOpenP,GHC.AnnCloseP]
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType

    LexicalFixity
-> Located RdrName
-> [Located (HsTyVarBndr () GhcPs)]
-> Annotated ()
forall a ast.
(Annotate a, Annotate ast) =>
LexicalFixity -> Located a -> [Located ast] -> Annotated ()
markTyClass LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln [Located (HsTyVarBndr () GhcPs)]
tyvars
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.DataDecl XDataDecl GhcPs
_ Located (IdP GhcPs)
ln (GHC.HsQTvs XHsQTvs GhcPs
_ [Located (HsTyVarBndr () GhcPs)]
tyVars) LexicalFixity
fixity
                (GHC.HsDataDefn XCHsDataDefn GhcPs
_ NewOrData
nd LHsContext GhcPs
ctx Maybe (Located CType)
mctyp Maybe (LBangType GhcPs)
mk [LConDecl GhcPs]
cons HsDeriving GhcPs
derivs)) = do
    if NewOrData
nd NewOrData -> NewOrData -> Bool
forall a. Eq a => a -> a -> Bool
== NewOrData
GHC.DataType
      then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnData
      else AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnNewtype
    Maybe (Located CType) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located CType)
mctyp
    LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
ctx
    LexicalFixity
-> Located RdrName
-> [Located (HsTyVarBndr () GhcPs)]
-> Annotated ()
forall a ast.
(Annotate a, Annotate ast) =>
LexicalFixity -> Located a -> [Located ast] -> Annotated ()
markTyClass LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln [Located (HsTyVarBndr () GhcPs)]
tyVars
    case Maybe (LBangType GhcPs)
mk of
      Maybe (LBangType GhcPs)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just LBangType GhcPs
k -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
k
    if [LConDecl GhcPs] -> Bool
forall name. [LConDecl name] -> Bool
isGadt [LConDecl GhcPs]
cons
      then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
      else Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([LConDecl GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LConDecl GhcPs]
cons) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
    -- markOptional GHC.AnnWhere
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC
    Annotated () -> Annotated ()
setLayoutFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
NoPrecedingSpace)
                  (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ ListContexts -> [LConDecl GhcPs] -> Annotated ()
forall ast.
Annotate ast =>
ListContexts -> [Located ast] -> Annotated ()
markListWithContexts' ListContexts
listContexts [LConDecl GhcPs]
cons
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC
    Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Deriving,AstContext
NoDarrow]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ HsDeriving GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated HsDeriving GhcPs
derivs
    Annotated ()
markTrailingSemi

  -- -----------------------------------

  markAST SrcSpan
_ (GHC.ClassDecl XClassDecl GhcPs
_ LHsContext GhcPs
ctx Located (IdP GhcPs)
ln (GHC.HsQTvs XHsQTvs GhcPs
_ [Located (HsTyVarBndr () GhcPs)]
tyVars) LexicalFixity
fixity [LHsFunDep GhcPs]
fds
                          [Located (Sig GhcPs)]
sigs LHsBinds GhcPs
meths [LFamilyDecl GhcPs]
ats [LTyFamInstDecl GhcPs]
atdefs [Located DocDecl]
docs) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnClass
    LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
ctx

    LexicalFixity
-> Located RdrName
-> [Located (HsTyVarBndr () GhcPs)]
-> Annotated ()
forall a ast.
(Annotate a, Annotate ast) =>
LexicalFixity -> Located a -> [Located ast] -> Annotated ()
markTyClass LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln [Located (HsTyVarBndr () GhcPs)]
tyVars

    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Located (FunDep (Located RdrName))] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsFunDep GhcPs]
[Located (FunDep (Located RdrName))]
fds) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
      (Located (FunDep (Located RdrName)) -> Annotated ())
-> PhaseNum -> [Located (FunDep (Located RdrName))] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel Located (FunDep (Located RdrName)) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LHsFunDep GhcPs]
[Located (FunDep (Located RdrName))]
fds
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- '{'
    AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markInside AnnKeywordId
GHC.AnnSemi
    -- AZ:TODO: we end up with both the tyVars and the following body of the
    -- class defn in annSortKey for the class. This could cause problems when
    -- changing things.
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InClassDecl) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$
      [(AnnSpan, Annotated ())] -> Annotated ()
applyListAnnotationsLayout
                           ([Located (Sig GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located (Sig GhcPs)]
sigs
                         [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [Located (HsBind GhcPs)] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation (LHsBinds GhcPs -> [Located (HsBind GhcPs)]
forall a. Bag a -> [a]
GHC.bagToList LHsBinds GhcPs
meths)
                         [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [LFamilyDecl GhcPs] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [LFamilyDecl GhcPs]
ats
                         [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [LTyFamInstDecl GhcPs] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [LTyFamInstDecl GhcPs]
atdefs
                         [(AnnSpan, Annotated ())]
-> [(AnnSpan, Annotated ())] -> [(AnnSpan, Annotated ())]
forall a. [a] -> [a] -> [a]
++ [Located DocDecl] -> [(AnnSpan, Annotated ())]
forall a. Annotate a => [Located a] -> [(AnnSpan, Annotated ())]
prepareListAnnotation [Located DocDecl]
docs
                           )
    AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- '}'
    Annotated ()
markTrailingSemi
{-
  | ClassDecl { tcdCExt    :: XClassDecl pass,         -- ^ Post renamer, FVs
                tcdCtxt    :: LHsContext pass,         -- ^ Context...
                tcdLName   :: Located (IdP pass),      -- ^ Name of the class
                tcdTyVars  :: LHsQTyVars pass,         -- ^ Class type variables
                tcdFixity  :: LexicalFixity, -- ^ Fixity used in the declaration
                tcdFDs     :: [Located (FunDep (Located (IdP pass)))],
                                                        -- ^ Functional deps
                tcdSigs    :: [LSig pass],              -- ^ Methods' signatures
                tcdMeths   :: LHsBinds pass,            -- ^ Default methods
                tcdATs     :: [LFamilyDecl pass],       -- ^ Associated types;
                tcdATDefs  :: [LTyFamDefltEqn pass],
                                                   -- ^ Associated type defaults
                tcdDocs    :: [LDocDecl]                -- ^ Haddock docs
    }

-}

-- ---------------------------------------------------------------------

markTypeApp :: GHC.SrcSpan -> Annotated ()
markTypeApp :: SrcSpan -> Annotated ()
markTypeApp SrcSpan
loc = do
  let l :: SrcSpan
l = SrcSpan -> SrcSpan
GHC.srcSpanFirstCharacter SrcSpan
loc
  SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"@"

-- ---------------------------------------------------------------------

markTyClassArgs :: (Annotate a, Data flag)
            => Maybe [GHC.LHsTyVarBndr flag GhcPs] -> GHC.LexicalFixity
            -> GHC.Located a -> [GHC.LHsTypeArg GhcPs] -> Annotated ()
markTyClassArgs :: forall a flag.
(Annotate a, Data flag) =>
Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity -> Located a -> HsTyPats GhcPs -> Annotated ()
markTyClassArgs Maybe [LHsTyVarBndr flag GhcPs]
mbndrs LexicalFixity
fixity Located a
ln HsTyPats GhcPs
tyVars = do
  let
    cvt :: HsArg (Located ast) (Located ast) -> Annotated ()
cvt (GHC.HsValArg  Located ast
val) = Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
val
    cvt (GHC.HsTypeArg SrcSpan
loc Located ast
typ) = do
      SrcSpan -> Annotated ()
markTypeApp SrcSpan
loc
      Annotated () -> Annotated ()
markTightPrefix (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located ast
typ
    cvt (GHC.HsArgPar SrcSpan
_ss) = Annotated ()
forall a. HasCallStack => a
undefined
  (HsArg (LBangType GhcPs) (LBangType GhcPs) -> Annotated ())
-> Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity
-> Located a
-> HsTyPats GhcPs
-> Annotated ()
forall a flag b.
(Annotate a, Data flag) =>
(b -> Annotated ())
-> Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity
-> Located a
-> [b]
-> Annotated ()
markTyClassWorker HsArg (LBangType GhcPs) (LBangType GhcPs) -> Annotated ()
forall {ast} {ast}.
(Annotate ast, Annotate ast) =>
HsArg (Located ast) (Located ast) -> Annotated ()
cvt Maybe [LHsTyVarBndr flag GhcPs]
mbndrs LexicalFixity
fixity Located a
ln HsTyPats GhcPs
tyVars
    {-
type LHsTypeArg p = HsArg (LHsType p) (LHsKind p)

data HsArg tm ty
  = HsValArg tm   -- Argument is an ordinary expression     (f arg)
  | HsTypeArg  ty -- Argument is a visible type application (f @ty)
  | HsArgPar SrcSpan -- See Note [HsArgPar]
-}

-- TODO:AZ: simplify
markTyClass :: (Annotate a, Annotate ast)
            => GHC.LexicalFixity -> GHC.Located a
            -> [GHC.Located ast] -> Annotated ()
markTyClass :: forall a ast.
(Annotate a, Annotate ast) =>
LexicalFixity -> Located a -> [Located ast] -> Annotated ()
markTyClass = (Located ast -> Annotated ())
-> Maybe [Located (HsTyVarBndr () GhcPs)]
-> LexicalFixity
-> Located a
-> [Located ast]
-> Annotated ()
forall a flag b.
(Annotate a, Data flag) =>
(b -> Annotated ())
-> Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity
-> Located a
-> [b]
-> Annotated ()
markTyClassWorker Located ast -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (Maybe [Located (HsTyVarBndr () GhcPs)]
forall a. Maybe a
Nothing :: Maybe [GHC.LHsTyVarBndr () GhcPs])

markTyClassWorker :: (Annotate a, Data flag)
            => (b -> Annotated ()) -> Maybe [GHC.LHsTyVarBndr flag GhcPs] -> GHC.LexicalFixity
            -> GHC.Located a -> [b] -> Annotated ()
markTyClassWorker :: forall a flag b.
(Annotate a, Data flag) =>
(b -> Annotated ())
-> Maybe [LHsTyVarBndr flag GhcPs]
-> LexicalFixity
-> Located a
-> [b]
-> Annotated ()
markTyClassWorker b -> Annotated ()
markFn Maybe [LHsTyVarBndr flag GhcPs]
mbndrs LexicalFixity
fixity Located a
ln [b]
tyVars = do
    let processBinders :: Annotated ()
processBinders =
          case Maybe [LHsTyVarBndr flag GhcPs]
mbndrs of
            Maybe [LHsTyVarBndr flag GhcPs]
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
            Just [LHsTyVarBndr flag GhcPs]
bndrs -> do
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
              (LHsTyVarBndr flag GhcPs -> Annotated ())
-> [LHsTyVarBndr flag GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsTyVarBndr flag GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsTyVarBndr flag GhcPs]
bndrs
              AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot

    -- There may be arbitrary parens around parts of the constructor
    -- Turn these into comments so that they feed into the right place automatically
    [AnnKeywordId] -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
[AnnKeywordId] -> m ()
annotationsToComments [AnnKeywordId
GHC.AnnOpenP,AnnKeywordId
GHC.AnnCloseP]
    let markParens :: AnnKeywordId -> Annotated ()
markParens = if LexicalFixity
fixity LexicalFixity -> LexicalFixity -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFixity
GHC.Infix Bool -> Bool -> Bool
&& [b] -> PhaseNum
forall (t :: * -> *) a. Foldable t => t a -> PhaseNum
length [b]
tyVars PhaseNum -> PhaseNum -> Bool
forall a. Ord a => a -> a -> Bool
> PhaseNum
2
          then AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany
          else AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional
    if LexicalFixity
fixity LexicalFixity -> LexicalFixity -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFixity
GHC.Prefix
      then do
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
GHC.AnnOpenP
        Annotated ()
processBinders
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located a -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located a
ln
        -- setContext (Set.singleton PrefixOp) $ mapM_ markLocated tyVars
        Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (b -> Annotated ()) -> [b] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ b -> Annotated ()
markFn ([b] -> Annotated ()) -> [b] -> Annotated ()
forall a b. (a -> b) -> a -> b
$ PhaseNum -> [b] -> [b]
forall a. PhaseNum -> [a] -> [a]
take PhaseNum
2 [b]
tyVars
        Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([b] -> PhaseNum
forall (t :: * -> *) a. Foldable t => t a -> PhaseNum
length [b]
tyVars PhaseNum -> PhaseNum -> Bool
forall a. Ord a => a -> a -> Bool
>= PhaseNum
2) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
          AnnKeywordId -> Annotated ()
markParens AnnKeywordId
GHC.AnnCloseP
          Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (b -> Annotated ()) -> [b] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ b -> Annotated ()
markFn ([b] -> Annotated ()) -> [b] -> Annotated ()
forall a b. (a -> b) -> a -> b
$ PhaseNum -> [b] -> [b]
forall a. PhaseNum -> [a] -> [a]
drop PhaseNum
2 [b]
tyVars
        AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
GHC.AnnCloseP
      else do
        case [b]
tyVars of
          (b
x:b
y:[b]
xs) -> do
            AnnKeywordId -> Annotated ()
markParens AnnKeywordId
GHC.AnnOpenP
            Annotated ()
processBinders
            b -> Annotated ()
markFn b
x
            Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
InfixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located a -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located a
ln
            b -> Annotated ()
markFn b
y
            AnnKeywordId -> Annotated ()
markParens AnnKeywordId
GHC.AnnCloseP
            (b -> Annotated ()) -> [b] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ b -> Annotated ()
markFn [b]
xs
            AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
GHC.AnnCloseP
          [b]
_ -> String -> Annotated ()
forall a. HasCallStack => String -> a
error (String -> Annotated ()) -> String -> Annotated ()
forall a b. (a -> b) -> a -> b
$ String
"markTyClass: Infix op without operands"

-- ---------------------------------------------------------------------

instance Annotate [GHC.LHsDerivingClause GHC.GhcPs] where
  markAST :: SrcSpan -> [LHsDerivingClause GhcPs] -> Annotated ()
markAST SrcSpan
_ [LHsDerivingClause GhcPs]
ds = (LHsDerivingClause GhcPs -> Annotated ())
-> [LHsDerivingClause GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsDerivingClause GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsDerivingClause GhcPs]
ds

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsDerivingClause GHC.GhcPs) where
  markAST :: SrcSpan -> HsDerivingClause GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.HsDerivingClause XCHsDerivingClause GhcPs
_ Maybe (LDerivStrategy GhcPs)
mstrategy Located [LHsSigType GhcPs]
typs) = do
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDeriving
    case Maybe (LDerivStrategy GhcPs)
mstrategy of
      Maybe (LDerivStrategy GhcPs)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just (GHC.L SrcSpan
_ (GHC.ViaStrategy{})) -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just LDerivStrategy GhcPs
s -> LDerivStrategy GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LDerivStrategy GhcPs
s
    Located [LHsSigType GhcPs] -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located [LHsSigType GhcPs]
typs
    case Maybe (LDerivStrategy GhcPs)
mstrategy of
      Just s :: LDerivStrategy GhcPs
s@(GHC.L SrcSpan
_ (GHC.ViaStrategy{})) -> LDerivStrategy GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LDerivStrategy GhcPs
s
      Maybe (LDerivStrategy GhcPs)
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- ---------------------------------------------------------------------

instance Annotate (GHC.FamilyDecl GHC.GhcPs) where
  markAST :: SrcSpan -> FamilyDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.FamilyDecl XCFamilyDecl GhcPs
_ FamilyInfo GhcPs
info Located (IdP GhcPs)
ln (GHC.HsQTvs XHsQTvs GhcPs
_ [Located (HsTyVarBndr () GhcPs)]
tyvars) LexicalFixity
fixity LFamilyResultSig GhcPs
rsig Maybe (LInjectivityAnn GhcPs)
minj) = do
    case FamilyInfo GhcPs
info of
      FamilyInfo GhcPs
GHC.DataFamily -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnData
      FamilyInfo GhcPs
_              -> AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnType

    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnFamily

    LexicalFixity
-> Located RdrName
-> [Located (HsTyVarBndr () GhcPs)]
-> Annotated ()
forall a ast.
(Annotate a, Annotate ast) =>
LexicalFixity -> Located a -> [Located ast] -> Annotated ()
markTyClass LexicalFixity
fixity Located (IdP GhcPs)
Located RdrName
ln [Located (HsTyVarBndr () GhcPs)]
tyvars
    case LFamilyResultSig GhcPs -> FamilyResultSig GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LFamilyResultSig GhcPs
rsig of
      GHC.NoSig XNoSig GhcPs
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      GHC.KindSig XCKindSig GhcPs
_ LBangType GhcPs
_ -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
        LFamilyResultSig GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LFamilyResultSig GhcPs
rsig
      GHC.TyVarSig XTyVarSig GhcPs
_ Located (HsTyVarBndr () GhcPs)
_ -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
        LFamilyResultSig GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LFamilyResultSig GhcPs
rsig
    case Maybe (LInjectivityAnn GhcPs)
minj of
      Maybe (LInjectivityAnn GhcPs)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just LInjectivityAnn GhcPs
inj -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
        LInjectivityAnn GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LInjectivityAnn GhcPs
inj
    case FamilyInfo GhcPs
info of
      GHC.ClosedTypeFamily (Just [LTyFamInstEqn GhcPs]
eqns) -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnOpenC -- {
        [LTyFamInstEqn GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LTyFamInstEqn GhcPs]
eqns
        AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnCloseC -- }
      GHC.ClosedTypeFamily Maybe [LTyFamInstEqn GhcPs]
Nothing -> do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnWhere
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenC -- {
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDotdot
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseC -- }
      FamilyInfo GhcPs
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

instance Annotate (GHC.FamilyResultSig GHC.GhcPs) where
  markAST :: SrcSpan -> FamilyResultSig GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.NoSig XNoSig GhcPs
_)        = () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  markAST SrcSpan
_ (GHC.KindSig XCKindSig GhcPs
_ LBangType GhcPs
k)    = LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
k
  markAST SrcSpan
_ (GHC.TyVarSig XTyVarSig GhcPs
_ Located (HsTyVarBndr () GhcPs)
ltv) = Located (HsTyVarBndr () GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsTyVarBndr () GhcPs)
ltv

-- ---------------------------------------------------------------------

instance Annotate (GHC.InjectivityAnn GHC.GhcPs) where
  markAST :: SrcSpan -> InjectivityAnn GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.InjectivityAnn Located (IdP GhcPs)
ln [Located (IdP GhcPs)]
lns) = do
    Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
    (Located RdrName -> Annotated ())
-> [Located RdrName] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located (IdP GhcPs)]
[Located RdrName]
lns

-- ---------------------------------------------------------------------

instance Annotate (GHC.TyFamInstEqn GHC.GhcPs) where
{-
type TyFamInstEqn pass = FamInstEqn pass (LHsType pass)

type FamInstEqn pass rhs
  = HsImplicitBndrs pass (FamEqn pass (HsTyPats pass) rhs)

type HsTyPats pass = [LHsTypeArg pass]

-}
  markAST :: SrcSpan
-> HsImplicitBndrs GhcPs (FamEqn GhcPs (LBangType GhcPs))
-> Annotated ()
markAST SrcSpan
_ (GHC.HsIB XHsIB GhcPs (FamEqn GhcPs (LBangType GhcPs))
_ FamEqn GhcPs (LBangType GhcPs)
eqn) = do
    FamEqn GhcPs (LBangType GhcPs) -> Annotated ()
markFamEqn FamEqn GhcPs (LBangType GhcPs)
eqn
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

-- instance Annotate (GHC.TyFamDefltEqn GHC.GhcPs) where

--   markAST _ (GHC.FamEqn _ ln mbndrs (GHC.HsQTvs _ bndrs) fixity typ) = do
--     mark GHC.AnnType
--     mark GHC.AnnInstance
--     markTyClass mbndrs fixity ln bndrs
--     mark GHC.AnnEqual
--     markLocated typ

  -- markAST _ (GHC.FamEqn _ _ _ (GHC.XLHsQTyVars _) _ _)
  --   = error "TyFamDefltEqn hit extension point"
  -- markAST _ (GHC.XFamEqn _)
  --   = error "TyFamDefltEqn hit extension point"

-- ---------------------------------------------------------------------

-- TODO: modify lexer etc, in the meantime to not set haddock flag
instance Annotate GHC.DocDecl where
  markAST :: SrcSpan -> DocDecl -> Annotated ()
markAST SrcSpan
l DocDecl
v =
    let str :: String
str =
          case DocDecl
v of
            (GHC.DocCommentNext HsDocString
ds)     -> HsDocString -> String
GHC.unpackHDS HsDocString
ds
            (GHC.DocCommentPrev HsDocString
ds)     -> HsDocString -> String
GHC.unpackHDS HsDocString
ds
            (GHC.DocCommentNamed String
_s HsDocString
ds) -> HsDocString -> String
GHC.unpackHDS HsDocString
ds
            (GHC.DocGroup PhaseNum
_i HsDocString
ds)        -> HsDocString -> String
GHC.unpackHDS HsDocString
ds
    in
      SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
str Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Annotated ()
markTrailingSemi
{-
data DocDecl
  = DocCommentNext HsDocString
  | DocCommentPrev HsDocString
  | DocCommentNamed String HsDocString
  | DocGroup Int HsDocString

-}

-- ---------------------------------------------------------------------

markDataDefn :: GHC.SrcSpan -> GHC.HsDataDefn GHC.GhcPs -> Annotated ()
markDataDefn :: SrcSpan -> HsDataDefn GhcPs -> Annotated ()
markDataDefn SrcSpan
_ (GHC.HsDataDefn XCHsDataDefn GhcPs
_ NewOrData
_ LHsContext GhcPs
ctx Maybe (Located CType)
typ Maybe (LBangType GhcPs)
_mk [LConDecl GhcPs]
cons HsDeriving GhcPs
derivs) = do
  LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
ctx
  Maybe (Located CType) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (Located CType)
typ
  if [LConDecl GhcPs] -> Bool
forall name. [LConDecl name] -> Bool
isGadt [LConDecl GhcPs]
cons
    then [LConDecl GhcPs] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListWithLayout [LConDecl GhcPs]
cons
    else (LConDecl GhcPs -> Annotated ())
-> PhaseNum -> [LConDecl GhcPs] -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LConDecl GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 [LConDecl GhcPs]
cons
  Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Deriving) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ HsDeriving GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated HsDeriving GhcPs
derivs

-- ---------------------------------------------------------------------

-- Note: GHC.HsContext name aliases to here too
instance Annotate [GHC.LHsType GHC.GhcPs] where
  markAST :: SrcSpan -> HsContext GhcPs -> Annotated ()
markAST SrcSpan
l HsContext GhcPs
ts = do
    -- Note: A single item in parens in a standalone deriving clause
    -- is parsed as a HsSigType, which is always a HsForAllTy or
    -- HsQualTy. Without parens it is always a HsVar. So for round
    -- trip pretty printing we need to take this into account.
    let
      parenIfNeeded' :: AnnKeywordId -> Annotated ()
parenIfNeeded' AnnKeywordId
pa =
        case HsContext GhcPs
ts of
          []  -> if SrcSpan
l SrcSpan -> SrcSpan -> Bool
forall a. Eq a => a -> a -> Bool
== SrcSpan
GHC.noSrcSpan
            then AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
pa
            else AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany AnnKeywordId
pa
          [GHC.L SrcSpan
_ GHC.HsForAllTy{}] -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany AnnKeywordId
pa
          [GHC.L SrcSpan
_ GHC.HsQualTy{}] -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany AnnKeywordId
pa
          [LBangType GhcPs
_] -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
pa
          HsContext GhcPs
_   -> AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany         AnnKeywordId
pa

      parenIfNeeded'' :: AnnKeywordId -> Annotated ()
parenIfNeeded'' AnnKeywordId
pa =
        Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
Parens) -- AZ:TODO: this is never set?
          (AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markMany AnnKeywordId
pa)
          (AnnKeywordId -> Annotated ()
parenIfNeeded' AnnKeywordId
pa)

      parenIfNeeded :: AnnKeywordId -> Annotated ()
parenIfNeeded AnnKeywordId
pa =
        case HsContext GhcPs
ts of
          [GHC.L SrcSpan
_ GHC.HsParTy{}] -> AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
pa
          HsContext GhcPs
_ -> AnnKeywordId -> Annotated ()
parenIfNeeded'' AnnKeywordId
pa

    -- -------------

    AnnKeywordId -> Annotated ()
parenIfNeeded AnnKeywordId
GHC.AnnOpenP

    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ (LBangType GhcPs -> Annotated ())
-> PhaseNum -> HsContext GhcPs -> Annotated ()
forall t. (t -> Annotated ()) -> PhaseNum -> [t] -> Annotated ()
markListIntercalateWithFunLevel LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated PhaseNum
2 HsContext GhcPs
ts

    AnnKeywordId -> Annotated ()
parenIfNeeded AnnKeywordId
GHC.AnnCloseP

    Set AstContext -> Annotated () -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
Set AstContext -> Annotated () -> Annotated () -> m ()
ifInContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
NoDarrow)
      (() -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
      (if HsContext GhcPs -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HsContext GhcPs
ts Bool -> Bool -> Bool
&& (SrcSpan
l SrcSpan -> SrcSpan -> Bool
forall a. Eq a => a -> a -> Bool
== SrcSpan
GHC.noSrcSpan)
         then AnnKeywordId -> Annotated ()
markOptional AnnKeywordId
GHC.AnnDarrow
         else AnnKeywordId -> Annotated ()
mark         AnnKeywordId
GHC.AnnDarrow)

-- ---------------------------------------------------------------------

instance Annotate (GHC.ConDecl GHC.GhcPs) where
  markAST :: SrcSpan -> ConDecl GhcPs -> Annotated ()
markAST SrcSpan
_ (GHC.ConDeclH98 XConDeclH98 GhcPs
_ Located (IdP GhcPs)
ln (GHC.L SrcSpan
_ Bool
fa) [LHsTyVarBndr Specificity GhcPs]
mqtvs Maybe (LHsContext GhcPs)
mctx
                         HsConDeclDetails GhcPs
dets Maybe LHsDocString
_) = do
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
fa (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
        (LHsTyVarBndr Specificity GhcPs -> Annotated ())
-> [LHsTyVarBndr Specificity GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsTyVarBndr Specificity GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsTyVarBndr Specificity GhcPs]
mqtvs
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot

    case Maybe (LHsContext GhcPs)
mctx of
      Just LHsContext GhcPs
ctx -> do
        Set AstContext -> Annotated () -> Annotated ()
setContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
NoDarrow]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LHsContext GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LHsContext GhcPs
ctx
        AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDarrow
      Maybe (LHsContext GhcPs)
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

    case HsConDeclDetails GhcPs
dets of
      GHC.InfixCon HsScaled GhcPs (LBangType GhcPs)
_ HsScaled GhcPs (LBangType GhcPs)
_ -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      HsConDeclDetails GhcPs
_ -> Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (IdP GhcPs)
Located RdrName
ln

    Bool
-> Bool
-> [Located RdrName]
-> HsConDeclDetails GhcPs
-> Annotated ()
markHsConDeclDetails Bool
False Bool
False [Located (IdP GhcPs)
Located RdrName
ln] HsConDeclDetails GhcPs
dets

    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnVbar
    Annotated ()
markTrailingSemi

  markAST SrcSpan
_ (GHC.ConDeclGADT XConDeclGADT GhcPs
_ [Located (IdP GhcPs)]
lns (GHC.L SrcSpan
l Bool
forall) [LHsTyVarBndr Specificity GhcPs]
qvars Maybe (LHsContext GhcPs)
mbCxt HsConDeclDetails GhcPs
args LBangType GhcPs
typ Maybe LHsDocString
_) = do
    let
      surroundParens :: Bool
surroundParens
        = case HsConDeclDetails GhcPs
args of
            GHC.PrefixCon [] -> [LHsTyVarBndr Specificity GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsTyVarBndr Specificity GhcPs]
qvars Bool -> Bool -> Bool
&& Bool -> Bool
not (Maybe (LHsContext GhcPs) -> Bool
forall a. Maybe a -> Bool
isJust Maybe (LHsContext GhcPs)
mbCxt)
            HsConDeclDetails GhcPs
_ -> Bool
False

        -- null qvars &&
        -- mbCxt == Nothing &&
    Set AstContext -> Annotated () -> Annotated ()
setContext (AstContext -> Set AstContext
forall a. a -> Set a
Set.singleton AstContext
PrefixOp) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ [Located RdrName] -> Annotated ()
forall ast. Annotate ast => [Located ast] -> Annotated ()
markListIntercalate [Located (IdP GhcPs)]
[Located RdrName]
lns
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDcolon
    [AnnKeywordId] -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
[AnnKeywordId] -> m ()
annotationsToComments [AnnKeywordId
GHC.AnnOpenP]
    if Bool
surroundParens
      then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnOpenP
      else () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    Located ResTyGADTHook -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated (SrcSpan -> ResTyGADTHook -> Located ResTyGADTHook
forall l e. l -> e -> GenLocated l e
GHC.L SrcSpan
l (Bool -> [LHsTyVarBndr Specificity GhcPs] -> ResTyGADTHook
ResTyGADTHook Bool
forall [LHsTyVarBndr Specificity GhcPs]
qvars))
    Maybe (LHsContext GhcPs) -> Annotated ()
forall ast. Annotate ast => Maybe (Located ast) -> Annotated ()
markMaybe Maybe (LHsContext GhcPs)
mbCxt
    Bool
-> Bool
-> [Located RdrName]
-> HsConDeclDetails GhcPs
-> Annotated ()
markHsConDeclDetails Bool
False Bool
True [Located (IdP GhcPs)]
[Located RdrName]
lns HsConDeclDetails GhcPs
args
    LBangType GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LBangType GhcPs
typ
    if Bool
surroundParens
      then AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnCloseP
      else AnnKeywordId -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AnnKeywordId -> m ()
markManyOptional AnnKeywordId
GHC.AnnCloseP
    Annotated ()
markTrailingSemi

-- ---------------------------------------------------------------------

-- ResTyGADT has a SrcSpan for the original sigtype, we need to create
-- a type for exactPC and annotatePC
data ResTyGADTHook = ResTyGADTHook Bool [GHC.LHsTyVarBndr GHC.Specificity GHC.GhcPs]
                   deriving (Typeable)
deriving instance Data (ResTyGADTHook)

instance GHC.Outputable ResTyGADTHook where
  ppr :: ResTyGADTHook -> SDoc
ppr (ResTyGADTHook Bool
b [LHsTyVarBndr Specificity GhcPs]
bs) = String -> SDoc
GHC.text String
"ResTyGADTHook" SDoc -> SDoc -> SDoc
GHC.<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
GHC.ppr Bool
b SDoc -> SDoc -> SDoc
GHC.<+> [LHsTyVarBndr Specificity GhcPs] -> SDoc
forall a. Outputable a => a -> SDoc
GHC.ppr [LHsTyVarBndr Specificity GhcPs]
bs


-- WildCardAnon exists because the GHC anonymous wildcard type is defined as
--      = AnonWildCard (PostRn name Name)
-- We need to reconstruct this from the typed hole SrcSpan in an HsForAllTy, but
-- the instance doing this is parameterised on name, so we cannot put a value in
-- for the (PostRn name Name) field. This is used instead.
data WildCardAnon = WildCardAnon deriving (PhaseNum -> WildCardAnon -> String -> String
[WildCardAnon] -> String -> String
WildCardAnon -> String
(PhaseNum -> WildCardAnon -> String -> String)
-> (WildCardAnon -> String)
-> ([WildCardAnon] -> String -> String)
-> Show WildCardAnon
forall a.
(PhaseNum -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [WildCardAnon] -> String -> String
$cshowList :: [WildCardAnon] -> String -> String
show :: WildCardAnon -> String
$cshow :: WildCardAnon -> String
showsPrec :: PhaseNum -> WildCardAnon -> String -> String
$cshowsPrec :: PhaseNum -> WildCardAnon -> String -> String
Show,Typeable WildCardAnon
Typeable WildCardAnon
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> WildCardAnon -> c WildCardAnon)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c WildCardAnon)
-> (WildCardAnon -> Constr)
-> (WildCardAnon -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c WildCardAnon))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c WildCardAnon))
-> ((forall b. Data b => b -> b) -> WildCardAnon -> WildCardAnon)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r)
-> (forall u. (forall d. Data d => d -> u) -> WildCardAnon -> [u])
-> (forall u.
    PhaseNum -> (forall d. Data d => d -> u) -> WildCardAnon -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon)
-> Data WildCardAnon
WildCardAnon -> DataType
WildCardAnon -> Constr
(forall b. Data b => b -> b) -> WildCardAnon -> WildCardAnon
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. PhaseNum -> (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.
PhaseNum -> (forall d. Data d => d -> u) -> WildCardAnon -> u
forall u. (forall d. Data d => d -> u) -> WildCardAnon -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WildCardAnon
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WildCardAnon -> c WildCardAnon
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WildCardAnon)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c WildCardAnon)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> WildCardAnon -> m WildCardAnon
gmapQi :: forall u.
PhaseNum -> (forall d. Data d => d -> u) -> WildCardAnon -> u
$cgmapQi :: forall u.
PhaseNum -> (forall d. Data d => d -> u) -> WildCardAnon -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> WildCardAnon -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> WildCardAnon -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WildCardAnon -> r
gmapT :: (forall b. Data b => b -> b) -> WildCardAnon -> WildCardAnon
$cgmapT :: (forall b. Data b => b -> b) -> WildCardAnon -> WildCardAnon
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c WildCardAnon)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c WildCardAnon)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WildCardAnon)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c WildCardAnon)
dataTypeOf :: WildCardAnon -> DataType
$cdataTypeOf :: WildCardAnon -> DataType
toConstr :: WildCardAnon -> Constr
$ctoConstr :: WildCardAnon -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WildCardAnon
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c WildCardAnon
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WildCardAnon -> c WildCardAnon
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WildCardAnon -> c WildCardAnon
Data,Typeable)

instance Annotate WildCardAnon where
  markAST :: SrcSpan -> WildCardAnon -> Annotated ()
markAST SrcSpan
l WildCardAnon
WildCardAnon = do
    SrcSpan -> AnnKeywordId -> String -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
SrcSpan -> AnnKeywordId -> String -> m ()
markExternal SrcSpan
l AnnKeywordId
GHC.AnnVal String
"_"

-- ---------------------------------------------------------------------

instance Annotate ResTyGADTHook where
  markAST :: SrcSpan -> ResTyGADTHook -> Annotated ()
markAST SrcSpan
_ (ResTyGADTHook Bool
forall [LHsTyVarBndr Specificity GhcPs]
bndrs) = do
    -- markManyOptional GHC.AnnOpenP
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
forall (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnForall
    (LHsTyVarBndr Specificity GhcPs -> Annotated ())
-> [LHsTyVarBndr Specificity GhcPs] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsTyVarBndr Specificity GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [LHsTyVarBndr Specificity GhcPs]
bndrs
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
forall (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnDot
    -- markManyOptional GHC.AnnCloseP

-- ---------------------------------------------------------------------

instance Annotate (GHC.HsRecField GHC.GhcPs (GHC.Located (GHC.Pat GHC.GhcPs))) where
  markAST :: SrcSpan -> HsRecField GhcPs (Located (Pat GhcPs)) -> Annotated ()
markAST SrcSpan
_ (GHC.HsRecField LFieldOcc GhcPs
n Located (Pat GhcPs)
e Bool
punFlag) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LFieldOcc GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LFieldOcc GhcPs
n
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
punFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (Pat GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (Pat GhcPs)
e
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma


-- instance Annotate (GHC.HsRecField GHC.GhcPs (GHC.LPat GHC.GhcPs)) where
--   markAST _ (GHC.HsRecField n e punFlag) = do
--     unsetContext Intercalate $ markLocated n
--     unless punFlag $ do
--       mark GHC.AnnEqual
--       unsetContext Intercalate $ markLocated e
--     inContext (Set.fromList [Intercalate]) $ mark GHC.AnnComma


instance Annotate (GHC.HsRecField GHC.GhcPs (GHC.LHsExpr GHC.GhcPs)) where
  markAST :: SrcSpan
-> HsRecField GhcPs (Located (HsExpr GhcPs)) -> Annotated ()
markAST SrcSpan
_ (GHC.HsRecField LFieldOcc GhcPs
n Located (HsExpr GhcPs)
e Bool
punFlag) = do
    AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ LFieldOcc GhcPs -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated LFieldOcc GhcPs
n
    Bool -> Annotated () -> Annotated ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
punFlag (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ do
      AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnEqual
      AstContext -> Annotated () -> Annotated ()
forall (m :: * -> *).
MonadFree AnnotationF m =>
AstContext -> Annotated () -> m ()
unsetContext AstContext
Intercalate (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs) -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated Located (HsExpr GhcPs)
e
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate (GHC.FunDep (GHC.Located GHC.RdrName)) where

  markAST :: SrcSpan -> FunDep (Located RdrName) -> Annotated ()
markAST SrcSpan
_ ([Located RdrName]
ls,[Located RdrName]
rss) = do
    (Located RdrName -> Annotated ())
-> [Located RdrName] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located RdrName]
ls
    AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnRarrow
    (Located RdrName -> Annotated ())
-> [Located RdrName] -> Annotated ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Located RdrName -> Annotated ()
forall ast. Annotate ast => Located ast -> Annotated ()
markLocated [Located RdrName]
rss
    Set AstContext -> Annotated () -> Annotated ()
inContext ([AstContext] -> Set AstContext
forall a. Ord a => [a] -> Set a
Set.fromList [AstContext
Intercalate]) (Annotated () -> Annotated ()) -> Annotated () -> Annotated ()
forall a b. (a -> b) -> a -> b
$ AnnKeywordId -> Annotated ()
mark AnnKeywordId
GHC.AnnComma

-- ---------------------------------------------------------------------

instance Annotate GHC.CType where
  markAST :: SrcSpan -> CType -> Annotated ()
markAST SrcSpan
_ (GHC.CType SourceText
src Maybe Header
mh (SourceText, FastString)
f) = do
    -- markWithString GHC.AnnOpen src
    SourceText -> String -> Annotated ()
markAnnOpen SourceText
src String
""
    case Maybe Header
mh of
      Maybe Header
Nothing -> () -> Annotated ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      Just (GHC.Header SourceText
srcH FastString
_h) ->
         -- markWithString GHC.AnnHeader srcH
         AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnHeader (SourceText -> String -> String -> String
forall a. Show a => SourceText -> a -> String -> String
toSourceTextWithSuffix SourceText
srcH String
"" String
"")
    -- markWithString GHC.AnnVal (fst f)
    SourceText -> String -> Annotated ()
markSourceText  ((SourceText, FastString) -> SourceText
forall a b. (a, b) -> a
fst (SourceText, FastString)
f) (FastString -> String
GHC.unpackFS (FastString -> String) -> FastString -> String
forall a b. (a -> b) -> a -> b
$ (SourceText, FastString) -> FastString
forall a b. (a, b) -> b
snd (SourceText, FastString)
f)
    AnnKeywordId -> String -> Annotated ()
markWithString AnnKeywordId
GHC.AnnClose String
"#-}"

-- ---------------------------------------------------------------------

stringLiteralToString :: GHC.StringLiteral -> String
stringLiteralToString :: StringLiteral -> String
stringLiteralToString (GHC.StringLiteral SourceText
st FastString
fs) =
  case SourceText
st of
    SourceText
GHC.NoSourceText   -> FastString -> String
GHC.unpackFS FastString
fs
    GHC.SourceText String
src -> String
src

-- ---------------------------------------------------------------------