Safe Haskell | None |
---|---|
Language | Haskell98 |
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
- type ParseResult = TypecheckedModule
- data VerboseLevel
- data RefactSettings = RefSet {
- rsetVerboseLevel :: !VerboseLevel
- rsetEnabledTargets :: (Bool, Bool, Bool, Bool)
- type TargetModule = ModulePath
- data RefactFlags = RefFlags {}
- data 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 ()
- parseSourceFileGhc :: FilePath -> RefactGhc ()
- getTargetGhc :: TargetModule -> RefactGhc ()
- runRefacSession :: RefactSettings -> Options -> RefactGhc [ApplyRefacResult] -> IO [FilePath]
- applyRefac :: RefactGhc a -> RefacSource -> RefactGhc (ApplyRefacResult, a)
- refactDone :: [ApplyRefacResult] -> Bool
- type ApplyRefacResult = ((FilePath, RefacResult), (Anns, ParsedSource))
- data RefacSource
- nameSybQuery :: (Typeable a, Typeable t) => (Located a -> Maybe r) -> t -> Maybe r
- fileNameFromModSummary :: ModSummary -> FilePath
- getModuleName :: ParsedSource -> Maybe (ModuleName, String)
- clientModsAndFiles :: ModulePath -> RefactGhc [TargetModule]
- serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary]
- getTypecheckedModule :: RefactGhc TypecheckedModule
- data RefacResult
- getRefactStreamModified :: RefactGhc RefacResult
- 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)
- getGhcLoc :: SrcSpan -> (Int, Int)
- 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)
- 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
- inScopeInfo :: InScopes -> [(String, NameSpace, ModuleName, Maybe ModuleName)]
- isInScopeAndUnqualified :: String -> InScopes -> Bool
- isInScopeAndUnqualifiedGhc :: String -> Maybe Name -> RefactGhc Bool
- inScopeNames :: String -> RefactGhc [Name]
- isExported :: Name -> RefactGhc Bool
- isExplicitlyExported :: Name -> RenamedSource -> Bool
- modIsExported :: ModuleName -> RenamedSource -> Bool
- equivalentNameInNewMod :: Name -> RefactGhc [Name]
- isFieldName :: Name -> Bool
- isClassName :: Name -> Bool
- isInstanceName :: Name -> Bool
- hsPNs :: Data t => t -> [PName]
- hsBinds :: HsValBinds t name => t -> [LHsBind name]
- class (Data t, Data name) => HsValBinds t name | t -> name where
- hsValBinds :: t -> HsValBinds name
- hsTyDecls :: t -> [[LTyClDecl name]]
- isDeclaredIn :: HsValBinds t Name => Name -> t -> Bool
- isDeclaredInRdr :: NameMap -> Name -> [LHsDecl RdrName] -> Bool
- data FreeNames = FN {}
- data DeclaredNames = DN {}
- hsFreeAndDeclaredPNsOld :: Data t => t -> ([Name], [Name])
- hsFreeAndDeclaredNameStrings :: (Data t, Outputable t) => t -> RefactGhc ([String], [String])
- hsFreeAndDeclaredRdr :: Data t => NameMap -> t -> (FreeNames, DeclaredNames)
- hsFreeAndDeclaredPNs :: Data t => t -> RefactGhc ([Name], [Name])
- hsFreeAndDeclaredGhc :: Data t => t -> RefactGhc (FreeNames, DeclaredNames)
- getDeclaredTypes :: LTyClDecl Name -> [Name]
- getFvs :: [LHsBind Name] -> [([Name], NameSet)]
- getFreeVars :: [LHsBind Name] -> [Name]
- getDeclaredVars :: [LHsBind Name] -> [Name]
- hsVisiblePNs :: (FindEntity e, HsValBinds t Name, Outputable e) => e -> t -> RefactGhc [Name]
- hsVisiblePNsRdr :: (FindEntity e, Data t, Outputable e) => NameMap -> e -> t -> RefactGhc [Name]
- hsVisibleNames :: (FindEntity t1, HsValBinds t2 Name, Outputable t1) => t1 -> t2 -> RefactGhc [String]
- hsVisibleNamesRdr :: (FindEntity t1, Data t2, Outputable t1) => t1 -> t2 -> RefactGhc [String]
- hsFDsFromInsideRdr :: Data t => NameMap -> t -> RefactGhc (FreeNames, DeclaredNames)
- hsFDNamesFromInsideRdr :: Data t => t -> RefactGhc ([String], [String])
- hsFDsFromInside :: Data t => t -> RefactGhc ([Name], [Name])
- hsFDNamesFromInside :: Data t => t -> RefactGhc ([String], [String])
- hsVisibleDs :: (FindEntity e, Outputable e, Data t, HsValBinds t Name) => e -> t -> RefactGhc DeclaredNames
- rdrName2Name :: Located RdrName -> RefactGhc Name
- rdrName2NamePure :: NameMap -> Located RdrName -> Name
- isVarId :: String -> Bool
- isConId :: String -> Bool
- isOperator :: String -> Bool
- isTopLevelPN :: Name -> RefactGhc Bool
- isLocalPN :: Name -> Bool
- isNonLibraryName :: Name -> Bool
- isQualifiedPN :: Name -> RefactGhc Bool
- isFunOrPatName :: Data t => Name -> t -> Bool
- isTypeSig :: LSig a -> Bool
- isFunBindP :: HsDeclP -> Bool
- isFunBindR :: LHsBind t -> Bool
- isPatBindP :: HsDeclP -> Bool
- isPatBindR :: LHsBind t -> Bool
- isSimplePatBind :: DataId t => LHsBind t -> Bool
- isSimplePatDecl :: DataId t => LHsDecl t -> Bool
- isComplexPatBind :: LHsBind name -> Bool
- isComplexPatDecl :: LHsDecl name -> Bool
- isFunOrPatBindP :: HsDeclP -> Bool
- isFunOrPatBindR :: LHsBind t -> Bool
- usedWithoutQualR :: Data t => Name -> t -> Bool
- isUsedInRhs :: Data t => Located Name -> t -> Bool
- findNameInRdr :: Data t => NameMap -> Name -> t -> Bool
- findPNT :: Data t => Located Name -> t -> Bool
- findPN :: Data t => Name -> t -> Bool
- findAllNameOccurences :: Data t => Name -> t -> [Located Name]
- findPNs :: Data t => [Name] -> t -> Bool
- findNamesRdr :: Data t => NameMap -> [Name] -> t -> Bool
- findEntity :: (FindEntity a, Data b) => a -> b -> Bool
- findEntity' :: (Data a, Data b) => a -> b -> Maybe (SimpPos, SimpPos)
- sameOccurrence :: Located t -> Located t -> Bool
- findIdForName :: Name -> RefactGhc (Maybe Id)
- getTypeForName :: Name -> RefactGhc (Maybe Type)
- defines :: Name -> LHsBind Name -> Bool
- definesP :: PName -> HsDeclP -> Bool
- definesTypeSig :: Name -> LSig Name -> Bool
- sameBind :: LHsBind Name -> LHsBind Name -> Bool
- sameBindRdr :: NameMap -> LHsDecl RdrName -> LHsDecl RdrName -> Bool
- class Data t => UsedByRhs t where
- isMainModule :: Module -> Bool
- getModule :: RefactGhc Module
- defineLoc :: Located Name -> SrcLoc
- useLoc :: Located Name -> SrcLoc
- locToExp :: (Data t, Typeable n) => SimpPos -> SimpPos -> t -> Maybe (Located (HsExpr n))
- locToName :: Data t => SimpPos -> t -> Maybe (Located Name)
- locToRdrName :: Data t => SimpPos -> t -> Maybe (Located RdrName)
- getName :: Data t => String -> t -> Maybe Name
- addDecl :: (Data t, Typeable t) => t -> Maybe Name -> ([LHsDecl RdrName], Maybe Anns) -> RefactGhc t
- addItemsToImport :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource
- addHiding :: ModuleName -> ParsedSource -> [RdrName] -> RefactGhc ParsedSource
- addParamsToDecls :: [LHsDecl RdrName] -> Name -> [RdrName] -> RefactGhc [LHsDecl RdrName]
- addActualParamsToRhs :: Data t => Name -> [RdrName] -> t -> RefactGhc t
- addImportDecl :: ParsedSource -> ModuleName -> Maybe FastString -> Bool -> Bool -> Bool -> Maybe String -> Bool -> [RdrName] -> RefactGhc ParsedSource
- duplicateDecl :: [LHsDecl RdrName] -> Name -> Name -> RefactGhc [LHsDecl RdrName]
- rmDecl :: Data t => Name -> Bool -> t -> RefactGhc (t, LHsDecl RdrName, Maybe (LSig RdrName))
- rmTypeSig :: Data t => Name -> t -> RefactGhc (t, Maybe (LSig RdrName))
- rmTypeSigs :: Data t => [Name] -> t -> RefactGhc (t, [LSig RdrName])
- class (Data t, Data t1) => Update t t1 where
- rmQualifier :: Data t => [Name] -> t -> RefactGhc t
- qualifyToplevelName :: Name -> RefactGhc ()
- renamePN' :: Data t => Name -> Name -> Bool -> t -> RefactGhc t
- autoRenameLocalVar :: Data t => Name -> t -> RefactGhc t
- showEntities :: (t -> String) -> [t] -> String
- showPNwithLoc :: Located Name -> String
- defaultPN :: PName
- defaultName :: Name
- defaultExp :: HsExpP
- ghcToPN :: RdrName -> PName
- lghcToPN :: Located RdrName -> PName
- expToName :: LHsExpr Name -> Name
- expToNameRdr :: NameMap -> LHsExpr RdrName -> Maybe Name
- patToNameRdr :: NameMap -> LPat RdrName -> Maybe Name
- nameToString :: Name -> String
- patToPNT :: LPat Name -> Maybe Name
- pNtoPat :: name -> Pat name
- definedPNs :: LHsBind Name -> [Name]
- definedPNsRdr :: LHsDecl RdrName -> [Located RdrName]
- definedNamesRdr :: NameMap -> LHsDecl RdrName -> [Name]
- definingDeclsRdrNames :: NameMap -> [Name] -> [LHsDecl RdrName] -> Bool -> Bool -> [LHsDecl RdrName]
- definingDeclsRdrNames' :: Data t => NameMap -> [Name] -> t -> [LHsDecl RdrName]
- definingSigsRdrNames :: Data t => NameMap -> [Name] -> t -> [LSig RdrName]
- definingDeclsNames :: [Name] -> [LHsBind Name] -> Bool -> Bool -> [LHsBind Name]
- definingDeclsNames' :: Data t => [Name] -> t -> [LHsBind Name]
- definingSigsNames :: Data t => [Name] -> t -> [LSig Name]
- definingTyClDeclsNames :: Data t => [Name] -> t -> [LTyClDecl Name]
- allNames :: Data t => t -> [Located Name]
- divideDecls :: Data t => [t] -> Located Name -> RefactGhc ([t], [t], [t])
- mkRdrName :: String -> RdrName
- mkNewGhcName :: Maybe Module -> String -> RefactGhc Name
- mkNewName :: String -> [String] -> Int -> String
- mkNewToplevelName :: Module -> String -> SrcSpan -> RefactGhc Name
- causeNameClashInExports :: Name -> Name -> ModuleName -> RenamedSource -> Bool
- declsSybTransform :: Typeable a => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a
- getParsedForRenamedLPat :: ParsedSource -> LPat Name -> LPat RdrName
- getParsedForRenamedName :: ParsedSource -> Located Name -> Located RdrName
- getParsedForRenamedLocated :: Typeable b => Located a -> RefactGhc (Located b)
- stripLeadingSpaces :: [String] -> [String]
- everywhereMStaged' :: Monad m => Stage -> GenericM m -> GenericM m
- everywhereStaged :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a
- everywhereStaged' :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a
- onelayerStaged :: Stage -> r -> GenericQ r -> GenericQ [r]
- listifyStaged :: (Data a, Typeable a1) => Stage -> (a1 -> Bool) -> a -> [a1]
- zeverywhereStaged :: Typeable a => Stage -> GenericT -> Zipper a -> Zipper a
- zopenStaged :: Typeable a => Stage -> GenericQ Bool -> Zipper a -> [Zipper a]
- zsomewhereStaged :: MonadPlus m => Stage -> GenericM m -> Zipper a -> m (Zipper a)
- transZ :: Stage -> GenericQ Bool -> (Stage -> Zipper a -> Zipper a) -> Zipper a -> Zipper a
- transZM :: Monad m => Stage -> GenericQ Bool -> (Stage -> Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a)
- zopenStaged' :: Typeable a => Stage -> GenericQ (Maybe b) -> Zipper a -> [(Zipper a, b)]
- ztransformStagedM :: (Typeable a, Monad m) => Stage -> GenericQ (Maybe (Stage -> Zipper a -> m (Zipper a))) -> Zipper a -> m (Zipper a)
- upUntil :: GenericQ Bool -> Zipper a -> Maybe (Zipper a)
- findAbove :: Data a => (a -> Bool) -> Zipper a -> Maybe a
- 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
- replace :: AnnKey -> AnnKey -> Anns -> Maybe Anns
- setRefactAnns :: Anns -> RefactGhc ()
from Monad
type ParseResult = TypecheckedModule Source
Result of parsing a Haskell source file. It is simply the TypeCheckedModule produced by GHC.
data RefactSettings Source
RefSet | |
|
type TargetModule = ModulePath Source
data RefactFlags Source
data StateStorage Source
Provide some temporary storage while the refactoring is taking place
The GHC Monad
runRefactGhc :: RefactGhc a -> RefactState -> Options -> IO (a, RefactState) Source
logDataWithAnns :: Data a => String -> a -> RefactGhc () Source
from Utils
Managing the GHC / project environment
parseSourceFileGhc :: FilePath -> RefactGhc () Source
Parse a single source file into a GHC session
getTargetGhc :: TargetModule -> RefactGhc () Source
The bits that do the work
:: RefactSettings | |
-> Options | ghc-mod options |
-> RefactGhc [ApplyRefacResult] | The computation doing the
refactoring. Normally created
via |
-> IO [FilePath] |
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
:: RefactGhc a | The refactoring |
-> RefacSource | where to get the module and toks |
-> RefactGhc (ApplyRefacResult, a) |
Apply a refactoring (or part of a refactoring) to a single module
refactDone :: [ApplyRefacResult] -> Bool Source
Returns True if any of the results has its modified flag set
type ApplyRefacResult = ((FilePath, RefacResult), (Anns, ParsedSource)) Source
The result of a refactoring is the file, a flag as to whether it was modified, and the updated AST
getModuleName :: ParsedSource -> Maybe (ModuleName, String) Source
Extract the module name from the parsed source, if there is one
clientModsAndFiles :: ModulePath -> RefactGhc [TargetModule] Source
Return the client modules and file names. The client modules of module, say m, are those modules which directly or indirectly import module m.
serverModsAndFiles :: GhcMonad m => ModuleName -> m [ModSummary] Source
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?
from MonadFunctions
Conveniences for state access
data RefacResult Source
setRefactStreamModified :: RefacResult -> RefactGhc () Source
For testing
putRefactRenamed :: RenamedSource -> RefactGhc () Source
putRefactParsed :: ParsedSource -> Anns -> RefactGhc () Source
putParsedModule :: [Comment] -> TypecheckedModule -> RefactGhc () Source
clearParsedModule :: RefactGhc () Source
New ghc-exactprint interfacing
liftT :: HasTransform m => forall a. Transform a -> m a
State flags for managing generic traversals
setRefactDone :: RefactGhc () Source
clearRefactDone :: RefactGhc () Source
setStateStorage :: StateStorage -> RefactGhc () Source
from LocUtils
getGhcLoc :: SrcSpan -> (Int, Int) Source
gets the (row,col) of the start of the GHC.SrcSpan
, or (-1,-1)
if there is an GHC.UnhelpfulSpan
getGhcLocEnd :: SrcSpan -> (Int, Int) Source
gets the (row,col) of the end of the GHC.SrcSpan
, or (-1,-1)
if there is an GHC.UnhelpfulSpan
getLocatedStart :: GenLocated SrcSpan t -> (Int, Int) Source
getLocatedEnd :: GenLocated SrcSpan t -> (Int, Int) Source
getStartEndLoc :: Data t => t -> (SimpPos, SimpPos) Source
startEndLocGhc :: Located b -> (SimpPos, SimpPos) Source
emptyList :: [t] -> Bool Source
Get around lack of instance Eq when simply testing for empty list
TODO: get rid of this in favour of null
built in fn
nonEmptyList :: [t] -> Bool Source
from TypeSyn
from TypeUtils
Program Analysis
Imports and exports
:: InScopes | The inscope relation . |
-> [(String, NameSpace, ModuleName, Maybe ModuleName)] | The result |
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.
isInScopeAndUnqualified Source
Return True if the identifier is inscope and can be used without a qualifier.
isInScopeAndUnqualifiedGhc Source
:: String | The identifier name. |
-> Maybe Name | Existing name, to be excluded from test, if known |
-> RefactGhc Bool | The result. |
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.
Return all Name
s that correspond to the given string, in the current
module.
isExported :: Name -> RefactGhc Bool Source
Return True if an identifier is exported by the module currently being refactored.
:: Name | The identifier |
-> RenamedSource | The AST of the module |
-> Bool | The result |
Return True if an identifier is explicitly exported by the module.
:: ModuleName | The module name |
-> RenamedSource | The AST of the module |
-> Bool | The result |
Return True if the current module is exported either by default or by specifying the module name in the export.
equivalentNameInNewMod :: Name -> RefactGhc [Name] Source
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.
Variable analysis
isFieldName :: Name -> Bool Source
True if the name is a field name
isClassName :: Name -> Bool Source
True if the name is a field name
isInstanceName :: Name -> Bool Source
True if the name is a class instance
hsPNs :: Data t => t -> [PName] Source
Collect the identifiers (in PName format) in a given syntax phrase.
hsBinds :: HsValBinds t name => t -> [LHsBind name] Source
class (Data t, Data name) => HsValBinds t name | t -> name where Source
hsValBinds :: t -> HsValBinds name Source
Return the binds that are directly enclosed in the given syntax phrase. hsValBinds :: t -> [GHC.LHsBind GHC.Name]
hsTyDecls :: t -> [[LTyClDecl name]] Source
Return the type class definitions that are directly enclosed in the given syntax phrase. Note: only makes sense for GHC.RenamedSource
isDeclaredIn :: HsValBinds t Name => Name -> t -> Bool Source
For free variables
data DeclaredNames Source
For declared variables
hsFreeAndDeclaredPNsOld :: Data t => t -> ([Name], [Name]) Source
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
hsFreeAndDeclaredNameStrings :: (Data t, Outputable t) => t -> RefactGhc ([String], [String]) Source
The same as hsFreeAndDeclaredPNs
except that the returned
variables are in the String format.
hsFreeAndDeclaredRdr :: Data t => NameMap -> t -> (FreeNames, DeclaredNames) Source
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
hsFreeAndDeclaredGhc :: Data t => t -> RefactGhc (FreeNames, DeclaredNames) Source
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)
getDeclaredTypes :: LTyClDecl Name -> [Name] Source
Get the names of all types declared in the given declaration
getFreeVars :: [LHsBind Name] -> [Name] Source
getDeclaredVars :: [LHsBind Name] -> [Name] Source
hsVisiblePNs :: (FindEntity e, HsValBinds t Name, Outputable e) => e -> t -> RefactGhc [Name] Source
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] Source
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 [].
hsVisibleNames :: (FindEntity t1, HsValBinds t2 Name, Outputable t1) => t1 -> t2 -> RefactGhc [String] Source
Same as hsVisiblePNs
except that the returned identifiers are
in String format.
hsVisibleNamesRdr :: (FindEntity t1, Data t2, Outputable t1) => t1 -> t2 -> RefactGhc [String] Source
Same as hsVisiblePNs
except that the returned identifiers are
in String format.
hsFDsFromInsideRdr :: Data t => NameMap -> t -> RefactGhc (FreeNames, DeclaredNames) Source
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
hsFDNamesFromInsideRdr :: Data t => t -> RefactGhc ([String], [String]) Source
The same as hsFDsFromInside
except that the returned variables
are in the String format
hsFDsFromInside :: Data t => t -> RefactGhc ([Name], [Name]) Source
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
hsFDNamesFromInside :: Data t => t -> RefactGhc ([String], [String]) Source
The same as hsFDsFromInside
except that the returned variables
are in the String format
hsVisibleDs :: (FindEntity e, Outputable e, Data t, HsValBinds t Name) => e -> t -> RefactGhc DeclaredNames Source
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 [].
Property checking
isOperator :: String -> Bool Source
Return True if a string is a lexically valid operator name.
isTopLevelPN :: Name -> RefactGhc Bool Source
Return True if a PName is a toplevel PName.
isNonLibraryName :: Name -> Bool Source
Return True if the name has a GHC.SrcSpan
, i.e. is declared in
source we care about
isQualifiedPN :: Name -> RefactGhc Bool Source
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
isFunOrPatName :: Data t => Name -> t -> Bool Source
Return True if a PName is a function/pattern name defined in t.
isFunBindP :: HsDeclP -> Bool Source
Return True if a declaration is a function definition.
isFunBindR :: LHsBind t -> Bool Source
isPatBindP :: HsDeclP -> Bool Source
Returns True if a declaration is a pattern binding.
isPatBindR :: LHsBind t -> Bool Source
isSimplePatBind :: DataId t => LHsBind t -> Bool Source
Return True if a declaration is a pattern binding which only defines a variable value.
isSimplePatDecl :: DataId t => LHsDecl t -> Bool Source
Return True if a declaration is a pattern binding which only defines a variable value.
isComplexPatBind :: LHsBind name -> Bool Source
Return True if a LHsBin is a pattern binding but not a simple one.
isComplexPatDecl :: LHsDecl name -> Bool Source
Return True if a declaration is a pattern binding but not a simple one.
isFunOrPatBindP :: HsDeclP -> Bool Source
Return True if a declaration is a function/pattern definition.
isFunOrPatBindR :: LHsBind t -> Bool Source
Return True if a declaration is a function/pattern definition.
usedWithoutQualR :: Data t => Name -> t -> Bool Source
Return True if the identifier is unqualifiedly used in the given syntax phrase. usedWithoutQualR :: GHC.Name -> GHC.ParsedSource -> Bool
isUsedInRhs :: Data t => Located Name -> t -> Bool Source
Return True if the identifier is used in the RHS if a function/pattern binding.
findPNT :: Data t => Located Name -> t -> Bool Source
Return True if the identifier occurs in the given syntax phrase.
findPN :: Data t => Name -> t -> Bool Source
Return True if the identifier occurs in the given syntax phrase.
findAllNameOccurences :: Data t => Name -> t -> [Located Name] Source
Find all occurrences with location of the given name
findPNs :: Data t => [Name] -> t -> Bool Source
Return True if any of the specified PNames ocuur in the given syntax phrase.
findNamesRdr :: Data t => NameMap -> [Name] -> t -> Bool Source
Return True if any of the specified PNames ocuur in the given syntax phrase.
findEntity :: (FindEntity a, Data b) => a -> b -> Bool Source
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' :: (Data a, Data b) => a -> b -> Maybe (SimpPos, SimpPos) Source
Returns True is a syntax phrase, say a, is part of another syntax phrase, say b. Expects to be at least Parser output
sameOccurrence :: Located t -> Located t -> Bool Source
Return True if syntax phrases t1 and t2 refer to the same one.
defines :: Name -> LHsBind Name -> Bool Source
Return True if the function/pattern binding defines the specified identifier.
definesTypeSig :: Name -> LSig Name -> Bool Source
Return True if the declaration defines the type signature of the specified identifier.
class Data t => UsedByRhs t where Source
usedByRhs :: t -> [Name] -> Bool Source
Return True if any of the GHC.Name's appear in the given syntax element
usedByRhsRdr :: NameMap -> t -> [Name] -> Bool Source
Modules and files
isMainModule :: Module -> Bool Source
Locations
defineLoc :: Located Name -> SrcLoc Source
Return the identifier's defining location. defineLoc::PNT->SrcLoc
:: (Data t, Typeable n) | |
=> SimpPos | The start position. |
-> SimpPos | The end position. |
-> t | The syntax phrase. |
-> Maybe (Located (HsExpr n)) | The result. |
Given the syntax phrase, find the largest-leftmost expression contained in the region specified by the start and end position, if found.
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.
:: Data t | |
=> SimpPos | The row and column number |
-> t | The syntax phrase |
-> Maybe (Located RdrName) | The result |
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.
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.
Program transformation
Adding
:: (Data t, Typeable t) | |
=> t | The AST to be updated |
-> Maybe Name | If this is Just, then the declaration will be added right after this identifier's definition. |
-> ([LHsDecl RdrName], Maybe Anns) | The declaration with optional signatures to be added, together with optional Annotations. |
-> RefactGhc t |
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.
:: ModuleName | The imported module name |
-> ParsedSource | The current module |
-> [RdrName] | The items to be added ->Maybe GHC.Name -- ^ The condition identifier. |
-> RefactGhc ParsedSource | The result |
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.
:: ModuleName | The imported module name |
-> ParsedSource | The current module |
-> [RdrName] | The items to be added |
-> RefactGhc ParsedSource | The result |
add items to the hiding list of an import declaration which imports the specified module.
:: ParsedSource | |
-> ModuleName | |
-> Maybe FastString | qualifier |
-> Bool | |
-> Bool | |
-> Bool | |
-> Maybe String | alias |
-> Bool | |
-> [RdrName] | |
-> 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 emport, then if the third argument is True, then create an explict export list to contain only the new identifiers, otherwise do nothing.
:: [LHsDecl RdrName] | decls to be updated, containing the original decl (and sig) |
-> Name | The identifier whose definition is to be duplicated |
-> Name | The new name (possibly qualified) |
-> RefactGhc [LHsDecl RdrName] | The result |
Duplicate a function/pattern binding declaration under a new name right after the original one.
Removing
:: Data t | |
=> Name | The identifier whose definition is to be removed. |
-> Bool | True means including the type signature. |
-> t | The AST fragment containting the declarations, originating from the ParsedSource |
-> RefactGhc (t, LHsDecl RdrName, Maybe (LSig RdrName)) | The result and the removed declaration and the possibly removed siganture |
Remove the declaration (and the type signature is the second parameter is True) that defines the given identifier from the declaration list.
:: Data t | |
=> Name | The identifier whose type signature is to be removed. |
-> t | The declarations |
-> RefactGhc (t, Maybe (LSig RdrName)) | The result and removed signature, if there was one |
Remove the type signature that defines the given identifier's type from the declaration list.
:: Data t | |
=> [Name] | The identifiers whose type signatures are to be removed. |
-> t | The declarations |
-> RefactGhc (t, [LSig RdrName]) | The result and removed signatures, if there were any |
Remove multiple type signatures
Updating
class (Data t, Data t1) => Update t t1 where Source
:: t | The syntax phrase to be updated. |
-> t | The new syntax phrase. |
-> t1 | The contex where the old syntax phrase occurs. |
-> RefactGhc t1 | The result. |
Update the occurrence of one syntax phrase in a given scope by another syntax phrase of the same type
(Data t, OutputableBndr n, DataId n) => Update (LHsType n) t Source | |
(Data t, OutputableBndr n, DataId n) => Update (LPat n) t Source | |
(Data t, OutputableBndr n, DataId n) => Update (Located (HsExpr n)) t Source | |
(Data t, OutputableBndr n1, OutputableBndr n2, DataId n1, DataId n2) => Update (LHsBindLR n1 n2) t Source |
Remove the qualifier from the given identifiers in the given syntax phrase.
qualifyToplevelName :: Name -> RefactGhc () Source
Replace all occurences of a top level GHC.Name with a qualified version.
:: Data t | |
=> Name | The identifier to be renamed. |
-> Name | The new name, including possible qualifier |
-> Bool | True means use the qualified form for the new name. |
-> t | The syntax phrase |
-> RefactGhc t |
Rename each occurrences of the identifier in the given syntax phrase with the new name.
Check whether the specified identifier is declared in the given syntax phrase t, if so, rename the identifier by creating a new name automatically.
Miscellous
Parsing, writing and showing
showEntities :: (t -> String) -> [t] -> String Source
Show a list of entities, the parameter f is a function that specifies how to format an entity.
showPNwithLoc :: Located Name -> String Source
Show a PName in a format like: pn
(at row:r, col: c).
Locations
Default values
Default expression.
Identifiers, expressions, patterns and declarations
expToName :: LHsExpr Name -> Name Source
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 Source
If an expression consists of only one identifier then return this identifier in the GHC.Name format, otherwise return the default Name
patToNameRdr :: NameMap -> LPat RdrName -> Maybe Name Source
If a pattern consists of only one identifier then return this identifier, otherwise return Nothing
nameToString :: Name -> String Source
patToPNT :: LPat Name -> Maybe Name Source
If a pattern consists of only one identifier then return this identifier, otherwise return Nothing
definedPNs :: LHsBind Name -> [Name] Source
Return the list of identifiers (in PName format) defined by a function/pattern binding.
:: NameMap | |
-> [Name] | The specified identifiers. |
-> [LHsDecl RdrName] | A collection of declarations. |
-> Bool | True means to include the type signature. |
-> Bool | True means to look at the local declarations as well. |
-> [LHsDecl RdrName] | The result. |
Find those declarations(function/pattern binding) which define the specified GHC.Names. incTypeSig indicates whether the corresponding type signature will be included.
:: Data t | |
=> NameMap | |
-> [Name] | The specified identifiers. |
-> t | A collection of declarations. |
-> [LHsDecl RdrName] | The result. |
Find those declarations(function/pattern binding) which define the specified GHC.Names. incTypeSig indicates whether the corresponding type signature will be included.
:: Data t | |
=> NameMap | |
-> [Name] | The specified identifiers. |
-> t | A collection of declarations. |
-> [LSig RdrName] | The result. |
Find those type signatures for the specified GHC.Names.
:: [Name] | The specified identifiers. |
-> [LHsBind Name] | A collection of declarations. |
-> Bool | True means to include the type signature. |
-> Bool | True means to look at the local declarations as well. |
-> [LHsBind Name] | The result. |
Find those declarations(function/pattern binding) which define the specified GHC.Names. incTypeSig indicates whether the corresponding type signature will be included.
:: Data t | |
=> [Name] | The specified identifiers. |
-> t | A collection of declarations. |
-> [LHsBind Name] | The result. |
Find those declarations(function/pattern binding) which define the specified GHC.Names. incTypeSig indicates whether the corresponding type signature will be included.
:: Data t | |
=> [Name] | The specified identifiers. |
-> t | A collection of declarations. |
-> [LSig Name] | The result. |
Find those type signatures for the specified GHC.Names.
:: Data t | |
=> [Name] | The specified identifiers. |
-> t | A collection of declarations. |
-> [LTyClDecl Name] | The result. |
Find those declarations which define the specified GHC.Names.
Find all Located Names in the given Syntax phrase.
Others
divideDecls :: Data t => [t] -> Located Name -> RefactGhc ([t], [t], [t]) Source
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
.
mkNewGhcName :: Maybe Module -> String -> RefactGhc Name Source
Make a new GHC.Name, using the Unique Int sequence stored in the RefactState.
:: String | The old name |
-> [String] | The set of names which the new name cannot take |
-> Int | The posfix value |
-> String | The result |
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.
causeNameClashInExports Source
:: Name | The original name |
-> Name | The new name |
-> ModuleName | The identity of the module |
-> RenamedSource | The AST of the module |
-> Bool | The result |
Check if the proposed new name will conflict with an existing export
declsSybTransform :: Typeable a => (forall b. HasDecls b => b -> RefactGhc b) -> a -> RefactGhc a Source
Typed AST traversals (added by CMB)
Miscellous
Debug stuff
getParsedForRenamedLPat :: ParsedSource -> LPat Name -> LPat RdrName Source
Given a RenamedSource LPAT, return the equivalent ParsedSource part. NOTE: returns pristine ParsedSource, since HaRe does not change it
getParsedForRenamedName :: ParsedSource -> Located Name -> Located RdrName Source
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) Source
Given a RenamedSource Located name, return the equivalent ParsedSource part. NOTE: returns pristine ParsedSource, since HaRe does not change it
stripLeadingSpaces :: [String] -> [String] Source
Take a list of strings and return a list with the longest prefix of spaces removed
from GhcUtils
SYB versions
everywhereMStaged' :: Monad m => Stage -> GenericM m -> GenericM m Source
Monadic variation on everywhere'
everywhereStaged :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a Source
Bottom-up transformation
everywhereStaged' :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> a Source
Top-down version of everywhereStaged
onelayerStaged :: Stage -> r -> GenericQ r -> GenericQ [r] Source
Perform a query on the immediate subterms only, avoiding holes
listifyStaged :: (Data a, Typeable a1) => Stage -> (a1 -> Bool) -> a -> [a1] Source
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.
Scrap Your Zipper versions
zeverywhereStaged :: Typeable a => Stage -> GenericT -> Zipper a -> Zipper a Source
Apply a generic transformation everywhere in a bottom-up manner.
zopenStaged :: Typeable a => Stage -> GenericQ Bool -> Zipper a -> [Zipper a] Source
Open a zipper to the point where the Geneneric query passes. returns the original zipper if the query does not pass (check this)
zsomewhereStaged :: MonadPlus m => Stage -> GenericM m -> Zipper a -> m (Zipper a) Source
Apply a generic monadic transformation once at the topmost leftmost successful location, avoiding holes in the GHC structures
transZ :: Stage -> GenericQ Bool -> (Stage -> Zipper a -> Zipper a) -> Zipper a -> Zipper a Source
Transform 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) Source
Monadic transform of a zipper opened with a given generic query
zopenStaged' :: Typeable a => Stage -> GenericQ (Maybe b) -> Zipper a -> [(Zipper a, b)] Source
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
ztransformStagedM :: (Typeable a, Monad m) => Stage -> GenericQ (Maybe (Stage -> Zipper a -> m (Zipper a))) -> Zipper a -> m (Zipper a) Source
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.
SYZ utilities
upUntil :: GenericQ Bool -> Zipper a -> Maybe (Zipper a) Source
Climb the tree until a predicate holds
findAbove :: Data a => (a -> Bool) -> Zipper a -> Maybe a Source
Up the zipper until a predicate holds, and then return the zipper hole
from GhcVersionSpecific
showGhc :: Outputable a => a -> String
showGhcQual :: Outputable a => a -> String Source
prettyprint :: Outputable a => a -> String Source
prettyprint2 :: Outputable a => a -> String Source
setGhcContext :: GhcMonad m => ModSummary -> m () Source
from TokenUtils
from ExactPrint'
replace :: AnnKey -> AnnKey -> Anns -> Maybe Anns Source
Replaces an old expression with a new expression
setRefactAnns :: Anns -> RefactGhc () Source
Internal low level interface to access the current annotations from the RefactGhc state.