-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | the Haskell Refactorer. -- -- A Haskell 2010 refactoring tool. HaRe supports the full Haskell 2010 -- standard, through making use of the GHC API. -- -- Version 0.7.2.8 supports up to GHC 7.6.3. -- -- There is no support for GHC 7.8.x. There will never be support for GHC -- 7.8.x -- -- From version 0.8.0.0, GHC 7.10.2 is supported. -- -- It is tested against GHC 7.10.2 (via travis-ci.org) -- -- It currently only has emacs integration built in, community input -- welcome for others. -- -- HaRe attempts to operate in a safe way, by first writing new files -- with proposed changes, and only swapping these with the originals when -- the change is accepted. In the process the original file is renamed to -- have the current date/time as a suffix. Thus it should be possible to -- (manually) undo changes. -- -- Even so, it is strongly advised to back up any source files before -- refactoring, as we can make no promises as to the reliability of this -- tool. Use at your own risk. -- -- At the moment parsing of any file with FFI exports will fail. -- -- See Language.Haskell.Refact.HaRe for the current list of refactorings -- supported @package HaRe @version 0.8.2.3 module Paths_HaRe version :: Version getBinDir :: IO FilePath getLibDir :: IO FilePath getDataDir :: IO FilePath getLibexecDir :: IO FilePath getDataFileName :: FilePath -> IO FilePath getSysconfDir :: IO FilePath module Language.Haskell.Refact.Utils.GhcModuleGraph getModulesAsGraph :: Bool -> [ModSummary] -> Maybe ModuleName -> Graph SummaryNode summaryNodeSummary :: SummaryNode -> ModSummary -- | Provide workarounds for bugs detected in GHC, until they are fixed in -- a later version module Language.Haskell.Refact.Utils.GhcBugWorkArounds -- | Replacement for original getRichTokenStream which will return -- the tokens for a file processed by CPP. See bug -- http://ghc.haskell.org/trac/ghc/ticket/8265 getRichTokenStreamWA :: GhcMonad m => Module -> m [(Located Token, String)] module Language.Haskell.Refact.Utils.Types -- | The result of a refactoring is the file, a flag as to whether it was -- modified, and the updated AST type ApplyRefacResult = ((FilePath, RefacResult), (Anns, ParsedSource)) data RefacResult RefacModified :: RefacResult RefacUnmodifed :: RefacResult data RefacSource RSFile :: FilePath -> RefacSource RSMod :: ModSummary -> RefacSource RSAlreadyLoaded :: RefacSource data TreeId TId :: !Int -> TreeId -- | Identifies the tree carrying the main tokens, not any work in progress -- or deleted ones mainTid :: TreeId data TokenCache a TK :: !(Map TreeId a) -> !TreeId -> TokenCache a [tkCache] :: TokenCache a -> !(Map TreeId a) [tkLastTreeId] :: TokenCache a -> !TreeId type SimpPos = (Int, Int) type SimpSpan = (SimpPos, SimpPos) type NameMap = Map SrcSpan Name instance GHC.Show.Show a => GHC.Show.Show (Language.Haskell.Refact.Utils.Types.TokenCache a) instance GHC.Show.Show Language.Haskell.Refact.Utils.Types.TreeId instance GHC.Classes.Ord Language.Haskell.Refact.Utils.Types.TreeId instance GHC.Classes.Eq Language.Haskell.Refact.Utils.Types.TreeId instance GHC.Classes.Eq Language.Haskell.Refact.Utils.Types.RefacResult instance GHC.Classes.Ord Language.Haskell.Refact.Utils.Types.RefacResult instance GHC.Show.Show Language.Haskell.Refact.Utils.Types.RefacResult -- | This is a legacy module from the pre-GHC HaRe, and will disappear -- eventually. module Language.Haskell.Refact.Utils.TypeSyn type HsExpP = HsExpr RdrName type HsPatP = Pat RdrName type HsDeclP = LHsDecl RdrName type HsDeclsP = HsGroup Name type InScopes = [Name] type Export = LIE RdrName -- | HsName is a name as it is found in the source This seems to be quite a -- close correlation type HsName = RdrName -- | The PN is the name as it occurs to the parser, and corresponds with -- the GHC.RdrName type PN = GHC.RdrName newtype PName PN :: HsName -> PName -- | The PNT is the unique name, after GHC renaming. It corresponds to -- GHC.Name data PNT = PNT GHC.Name deriving (Data,Typeable) -- Note: -- GHC.Name has SrcLoc in it already instance GHC.Classes.Eq Language.Haskell.Refact.Utils.TypeSyn.PName instance GHC.Show.Show OccName.NameSpace instance Outputable.Outputable OccName.NameSpace instance Outputable.Outputable (HsExpr.MatchGroup Name.Name (HsExpr.LHsExpr Name.Name)) instance Outputable.Outputable (HsExpr.Match Name.Name (HsExpr.LHsExpr Name.Name)) instance Outputable.Outputable (HsExpr.GRHSs Name.Name (HsExpr.LHsExpr Name.Name)) instance Outputable.Outputable (HsExpr.GRHS Name.Name (HsExpr.LHsExpr Name.Name)) instance Outputable.Outputable (HsExpr.HsTupArg Name.Name) instance Outputable.Outputable (HsTypes.ConDeclField Name.Name) instance Outputable.Outputable (HsDecls.TyFamEqn Name.Name (HsTypes.LHsTyVarBndrs Name.Name)) module Language.Haskell.Refact.Utils.Monad -- | Result of parsing a Haskell source file. It is simply the -- TypeCheckedModule produced by GHC. type ParseResult = TypecheckedModule data VerboseLevel Debug :: VerboseLevel Normal :: VerboseLevel Off :: VerboseLevel data RefactSettings RefSet :: !VerboseLevel -> (Bool, Bool, Bool, Bool) -> RefactSettings [rsetVerboseLevel] :: RefactSettings -> !VerboseLevel [rsetEnabledTargets] :: RefactSettings -> (Bool, Bool, Bool, Bool) -- | State for refactoring a single file. Holds/hides the ghc-exactprint -- annotations, which get updated transparently at key points. data RefactState RefSt :: !RefactSettings -> !Int -> !Int -> !RefactFlags -> !StateStorage -> !(Maybe TargetModule) -> !(Maybe RefactModule) -> RefactState -- | Session level settings [rsSettings] :: RefactState -> !RefactSettings -- | Current Unique creator value, incremented every time it is used [rsUniqState] :: RefactState -> !Int -- | Current SrcSpan creator value, incremented every time it is used [rsSrcSpanCol] :: RefactState -> !Int -- | Flags for controlling generic traversals [rsFlags] :: RefactState -> !RefactFlags -- | Temporary storage of values while refactoring takes place [rsStorage] :: RefactState -> !StateStorage [rsCurrentTarget] :: RefactState -> !(Maybe TargetModule) -- | The current module being refactored [rsModule] :: RefactState -> !(Maybe RefactModule) data RefactModule RefMod :: !TypecheckedModule -> NameMap -> !(TokenCache Anns) -> !RefacResult -> RefactModule [rsTypecheckedMod] :: RefactModule -> !TypecheckedModule -- | Mapping from the names in the ParsedSource to the renamed versions. -- Note: No strict mark, can be computed lazily. [rsNameMap] :: RefactModule -> NameMap -- | Token stream for the current module, maybe modified, in SrcSpan tree -- form [rsTokenCache] :: RefactModule -> !(TokenCache Anns) -- | current module has updated the AST [rsStreamModified] :: RefactModule -> !RefacResult type TargetModule = ModulePath type Targets = [Either FilePath ModuleName] type CabalGraph = Map ChComponentName (GmComponent GMCResolved (Set ModulePath)) data RefactStashId Stash :: !String -> RefactStashId data RefactFlags RefFlags :: !Bool -> RefactFlags -- | Current traversal has already made a change [rsDone] :: RefactFlags -> !Bool -- | Provide some temporary storage while the refactoring is taking place data StateStorage StorageNone :: StateStorage StorageBind :: (LHsBind Name) -> StateStorage StorageSig :: (LSig Name) -> StateStorage StorageBindRdr :: (LHsBind RdrName) -> StateStorage StorageDeclRdr :: (LHsDecl RdrName) -> StateStorage StorageSigRdr :: (LSig RdrName) -> StateStorage newtype RefactGhc a RefactGhc :: GhcModT (StateT RefactState IO) a -> RefactGhc a [unRefactGhc] :: RefactGhc a -> GhcModT (StateT RefactState IO) a runRefactGhc :: RefactGhc a -> RefactState -> Options -> IO (a, RefactState) getRefacSettings :: RefactGhc RefactSettings defaultSettings :: RefactSettings logSettings :: RefactSettings cabalModuleGraphs :: RefactGhc [GmModuleGraph] canonicalizeGraph :: [ModSummary] -> RefactGhc [(Maybe FilePath, ModSummary)] canonicalizeModSummary :: (MonadIO m) => ModSummary -> m (Maybe FilePath, ModSummary) logm :: String -> RefactGhc () instance Exception.ExceptionMonad Language.Haskell.Refact.Utils.Monad.RefactGhc instance Language.Haskell.GhcMod.Types.MonadIO Language.Haskell.Refact.Utils.Monad.RefactGhc instance Language.Haskell.GhcMod.Monad.Out.GmOut Language.Haskell.Refact.Utils.Monad.RefactGhc instance Language.Haskell.GhcMod.Monad.Env.GmEnv Language.Haskell.Refact.Utils.Monad.RefactGhc instance Control.Monad.IO.Class.MonadIO Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Base.MonadPlus Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Base.Monad Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Base.Alternative Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Base.Applicative Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Base.Functor Language.Haskell.Refact.Utils.Monad.RefactGhc instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.RefactState instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.RefactFlags instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.RefactModule instance GHC.Classes.Ord Language.Haskell.Refact.Utils.Monad.RefactStashId instance GHC.Classes.Eq Language.Haskell.Refact.Utils.Monad.RefactStashId instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.RefactStashId instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.RefactSettings instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.VerboseLevel instance GHC.Classes.Eq Language.Haskell.Refact.Utils.Monad.VerboseLevel instance GHC.Show.Show (SrcLoc.GenLocated SrcLoc.SrcSpan Lexer.Token) instance GHC.Show.Show Name.Name instance GHC.Show.Show GHC.TypecheckedModule instance Outputable.Outputable Language.Haskell.Refact.Utils.Monad.TargetModule instance GHC.Show.Show Language.Haskell.Refact.Utils.Monad.StateStorage instance Language.Haskell.GhcMod.Monad.Out.GmOut (Control.Monad.Trans.State.Lazy.StateT Language.Haskell.Refact.Utils.Monad.RefactState GHC.Types.IO) instance Language.Haskell.GhcMod.Types.MonadIO (Control.Monad.Trans.State.Lazy.StateT Language.Haskell.Refact.Utils.Monad.RefactState GHC.Types.IO) instance Control.Monad.State.Class.MonadState Language.Haskell.Refact.Utils.Monad.RefactState Language.Haskell.Refact.Utils.Monad.RefactGhc instance GhcMonad.GhcMonad Language.Haskell.Refact.Utils.Monad.RefactGhc instance DynFlags.HasDynFlags Language.Haskell.Refact.Utils.Monad.RefactGhc instance Exception.ExceptionMonad (Control.Monad.Trans.State.Lazy.StateT Language.Haskell.Refact.Utils.Monad.RefactState GHC.Types.IO) instance GHC.Show.Show HscTypes.ModSummary instance GHC.Show.Show Module.Module module Language.Haskell.Refact.Utils.MonadFunctions -- | fetch the final annotations fetchAnnsFinal :: RefactGhc Anns getTypecheckedModule :: RefactGhc TypecheckedModule getRefactStreamModified :: RefactGhc RefacResult -- | For testing setRefactStreamModified :: RefacResult -> RefactGhc () getRefactInscopes :: RefactGhc InScopes getRefactRenamed :: RefactGhc RenamedSource putRefactRenamed :: RenamedSource -> RefactGhc () getRefactParsed :: RefactGhc ParsedSource putRefactParsed :: ParsedSource -> Anns -> RefactGhc () -- | Internal low level interface to access the current annotations from -- the RefactGhc state. setRefactAnns :: Anns -> RefactGhc () putParsedModule :: [Comment] -> TypecheckedModule -> RefactGhc () clearParsedModule :: RefactGhc () getRefactFileName :: RefactGhc (Maybe FilePath) getRefactTargetModule :: RefactGhc TargetModule getRefactModule :: RefactGhc Module getRefactModuleName :: RefactGhc ModuleName getRefactNameMap :: RefactGhc NameMap liftT :: HasTransform m => forall a. Transform a -> m a getRefactDone :: RefactGhc Bool setRefactDone :: RefactGhc () clearRefactDone :: RefactGhc () setStateStorage :: StateStorage -> RefactGhc () getStateStorage :: RefactGhc StateStorage parseDeclWithAnns :: String -> RefactGhc (LHsDecl RdrName) nameSybTransform :: (Monad m, Typeable t) => (Located RdrName -> m (Located RdrName)) -> t -> m t nameSybQuery :: (Typeable a, Typeable t) => (Located a -> Maybe r) -> t -> Maybe r fileNameFromModSummary :: ModSummary -> FilePath mkNewGhcNamePure :: Char -> Int -> Maybe Module -> String -> Name logDataWithAnns :: (Data a) => String -> a -> RefactGhc () logAnns :: String -> RefactGhc () logParsedSource :: String -> RefactGhc () initRefactModule :: [Comment] -> TypecheckedModule -> Maybe RefactModule initTokenCacheLayout :: a -> TokenCache a -- | We need the ParsedSource because it more closely reflects the actual -- source code, but must be able to work with the renamed representation -- of the names involved. This function constructs a map from every -- Located RdrName in the ParsedSource to its corresponding name in the -- RenamedSource. It also deals with the wrinkle that we need to Location -- of the RdrName to make sure we have the right Name, but not all -- RdrNames have a Location. This function is called before the RefactGhc -- monad is active. initRdrNameMap :: TypecheckedModule -> NameMap instance Language.Haskell.GHC.ExactPrint.Transform.HasTransform Language.Haskell.Refact.Utils.Monad.RefactGhc module Language.Haskell.Refact.Utils.LocUtils unmodified :: Bool modified :: Bool nullSrcSpan :: SrcSpan -- | Get the first SrcSpan found, in top down traversal getSrcSpan :: (Data t) => t -> Maybe SrcSpan prettyprintPatList :: (t -> String) -> Bool -> [t] -> String -- | gets the (row,col) of the start of the GHC.SrcSpan, or -- (-1,-1) if there is an GHC.UnhelpfulSpan getGhcLoc :: SrcSpan -> (Int, Int) -- | gets the (row,col) of the end of the GHC.SrcSpan, or (-1,-1) -- if there is an GHC.UnhelpfulSpan getGhcLocEnd :: SrcSpan -> (Int, Int) getLocatedStart :: GenLocated SrcSpan t -> (Int, Int) getLocatedEnd :: GenLocated SrcSpan t -> (Int, Int) ghcSpanStartEnd :: SrcSpan -> ((Int, Int), (Int, Int)) getStartEndLoc :: (Data t) => t -> (SimpPos, SimpPos) startEndLocGhc :: Located b -> (SimpPos, SimpPos) -- | Get around lack of instance Eq when simply testing for empty list -- TODO: get rid of this in favour of null built in fn emptyList :: [t] -> Bool nonEmptyList :: [t] -> Bool -- | This module contains all the code that depends on a specific version -- of GHC, and should be the only one requiring CPP module Language.Haskell.Refact.Utils.GhcVersionSpecific prettyprint :: (Outputable a) => a -> String prettyprint2 :: (Outputable a) => a -> String ppType :: Type -> String setGhcContext :: GhcMonad m => ModSummary -> m () showGhcQual :: (Outputable a) => a -> String module Language.Haskell.Refact.Utils.Utils getTargetGhc :: TargetModule -> RefactGhc () -- | Parse a single source file into a GHC session parseSourceFileGhc :: FilePath -> RefactGhc () -- | Manage a whole refactor session. Initialise the monad, load the whole -- project if required, and then apply the individual refactorings, and -- write out the resulting files. -- -- It is intended that this forms the umbrella function, in which -- applyRefac is called runRefacSession :: RefactSettings -> Options -> RefactGhc [ApplyRefacResult] -> IO [FilePath] -- | Apply a refactoring (or part of a refactoring) to a single module applyRefac :: RefactGhc a -> RefacSource -> RefactGhc (ApplyRefacResult, a) -- | Returns True if any of the results has its modified flag set refactDone :: [ApplyRefacResult] -> Bool fileNameFromModSummary :: ModSummary -> FilePath -- | Extract the module name from the parsed source, if there is one getModuleName :: ParsedSource -> Maybe (ModuleName, String) -- | Return the client modules and file names. The client modules of -- module, say m, are those modules which directly or indirectly import -- module m. clientModsAndFiles :: ModulePath -> RefactGhc [TargetModule] -- | Return the server module and file names. The server modules of module, -- say m, are those modules which are directly or indirectly imported by -- module m. This can only be called in a live GHC session TODO: make -- sure this works with multiple targets. Is that needed? No? serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary] modifiedFiles :: [ApplyRefacResult] -> [String] -- | Write refactored program source to files. writeRefactoredFiles :: VerboseLevel -> [ApplyRefacResult] -> IO () -- | This module contains routines used to perform generic traversals of -- the GHC AST, avoiding the traps resulting from certain fields being -- populated with values defined to trigger an error if ever evaluated. -- -- This is a useful feature for tracking down bugs in GHC, but makes use -- of the GHC library problematic. module Language.Haskell.Refact.Utils.GhcUtils -- | Monadic variation on everywhere' everywhereM' :: Monad m => GenericM m -> GenericM m -- | Monadic variation on everywhere' everywhereMStaged' :: Monad m => Stage -> GenericM m -> GenericM m -- | Bottom-up transformation everywhereStaged :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a -- | Top-down version of everywhereStaged everywhereStaged' :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a -- | Perform a query on the immediate subterms only, avoiding holes onelayerStaged :: Stage -> r -> GenericQ r -> GenericQ [r] -- | Staged variation of SYB.listify The stage must be provided to avoid -- trying to modify elements which may not be present at all stages of -- AST processing. listifyStaged :: (Data a, Typeable a1) => Stage -> (a1 -> Bool) -> a -> [a1] -- | Apply a generic transformation everywhere in a bottom-up manner. zeverywhereStaged :: (Typeable a) => Stage -> GenericT -> Zipper a -> Zipper a -- | Open a zipper to the point where the Geneneric query passes. returns -- the original zipper if the query does not pass (check this) zopenStaged :: (Typeable a) => Stage -> GenericQ Bool -> Zipper a -> [Zipper a] -- | Apply a generic monadic transformation once at the topmost leftmost -- successful location, avoiding holes in the GHC structures zsomewhereStaged :: (MonadPlus m) => Stage -> GenericM m -> Zipper a -> m (Zipper a) -- | Transform a zipper opened with a given generic query transZ :: Stage -> GenericQ Bool -> (Stage -> Zipper a -> Zipper a) -> Zipper a -> Zipper a -- | Monadic transform of a zipper opened with a given generic query transZM :: Monad m => Stage -> GenericQ Bool -> (Stage -> Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a) -- | Open a zipper to the point where the Generic query passes, returning -- the zipper and a value from the specific part of the GenericQ that -- matched. This allows the components of the query to return a specific -- transformation routine, to apply to the returned zipper zopenStaged' :: (Typeable a) => Stage -> GenericQ (Maybe b) -> Zipper a -> [(Zipper a, b)] -- | Open a zipper to the point where the Generic query passes, and apply -- the transformation returned from the specific part of the GenericQ -- that matched. ztransformStagedM :: (Typeable a, Monad m) => Stage -> GenericQ (Maybe (Stage -> Zipper a -> m (Zipper a))) -> Zipper a -> m (Zipper a) -- | Climb the tree until a predicate holds upUntil :: GenericQ Bool -> Zipper a -> Maybe (Zipper a) -- | Up the zipper until a predicate holds, and then return the zipper hole findAbove :: (Data a) => (a -> Bool) -> Zipper a -> Maybe a module Language.Haskell.Refact.Utils.ExactPrint -- | Replaces an old expression with a new expression replace :: AnnKey -> AnnKey -> Anns -> Maybe Anns replaceAnnKey :: (Data old, Data new) => Located old -> Located new -> Anns -> Anns copyAnn :: (Data old, Data new) => Located old -> Located new -> Anns -> Anns -- | This module contains a collection of program analysis and -- transformation functions (the API) that work over the Type Decorated -- AST. Most of the functions defined in the module are taken directly -- from the API, but in some cases are modified to work with the type -- decorated AST. -- -- In particular some new functions have been added to make type -- decorated AST traversals easier. -- -- In HaRe, in order to preserve the comments and layout of refactored -- programs, a refactoring modifies not only the AST but also the token -- stream, and the program source after the refactoring is extracted from -- the token stream rather than the AST, for the comments and layout -- information is kept in the token steam instead of the AST. As a -- consequence, a program transformation function from this API modifies -- both the AST and the token stream (unless explicitly stated). So when -- you build your own program transformations, try to use the API to do -- the transformation, as this can liberate you from caring about the -- token stream. -- -- This type decorated API is still in development. Any suggestions and -- comments are very much welcome. module Language.Haskell.Refact.Utils.Binds hsBinds :: (HsValBinds t name) => t -> [LHsBind name] getValBindSigs :: HsValBinds RdrName -> [LSig RdrName] class (Data t, Data name) => HsValBinds t name | t -> name -- | Return the binds that are directly enclosed in the given syntax -- phrase. hsValBinds :: t -> [GHC.LHsBind GHC.Name] hsValBinds :: HsValBinds t name => t -> HsValBinds name -- | Return the type class definitions that are directly enclosed in the -- given syntax phrase. Note: only makes sense for GHC.RenamedSource hsTyDecls :: HsValBinds t name => t -> [[LTyClDecl name]] instance Language.Haskell.Refact.Utils.Binds.HsValBinds GHC.ParsedSource RdrName.RdrName instance Language.Haskell.Refact.Utils.Binds.HsValBinds GHC.RenamedSource Name.Name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.HsValBinds name) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.HsGroup name) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.HsLocalBinds name) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.GRHSs name (HsExpr.LHsExpr name)) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.MatchGroup name (HsExpr.LHsExpr name)) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsExpr.LMatch name (HsExpr.LHsExpr name)] name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.LMatch name (HsExpr.LHsExpr name)) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.Match name (HsExpr.LHsExpr name)) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.HsBind name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.HsExpr name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.Stmt name (HsExpr.LHsExpr name)) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.LHsBinds name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.LHsBind name) name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsBinds.LHsBind name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.LHsExpr name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsExpr.LGRHS name (HsExpr.LHsExpr name)] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.LGRHS name (HsExpr.LHsExpr name)) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsExpr.LStmt name (HsExpr.LHsExpr name)] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsExpr.LStmt name (HsExpr.LHsExpr name)) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsPat.LPat name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsPat.LPat name) name instance Language.Haskell.Refact.Utils.Binds.HsValBinds Name.Name Name.Name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsExpr.SyntaxExpr name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.TyClGroup name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.TyClGroup name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [[HsDecls.LTyClDecl name]] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.LTyClDecl name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.LTyClDecl name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.LTyFamInstDecl name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.LDataFamInstDecl name] name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.LTyFamInstEqn name] name instance (PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.LTyFamInstEqn name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.HsDataDefn name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.HsTyPats name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsDecls.LInstDecl name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsDecls.LInstDecl name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsTypes.LHsType name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsTypes.LHsType name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds [HsBinds.LSig name] name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.LSig name) name instance (Outputable.OutputableBndr name, PlaceHolder.DataId name, Data.Data.Data name) => Language.Haskell.Refact.Utils.Binds.HsValBinds (HsBinds.HsIPBinds name) name module Language.Haskell.Refact.Utils.Variables -- | True if the name is a field name isFieldName :: Name -> Bool -- | True if the name is a field name isClassName :: Name -> Bool -- | True if the name is a class instance isInstanceName :: Name -> Bool isDeclaredIn :: (HsValBinds t Name) => Name -> t -> Bool isDeclaredInRdr :: NameMap -> Name -> [LHsDecl RdrName] -> Bool -- | For free variables data FreeNames FN :: [Name] -> FreeNames [fn] :: FreeNames -> [Name] -- | For declared variables data DeclaredNames DN :: [Name] -> DeclaredNames [dn] :: DeclaredNames -> [Name] -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. -- Expects RenamedSource hsFreeAndDeclaredPNsOld :: (Data t) => t -> ([Name], [Name]) -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. -- Expects RenamedSource hsFreeAndDeclaredRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) -- | The same as hsFreeAndDeclaredPNs except that the returned -- variables are in the String format. hsFreeAndDeclaredNameStrings :: (Data t, Outputable t) => t -> RefactGhc ([String], [String]) hsFreeAndDeclaredPNs :: (Data t) => t -> RefactGhc ([Name], [Name]) -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. TODO: -- use GHC.NameSet instead of lists for FreeNames/DeclaredNames NOTE: The -- GHC fvs fields only carry non-GHC values, as they are used in the -- renaming process hsFreeAndDeclaredGhc :: (SYB.Data t,GHC.Outputable t) hsFreeAndDeclaredGhc :: (Data t) => t -> RefactGhc (FreeNames, DeclaredNames) -- | Get the names of all types declared in the given declaration getDeclaredTypes :: LTyClDecl Name -> [Name] -- | Get the names of all types declared in the given declaration -- getDeclaredTypesRdr :: GHC.LTyClDecl GHC.RdrName -> RefactGhc -- [GHC.Name] getDeclaredTypesRdr :: LHsDecl RdrName -> RefactGhc [Name] -- | Experiment with GHC fvs stuff getFvs :: [LHsBind Name] -> [([Name], NameSet)] getFreeVars :: [LHsBind Name] -> [Name] getDeclaredVars :: [LHsBind Name] -> [Name] -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisiblePNs :: (FindEntity e, HsValBinds t Name, Outputable e) => e -> t -> RefactGhc [Name] -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisiblePNsRdr :: (FindEntity e, Data t, Outputable e) => NameMap -> e -> t -> RefactGhc [Name] -- | Same as hsVisiblePNs except that the returned identifiers are -- in String format. hsVisibleNames :: (FindEntity t1, HsValBinds t2 Name, Outputable t1) => t1 -> t2 -> RefactGhc [String] -- | Same as hsVisiblePNs except that the returned identifiers are -- in String format. hsVisibleNamesRdr :: (FindEntity t1, Data t2, Outputable t1) => t1 -> t2 -> RefactGhc [String] -- | hsFDsFromInsideRdr is different from -- hsFreeAndDeclaredPNs in that: given an syntax phrase t, -- hsFDsFromInsideRdr returns not only the declared variables that -- are visible from outside of t, but also those declared variables that -- are visible to the main expression inside t. NOTE: Expects to be given -- RenamedSource hsFDsFromInsideRdr :: (Data t) => NameMap -> t -> RefactGhc (FreeNames, DeclaredNames) -- | The same as hsFDsFromInside except that the returned variables -- are in the String format hsFDNamesFromInsideRdr :: (Data t) => t -> RefactGhc ([String], [String]) -- | hsFDsFromInside is different from hsFreeAndDeclaredPNs -- in that: given an syntax phrase t, hsFDsFromInside returns not -- only the declared variables that are visible from outside of t, but -- also those declared variables that are visible to the main expression -- inside t. NOTE: Expects to be given RenamedSource hsFDsFromInside :: (Data t) => t -> RefactGhc ([Name], [Name]) -- | The same as hsFDsFromInside except that the returned variables -- are in the String format hsFDNamesFromInside :: (Data t) => t -> RefactGhc ([String], [String]) -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisibleDs :: (FindEntity e, Outputable e, Data t, HsValBinds t Name) => e -> t -> RefactGhc DeclaredNames -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisibleDsRdr :: (FindEntity e, Outputable e, Data t) => NameMap -> e -> t -> RefactGhc DeclaredNames rdrName2Name :: Located RdrName -> RefactGhc Name rdrName2NamePure :: NameMap -> Located RdrName -> Name eqRdrNamePure :: NameMap -> Located RdrName -> Name -> Bool rdrName2Name' :: Located RdrName -> RefactGhc Name class (Data a, Typeable a) => FindEntity a -- | Returns True is a syntax phrase, say a, is part of another syntax -- phrase, say b. NOTE: very important: only do a shallow check findEntity :: (FindEntity a, Data b) => a -> b -> Bool -- | Return True if syntax phrases t1 and t2 refer to the same one. sameOccurrence :: (Located t) -> (Located t) -> Bool -- | Return the list of identifiers (in PName format) defined by a -- function/pattern binding. definedPNs :: LHsBind Name -> [Name] definedPNsRdr :: LHsDecl RdrName -> [Located RdrName] definedNamesRdr :: NameMap -> LHsDecl RdrName -> [Name] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsRdrNames :: NameMap -> [Name] -> [LHsDecl RdrName] -> Bool -> Bool -> [LHsDecl RdrName] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsRdrNames' :: (Data t) => NameMap -> [Name] -> t -> [LHsDecl RdrName] -- | Find those type signatures for the specified GHC.Names. definingSigsRdrNames :: (Data t) => NameMap -> [Name] -> t -> [LSig RdrName] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsNames :: [Name] -> [LHsBind Name] -> Bool -> Bool -> [LHsBind Name] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsNames' :: (Data t) => [Name] -> t -> [LHsBind Name] -- | Find those type signatures for the specified GHC.Names. definingSigsNames :: (Data t) => [Name] -> t -> [LSig Name] -- | Find those declarations which define the specified GHC.Names. definingTyClDeclsNames :: (Data t) => [Name] -> t -> [LTyClDecl Name] -- | Return True if the function/pattern binding defines the specified -- identifier. defines :: Name -> LHsBind Name -> Bool -- | Return True if the function/pattern binding defines the specified -- identifier. definesRdr :: NameMap -> Name -> LHsBind RdrName -> Bool -- | Unwraps a LHsDecl and calls definesRdr on the result if a HsBind definesDeclRdr :: NameMap -> Name -> LHsDecl RdrName -> Bool -- | Return True if the declaration defines the type signature of the -- specified identifier. definesTypeSig :: Name -> LSig Name -> Bool -- | Return True if the declaration defines the type signature of the -- specified identifier. definesTypeSigRdr :: NameMap -> Name -> Sig RdrName -> Bool -- | Unwraps a LHsDecl and calls definesRdr on the result if a Sig definesSigDRdr :: NameMap -> Name -> LHsDecl RdrName -> Bool definesP :: PName -> HsDeclP -> Bool -- | Find all Located Names in the given Syntax phrase. allNames :: (Data t) => t -> [Located Name] -- | Collect the identifiers (in PName format) in a given syntax phrase. hsPNs :: (Data t) => t -> [PName] -- | Get all the names in the given syntax element hsNamess :: (Data t) => t -> [Name] -- | Get all the names in the given syntax element hsNamessRdr :: (Data t) => t -> [Located RdrName] -- | Find the identifier(in GHC.Name format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToName :: (Data t) => SimpPos -> t -> Maybe (Located Name) -- | Find the identifier(in GHC.RdrName format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToRdrName :: (Data t) => SimpPos -> t -> Maybe (Located RdrName) instance Language.Haskell.Refact.Utils.Variables.FindEntity Name.Name instance Language.Haskell.Refact.Utils.Variables.FindEntity (SrcLoc.Located RdrName.RdrName) instance Language.Haskell.Refact.Utils.Variables.FindEntity (SrcLoc.Located Name.Name) instance Language.Haskell.Refact.Utils.Variables.FindEntity (HsExpr.LHsExpr RdrName.RdrName) instance Language.Haskell.Refact.Utils.Variables.FindEntity (HsExpr.LHsExpr Name.Name) instance Language.Haskell.Refact.Utils.Variables.FindEntity (SrcLoc.Located (HsBinds.HsBindLR Name.Name Name.Name)) instance Language.Haskell.Refact.Utils.Variables.FindEntity (SrcLoc.Located (HsDecls.HsDecl Name.Name)) instance GHC.Show.Show Language.Haskell.Refact.Utils.Variables.FreeNames instance GHC.Show.Show Language.Haskell.Refact.Utils.Variables.DeclaredNames instance GHC.Base.Monoid Language.Haskell.Refact.Utils.Variables.FreeNames instance GHC.Base.Monoid Language.Haskell.Refact.Utils.Variables.DeclaredNames -- | This module contains a collection of program analysis and -- transformation functions (the API) that work over the Type Decorated -- AST. Most of the functions defined in the module are taken directly -- from the API, but in some cases are modified to work with the type -- decorated AST. -- -- In particular some new functions have been added to make type -- decorated AST traversals easier. -- -- In HaRe, in order to preserve the comments and layout of refactored -- programs, a refactoring modifies not only the AST but also the token -- stream, and the program source after the refactoring is extracted from -- the token stream rather than the AST, for the comments and layout -- information is kept in the token steam instead of the AST. As a -- consequence, a program transformation function from this API modifies -- both the AST and the token stream (unless explicitly stated). So when -- you build your own program transformations, try to use the API to do -- the transformation, as this can liberate you from caring about the -- token stream. -- -- This type decorated API is still in development. Any suggestions and -- comments are very much welcome. module Language.Haskell.Refact.Utils.TypeUtils -- | Process the inscope relation returned from the parsing and module -- analysis pass, and return a list of four-element tuples. Each tuple -- contains an identifier name, the identifier's namespace info, the -- identifier's defining module name and its qualifier name. -- -- The same identifier may have multiple entries in the result because it -- may have different qualifiers. This makes it easier to decide whether -- the identifier can be used unqualifiedly by just checking whether -- there is an entry for it with the qualifier field being Nothing. inScopeInfo :: InScopes -> [(String, NameSpace, ModuleName, Maybe ModuleName)] -- | Return True if the identifier is inscope and can be used without a -- qualifier. isInScopeAndUnqualified :: String -> InScopes -> Bool -- | Return True if the identifier is inscope and can be used without a -- qualifier. The identifier name string may have a qualifier already -- NOTE: may require qualification based on name clash with an existing -- identifier. isInScopeAndUnqualifiedGhc :: String -> (Maybe Name) -> RefactGhc Bool -- | Return all Names that correspond to the given string, in the -- current module. inScopeNames :: String -> RefactGhc [Name] -- | Return True if an identifier is exported by the module currently being -- refactored. isExported :: Name -> RefactGhc Bool -- | Return True if an identifier is explicitly exported by the module. isExplicitlyExported :: Name -> RenamedSource -> Bool -- | Return True if the current module is exported either by default or by -- specifying the module name in the export. modIsExported :: ModuleName -> RenamedSource -> Bool -- | Given a Name defined in one module, find the equivalent one in -- the currently loaded module. This is required otherwise name equality -- checking based on nameUnique will fail. equivalentNameInNewMod :: Name -> RefactGhc [Name] -- | Return True if a string is a lexically valid variable name. isVarId :: String -> Bool -- | Return True if a string is a lexically valid constructor name. isConId :: String -> Bool -- | Return True if a string is a lexically valid operator name. isOperator :: String -> Bool -- | Return True if a PName is a toplevel PName. isTopLevelPN :: Name -> RefactGhc Bool -- | Return True if a PName is a local PName. isLocalPN :: Name -> Bool -- | Return True if the name has a GHC.SrcSpan, i.e. is declared -- in source we care about isNonLibraryName :: Name -> Bool -- | Return True if a PName is a qualified PName. AZ:NOTE: this tests the -- use instance, the underlying name may be qualified. e.g. used name is -- zip, GHC.List.zip NOTE2: not sure if this gives a meaningful result -- for a GHC.Name isQualifiedPN :: Name -> RefactGhc Bool -- | Return True if a PName is a function/pattern name defined in t. isFunOrPatName :: (Data t) => Name -> t -> Bool -- | Return True if a declaration is a type signature declaration. isTypeSig :: LSig a -> Bool -- | Return True if a declaration is a type signature declaration. isTypeSigDecl :: LHsDecl a -> Bool -- | Return True if a declaration is a function definition. isFunBindP :: HsDeclP -> Bool isFunBindR :: LHsBind t -> Bool -- | Returns True if a declaration is a pattern binding. isPatBindP :: HsDeclP -> Bool isPatBindR :: LHsBind t -> Bool -- | Return True if a declaration is a pattern binding which only defines a -- variable value. isSimplePatBind :: (DataId t) => LHsBind t -> Bool -- | Return True if a declaration is a pattern binding which only defines a -- variable value. isSimplePatDecl :: (DataId t) => LHsDecl t -> Bool -- | Return True if a LHsBin is a pattern binding but not a simple one. isComplexPatBind :: LHsBind name -> Bool -- | Return True if a declaration is a pattern binding but not a simple -- one. isComplexPatDecl :: LHsDecl name -> Bool -- | Return True if a declaration is a function/pattern definition. isFunOrPatBindP :: HsDeclP -> Bool -- | Return True if a declaration is a function/pattern definition. isFunOrPatBindR :: LHsBind t -> Bool -- | Return True if the identifier is unqualifiedly used in the given -- syntax phrase. usedWithoutQualR :: GHC.Name -> GHC.ParsedSource -- -> Bool usedWithoutQualR :: (Data t) => Name -> t -> Bool -- | Return True if the identifier is used in the RHS if a function/pattern -- binding. isUsedInRhs :: (Data t) => (Located Name) -> t -> Bool findNameInRdr :: (Data t) => NameMap -> Name -> t -> Bool -- | Return True if the identifier occurs in the given syntax phrase. findPNT :: (Data t) => Located Name -> t -> Bool -- | Return True if the identifier occurs in the given syntax phrase. findPN :: (Data t) => Name -> t -> Bool -- | Find all occurrences with location of the given name findAllNameOccurences :: (Data t) => Name -> t -> [(Located Name)] -- | Return True if any of the specified PNames ocuur in the given syntax -- phrase. findPNs :: (Data t) => [Name] -> t -> Bool -- | Return True if any of the specified PNames ocuur in the given syntax -- phrase. findNamesRdr :: (Data t) => NameMap -> [Name] -> t -> Bool -- | Returns True is a syntax phrase, say a, is part of another syntax -- phrase, say b. NOTE: very important: only do a shallow check findEntity :: (FindEntity a, Data b) => a -> b -> Bool -- | Returns True is a syntax phrase, say a, is part of another syntax -- phrase, say b. Expects to be at least Parser output findEntity' :: (Data a, Data b) => a -> b -> Maybe (SimpPos, SimpPos) -- | Return the type checked Id corresponding to the given -- Name findIdForName :: Name -> RefactGhc (Maybe Id) getTypeForName :: Name -> RefactGhc (Maybe Type) -- | Return True if the function/pattern binding defines the specified -- identifier. defines :: Name -> LHsBind Name -> Bool definesP :: PName -> HsDeclP -> Bool -- | Return True if the declaration defines the type signature of the -- specified identifier. definesTypeSig :: Name -> LSig Name -> Bool -- | Return True if the declaration defines the type signature of the -- specified identifier. definesTypeSigRdr :: NameMap -> Name -> Sig RdrName -> Bool sameBind :: LHsBind Name -> LHsBind Name -> Bool sameBindRdr :: NameMap -> LHsDecl RdrName -> LHsDecl RdrName -> Bool class (Data t) => UsedByRhs t -- | Return True if any of the GHC.Name's appear in the given syntax -- element usedByRhs :: UsedByRhs t => t -> [Name] -> Bool usedByRhsRdr :: UsedByRhs t => NameMap -> t -> [Name] -> Bool isMainModule :: Module -> Bool getModule :: RefactGhc Module -- | Return the identifier's defining location. defineLoc::PNT->SrcLoc defineLoc :: Located Name -> SrcLoc -- | Return the identifier's source location. useLoc::PNT->SrcLoc useLoc :: (Located Name) -> SrcLoc -- | Given the syntax phrase, find the largest-leftmost expression -- contained in the region specified by the start and end position, if -- found. locToExp :: (Data t, Typeable n) => SimpPos -> SimpPos -> t -> Maybe (Located (HsExpr n)) -- | Find the identifier(in GHC.Name format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToName :: (Data t) => SimpPos -> t -> Maybe (Located Name) -- | Find the identifier(in GHC.RdrName format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToRdrName :: (Data t) => SimpPos -> t -> Maybe (Located RdrName) -- | Find the identifier with the given name. This looks through the given -- syntax phrase for the first GHC.Name which matches. Because it is -- Renamed source, the GHC.Name will include its defining location. -- Returns Nothing if the name is not found. getName :: (Data t) => String -> t -> Maybe Name -- | Adding a declaration to the declaration list of the given syntax -- phrase. If the second argument is Nothing, then the declaration will -- be added to the beginning of the declaration list, but after the data -- type declarations is there is any. addDecl :: (Data t, Typeable t) => t -> Maybe Name -> ([LHsDecl RdrName], Maybe Anns) -> RefactGhc t -- | Add identifiers (given by the third argument) to the explicit entity -- list in the declaration importing the specified module name. This -- function does nothing if the import declaration does not have an -- explicit entity list. addItemsToImport :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource addItemsToExport :: ParsedSource -> Maybe PName -> Bool -> Either [String] [LIE RdrName] -> RefactGhc ParsedSource -- | add items to the hiding list of an import declaration which imports -- the specified module. addHiding :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource addParamsToDecls :: [LHsDecl RdrName] -> Name -> [RdrName] -> RefactGhc [LHsDecl RdrName] addActualParamsToRhs :: (Data t) => Name -> [RdrName] -> t -> RefactGhc t -- | Add identifiers to the export list of a module. If the second argument -- is like: Just p, then do the adding only if p occurs in the export -- list, and the new identifiers are added right after p in the export -- list. Otherwise the new identifiers are add to the beginning of the -- export list. In the case that the export list is emport, then if the -- third argument is True, then create an explict export list to contain -- only the new identifiers, otherwise do nothing. addImportDecl :: ParsedSource -> ModuleName -> Maybe FastString -> Bool -> Bool -> Bool -> Maybe String -> Bool -> [RdrName] -> RefactGhc ParsedSource -- | Duplicate a function/pattern binding declaration under a new name -- right after the original one. duplicateDecl :: [LHsDecl RdrName] -> Name -> Name -> RefactGhc [LHsDecl RdrName] -- | Remove the declaration (and the type signature is the second parameter -- is True) that defines the given identifier from the declaration list. rmDecl :: (Data t) => Name -> Bool -> t -> RefactGhc (t, LHsDecl RdrName, Maybe (LSig RdrName)) -- | Remove the type signature that defines the given identifier's type -- from the declaration list. rmTypeSig :: (Data t) => Name -> t -> RefactGhc (t, Maybe (LSig RdrName)) -- | Remove multiple type signatures rmTypeSigs :: (Data t) => [Name] -> t -> RefactGhc (t, [LSig RdrName]) -- | Remove the qualifier from the given identifiers in the given syntax -- phrase. rmQualifier :: (Data t) => [Name] -> t -> RefactGhc t -- | Replace all occurences of a top level GHC.Name with a qualified -- version. qualifyToplevelName :: Name -> RefactGhc () -- | Rename each occurrences of the identifier in the given syntax phrase -- with the new name. renamePN :: (Data t) => Name -> Name -> Bool -> t -> RefactGhc t -- | Check whether the specified identifier is declared in the given syntax -- phrase t, if so, rename the identifier by creating a new name -- automatically. autoRenameLocalVar :: (Data t) => Name -> t -> RefactGhc t ghcToPN :: RdrName -> PName lghcToPN :: Located RdrName -> PName -- | If an expression consists of only one identifier then return this -- identifier in the GHC.Name format, otherwise return the default Name expToName :: LHsExpr Name -> Name -- | If an expression consists of only one identifier then return this -- identifier in the GHC.Name format, otherwise return the default Name expToNameRdr :: NameMap -> LHsExpr RdrName -> Maybe Name nameToString :: Name -> String -- | If a pattern consists of only one identifier then return this -- identifier, otherwise return Nothing patToNameRdr :: NameMap -> LPat RdrName -> Maybe Name -- | If a pattern consists of only one identifier then return this -- identifier, otherwise return Nothing patToPNT :: LPat Name -> Maybe Name -- | Compose a pattern from a pName. pNtoPat :: name -> Pat name -- | Divide a declaration list into three parts (before, parent, after) -- according to the PNT, where parent is the first decl -- containing the PNT, before are those decls before -- parent and after are those decls after -- parent. divideDecls :: Data t => [t] -> Located Name -> RefactGhc ([t], [t], [t]) -- | Make a simple unqualified RdrName mkRdrName :: String -> RdrName -- | Make a new GHC.Name, using the Unique Int sequence stored in the -- RefactState. mkNewGhcName :: Maybe Module -> String -> RefactGhc Name -- | Create a new name base on the old name. Suppose the old name is -- f, then the new name would be like f_i where -- i is an integer. mkNewName :: String -> [String] -> Int -> String mkNewToplevelName :: Module -> String -> SrcSpan -> RefactGhc Name -- | Check if the proposed new name will conflict with an existing export causeNameClashInExports :: Name -> Name -> ModuleName -> RenamedSource -> Bool declsSybTransform :: (Typeable a) => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a -- | Given a RenamedSource LPAT, return the equivalent ParsedSource part. -- NOTE: returns pristine ParsedSource, since HaRe does not change it getParsedForRenamedLPat :: ParsedSource -> LPat Name -> LPat RdrName -- | Given a RenamedSource Located name, return the equivalent ParsedSource -- part. NOTE: returns pristine ParsedSource, since HaRe does not change -- it getParsedForRenamedName :: ParsedSource -> Located Name -> Located RdrName -- | Given a RenamedSource Located name, return the equivalent ParsedSource -- part. NOTE: returns pristine ParsedSource, since HaRe does not change -- it getParsedForRenamedLocated :: (Typeable b) => Located a -> RefactGhc (Located b) rdrNameFromName :: Bool -> Name -> RefactGhc RdrName -- | Take a list of strings and return a list with the longest prefix of -- spaces removed stripLeadingSpaces :: [String] -> [String] instance GHC.Classes.Eq Language.Haskell.Refact.Utils.TypeUtils.HowToQual instance GHC.Show.Show Language.Haskell.Refact.Utils.TypeUtils.HowToQual instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs GHC.RenamedSource instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsSyn.HsModule RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs a => Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (SrcLoc.Located a) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs [HsDecls.LHsDecl RdrName.RdrName] instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.HsDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.TyClDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.InstDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.DerivDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.ForeignDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.WarnDecls RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.AnnDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.RoleAnnotDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsTypes.HsQuasiQuote RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.DefaultDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.SpliceDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.VectDecl RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsDecls.RuleDecls RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs HsDecls.DocDecl instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.Sig RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.LHsBinds Name.Name) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.HsValBinds Name.Name) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.Match Name.Name (HsExpr.LHsExpr Name.Name)) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.Match RdrName.RdrName (HsExpr.LHsExpr RdrName.RdrName)) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs [HsBinds.LHsBind Name.Name] instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.HsBind Name.Name) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.HsBind RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.HsExpr Name.Name) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.HsExpr RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.Stmt Name.Name (HsExpr.LHsExpr Name.Name)) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.Stmt RdrName.RdrName (HsExpr.LHsExpr RdrName.RdrName)) -- | This module should provide all that is required to write further -- refactorings. NOTE: it is currently unstable, and may change without -- notice on minor version number bumps module Language.Haskell.Refact.API -- | Result of parsing a Haskell source file. It is simply the -- TypeCheckedModule produced by GHC. type ParseResult = TypecheckedModule data VerboseLevel Debug :: VerboseLevel Normal :: VerboseLevel Off :: VerboseLevel data RefactSettings RefSet :: !VerboseLevel -> (Bool, Bool, Bool, Bool) -> RefactSettings [rsetVerboseLevel] :: RefactSettings -> !VerboseLevel [rsetEnabledTargets] :: RefactSettings -> (Bool, Bool, Bool, Bool) type TargetModule = ModulePath data RefactFlags RefFlags :: !Bool -> RefactFlags -- | Current traversal has already made a change [rsDone] :: RefactFlags -> !Bool -- | Provide some temporary storage while the refactoring is taking place data StateStorage StorageNone :: StateStorage StorageBind :: (LHsBind Name) -> StateStorage StorageSig :: (LSig Name) -> StateStorage StorageBindRdr :: (LHsBind RdrName) -> StateStorage StorageDeclRdr :: (LHsDecl RdrName) -> StateStorage StorageSigRdr :: (LSig RdrName) -> StateStorage data RefactGhc a runRefactGhc :: RefactGhc a -> RefactState -> Options -> IO (a, RefactState) getRefacSettings :: RefactGhc RefactSettings defaultSettings :: RefactSettings logSettings :: RefactSettings logm :: String -> RefactGhc () logDataWithAnns :: (Data a) => String -> a -> RefactGhc () -- | Parse a single source file into a GHC session parseSourceFileGhc :: FilePath -> RefactGhc () getTargetGhc :: TargetModule -> RefactGhc () -- | Manage a whole refactor session. Initialise the monad, load the whole -- project if required, and then apply the individual refactorings, and -- write out the resulting files. -- -- It is intended that this forms the umbrella function, in which -- applyRefac is called runRefacSession :: RefactSettings -> Options -> RefactGhc [ApplyRefacResult] -> IO [FilePath] -- | Apply a refactoring (or part of a refactoring) to a single module applyRefac :: RefactGhc a -> RefacSource -> RefactGhc (ApplyRefacResult, a) -- | Returns True if any of the results has its modified flag set refactDone :: [ApplyRefacResult] -> Bool -- | The result of a refactoring is the file, a flag as to whether it was -- modified, and the updated AST type ApplyRefacResult = ((FilePath, RefacResult), (Anns, ParsedSource)) data RefacSource RSFile :: FilePath -> RefacSource RSMod :: ModSummary -> RefacSource RSAlreadyLoaded :: RefacSource nameSybQuery :: (Typeable a, Typeable t) => (Located a -> Maybe r) -> t -> Maybe r fileNameFromModSummary :: ModSummary -> FilePath -- | Extract the module name from the parsed source, if there is one getModuleName :: ParsedSource -> Maybe (ModuleName, String) -- | Return the client modules and file names. The client modules of -- module, say m, are those modules which directly or indirectly import -- module m. clientModsAndFiles :: ModulePath -> RefactGhc [TargetModule] -- | Return the server module and file names. The server modules of module, -- say m, are those modules which are directly or indirectly imported by -- module m. This can only be called in a live GHC session TODO: make -- sure this works with multiple targets. Is that needed? No? serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary] getTypecheckedModule :: RefactGhc TypecheckedModule data RefacResult RefacModified :: RefacResult RefacUnmodifed :: RefacResult getRefactStreamModified :: RefactGhc RefacResult -- | For testing setRefactStreamModified :: RefacResult -> RefactGhc () getRefactInscopes :: RefactGhc InScopes getRefactRenamed :: RefactGhc RenamedSource putRefactRenamed :: RenamedSource -> RefactGhc () getRefactParsed :: RefactGhc ParsedSource putRefactParsed :: ParsedSource -> Anns -> RefactGhc () putParsedModule :: [Comment] -> TypecheckedModule -> RefactGhc () clearParsedModule :: RefactGhc () getRefactFileName :: RefactGhc (Maybe FilePath) getRefactTargetModule :: RefactGhc TargetModule getRefactNameMap :: RefactGhc NameMap getRefactModule :: RefactGhc Module getRefactModuleName :: RefactGhc ModuleName liftT :: HasTransform m => forall a. Transform a -> m a getRefactDone :: RefactGhc Bool setRefactDone :: RefactGhc () clearRefactDone :: RefactGhc () setStateStorage :: StateStorage -> RefactGhc () getStateStorage :: RefactGhc StateStorage type SimpPos = (Int, Int) -- | gets the (row,col) of the start of the GHC.SrcSpan, or -- (-1,-1) if there is an GHC.UnhelpfulSpan getGhcLoc :: SrcSpan -> (Int, Int) -- | gets the (row,col) of the end of the GHC.SrcSpan, or (-1,-1) -- if there is an GHC.UnhelpfulSpan getGhcLocEnd :: SrcSpan -> (Int, Int) getLocatedStart :: GenLocated SrcSpan t -> (Int, Int) getLocatedEnd :: GenLocated SrcSpan t -> (Int, Int) getStartEndLoc :: (Data t) => t -> (SimpPos, SimpPos) startEndLocGhc :: Located b -> (SimpPos, SimpPos) -- | Get around lack of instance Eq when simply testing for empty list -- TODO: get rid of this in favour of null built in fn emptyList :: [t] -> Bool nonEmptyList :: [t] -> Bool type InScopes = [Name] ghead :: String -> [a] -> a glast :: String -> [a] -> a gtail :: String -> [a] -> [a] gfromJust :: String -> Maybe a -> a -- | Process the inscope relation returned from the parsing and module -- analysis pass, and return a list of four-element tuples. Each tuple -- contains an identifier name, the identifier's namespace info, the -- identifier's defining module name and its qualifier name. -- -- The same identifier may have multiple entries in the result because it -- may have different qualifiers. This makes it easier to decide whether -- the identifier can be used unqualifiedly by just checking whether -- there is an entry for it with the qualifier field being Nothing. inScopeInfo :: InScopes -> [(String, NameSpace, ModuleName, Maybe ModuleName)] -- | Return True if the identifier is inscope and can be used without a -- qualifier. isInScopeAndUnqualified :: String -> InScopes -> Bool -- | Return True if the identifier is inscope and can be used without a -- qualifier. The identifier name string may have a qualifier already -- NOTE: may require qualification based on name clash with an existing -- identifier. isInScopeAndUnqualifiedGhc :: String -> (Maybe Name) -> RefactGhc Bool -- | Return all Names that correspond to the given string, in the -- current module. inScopeNames :: String -> RefactGhc [Name] -- | Return True if an identifier is exported by the module currently being -- refactored. isExported :: Name -> RefactGhc Bool -- | Return True if an identifier is explicitly exported by the module. isExplicitlyExported :: Name -> RenamedSource -> Bool -- | Return True if the current module is exported either by default or by -- specifying the module name in the export. modIsExported :: ModuleName -> RenamedSource -> Bool -- | Given a Name defined in one module, find the equivalent one in -- the currently loaded module. This is required otherwise name equality -- checking based on nameUnique will fail. equivalentNameInNewMod :: Name -> RefactGhc [Name] -- | True if the name is a field name isFieldName :: Name -> Bool -- | True if the name is a field name isClassName :: Name -> Bool -- | True if the name is a class instance isInstanceName :: Name -> Bool -- | Collect the identifiers (in PName format) in a given syntax phrase. hsPNs :: (Data t) => t -> [PName] hsBinds :: (HsValBinds t name) => t -> [LHsBind name] class (Data t, Data name) => HsValBinds t name | t -> name -- | Return the binds that are directly enclosed in the given syntax -- phrase. hsValBinds :: t -> [GHC.LHsBind GHC.Name] hsValBinds :: HsValBinds t name => t -> HsValBinds name -- | Return the type class definitions that are directly enclosed in the -- given syntax phrase. Note: only makes sense for GHC.RenamedSource hsTyDecls :: HsValBinds t name => t -> [[LTyClDecl name]] isDeclaredIn :: (HsValBinds t Name) => Name -> t -> Bool isDeclaredInRdr :: NameMap -> Name -> [LHsDecl RdrName] -> Bool -- | For free variables data FreeNames FN :: [Name] -> FreeNames [fn] :: FreeNames -> [Name] -- | For declared variables data DeclaredNames DN :: [Name] -> DeclaredNames [dn] :: DeclaredNames -> [Name] -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. -- Expects RenamedSource hsFreeAndDeclaredPNsOld :: (Data t) => t -> ([Name], [Name]) -- | The same as hsFreeAndDeclaredPNs except that the returned -- variables are in the String format. hsFreeAndDeclaredNameStrings :: (Data t, Outputable t) => t -> RefactGhc ([String], [String]) -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. -- Expects RenamedSource hsFreeAndDeclaredRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) hsFreeAndDeclaredPNs :: (Data t) => t -> RefactGhc ([Name], [Name]) -- | Collect the free and declared variables (in the GHC.Name format) in a -- given syntax phrase t. In the result, the first list contains the free -- variables, and the second list contains the declared variables. TODO: -- use GHC.NameSet instead of lists for FreeNames/DeclaredNames NOTE: The -- GHC fvs fields only carry non-GHC values, as they are used in the -- renaming process hsFreeAndDeclaredGhc :: (SYB.Data t,GHC.Outputable t) hsFreeAndDeclaredGhc :: (Data t) => t -> RefactGhc (FreeNames, DeclaredNames) -- | Get the names of all types declared in the given declaration getDeclaredTypes :: LTyClDecl Name -> [Name] -- | Experiment with GHC fvs stuff getFvs :: [LHsBind Name] -> [([Name], NameSet)] getFreeVars :: [LHsBind Name] -> [Name] getDeclaredVars :: [LHsBind Name] -> [Name] -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisiblePNs :: (FindEntity e, HsValBinds t Name, Outputable e) => e -> t -> RefactGhc [Name] -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisiblePNsRdr :: (FindEntity e, Data t, Outputable e) => NameMap -> e -> t -> RefactGhc [Name] -- | Same as hsVisiblePNs except that the returned identifiers are -- in String format. hsVisibleNames :: (FindEntity t1, HsValBinds t2 Name, Outputable t1) => t1 -> t2 -> RefactGhc [String] -- | Same as hsVisiblePNs except that the returned identifiers are -- in String format. hsVisibleNamesRdr :: (FindEntity t1, Data t2, Outputable t1) => t1 -> t2 -> RefactGhc [String] -- | hsFDsFromInsideRdr is different from -- hsFreeAndDeclaredPNs in that: given an syntax phrase t, -- hsFDsFromInsideRdr returns not only the declared variables that -- are visible from outside of t, but also those declared variables that -- are visible to the main expression inside t. NOTE: Expects to be given -- RenamedSource hsFDsFromInsideRdr :: (Data t) => NameMap -> t -> RefactGhc (FreeNames, DeclaredNames) -- | The same as hsFDsFromInside except that the returned variables -- are in the String format hsFDNamesFromInsideRdr :: (Data t) => t -> RefactGhc ([String], [String]) -- | hsFDsFromInside is different from hsFreeAndDeclaredPNs -- in that: given an syntax phrase t, hsFDsFromInside returns not -- only the declared variables that are visible from outside of t, but -- also those declared variables that are visible to the main expression -- inside t. NOTE: Expects to be given RenamedSource hsFDsFromInside :: (Data t) => t -> RefactGhc ([Name], [Name]) -- | The same as hsFDsFromInside except that the returned variables -- are in the String format hsFDNamesFromInside :: (Data t) => t -> RefactGhc ([String], [String]) -- | Given syntax phrases e and t, if e occurs in t, then return those -- variables which are declared in t and accessible to e, otherwise -- return []. hsVisibleDs :: (FindEntity e, Outputable e, Data t, HsValBinds t Name) => e -> t -> RefactGhc DeclaredNames rdrName2Name :: Located RdrName -> RefactGhc Name rdrName2NamePure :: NameMap -> Located RdrName -> Name -- | Return True if a string is a lexically valid variable name. isVarId :: String -> Bool -- | Return True if a string is a lexically valid constructor name. isConId :: String -> Bool -- | Return True if a string is a lexically valid operator name. isOperator :: String -> Bool -- | Return True if a PName is a toplevel PName. isTopLevelPN :: Name -> RefactGhc Bool -- | Return True if a PName is a local PName. isLocalPN :: Name -> Bool -- | Return True if the name has a GHC.SrcSpan, i.e. is declared -- in source we care about isNonLibraryName :: Name -> Bool -- | Return True if a PName is a qualified PName. AZ:NOTE: this tests the -- use instance, the underlying name may be qualified. e.g. used name is -- zip, GHC.List.zip NOTE2: not sure if this gives a meaningful result -- for a GHC.Name isQualifiedPN :: Name -> RefactGhc Bool -- | Return True if a PName is a function/pattern name defined in t. isFunOrPatName :: (Data t) => Name -> t -> Bool -- | Return True if a declaration is a type signature declaration. isTypeSig :: LSig a -> Bool -- | Return True if a declaration is a function definition. isFunBindP :: HsDeclP -> Bool isFunBindR :: LHsBind t -> Bool -- | Returns True if a declaration is a pattern binding. isPatBindP :: HsDeclP -> Bool isPatBindR :: LHsBind t -> Bool -- | Return True if a declaration is a pattern binding which only defines a -- variable value. isSimplePatBind :: (DataId t) => LHsBind t -> Bool -- | Return True if a declaration is a pattern binding which only defines a -- variable value. isSimplePatDecl :: (DataId t) => LHsDecl t -> Bool -- | Return True if a LHsBin is a pattern binding but not a simple one. isComplexPatBind :: LHsBind name -> Bool -- | Return True if a declaration is a pattern binding but not a simple -- one. isComplexPatDecl :: LHsDecl name -> Bool -- | Return True if a declaration is a function/pattern definition. isFunOrPatBindP :: HsDeclP -> Bool -- | Return True if a declaration is a function/pattern definition. isFunOrPatBindR :: LHsBind t -> Bool -- | Return True if the identifier is unqualifiedly used in the given -- syntax phrase. usedWithoutQualR :: GHC.Name -> GHC.ParsedSource -- -> Bool usedWithoutQualR :: (Data t) => Name -> t -> Bool -- | Return True if the identifier is used in the RHS if a function/pattern -- binding. isUsedInRhs :: (Data t) => (Located Name) -> t -> Bool findNameInRdr :: (Data t) => NameMap -> Name -> t -> Bool -- | Return True if the identifier occurs in the given syntax phrase. findPNT :: (Data t) => Located Name -> t -> Bool -- | Return True if the identifier occurs in the given syntax phrase. findPN :: (Data t) => Name -> t -> Bool -- | Find all occurrences with location of the given name findAllNameOccurences :: (Data t) => Name -> t -> [(Located Name)] -- | Return True if any of the specified PNames ocuur in the given syntax -- phrase. findPNs :: (Data t) => [Name] -> t -> Bool -- | Return True if any of the specified PNames ocuur in the given syntax -- phrase. findNamesRdr :: (Data t) => NameMap -> [Name] -> t -> Bool -- | Returns True is a syntax phrase, say a, is part of another syntax -- phrase, say b. NOTE: very important: only do a shallow check findEntity :: (FindEntity a, Data b) => a -> b -> Bool -- | Returns True is a syntax phrase, say a, is part of another syntax -- phrase, say b. Expects to be at least Parser output findEntity' :: (Data a, Data b) => a -> b -> Maybe (SimpPos, SimpPos) -- | Return True if syntax phrases t1 and t2 refer to the same one. sameOccurrence :: (Located t) -> (Located t) -> Bool -- | Return the type checked Id corresponding to the given -- Name findIdForName :: Name -> RefactGhc (Maybe Id) getTypeForName :: Name -> RefactGhc (Maybe Type) -- | Return True if the function/pattern binding defines the specified -- identifier. defines :: Name -> LHsBind Name -> Bool definesP :: PName -> HsDeclP -> Bool -- | Return True if the declaration defines the type signature of the -- specified identifier. definesTypeSig :: Name -> LSig Name -> Bool sameBind :: LHsBind Name -> LHsBind Name -> Bool sameBindRdr :: NameMap -> LHsDecl RdrName -> LHsDecl RdrName -> Bool class (Data t) => UsedByRhs t -- | Return True if any of the GHC.Name's appear in the given syntax -- element usedByRhs :: UsedByRhs t => t -> [Name] -> Bool usedByRhsRdr :: UsedByRhs t => NameMap -> t -> [Name] -> Bool isMainModule :: Module -> Bool getModule :: RefactGhc Module -- | Return the identifier's defining location. defineLoc::PNT->SrcLoc defineLoc :: Located Name -> SrcLoc -- | Return the identifier's source location. useLoc::PNT->SrcLoc useLoc :: (Located Name) -> SrcLoc -- | Given the syntax phrase, find the largest-leftmost expression -- contained in the region specified by the start and end position, if -- found. locToExp :: (Data t, Typeable n) => SimpPos -> SimpPos -> t -> Maybe (Located (HsExpr n)) -- | Find the identifier(in GHC.Name format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToName :: (Data t) => SimpPos -> t -> Maybe (Located Name) -- | Find the identifier(in GHC.RdrName format) whose start position is -- (row,col) in the file specified by the fileName, and returns -- Nothing if such an identifier does not exist. locToRdrName :: (Data t) => SimpPos -> t -> Maybe (Located RdrName) -- | Find the identifier with the given name. This looks through the given -- syntax phrase for the first GHC.Name which matches. Because it is -- Renamed source, the GHC.Name will include its defining location. -- Returns Nothing if the name is not found. getName :: (Data t) => String -> t -> Maybe Name -- | Adding a declaration to the declaration list of the given syntax -- phrase. If the second argument is Nothing, then the declaration will -- be added to the beginning of the declaration list, but after the data -- type declarations is there is any. addDecl :: (Data t, Typeable t) => t -> Maybe Name -> ([LHsDecl RdrName], Maybe Anns) -> RefactGhc t -- | Add identifiers (given by the third argument) to the explicit entity -- list in the declaration importing the specified module name. This -- function does nothing if the import declaration does not have an -- explicit entity list. addItemsToImport :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource addItemsToExport :: ParsedSource -> Maybe PName -> Bool -> Either [String] [LIE RdrName] -> RefactGhc ParsedSource -- | add items to the hiding list of an import declaration which imports -- the specified module. addHiding :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource addParamsToDecls :: [LHsDecl RdrName] -> Name -> [RdrName] -> RefactGhc [LHsDecl RdrName] addActualParamsToRhs :: (Data t) => Name -> [RdrName] -> t -> RefactGhc t -- | Add identifiers to the export list of a module. If the second argument -- is like: Just p, then do the adding only if p occurs in the export -- list, and the new identifiers are added right after p in the export -- list. Otherwise the new identifiers are add to the beginning of the -- export list. In the case that the export list is emport, then if the -- third argument is True, then create an explict export list to contain -- only the new identifiers, otherwise do nothing. addImportDecl :: ParsedSource -> ModuleName -> Maybe FastString -> Bool -> Bool -> Bool -> Maybe String -> Bool -> [RdrName] -> RefactGhc ParsedSource -- | Duplicate a function/pattern binding declaration under a new name -- right after the original one. duplicateDecl :: [LHsDecl RdrName] -> Name -> Name -> RefactGhc [LHsDecl RdrName] -- | Remove the declaration (and the type signature is the second parameter -- is True) that defines the given identifier from the declaration list. rmDecl :: (Data t) => Name -> Bool -> t -> RefactGhc (t, LHsDecl RdrName, Maybe (LSig RdrName)) -- | Remove the type signature that defines the given identifier's type -- from the declaration list. rmTypeSig :: (Data t) => Name -> t -> RefactGhc (t, Maybe (LSig RdrName)) -- | Remove multiple type signatures rmTypeSigs :: (Data t) => [Name] -> t -> RefactGhc (t, [LSig RdrName]) -- | Remove the qualifier from the given identifiers in the given syntax -- phrase. rmQualifier :: (Data t) => [Name] -> t -> RefactGhc t -- | Replace all occurences of a top level GHC.Name with a qualified -- version. qualifyToplevelName :: Name -> RefactGhc () -- | Rename each occurrences of the identifier in the given syntax phrase -- with the new name. renamePN :: (Data t) => Name -> Name -> Bool -> t -> RefactGhc t -- | Check whether the specified identifier is declared in the given syntax -- phrase t, if so, rename the identifier by creating a new name -- automatically. autoRenameLocalVar :: (Data t) => Name -> t -> RefactGhc t ghcToPN :: RdrName -> PName lghcToPN :: Located RdrName -> PName -- | If an expression consists of only one identifier then return this -- identifier in the GHC.Name format, otherwise return the default Name expToName :: LHsExpr Name -> Name -- | If an expression consists of only one identifier then return this -- identifier in the GHC.Name format, otherwise return the default Name expToNameRdr :: NameMap -> LHsExpr RdrName -> Maybe Name -- | If a pattern consists of only one identifier then return this -- identifier, otherwise return Nothing patToNameRdr :: NameMap -> LPat RdrName -> Maybe Name nameToString :: Name -> String -- | If a pattern consists of only one identifier then return this -- identifier, otherwise return Nothing patToPNT :: LPat Name -> Maybe Name -- | Compose a pattern from a pName. pNtoPat :: name -> Pat name -- | Return the list of identifiers (in PName format) defined by a -- function/pattern binding. definedPNs :: LHsBind Name -> [Name] definedPNsRdr :: LHsDecl RdrName -> [Located RdrName] definedNamesRdr :: NameMap -> LHsDecl RdrName -> [Name] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsRdrNames :: NameMap -> [Name] -> [LHsDecl RdrName] -> Bool -> Bool -> [LHsDecl RdrName] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsRdrNames' :: (Data t) => NameMap -> [Name] -> t -> [LHsDecl RdrName] -- | Find those type signatures for the specified GHC.Names. definingSigsRdrNames :: (Data t) => NameMap -> [Name] -> t -> [LSig RdrName] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsNames :: [Name] -> [LHsBind Name] -> Bool -> Bool -> [LHsBind Name] -- | Find those declarations(function/pattern binding) which define the -- specified GHC.Names. incTypeSig indicates whether the corresponding -- type signature will be included. definingDeclsNames' :: (Data t) => [Name] -> t -> [LHsBind Name] -- | Find those type signatures for the specified GHC.Names. definingSigsNames :: (Data t) => [Name] -> t -> [LSig Name] -- | Find those declarations which define the specified GHC.Names. definingTyClDeclsNames :: (Data t) => [Name] -> t -> [LTyClDecl Name] -- | Find all Located Names in the given Syntax phrase. allNames :: (Data t) => t -> [Located Name] -- | Divide a declaration list into three parts (before, parent, after) -- according to the PNT, where parent is the first decl -- containing the PNT, before are those decls before -- parent and after are those decls after -- parent. divideDecls :: Data t => [t] -> Located Name -> RefactGhc ([t], [t], [t]) -- | Make a simple unqualified RdrName mkRdrName :: String -> RdrName -- | Make a new GHC.Name, using the Unique Int sequence stored in the -- RefactState. mkNewGhcName :: Maybe Module -> String -> RefactGhc Name -- | Create a new name base on the old name. Suppose the old name is -- f, then the new name would be like f_i where -- i is an integer. mkNewName :: String -> [String] -> Int -> String mkNewToplevelName :: Module -> String -> SrcSpan -> RefactGhc Name -- | Check if the proposed new name will conflict with an existing export causeNameClashInExports :: Name -> Name -> ModuleName -> RenamedSource -> Bool declsSybTransform :: (Typeable a) => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a -- | Given a RenamedSource LPAT, return the equivalent ParsedSource part. -- NOTE: returns pristine ParsedSource, since HaRe does not change it getParsedForRenamedLPat :: ParsedSource -> LPat Name -> LPat RdrName -- | Given a RenamedSource Located name, return the equivalent ParsedSource -- part. NOTE: returns pristine ParsedSource, since HaRe does not change -- it getParsedForRenamedName :: ParsedSource -> Located Name -> Located RdrName -- | Given a RenamedSource Located name, return the equivalent ParsedSource -- part. NOTE: returns pristine ParsedSource, since HaRe does not change -- it getParsedForRenamedLocated :: (Typeable b) => Located a -> RefactGhc (Located b) -- | Take a list of strings and return a list with the longest prefix of -- spaces removed stripLeadingSpaces :: [String] -> [String] -- | Monadic variation on everywhere' everywhereMStaged' :: Monad m => Stage -> GenericM m -> GenericM m -- | Bottom-up transformation everywhereStaged :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a -- | Top-down version of everywhereStaged everywhereStaged' :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a -- | Perform a query on the immediate subterms only, avoiding holes onelayerStaged :: Stage -> r -> GenericQ r -> GenericQ [r] -- | Staged variation of SYB.listify The stage must be provided to avoid -- trying to modify elements which may not be present at all stages of -- AST processing. listifyStaged :: (Data a, Typeable a1) => Stage -> (a1 -> Bool) -> a -> [a1] -- | Apply a generic transformation everywhere in a bottom-up manner. zeverywhereStaged :: (Typeable a) => Stage -> GenericT -> Zipper a -> Zipper a -- | Open a zipper to the point where the Geneneric query passes. returns -- the original zipper if the query does not pass (check this) zopenStaged :: (Typeable a) => Stage -> GenericQ Bool -> Zipper a -> [Zipper a] -- | Apply a generic monadic transformation once at the topmost leftmost -- successful location, avoiding holes in the GHC structures zsomewhereStaged :: (MonadPlus m) => Stage -> GenericM m -> Zipper a -> m (Zipper a) -- | Transform a zipper opened with a given generic query transZ :: Stage -> GenericQ Bool -> (Stage -> Zipper a -> Zipper a) -> Zipper a -> Zipper a -- | Monadic transform of a zipper opened with a given generic query transZM :: Monad m => Stage -> GenericQ Bool -> (Stage -> Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a) -- | Open a zipper to the point where the Generic query passes, returning -- the zipper and a value from the specific part of the GenericQ that -- matched. This allows the components of the query to return a specific -- transformation routine, to apply to the returned zipper zopenStaged' :: (Typeable a) => Stage -> GenericQ (Maybe b) -> Zipper a -> [(Zipper a, b)] -- | Open a zipper to the point where the Generic query passes, and apply -- the transformation returned from the specific part of the GenericQ -- that matched. ztransformStagedM :: (Typeable a, Monad m) => Stage -> GenericQ (Maybe (Stage -> Zipper a -> m (Zipper a))) -> Zipper a -> m (Zipper a) -- | Climb the tree until a predicate holds upUntil :: GenericQ Bool -> Zipper a -> Maybe (Zipper a) -- | Up the zipper until a predicate holds, and then return the zipper hole findAbove :: (Data a) => (a -> Bool) -> Zipper a -> Maybe a -- | Show a GHC.Outputable structure showGhc :: Outputable a => a -> String showGhcQual :: (Outputable a) => a -> String prettyprint :: (Outputable a) => a -> String prettyprint2 :: (Outputable a) => a -> String ppType :: Type -> String setGhcContext :: GhcMonad m => ModSummary -> m () type NameMap = Map SrcSpan Name -- | Replaces an old expression with a new expression replace :: AnnKey -> AnnKey -> Anns -> Maybe Anns -- | Internal low level interface to access the current annotations from -- the RefactGhc state. setRefactAnns :: Anns -> RefactGhc () module Language.Haskell.Refact.Refactoring.Case -- | Convert an if expression to a case expression ifToCase :: RefactSettings -> Options -> FilePath -> SimpPos -> SimpPos -> IO [FilePath] compIfToCase :: FilePath -> SimpPos -> SimpPos -> RefactGhc [ApplyRefacResult] module Language.Haskell.Refact.Refactoring.DupDef -- | This refactoring duplicates a definition (function binding or simple -- pattern binding) at the same level with a new name provided by the -- user. The new name should not cause name clash/capture. duplicateDef :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] compDuplicateDef :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] instance GHC.Show.Show Language.Haskell.Refact.Refactoring.DupDef.DupDefResult instance GHC.Classes.Eq Language.Haskell.Refact.Refactoring.DupDef.DupDefResult module Language.Haskell.Refact.Refactoring.MoveDef -- | Lift a definition to the top level liftToTopLevel :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compLiftToTopLevel :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Move a definition one level up from where it is now liftOneLevel :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compLiftOneLevel :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Move a definition one level down demote :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compDemote :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] module Language.Haskell.Refact.Refactoring.Renaming -- | Rename the given identifier. rename :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] -- | Body of the refactoring compRename :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] module Language.Haskell.Refact.Refactoring.RoundTrip -- | Roundtrip the source code, to check that the infrastructure is solid roundTrip :: RefactSettings -> Options -> FilePath -> IO [FilePath] module Language.Haskell.Refact.HaRe data RefactSettings RefSet :: !VerboseLevel -> (Bool, Bool, Bool, Bool) -> RefactSettings [rsetVerboseLevel] :: RefactSettings -> !VerboseLevel [rsetEnabledTargets] :: RefactSettings -> (Bool, Bool, Bool, Bool) data VerboseLevel Debug :: VerboseLevel Normal :: VerboseLevel Off :: VerboseLevel defaultSettings :: RefactSettings type SimpPos = (Int, Int) data Options :: * Options :: OutputOpts -> Programs -> [GHCOption] -> [(FilePath, Maybe FilePath)] -> Options [optOutput] :: Options -> OutputOpts [optPrograms] :: Options -> Programs -- | GHC command line options set on the ghc-mod command line [optGhcUserOptions] :: Options -> [GHCOption] [optFileMappings] :: Options -> [(FilePath, Maybe FilePath)] -- | A default Options. defaultOptions :: Options -- | Convert an if expression to a case expression ifToCase :: RefactSettings -> Options -> FilePath -> SimpPos -> SimpPos -> IO [FilePath] compIfToCase :: FilePath -> SimpPos -> SimpPos -> RefactGhc [ApplyRefacResult] -- | This refactoring duplicates a definition (function binding or simple -- pattern binding) at the same level with a new name provided by the -- user. The new name should not cause name clash/capture. duplicateDef :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] compDuplicateDef :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Lift a definition to the top level liftToTopLevel :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compLiftToTopLevel :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Move a definition one level up from where it is now liftOneLevel :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compLiftOneLevel :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Move a definition one level down demote :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compDemote :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Rename the given identifier. rename :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] -- | Body of the refactoring compRename :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Roundtrip the source code, to check that the infrastructure is solid roundTrip :: RefactSettings -> Options -> FilePath -> IO [FilePath] module Language.Haskell.Refact.Refactoring.AddRmParam addOneParameter :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] module Language.Haskell.Refact.Refactoring.Simple -- | Convert an if expression to a case expression removeBracket :: RefactSettings -> Options -> FilePath -> SimpPos -> SimpPos -> IO [FilePath] module Language.Haskell.Refact.Refactoring.SwapArgs swapArgs :: RefactSettings -> Options -> [String] -> IO [FilePath]