{-# LANGUAGE CPP #-}
module Agda.TypeChecking.Monad.Env where
import Control.Monad.Reader
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Data.Monoid
import Agda.Syntax.Common
import Agda.Syntax.Abstract.Name
import Agda.TypeChecking.Monad.Base
import Agda.Utils.FileName
#include "undefined.h"
import Agda.Utils.Impossible
{-# SPECIALIZE currentModule :: TCM ModuleName #-}
{-# SPECIALIZE currentModule :: ReduceM ModuleName #-}
currentModule :: MonadTCEnv m => m ModuleName
currentModule = asksTC envCurrentModule
withCurrentModule :: ModuleName -> TCM a -> TCM a
withCurrentModule m =
localTC $ \ e -> e { envCurrentModule = m }
getCurrentPath :: MonadTCEnv m => m AbsolutePath
getCurrentPath = fromMaybe __IMPOSSIBLE__ <$> asksTC envCurrentPath
{-# SPECIALIZE getAnonymousVariables :: ModuleName -> TCM Nat #-}
{-# SPECIALIZE getAnonymousVariables :: ModuleName -> ReduceM Nat #-}
getAnonymousVariables :: MonadTCEnv m => ModuleName -> m Nat
getAnonymousVariables m = do
ms <- asksTC envAnonymousModules
return $ sum [ n | (m', n) <- ms, mnameToList m' `List.isPrefixOf` mnameToList m ]
withAnonymousModule :: ModuleName -> Nat -> TCM a -> TCM a
withAnonymousModule m n =
localTC $ \ e -> e { envAnonymousModules = (m, n) : envAnonymousModules e }
withEnv :: TCEnv -> TCM a -> TCM a
withEnv env = localTC $ \ env0 -> env
{ envPrintMetasBare = envPrintMetasBare env0
}
getEnv :: TCM TCEnv
getEnv = askTC
withIncreasedModuleNestingLevel :: TCM a -> TCM a
withIncreasedModuleNestingLevel =
localTC $ \ e -> e { envModuleNestingLevel =
envModuleNestingLevel e + 1 }
withHighlightingLevel :: HighlightingLevel -> TCM a -> TCM a
withHighlightingLevel h = localTC $ \ e -> e { envHighlightingLevel = h }
withoutOptionsChecking :: TCM a -> TCM a
withoutOptionsChecking = localTC $ \ e -> e { envCheckOptionConsistency = False }
doExpandLast :: TCM a -> TCM a
doExpandLast = localTC $ \ e -> e { envExpandLast = ExpandLast }
dontExpandLast :: TCM a -> TCM a
dontExpandLast = localTC $ \ e -> e { envExpandLast = DontExpandLast }
{-# SPECIALIZE performedSimplification :: TCM a -> TCM a #-}
performedSimplification :: MonadTCEnv m => m a -> m a
performedSimplification = localTC $ \ e -> e { envSimplification = YesSimplification }
{-# SPECIALIZE performedSimplification' :: Simplification -> TCM a -> TCM a #-}
performedSimplification' :: MonadTCEnv m => Simplification -> m a -> m a
performedSimplification' simpl = localTC $ \ e -> e { envSimplification = simpl `mappend` envSimplification e }
getSimplification :: MonadTCEnv m => m Simplification
getSimplification = asksTC envSimplification
updateAllowedReductions :: (AllowedReductions -> AllowedReductions) -> TCEnv -> TCEnv
updateAllowedReductions f e = e { envAllowedReductions = f (envAllowedReductions e) }
modifyAllowedReductions :: (AllowedReductions -> AllowedReductions) -> TCM a -> TCM a
modifyAllowedReductions = localTC . updateAllowedReductions
putAllowedReductions :: AllowedReductions -> TCM a -> TCM a
putAllowedReductions = modifyAllowedReductions . const
onlyReduceProjections :: TCM a -> TCM a
onlyReduceProjections = putAllowedReductions [ProjectionReductions]
allowAllReductions :: TCM a -> TCM a
allowAllReductions = putAllowedReductions allReductions
allowNonTerminatingReductions :: TCM a -> TCM a
allowNonTerminatingReductions = putAllowedReductions $ [NonTerminatingReductions] ++ allReductions
insideDotPattern :: TCM a -> TCM a
insideDotPattern = localTC $ \ e -> e { envInsideDotPattern = True }
isInsideDotPattern :: TCM Bool
isInsideDotPattern = asksTC envInsideDotPattern
callByName :: TCM a -> TCM a
callByName = localTC $ \ e -> e { envCallByNeed = False }