-- 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. -- -- From version 0.8.3.0, GHC 8.0.1 is supported. -- -- From version 0.8.4.0, GHC 8.0.2 is supported. -- -- It is tested against GHC 7.10.3, GHC 8.0.1 and GHC 8.0.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.4.1 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.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 TypecheckedModule TypecheckedModule :: !ParsedModule -> !RenamedSource -> !TypecheckedSource -> [AvailInfo] -> (Maybe GlobalRdrEnv) -> TypecheckedModule [tmParsedModule] :: TypecheckedModule -> !ParsedModule [tmRenamedSource] :: TypecheckedModule -> !RenamedSource [tmTypecheckedSource] :: TypecheckedModule -> !TypecheckedSource [tmMinfExports] :: TypecheckedModule -> [AvailInfo] [tmMinfRdrEnv] :: TypecheckedModule -> (Maybe GlobalRdrEnv) 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 instance GHC.Show.Show Language.Haskell.Refact.Utils.Types.TypecheckedModule -- | 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) module Language.Haskell.Refact.Utils.Synonyms type UnlocParsedHsBind = HsBindLR RdrName RdrName type ParsedGRHSs = GRHSs RdrName (LHsExpr RdrName) type ParsedMatchGroup = MatchGroup RdrName (LHsExpr RdrName) type ParsedLMatch = LMatch RdrName (LHsExpr RdrName) type ParsedExpr = HsExpr RdrName type ParsedLExpr = LHsExpr RdrName type ParsedLStmt = LStmt RdrName (LHsExpr RdrName) type ParsedBind = HsBind RdrName 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 data RefacSource RSFile :: FilePath -> RefacSource RSTarget :: TargetModule -> RefacSource RSMod :: ModSummary -> RefacSource RSAlreadyLoaded :: RefacSource 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 GhcMod.Types.MonadIO Language.Haskell.Refact.Utils.Monad.RefactGhc instance GhcMod.Monad.Out.GmOut Language.Haskell.Refact.Utils.Monad.RefactGhc instance 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 GhcMod.Monad.Out.GmOut (Control.Monad.Trans.State.Lazy.StateT Language.Haskell.Refact.Utils.Monad.RefactState GHC.Types.IO) instance GhcMod.Monad.Out.GmOut GHC.Types.IO instance 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 () -- | Merges new annotations with the currecnt annotations from the -- RefactGhc state. mergeRefactAnns :: Anns -> RefactGhc () putParsedModule :: [Comment] -> TypecheckedModule -> RefactGhc () clearParsedModule :: RefactGhc () getRefactFileName :: RefactGhc (Maybe FilePath) getRefactTargetModule :: RefactGhc TargetModule getRefactModule :: RefactGhc Module getRefactModuleName :: RefactGhc ModuleName getRefactNameMap :: RefactGhc NameMap addToNameMap :: SrcSpan -> Name -> RefactGhc () 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 () logExactprint :: (Annotate a) => String -> Located a -> RefactGhc () exactPrintParsed :: RefactGhc () exactPrintExpr :: Annotate ast => Located ast -> 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.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 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 ParsedSource hsFreeAndDeclaredRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) -- | The same as hsFreeAndDeclaredPNs except that the returned -- variables are in the String format. hsFreeAndDeclaredNameStrings :: (Data t) => t -> RefactGhc ([String], [String]) -- | Return the free and declared Names in the given syntax fragment. The -- syntax fragment MUST be parameterised by RdrName, else the empty list -- will be returned. hsFreeAndDeclaredPNs :: (Data t) => t -> RefactGhc ([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] getDeclaredVarsRdr :: NameMap -> [LHsDecl RdrName] -> [Name] -- | Same as hsVisiblePNsRdr except that the returned identifiers -- are in String format. hsVisibleNamesRdr :: (Data t2) => Name -> t2 -> RefactGhc [String] -- | Given a Name n and a syntax phrase t, if n occurs in t, then -- return those variables which are declared in t and accessible to n, -- otherwise return []. hsVisibleDsRdr :: (Data t) => NameMap -> Name -> t -> RefactGhc DeclaredNames -- | 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 -- ParsedSource hsFDsFromInsideRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) -- | The same as hsFDsFromInside except that the returned -- variables are in the String format hsFDNamesFromInsideRdr :: (Data t) => t -> RefactGhc ([String], [String]) -- | The same as hsFDsFromInside except that the returned -- variables are in the String format hsFDNamesFromInsideRdrPure :: (Data t) => NameMap -> t -> ([String], [String]) rdrName2Name :: Located RdrName -> RefactGhc Name rdrName2NamePure :: NameMap -> Located RdrName -> Name eqRdrNamePure :: NameMap -> Located RdrName -> Name -> Bool -- | Returns True if both GHC.Names are in the same -- GHC.NameSpace. sameNameSpace :: Name -> Name -> Bool -- | Deprecated: Can't use Renamed in GHC 8 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 the specified Name ocuurs in the given syntax phrase. findNameInRdr :: (Data t) => NameMap -> Name -> t -> Bool -- | Return True if any of the specified PNames ocuur in the given syntax -- phrase. findNamesRdr :: (Data t) => NameMap -> [Name] -> t -> Bool -- | Return True if syntax phrases t1 and t2 refer to the same one. sameOccurrence :: (Located t) -> (Located t) -> Bool 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 which define the specified GHC.Names. definingTyClDeclsNames :: (Data t) => NameMap -> [Name] -> t -> [LTyClDecl RdrName] -- | 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 or -- calls clsDeclDefinesRdr if a TyClD definesDeclRdr :: NameMap -> Name -> LHsDecl RdrName -> Bool -- | Returns True if the provided Name is defined in the LHsDecl definesNameRdr :: NameMap -> Name -> LHsDecl RdrName -> 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 -- | Collect those type variables that are declared in a given syntax -- phrase t. In the returned result, the first list is always be empty. hsTypeVbls :: (Data t) => t -> ([RdrName], [RdrName]) -- | Get all the names in the given syntax element hsNamessRdr :: (Data t) => t -> [Located RdrName] -- | Does the given Name appear as a Located RdrName -- anywhere in t? findLRdrName :: (Data t) => NameMap -> Name -> t -> Bool -- | 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. locToNameRdr :: (Data t) => SimpPos -> t -> RefactGhc (Maybe Name) -- | 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. locToNameRdrPure :: (Data t) => NameMap -> SimpPos -> t -> Maybe 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 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 -- | 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] everywhereButM :: Monad m => GenericQ Bool -> Generic m -> GenericM m -- | 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.GhcModuleGraph getModulesAsGraph :: Bool -> [ModSummary] -> Maybe ModuleName -> Graph SummaryNode summaryNodeSummary :: SummaryNode -> ModSummary 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) applyRefac' :: Bool -> 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? serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary] -- | Like runRefacSession but instead takes an ordered list of RefactGhc -- computations and runs all of them threading the state through all of -- the computations runMultRefacSession :: RefactSettings -> Options -> [RefactGhc [ApplyRefacResult]] -> IO [FilePath] modifiedFiles :: [ApplyRefacResult] -> [String] -- | Write refactored program source to files. writeRefactoredFiles :: VerboseLevel -> [ApplyRefacResult] -> IO () -- | In GHC 8 an error has an attached callstack. This is not always what -- we want, so this function strips it stripCallStack :: String -> String -- | 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.ExactPrint -- | Replaces an old expression with a new expression replace :: AnnKey -> AnnKey -> Anns -> Maybe Anns -- | The annotations are keyed to the constructor, so if we replace a -- qualified with an unqualified RdrName or vice versa we have to rebuild -- the key for the appropriate annotation. replaceAnnKey :: (Data old, Data new) => Located old -> Located new -> Anns -> Anns copyAnn :: (Data old, Data new) => Located old -> Located new -> Anns -> Anns -- | Change the DeltaPos for a given KeywordId if it -- appears in the annotation for the given item. setAnnKeywordDP :: (Data a) => Located a -> KeywordId -> DeltaPos -> Transform () -- | Remove any preceding comments from the given item clearPriorComments :: (Data a) => Located a -> Transform () balanceAllComments :: Data a => Located a -> Transform (Located a) locate :: (Data a) => a -> RefactGhc (Located a) addEmptyAnn :: (Data a) => Located a -> RefactGhc () addAnnVal :: (Data a) => Located a -> RefactGhc () addAnn :: (Data a) => Located a -> Annotation -> RefactGhc () zeroDP :: (Data a) => Located a -> RefactGhc () setDP :: (Data a) => DeltaPos -> Located a -> RefactGhc () handleParseResult :: String -> Either (SrcSpan, String) (Anns, a) -> RefactGhc (Anns, a) removeAnns :: (Data a) => a -> RefactGhc a synthesizeAnns :: (Data a) => a -> RefactGhc a addNewKeyword :: (Data a) => (KeywordId, DeltaPos) -> Located a -> RefactGhc () addNewKeywords :: (Data a) => [(KeywordId, DeltaPos)] -> Located a -> RefactGhc () -- | 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 :: NameMap -> Name -> ParsedSource -> 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 all the possible qualifiers for the identifier. The identifier -- is not inscope if the result is an empty list. NOTE: This is intended -- to be used when processing a client module, so the Name -- parameter is actually from a different module. hsQualifier :: Name -> RefactGhc [ModuleName] -- | 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) => NameMap -> 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 :: LHsDecl RdrName -> Bool isFunBindR :: LHsBind t -> Bool -- | Returns True if a declaration is a pattern binding. isPatBindP :: LHsDecl RdrName -> 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 :: LHsDecl RdrName -> 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 -- | 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 declaration defines the type signature of the -- specified identifier. definesTypeSigRdr :: NameMap -> Name -> Sig RdrName -> 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 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 (LHsExpr n) -- | 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 -> Maybe Name -> Either [RdrName] [LIE RdrName] -> ParsedSource -> RefactGhc ParsedSource -- | 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 empty, then if the -- third argument is True, then create an explict export list to contain -- only the new identifiers, otherwise do nothing. TODO:AZ: re-arrange -- params to line up with addItemsToExport addItemsToExport :: ParsedSource -> Maybe Name -> Bool -> Either [RdrName] [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] addParamsToSigs :: [Name] -> LSig RdrName -> RefactGhc (LSig 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 StringLiteral -> 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 -> HowToQual -> t -> RefactGhc t data HowToQual Qualify :: HowToQual NoQualify :: HowToQual PreserveQualify :: HowToQual -- | 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 -- | 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 -- | Compose a pattern from a pName. -- | Deprecated: Can't use Renamed in GHC 8 pNtoPat :: name -> Pat name -- | Return True if the identifier is unqualifiedly used in the given -- syntax phrase. Check in a way that the test can be done in a client -- module, i.e. not using the nameUnique usedWithoutQualR :: GHC.Name -- -> GHC.ParsedSource -> Bool usedWithoutQualR :: (Data t) => Name -> t -> Bool -- | 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 qualified RdrName mkQualifiedRdrName :: ModuleName -> 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 -- | Register a Located RdrName in the NameMap so it -- can be looked up if needed. This will create a brand new Name, -- so no guarantees are given as to matches later. Perhaps this is a bad -- idea. registerRdrName :: Located RdrName -> RefactGhc () -- | Check if the proposed new name will conflict with an existing export causeNameClashInExports :: NameMap -> Name -> Name -> ModuleName -> ParsedSource -> Bool declsSybTransform :: (Typeable a) => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a rdrNameFromName :: Bool -> Name -> RefactGhc RdrName 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 (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 a => Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (GHC.Base.Maybe a) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs [HsImpExp.LIE RdrName.RdrName] instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsImpExp.IE RdrName.RdrName) 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 (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 (HsExpr.Match RdrName.RdrName (HsExpr.LHsExpr RdrName.RdrName)) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsBinds.HsBind RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.HsExpr RdrName.RdrName) instance Language.Haskell.Refact.Utils.TypeUtils.UsedByRhs (HsExpr.Stmt RdrName.RdrName (HsExpr.LHsExpr RdrName.RdrName)) instance Outputable.Outputable Language.Haskell.Refact.Utils.TypeUtils.HowToQual module Language.Haskell.Refact.Utils.Query getVarAndRHS :: Match RdrName (LHsExpr RdrName) -> RefactGhc (LPat RdrName, ParsedGRHSs) getHsBind :: (Data a) => SimpPos -> a -> Maybe (HsBind RdrName) isHsVar :: String -> ParsedExpr -> Bool module Language.Haskell.Refact.Utils.Transform addSimpleImportDecl :: String -> RefactGhc () wrapInLambda :: String -> LPat RdrName -> ParsedGRHSs -> RefactGhc (LHsExpr RdrName) wrapInPars :: LHsExpr RdrName -> RefactGhc (LHsExpr RdrName) wrapInParsWithDPs :: DeltaPos -> DeltaPos -> LHsExpr RdrName -> RefactGhc (LHsExpr RdrName) addNewLines :: (Data a) => Int -> Located a -> RefactGhc () locate :: (Data a) => a -> RefactGhc (Located a) removePars :: ParsedLExpr -> RefactGhc ParsedLExpr -- | 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 () logExactprint :: (Annotate a) => String -> Located a -> RefactGhc () logParsedSource :: String -> 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] -- | Like runRefacSession but instead takes an ordered list of RefactGhc -- computations and runs all of them threading the state through all of -- the computations runMultRefacSession :: 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) applyRefac' :: Bool -> 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 RSTarget :: TargetModule -> 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? serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary] -- | In GHC 8 an error has an attached callstack. This is not always what -- we want, so this function strips it stripCallStack :: String -> String 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 -- | fetch the final annotations fetchAnnsFinal :: RefactGhc Anns parseDeclWithAnns :: String -> RefactGhc (LHsDecl RdrName) 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 :: NameMap -> Name -> ParsedSource -> 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 all the possible qualifiers for the identifier. The identifier -- is not inscope if the result is an empty list. NOTE: This is intended -- to be used when processing a client module, so the Name -- parameter is actually from a different module. hsQualifier :: Name -> RefactGhc [ModuleName] -- | 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 those type variables that are declared in a given syntax -- phrase t. In the returned result, the first list is always be empty. hsTypeVbls :: (Data t) => t -> ([RdrName], [RdrName]) -- | Get all the names in the given syntax element hsNamessRdr :: (Data t) => t -> [Located RdrName] 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] -- | The same as hsFreeAndDeclaredPNs except that the returned -- variables are in the String format. hsFreeAndDeclaredNameStrings :: (Data 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 ParsedSource hsFreeAndDeclaredRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) -- | Return the free and declared Names in the given syntax fragment. The -- syntax fragment MUST be parameterised by RdrName, else the empty list -- will be returned. hsFreeAndDeclaredPNs :: (Data t) => t -> RefactGhc ([Name], [Name]) getDeclaredVarsRdr :: NameMap -> [LHsDecl RdrName] -> [Name] -- | Same as hsVisiblePNsRdr except that the returned identifiers -- are in String format. hsVisibleNamesRdr :: (Data t2) => Name -> 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 -- ParsedSource hsFDsFromInsideRdr :: (Data t) => NameMap -> t -> (FreeNames, DeclaredNames) -- | The same as hsFDsFromInside except that the returned -- variables are in the String format hsFDNamesFromInsideRdr :: (Data t) => t -> RefactGhc ([String], [String]) -- | The same as hsFDsFromInside except that the returned -- variables are in the String format hsFDNamesFromInsideRdrPure :: (Data t) => NameMap -> t -> ([String], [String]) -- | Given a Name n and a syntax phrase t, if n occurs in t, then -- return those variables which are declared in t and accessible to n, -- otherwise return []. hsVisibleDsRdr :: (Data t) => NameMap -> Name -> t -> RefactGhc DeclaredNames rdrName2Name :: Located RdrName -> RefactGhc Name rdrName2NamePure :: NameMap -> Located RdrName -> Name eqRdrNamePure :: NameMap -> Located RdrName -> Name -> Bool -- | Returns True if both GHC.Names are in the same -- GHC.NameSpace. sameNameSpace :: Name -> Name -> Bool -- | 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) => NameMap -> 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 :: LHsDecl RdrName -> Bool isFunBindR :: LHsBind t -> Bool -- | Returns True if a declaration is a pattern binding. isPatBindP :: LHsDecl RdrName -> 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 :: LHsDecl RdrName -> 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. Check in a way that the test can be done in a client -- module, i.e. not using the nameUnique usedWithoutQualR :: GHC.Name -- -> GHC.ParsedSource -> Bool usedWithoutQualR :: (Data t) => Name -> t -> Bool -- | Return True if the specified Name ocuurs in the given syntax phrase. findNameInRdr :: (Data t) => NameMap -> 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 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 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 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 (LHsExpr n) -- | Does the given Name appear as a Located RdrName -- anywhere in t? findLRdrName :: (Data t) => NameMap -> Name -> t -> Bool -- | 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. locToNameRdr :: (Data t) => SimpPos -> t -> RefactGhc (Maybe Name) -- | 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. locToNameRdrPure :: (Data t) => NameMap -> SimpPos -> t -> Maybe 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 -> Maybe Name -> Either [RdrName] [LIE RdrName] -> ParsedSource -> RefactGhc ParsedSource -- | 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 empty, then if the -- third argument is True, then create an explict export list to contain -- only the new identifiers, otherwise do nothing. TODO:AZ: re-arrange -- params to line up with addItemsToExport addItemsToExport :: ParsedSource -> Maybe Name -> Bool -> Either [RdrName] [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] addParamsToSigs :: [Name] -> LSig RdrName -> RefactGhc (LSig 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 StringLiteral -> 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 -> HowToQual -> t -> RefactGhc t data HowToQual Qualify :: HowToQual NoQualify :: HowToQual PreserveQualify :: HowToQual -- | 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 -- | 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 -- | Compose a pattern from a pName. -- | Deprecated: Can't use Renamed in GHC 8 pNtoPat :: name -> Pat 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 which define the specified GHC.Names. definingTyClDeclsNames :: (Data t) => NameMap -> [Name] -> t -> [LTyClDecl RdrName] -- | 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 qualified RdrName mkQualifiedRdrName :: ModuleName -> 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 -- | Register a Located RdrName in the NameMap so it -- can be looked up if needed. This will create a brand new Name, -- so no guarantees are given as to matches later. Perhaps this is a bad -- idea. registerRdrName :: Located RdrName -> RefactGhc () -- | Check if the proposed new name will conflict with an existing export causeNameClashInExports :: NameMap -> Name -> Name -> ModuleName -> ParsedSource -> Bool declsSybTransform :: (Typeable a) => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a -- | 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 -- | 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] everywhereButM :: Monad m => GenericQ Bool -> Generic m -> GenericM m -- | 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 () -- | Merges new annotations with the currecnt annotations from the -- RefactGhc state. mergeRefactAnns :: Anns -> RefactGhc () -- | Change the DeltaPos for a given KeywordId if it -- appears in the annotation for the given item. setAnnKeywordDP :: (Data a) => Located a -> KeywordId -> DeltaPos -> Transform () copyAnn :: (Data old, Data new) => Located old -> Located new -> Anns -> Anns -- | Remove any preceding comments from the given item clearPriorComments :: (Data a) => Located a -> Transform () balanceAllComments :: Data a => Located a -> Transform (Located a) exactPrintParsed :: RefactGhc () exactPrintExpr :: Annotate ast => Located ast -> RefactGhc () zeroDP :: (Data a) => Located a -> RefactGhc () setDP :: (Data a) => DeltaPos -> Located a -> RefactGhc () handleParseResult :: String -> Either (SrcSpan, String) (Anns, a) -> RefactGhc (Anns, a) removeAnns :: (Data a) => a -> RefactGhc a synthesizeAnns :: (Data a) => a -> RefactGhc a addNewKeyword :: (Data a) => (KeywordId, DeltaPos) -> Located a -> RefactGhc () addNewKeywords :: (Data a) => [(KeywordId, DeltaPos)] -> Located a -> RefactGhc () addEmptyAnn :: (Data a) => Located a -> RefactGhc () addAnnVal :: (Data a) => Located a -> RefactGhc () addAnn :: (Data a) => Located a -> Annotation -> RefactGhc () type UnlocParsedHsBind = HsBindLR RdrName RdrName type ParsedGRHSs = GRHSs RdrName (LHsExpr RdrName) type ParsedMatchGroup = MatchGroup RdrName (LHsExpr RdrName) type ParsedLMatch = LMatch RdrName (LHsExpr RdrName) type ParsedExpr = HsExpr RdrName type ParsedLStmt = LStmt RdrName (LHsExpr RdrName) type ParsedLExpr = LHsExpr RdrName type ParsedBind = HsBind RdrName addSimpleImportDecl :: String -> RefactGhc () wrapInLambda :: String -> LPat RdrName -> ParsedGRHSs -> RefactGhc (LHsExpr RdrName) wrapInPars :: LHsExpr RdrName -> RefactGhc (LHsExpr RdrName) removePars :: ParsedLExpr -> RefactGhc ParsedLExpr addNewLines :: (Data a) => Int -> Located a -> RefactGhc () wrapInParsWithDPs :: DeltaPos -> DeltaPos -> LHsExpr RdrName -> RefactGhc (LHsExpr RdrName) locate :: (Data a) => a -> RefactGhc (Located a) getVarAndRHS :: Match RdrName (LHsExpr RdrName) -> RefactGhc (LPat RdrName, ParsedGRHSs) getHsBind :: (Data a) => SimpPos -> a -> Maybe (HsBind RdrName) isHsVar :: String -> ParsedExpr -> Bool module Language.Haskell.Refact.Refactoring.AddRmParam addOneParameter :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] compAddOneParameter :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] -- | The refactoring removes a user specified formal parameter in a -- function binding,and the corresponding actual parameters in all -- calling places of this function. The condition acompanying this -- refactoring is that the parameter to be removed is not being used. The -- SimpPos should be somwewhere inside the parameter to be -- removed rmOneParameter :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compRmOneParameter :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] 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.DeleteDef deleteDef :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compDeleteDef :: FilePath -> 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.GenApplicative genApplicative :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compGenApplicative :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] 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)] -> String -> Bool -> 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)] [optEncoding] :: Options -> String [optStackBuildDeps] :: Options -> Bool -- | 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] addOneParameter :: RefactSettings -> Options -> FilePath -> String -> SimpPos -> IO [FilePath] compAddOneParameter :: FilePath -> String -> SimpPos -> RefactGhc [ApplyRefacResult] -- | The refactoring removes a user specified formal parameter in a -- function binding,and the corresponding actual parameters in all -- calling places of this function. The condition acompanying this -- refactoring is that the parameter to be removed is not being used. The -- SimpPos should be somwewhere inside the parameter to be -- removed rmOneParameter :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compRmOneParameter :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] deleteDef :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compDeleteDef :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] -- | Roundtrip the source code, to check that the infrastructure is solid roundTrip :: RefactSettings -> Options -> FilePath -> IO [FilePath] genApplicative :: RefactSettings -> Options -> FilePath -> SimpPos -> IO [FilePath] compGenApplicative :: FilePath -> SimpPos -> RefactGhc [ApplyRefacResult] 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]