{-| An info object contains additional information about a piece of abstract
    syntax that isn't part of the actual syntax. For instance, it might contain
    the source code position of an expression or the concrete syntax that
    an internal expression originates from.
-}

module Agda.Syntax.Info where

import Prelude hiding (null)

import Control.DeepSeq

import Data.Semigroup (Semigroup)

import GHC.Generics (Generic)

import qualified Agda.Syntax.Concrete.Name as C
import Agda.Syntax.Common
import Agda.Syntax.Position
import Agda.Syntax.Concrete
import Agda.Syntax.Fixity
import Agda.Syntax.Scope.Base (ScopeInfo, emptyScopeInfo)

import Agda.Utils.Functor
import Agda.Utils.Null

{--------------------------------------------------------------------------
    Meta information
 --------------------------------------------------------------------------}

data MetaInfo = MetaInfo
  { MetaInfo -> Range
metaRange          :: Range
  , MetaInfo -> ScopeInfo
metaScope          :: ScopeInfo
  , MetaInfo -> Maybe MetaId
metaNumber         :: Maybe MetaId
  , MetaInfo -> String
metaNameSuggestion :: String
  }
  deriving (Int -> MetaInfo -> ShowS
[MetaInfo] -> ShowS
MetaInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetaInfo] -> ShowS
$cshowList :: [MetaInfo] -> ShowS
show :: MetaInfo -> String
$cshow :: MetaInfo -> String
showsPrec :: Int -> MetaInfo -> ShowS
$cshowsPrec :: Int -> MetaInfo -> ShowS
Show, MetaInfo -> MetaInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetaInfo -> MetaInfo -> Bool
$c/= :: MetaInfo -> MetaInfo -> Bool
== :: MetaInfo -> MetaInfo -> Bool
$c== :: MetaInfo -> MetaInfo -> Bool
Eq, forall x. Rep MetaInfo x -> MetaInfo
forall x. MetaInfo -> Rep MetaInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetaInfo x -> MetaInfo
$cfrom :: forall x. MetaInfo -> Rep MetaInfo x
Generic)

emptyMetaInfo :: MetaInfo
emptyMetaInfo :: MetaInfo
emptyMetaInfo = MetaInfo
  { metaRange :: Range
metaRange          = forall a. Range' a
noRange
  , metaScope :: ScopeInfo
metaScope          = ScopeInfo
emptyScopeInfo
  , metaNumber :: Maybe MetaId
metaNumber         = forall a. Maybe a
Nothing
  , metaNameSuggestion :: String
metaNameSuggestion = String
""
  }

instance HasRange MetaInfo where
  getRange :: MetaInfo -> Range
getRange = MetaInfo -> Range
metaRange

instance KillRange MetaInfo where
  killRange :: KillRangeT MetaInfo
killRange MetaInfo
m = MetaInfo
m { metaRange :: Range
metaRange = forall a. Range' a
noRange }

instance NFData MetaInfo

{--------------------------------------------------------------------------
    General expression information
 --------------------------------------------------------------------------}

newtype ExprInfo = ExprRange Range
  deriving (Int -> ExprInfo -> ShowS
[ExprInfo] -> ShowS
ExprInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExprInfo] -> ShowS
$cshowList :: [ExprInfo] -> ShowS
show :: ExprInfo -> String
$cshow :: ExprInfo -> String
showsPrec :: Int -> ExprInfo -> ShowS
$cshowsPrec :: Int -> ExprInfo -> ShowS
Show, ExprInfo -> ExprInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExprInfo -> ExprInfo -> Bool
$c/= :: ExprInfo -> ExprInfo -> Bool
== :: ExprInfo -> ExprInfo -> Bool
$c== :: ExprInfo -> ExprInfo -> Bool
Eq, ExprInfo
ExprInfo -> Bool
forall a. a -> (a -> Bool) -> Null a
null :: ExprInfo -> Bool
$cnull :: ExprInfo -> Bool
empty :: ExprInfo
$cempty :: ExprInfo
Null, ExprInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: ExprInfo -> ()
$crnf :: ExprInfo -> ()
NFData)

exprNoRange :: ExprInfo
exprNoRange :: ExprInfo
exprNoRange = Range -> ExprInfo
ExprRange forall a. Range' a
noRange

instance HasRange ExprInfo where
  getRange :: ExprInfo -> Range
getRange (ExprRange Range
r) = Range
r

instance KillRange ExprInfo where
  killRange :: KillRangeT ExprInfo
killRange (ExprRange Range
r) = ExprInfo
exprNoRange

{--------------------------------------------------------------------------
    Application information
 --------------------------------------------------------------------------}

-- | Information about application
data AppInfo = AppInfo
  { AppInfo -> Range
appRange  :: Range
  , AppInfo -> Origin
appOrigin :: Origin
  , AppInfo -> ParenPreference
appParens :: ParenPreference -- ^ Do we prefer a lambda argument with or without parens?
  }
  deriving (Int -> AppInfo -> ShowS
[AppInfo] -> ShowS
AppInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AppInfo] -> ShowS
$cshowList :: [AppInfo] -> ShowS
show :: AppInfo -> String
$cshow :: AppInfo -> String
showsPrec :: Int -> AppInfo -> ShowS
$cshowsPrec :: Int -> AppInfo -> ShowS
Show, AppInfo -> AppInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AppInfo -> AppInfo -> Bool
$c/= :: AppInfo -> AppInfo -> Bool
== :: AppInfo -> AppInfo -> Bool
$c== :: AppInfo -> AppInfo -> Bool
Eq, Eq AppInfo
AppInfo -> AppInfo -> Bool
AppInfo -> AppInfo -> Ordering
AppInfo -> AppInfo -> AppInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AppInfo -> AppInfo -> AppInfo
$cmin :: AppInfo -> AppInfo -> AppInfo
max :: AppInfo -> AppInfo -> AppInfo
$cmax :: AppInfo -> AppInfo -> AppInfo
>= :: AppInfo -> AppInfo -> Bool
$c>= :: AppInfo -> AppInfo -> Bool
> :: AppInfo -> AppInfo -> Bool
$c> :: AppInfo -> AppInfo -> Bool
<= :: AppInfo -> AppInfo -> Bool
$c<= :: AppInfo -> AppInfo -> Bool
< :: AppInfo -> AppInfo -> Bool
$c< :: AppInfo -> AppInfo -> Bool
compare :: AppInfo -> AppInfo -> Ordering
$ccompare :: AppInfo -> AppInfo -> Ordering
Ord, forall x. Rep AppInfo x -> AppInfo
forall x. AppInfo -> Rep AppInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AppInfo x -> AppInfo
$cfrom :: forall x. AppInfo -> Rep AppInfo x
Generic)

-- | Default is system inserted and prefer parens.
defaultAppInfo :: Range -> AppInfo
defaultAppInfo :: Range -> AppInfo
defaultAppInfo Range
r = AppInfo{ appRange :: Range
appRange = Range
r, appOrigin :: Origin
appOrigin = Origin
Inserted, appParens :: ParenPreference
appParens = ParenPreference
PreferParen }

-- | `AppInfo` with no range information.
defaultAppInfo_ :: AppInfo
defaultAppInfo_ :: AppInfo
defaultAppInfo_ = Range -> AppInfo
defaultAppInfo forall a. Range' a
noRange

instance HasRange AppInfo where
  getRange :: AppInfo -> Range
getRange = AppInfo -> Range
appRange

instance KillRange AppInfo where
  killRange :: AppInfo -> AppInfo
killRange (AppInfo Range
r Origin
o ParenPreference
p) = Range -> Origin -> ParenPreference -> AppInfo
AppInfo (forall a. KillRange a => KillRangeT a
killRange Range
r) Origin
o ParenPreference
p

instance LensOrigin AppInfo where
  getOrigin :: AppInfo -> Origin
getOrigin = AppInfo -> Origin
appOrigin
  mapOrigin :: (Origin -> Origin) -> AppInfo -> AppInfo
mapOrigin Origin -> Origin
f AppInfo
i = AppInfo
i { appOrigin :: Origin
appOrigin = Origin -> Origin
f (AppInfo -> Origin
appOrigin AppInfo
i) }

instance NFData AppInfo

{--------------------------------------------------------------------------
    Module information
 --------------------------------------------------------------------------}

data ModuleInfo = ModuleInfo
  { ModuleInfo -> Range
minfoRange    :: Range
  , ModuleInfo -> Range
minfoAsTo     :: Range
    -- ^ The range of the \"as\" and \"to\" keywords,
    -- if any. Retained for highlighting purposes.
  , ModuleInfo -> Maybe Name
minfoAsName   :: Maybe C.Name
    -- ^ The \"as\" module name, if any. Retained for highlighting purposes.
  , ModuleInfo -> Maybe OpenShortHand
minfoOpenShort :: Maybe OpenShortHand
  , ModuleInfo -> Maybe ImportDirective
minfoDirective :: Maybe ImportDirective
    -- ^ Retained for @abstractToConcrete@ of 'ModuleMacro'.
  }
  deriving (ModuleInfo -> ModuleInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModuleInfo -> ModuleInfo -> Bool
$c/= :: ModuleInfo -> ModuleInfo -> Bool
== :: ModuleInfo -> ModuleInfo -> Bool
$c== :: ModuleInfo -> ModuleInfo -> Bool
Eq, Int -> ModuleInfo -> ShowS
[ModuleInfo] -> ShowS
ModuleInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModuleInfo] -> ShowS
$cshowList :: [ModuleInfo] -> ShowS
show :: ModuleInfo -> String
$cshow :: ModuleInfo -> String
showsPrec :: Int -> ModuleInfo -> ShowS
$cshowsPrec :: Int -> ModuleInfo -> ShowS
Show, forall x. Rep ModuleInfo x -> ModuleInfo
forall x. ModuleInfo -> Rep ModuleInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModuleInfo x -> ModuleInfo
$cfrom :: forall x. ModuleInfo -> Rep ModuleInfo x
Generic)

instance HasRange ModuleInfo where
  getRange :: ModuleInfo -> Range
getRange = ModuleInfo -> Range
minfoRange

instance SetRange ModuleInfo where
  setRange :: Range -> ModuleInfo -> ModuleInfo
setRange Range
r ModuleInfo
i = ModuleInfo
i { minfoRange :: Range
minfoRange = Range
r }

instance KillRange ModuleInfo where
  killRange :: ModuleInfo -> ModuleInfo
killRange ModuleInfo
m = ModuleInfo
m { minfoRange :: Range
minfoRange = forall a. Range' a
noRange }

instance NFData ModuleInfo

---------------------------------------------------------------------------
-- Let info
---------------------------------------------------------------------------

newtype LetInfo = LetRange Range
  deriving (Int -> LetInfo -> ShowS
[LetInfo] -> ShowS
LetInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LetInfo] -> ShowS
$cshowList :: [LetInfo] -> ShowS
show :: LetInfo -> String
$cshow :: LetInfo -> String
showsPrec :: Int -> LetInfo -> ShowS
$cshowsPrec :: Int -> LetInfo -> ShowS
Show, LetInfo -> LetInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LetInfo -> LetInfo -> Bool
$c/= :: LetInfo -> LetInfo -> Bool
== :: LetInfo -> LetInfo -> Bool
$c== :: LetInfo -> LetInfo -> Bool
Eq, LetInfo
LetInfo -> Bool
forall a. a -> (a -> Bool) -> Null a
null :: LetInfo -> Bool
$cnull :: LetInfo -> Bool
empty :: LetInfo
$cempty :: LetInfo
Null, LetInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: LetInfo -> ()
$crnf :: LetInfo -> ()
NFData)

instance HasRange LetInfo where
  getRange :: LetInfo -> Range
getRange (LetRange Range
r)   = Range
r

instance KillRange LetInfo where
  killRange :: KillRangeT LetInfo
killRange (LetRange Range
r) = Range -> LetInfo
LetRange forall a. Range' a
noRange

{--------------------------------------------------------------------------
    Definition information (declarations that actually define something)
 --------------------------------------------------------------------------}

data DefInfo' t = DefInfo
  { forall t. DefInfo' t -> Fixity'
defFixity   :: Fixity'
  , forall t. DefInfo' t -> Access
defAccess   :: Access
  , forall t. DefInfo' t -> IsAbstract
defAbstract :: IsAbstract
  , forall t. DefInfo' t -> IsInstance
defInstance :: IsInstance
  , forall t. DefInfo' t -> IsMacro
defMacro    :: IsMacro
  , forall t. DefInfo' t -> DeclInfo
defInfo     :: DeclInfo
  , forall t. DefInfo' t -> Maybe t
defTactic   :: Maybe t
  }
  deriving (Int -> DefInfo' t -> ShowS
forall t. Show t => Int -> DefInfo' t -> ShowS
forall t. Show t => [DefInfo' t] -> ShowS
forall t. Show t => DefInfo' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefInfo' t] -> ShowS
$cshowList :: forall t. Show t => [DefInfo' t] -> ShowS
show :: DefInfo' t -> String
$cshow :: forall t. Show t => DefInfo' t -> String
showsPrec :: Int -> DefInfo' t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> DefInfo' t -> ShowS
Show, DefInfo' t -> DefInfo' t -> Bool
forall t. Eq t => DefInfo' t -> DefInfo' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefInfo' t -> DefInfo' t -> Bool
$c/= :: forall t. Eq t => DefInfo' t -> DefInfo' t -> Bool
== :: DefInfo' t -> DefInfo' t -> Bool
$c== :: forall t. Eq t => DefInfo' t -> DefInfo' t -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (DefInfo' t) x -> DefInfo' t
forall t x. DefInfo' t -> Rep (DefInfo' t) x
$cto :: forall t x. Rep (DefInfo' t) x -> DefInfo' t
$cfrom :: forall t x. DefInfo' t -> Rep (DefInfo' t) x
Generic)

mkDefInfo :: Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' t
mkDefInfo :: forall t.
Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' t
mkDefInfo Name
x Fixity'
f Access
a IsAbstract
ab Range
r = forall t.
Name
-> Fixity'
-> Access
-> IsAbstract
-> IsInstance
-> IsMacro
-> Range
-> DefInfo' t
mkDefInfoInstance Name
x Fixity'
f Access
a IsAbstract
ab IsInstance
NotInstanceDef IsMacro
NotMacroDef Range
r

-- | Same as @mkDefInfo@ but where we can also give the @IsInstance@
mkDefInfoInstance :: Name -> Fixity' -> Access -> IsAbstract -> IsInstance -> IsMacro -> Range -> DefInfo' t
mkDefInfoInstance :: forall t.
Name
-> Fixity'
-> Access
-> IsAbstract
-> IsInstance
-> IsMacro
-> Range
-> DefInfo' t
mkDefInfoInstance Name
x Fixity'
f Access
a IsAbstract
ab IsInstance
i IsMacro
m Range
r = forall t.
Fixity'
-> Access
-> IsAbstract
-> IsInstance
-> IsMacro
-> DeclInfo
-> Maybe t
-> DefInfo' t
DefInfo Fixity'
f Access
a IsAbstract
ab IsInstance
i IsMacro
m (Name -> Range -> DeclInfo
DeclInfo Name
x Range
r) forall a. Maybe a
Nothing

instance HasRange (DefInfo' t) where
  getRange :: DefInfo' t -> Range
getRange = forall a. HasRange a => a -> Range
getRange forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. DefInfo' t -> DeclInfo
defInfo

instance SetRange (DefInfo' t) where
  setRange :: Range -> DefInfo' t -> DefInfo' t
setRange Range
r DefInfo' t
i = DefInfo' t
i { defInfo :: DeclInfo
defInfo = forall a. SetRange a => Range -> a -> a
setRange Range
r (forall t. DefInfo' t -> DeclInfo
defInfo DefInfo' t
i) }

instance KillRange t => KillRange (DefInfo' t) where
  killRange :: KillRangeT (DefInfo' t)
killRange DefInfo' t
i = DefInfo' t
i { defInfo :: DeclInfo
defInfo   = forall a. KillRange a => KillRangeT a
killRange forall a b. (a -> b) -> a -> b
$ forall t. DefInfo' t -> DeclInfo
defInfo DefInfo' t
i,
                    defTactic :: Maybe t
defTactic = forall a. KillRange a => KillRangeT a
killRange forall a b. (a -> b) -> a -> b
$ forall t. DefInfo' t -> Maybe t
defTactic DefInfo' t
i }

instance LensIsAbstract (DefInfo' t) where
  lensIsAbstract :: Lens' IsAbstract (DefInfo' t)
lensIsAbstract IsAbstract -> f IsAbstract
f DefInfo' t
i = (IsAbstract -> f IsAbstract
f forall a b. (a -> b) -> a -> b
$! forall t. DefInfo' t -> IsAbstract
defAbstract DefInfo' t
i) forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ IsAbstract
a -> DefInfo' t
i { defAbstract :: IsAbstract
defAbstract = IsAbstract
a }

instance AnyIsAbstract (DefInfo' t) where
  anyIsAbstract :: DefInfo' t -> IsAbstract
anyIsAbstract = forall t. DefInfo' t -> IsAbstract
defAbstract

instance NFData t => NFData (DefInfo' t)

{--------------------------------------------------------------------------
    General declaration information
 --------------------------------------------------------------------------}

data DeclInfo = DeclInfo
  { DeclInfo -> Name
declName  :: Name
  , DeclInfo -> Range
declRange :: Range
  }
  deriving (Int -> DeclInfo -> ShowS
[DeclInfo] -> ShowS
DeclInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeclInfo] -> ShowS
$cshowList :: [DeclInfo] -> ShowS
show :: DeclInfo -> String
$cshow :: DeclInfo -> String
showsPrec :: Int -> DeclInfo -> ShowS
$cshowsPrec :: Int -> DeclInfo -> ShowS
Show, DeclInfo -> DeclInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeclInfo -> DeclInfo -> Bool
$c/= :: DeclInfo -> DeclInfo -> Bool
== :: DeclInfo -> DeclInfo -> Bool
$c== :: DeclInfo -> DeclInfo -> Bool
Eq, forall x. Rep DeclInfo x -> DeclInfo
forall x. DeclInfo -> Rep DeclInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeclInfo x -> DeclInfo
$cfrom :: forall x. DeclInfo -> Rep DeclInfo x
Generic)

instance HasRange DeclInfo where
  getRange :: DeclInfo -> Range
getRange = DeclInfo -> Range
declRange

instance SetRange DeclInfo where
  setRange :: Range -> DeclInfo -> DeclInfo
setRange Range
r DeclInfo
i = DeclInfo
i { declRange :: Range
declRange = Range
r }

instance KillRange DeclInfo where
  killRange :: DeclInfo -> DeclInfo
killRange DeclInfo
i = DeclInfo
i { declRange :: Range
declRange = forall a. Range' a
noRange }

instance NFData DeclInfo

{--------------------------------------------------------------------------
    Mutual block information
 --------------------------------------------------------------------------}

data MutualInfo = MutualInfo
  { MutualInfo -> TerminationCheck Name
mutualTerminationCheck :: TerminationCheck Name
  , MutualInfo -> CoverageCheck
mutualCoverageCheck    :: CoverageCheck
  , MutualInfo -> PositivityCheck
mutualPositivityCheck  :: PositivityCheck
  , MutualInfo -> Range
mutualRange            :: Range
  }
  deriving (Int -> MutualInfo -> ShowS
[MutualInfo] -> ShowS
MutualInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MutualInfo] -> ShowS
$cshowList :: [MutualInfo] -> ShowS
show :: MutualInfo -> String
$cshow :: MutualInfo -> String
showsPrec :: Int -> MutualInfo -> ShowS
$cshowsPrec :: Int -> MutualInfo -> ShowS
Show, MutualInfo -> MutualInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MutualInfo -> MutualInfo -> Bool
$c/= :: MutualInfo -> MutualInfo -> Bool
== :: MutualInfo -> MutualInfo -> Bool
$c== :: MutualInfo -> MutualInfo -> Bool
Eq, forall x. Rep MutualInfo x -> MutualInfo
forall x. MutualInfo -> Rep MutualInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MutualInfo x -> MutualInfo
$cfrom :: forall x. MutualInfo -> Rep MutualInfo x
Generic)

-- | Default value for 'MutualInfo'.
instance Null MutualInfo where
  empty :: MutualInfo
empty = TerminationCheck Name
-> CoverageCheck -> PositivityCheck -> Range -> MutualInfo
MutualInfo forall m. TerminationCheck m
TerminationCheck CoverageCheck
YesCoverageCheck PositivityCheck
YesPositivityCheck forall a. Range' a
noRange

instance HasRange MutualInfo where
  getRange :: MutualInfo -> Range
getRange = MutualInfo -> Range
mutualRange

instance KillRange MutualInfo where
  killRange :: KillRangeT MutualInfo
killRange MutualInfo
i = MutualInfo
i { mutualRange :: Range
mutualRange = forall a. Range' a
noRange }

instance NFData MutualInfo

{--------------------------------------------------------------------------
    Left hand side information
 --------------------------------------------------------------------------}

data LHSInfo = LHSInfo
  { LHSInfo -> Range
lhsRange    :: Range
  , LHSInfo -> ExpandedEllipsis
lhsEllipsis :: ExpandedEllipsis
  } deriving (Int -> LHSInfo -> ShowS
[LHSInfo] -> ShowS
LHSInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LHSInfo] -> ShowS
$cshowList :: [LHSInfo] -> ShowS
show :: LHSInfo -> String
$cshow :: LHSInfo -> String
showsPrec :: Int -> LHSInfo -> ShowS
$cshowsPrec :: Int -> LHSInfo -> ShowS
Show, LHSInfo -> LHSInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LHSInfo -> LHSInfo -> Bool
$c/= :: LHSInfo -> LHSInfo -> Bool
== :: LHSInfo -> LHSInfo -> Bool
$c== :: LHSInfo -> LHSInfo -> Bool
Eq, forall x. Rep LHSInfo x -> LHSInfo
forall x. LHSInfo -> Rep LHSInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LHSInfo x -> LHSInfo
$cfrom :: forall x. LHSInfo -> Rep LHSInfo x
Generic)

instance HasRange LHSInfo where
  getRange :: LHSInfo -> Range
getRange (LHSInfo Range
r ExpandedEllipsis
_) = Range
r

instance KillRange LHSInfo where
  killRange :: KillRangeT LHSInfo
killRange (LHSInfo Range
r ExpandedEllipsis
ell) = Range -> ExpandedEllipsis -> LHSInfo
LHSInfo forall a. Range' a
noRange ExpandedEllipsis
ell

instance Null LHSInfo where
  null :: LHSInfo -> Bool
null LHSInfo
i = forall a. Null a => a -> Bool
null (LHSInfo -> Range
lhsRange LHSInfo
i) Bool -> Bool -> Bool
&& forall a. Null a => a -> Bool
null (LHSInfo -> ExpandedEllipsis
lhsEllipsis LHSInfo
i)
  empty :: LHSInfo
empty  = Range -> ExpandedEllipsis -> LHSInfo
LHSInfo forall a. Null a => a
empty forall a. Null a => a
empty

instance NFData LHSInfo

{--------------------------------------------------------------------------
    Pattern information
 --------------------------------------------------------------------------}

-- | For a general pattern we remember the source code position.
newtype PatInfo
  = PatRange Range
  deriving (PatInfo -> PatInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatInfo -> PatInfo -> Bool
$c/= :: PatInfo -> PatInfo -> Bool
== :: PatInfo -> PatInfo -> Bool
$c== :: PatInfo -> PatInfo -> Bool
Eq, PatInfo
PatInfo -> Bool
forall a. a -> (a -> Bool) -> Null a
null :: PatInfo -> Bool
$cnull :: PatInfo -> Bool
empty :: PatInfo
$cempty :: PatInfo
Null, NonEmpty PatInfo -> PatInfo
PatInfo -> PatInfo -> PatInfo
forall b. Integral b => b -> PatInfo -> PatInfo
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> PatInfo -> PatInfo
$cstimes :: forall b. Integral b => b -> PatInfo -> PatInfo
sconcat :: NonEmpty PatInfo -> PatInfo
$csconcat :: NonEmpty PatInfo -> PatInfo
<> :: PatInfo -> PatInfo -> PatInfo
$c<> :: PatInfo -> PatInfo -> PatInfo
Semigroup, Semigroup PatInfo
PatInfo
[PatInfo] -> PatInfo
PatInfo -> PatInfo -> PatInfo
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [PatInfo] -> PatInfo
$cmconcat :: [PatInfo] -> PatInfo
mappend :: PatInfo -> PatInfo -> PatInfo
$cmappend :: PatInfo -> PatInfo -> PatInfo
mempty :: PatInfo
$cmempty :: PatInfo
Monoid, Int -> PatInfo -> ShowS
[PatInfo] -> ShowS
PatInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatInfo] -> ShowS
$cshowList :: [PatInfo] -> ShowS
show :: PatInfo -> String
$cshow :: PatInfo -> String
showsPrec :: Int -> PatInfo -> ShowS
$cshowsPrec :: Int -> PatInfo -> ShowS
Show, HasRange PatInfo
Range -> PatInfo -> PatInfo
forall a. HasRange a -> (Range -> a -> a) -> SetRange a
setRange :: Range -> PatInfo -> PatInfo
$csetRange :: Range -> PatInfo -> PatInfo
SetRange, PatInfo -> Range
forall a. (a -> Range) -> HasRange a
getRange :: PatInfo -> Range
$cgetRange :: PatInfo -> Range
HasRange,
            PatInfo -> PatInfo
forall a. KillRangeT a -> KillRange a
killRange :: PatInfo -> PatInfo
$ckillRange :: PatInfo -> PatInfo
KillRange, PatInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: PatInfo -> ()
$crnf :: PatInfo -> ()
NFData)

-- | Empty range for patterns.
patNoRange :: PatInfo
patNoRange :: PatInfo
patNoRange = Range -> PatInfo
PatRange forall a. Range' a
noRange

-- | Constructor pattern info.
data ConPatInfo = ConPatInfo
  { ConPatInfo -> ConOrigin
conPatOrigin   :: ConOrigin
    -- ^ Does this pattern come form the eta-expansion of an implicit pattern?
    ---  Or from a user written constructor or record pattern?
  , ConPatInfo -> PatInfo
conPatInfo     :: PatInfo
  , ConPatInfo -> ConPatLazy
conPatLazy     :: ConPatLazy
  }
  deriving (ConPatInfo -> ConPatInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConPatInfo -> ConPatInfo -> Bool
$c/= :: ConPatInfo -> ConPatInfo -> Bool
== :: ConPatInfo -> ConPatInfo -> Bool
$c== :: ConPatInfo -> ConPatInfo -> Bool
Eq, Int -> ConPatInfo -> ShowS
[ConPatInfo] -> ShowS
ConPatInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConPatInfo] -> ShowS
$cshowList :: [ConPatInfo] -> ShowS
show :: ConPatInfo -> String
$cshow :: ConPatInfo -> String
showsPrec :: Int -> ConPatInfo -> ShowS
$cshowsPrec :: Int -> ConPatInfo -> ShowS
Show, forall x. Rep ConPatInfo x -> ConPatInfo
forall x. ConPatInfo -> Rep ConPatInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConPatInfo x -> ConPatInfo
$cfrom :: forall x. ConPatInfo -> Rep ConPatInfo x
Generic)

instance HasRange ConPatInfo where
  getRange :: ConPatInfo -> Range
getRange = forall a. HasRange a => a -> Range
getRange forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConPatInfo -> PatInfo
conPatInfo

instance KillRange ConPatInfo where
  killRange :: KillRangeT ConPatInfo
killRange (ConPatInfo ConOrigin
b PatInfo
i ConPatLazy
l) = ConOrigin -> PatInfo -> ConPatLazy -> ConPatInfo
ConPatInfo ConOrigin
b (forall a. KillRange a => KillRangeT a
killRange PatInfo
i) ConPatLazy
l

instance SetRange ConPatInfo where
  setRange :: Range -> KillRangeT ConPatInfo
setRange Range
r (ConPatInfo ConOrigin
b PatInfo
i ConPatLazy
l) = ConOrigin -> PatInfo -> ConPatLazy -> ConPatInfo
ConPatInfo ConOrigin
b (Range -> PatInfo
PatRange Range
r) ConPatLazy
l

instance NFData ConPatInfo

-- | Has the constructor pattern a dotted (forced) constructor?
data ConPatLazy
  = ConPatLazy   -- ^ Dotted constructor.
  | ConPatEager  -- ^ Ordinary constructor.
  deriving (ConPatLazy -> ConPatLazy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConPatLazy -> ConPatLazy -> Bool
$c/= :: ConPatLazy -> ConPatLazy -> Bool
== :: ConPatLazy -> ConPatLazy -> Bool
$c== :: ConPatLazy -> ConPatLazy -> Bool
Eq, Eq ConPatLazy
ConPatLazy -> ConPatLazy -> Bool
ConPatLazy -> ConPatLazy -> Ordering
ConPatLazy -> ConPatLazy -> ConPatLazy
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ConPatLazy -> ConPatLazy -> ConPatLazy
$cmin :: ConPatLazy -> ConPatLazy -> ConPatLazy
max :: ConPatLazy -> ConPatLazy -> ConPatLazy
$cmax :: ConPatLazy -> ConPatLazy -> ConPatLazy
>= :: ConPatLazy -> ConPatLazy -> Bool
$c>= :: ConPatLazy -> ConPatLazy -> Bool
> :: ConPatLazy -> ConPatLazy -> Bool
$c> :: ConPatLazy -> ConPatLazy -> Bool
<= :: ConPatLazy -> ConPatLazy -> Bool
$c<= :: ConPatLazy -> ConPatLazy -> Bool
< :: ConPatLazy -> ConPatLazy -> Bool
$c< :: ConPatLazy -> ConPatLazy -> Bool
compare :: ConPatLazy -> ConPatLazy -> Ordering
$ccompare :: ConPatLazy -> ConPatLazy -> Ordering
Ord, Int -> ConPatLazy -> ShowS
[ConPatLazy] -> ShowS
ConPatLazy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConPatLazy] -> ShowS
$cshowList :: [ConPatLazy] -> ShowS
show :: ConPatLazy -> String
$cshow :: ConPatLazy -> String
showsPrec :: Int -> ConPatLazy -> ShowS
$cshowsPrec :: Int -> ConPatLazy -> ShowS
Show, ConPatLazy
forall a. a -> a -> Bounded a
maxBound :: ConPatLazy
$cmaxBound :: ConPatLazy
minBound :: ConPatLazy
$cminBound :: ConPatLazy
Bounded, Int -> ConPatLazy
ConPatLazy -> Int
ConPatLazy -> [ConPatLazy]
ConPatLazy -> ConPatLazy
ConPatLazy -> ConPatLazy -> [ConPatLazy]
ConPatLazy -> ConPatLazy -> ConPatLazy -> [ConPatLazy]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ConPatLazy -> ConPatLazy -> ConPatLazy -> [ConPatLazy]
$cenumFromThenTo :: ConPatLazy -> ConPatLazy -> ConPatLazy -> [ConPatLazy]
enumFromTo :: ConPatLazy -> ConPatLazy -> [ConPatLazy]
$cenumFromTo :: ConPatLazy -> ConPatLazy -> [ConPatLazy]
enumFromThen :: ConPatLazy -> ConPatLazy -> [ConPatLazy]
$cenumFromThen :: ConPatLazy -> ConPatLazy -> [ConPatLazy]
enumFrom :: ConPatLazy -> [ConPatLazy]
$cenumFrom :: ConPatLazy -> [ConPatLazy]
fromEnum :: ConPatLazy -> Int
$cfromEnum :: ConPatLazy -> Int
toEnum :: Int -> ConPatLazy
$ctoEnum :: Int -> ConPatLazy
pred :: ConPatLazy -> ConPatLazy
$cpred :: ConPatLazy -> ConPatLazy
succ :: ConPatLazy -> ConPatLazy
$csucc :: ConPatLazy -> ConPatLazy
Enum, forall x. Rep ConPatLazy x -> ConPatLazy
forall x. ConPatLazy -> Rep ConPatLazy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConPatLazy x -> ConPatLazy
$cfrom :: forall x. ConPatLazy -> Rep ConPatLazy x
Generic)

instance NFData ConPatLazy