ContentsIndex
RefacTypeUtils
Contents
Program Analysis
Imports and exports
Variable analysis
Property checking
Modules and files
Locations
Program transformation
Adding
Rmoving
Updating
Miscellous
Parsing, writing and showing
Locations
Default values
Identifiers, expressions, patterns and declarations
Others
Typed AST traversals (added by CMB)
Miscellous
Description

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.

As the API is based on Programatica's abstract syntax for Haskell, we have re-exported those related module from Programatica, so that you can browse the datatypes for the abstract syntax. Alternatively, you can go to Programatica's webpage at: http://www.cse.ogi.edu/~hallgren/Programatica/. For Strafunski, you can find it at: http://www.cs.vu.nl/Strafunski/.

This type decorated API is still in development. Any suggestions and comments are very much welcome.

Synopsis
inScopeInfo :: InScopes -> [(String, NameSpace, ModuleName, Maybe ModuleName)]
isInScopeAndUnqualified :: String -> InScopes -> Bool
hsQualifier :: PNT -> InScopes -> [ModuleName]
rmPrelude :: HsModuleP -> HsModuleP
exportInfo :: Exports -> [(String, NameSpace, ModuleName)]
isExported :: PNT -> Exports -> Bool
isExplicitlyExported :: PName -> HsModuleP -> Bool
modIsExported :: HsModuleP -> Bool
hsPNs :: Term t => t -> [PName]
hsPNTs :: Term t => t -> [PNT]
hsDataConstrs :: Term t => ModuleName -> t -> ([PName], [PName])
hsTypeConstrsAndClasses :: Term t => ModuleName -> t -> ([PName], [PName])
hsTypeVbls :: Term t => t -> ([PName], [PName])
hsClassMembers :: Term t => String -> ModuleName -> t -> ([PName], [PName])
class Term t => HsDecls t where
hsDecls :: t -> [HsDeclP]
replaceDecls :: t -> HsDeclsP -> t
isDeclaredIn :: PName -> t -> Bool
hsFreeAndDeclaredPNs :: (Term t, MonadPlus m) => t -> m ([PName], [PName])
hsFreeAndDeclaredNames :: (Term t, MonadPlus m) => t -> m ([String], [String])
hsVisiblePNs :: (Term t1, Term t2, FindEntity t1, MonadPlus m) => t1 -> t2 -> m [PName]
hsVisibleNames :: (Term t1, Term t2, FindEntity t1, MonadPlus m) => t1 -> t2 -> m [String]
hsFDsFromInside :: (Term t, MonadPlus m) => t -> m ([PName], [PName])
hsFDNamesFromInside :: (Term t, MonadPlus m) => t -> m ([String], [String])
isVarId :: String -> Bool
isConId :: String -> Bool
isOperator :: String -> Bool
isTopLevelPN :: PName -> Bool
isLocalPN :: PName -> Bool
isTopLevelPNT :: PNT -> Bool
isQualifiedPN :: PName -> Bool
isFunPNT :: Term t => PNT -> t -> Bool
isFunName :: Term t => PName -> t -> Bool
isPatName :: Term t => PName -> t -> Bool
isFunOrPatName :: Term t => PName -> t -> Bool
isTypeCon :: PNT -> Bool
isTypeSig :: HsDeclP -> Bool
isFunBind :: HsDeclP -> Bool
isPatBind :: HsDeclP -> Bool
isSimplePatBind :: HsDeclP -> Bool
isComplexPatBind :: HsDeclP -> Bool
isFunOrPatBind :: HsDeclP -> Bool
isClassDecl :: HsDeclP -> Bool
isInstDecl :: HsDeclP -> Bool
isDirectRecursiveDef :: HsDeclP -> Bool
usedWithoutQual :: Term t => String -> t -> Bool
canBeQualified :: Term t => PNT -> t -> Bool
hasFreeVars :: Term t => t -> Bool
isUsedInRhs :: Term t => PNT -> t -> Bool
findPNT :: Term t => PNT -> t -> Bool
findPN :: Term t => PName -> t -> Bool
findPNs :: Term t => [PName] -> t -> Bool
findEntity :: (FindEntity a, Term b) => a -> b -> Bool
sameOccurrence :: (Term t, Eq t) => t -> t -> Bool
defines :: PName -> HsDeclP -> Bool
definesTypeSig :: PName -> HsDeclP -> Bool
isTypeSigOf :: PNT -> HsDeclP -> Bool
class Term t => HasModName t where
hasModName :: t -> Maybe ModuleName
class HasNameSpace t where
hasNameSpace :: t -> NameSpace
clientModsAndFiles :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m [(ModuleName, String)]
serverModsAndFiles :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m [(ModuleName, String)]
isAnExistingMod :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m Bool
fileNameToModName :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => String -> PFE0MT n i ds ext m ModuleName
strToModName :: String -> ModuleName
modNameToStr :: ModuleName -> String
defineLoc :: PNT -> SrcLoc
useLoc :: PNT -> SrcLoc
locToPNT :: Term t => String -> (Int, Int) -> t -> PNT
locToPN :: Term t => String -> (Int, Int) -> t -> PName
locToExp :: Term t => SimpPos -> SimpPos -> [PosToken] -> t -> HsExpP
addDecl :: (MonadState (([PosToken], Bool), (Int, Int)) m, StartEndLoc t, HsDecls t, Printable t) => t -> Maybe PName -> ([HsDeclP], Maybe [PosToken]) -> Bool -> m t
addItemsToImport :: (Term t, MonadState (([PosToken], Bool), t1) m) => ModuleName -> Maybe PName -> Either [String] [EntSpecP] -> t -> m t
addHiding :: MonadState (([PosToken], Bool), t1) m => ModuleName -> HsModuleP -> [PName] -> m HsModuleP
rmItemsFromImport :: MonadState (([PosToken], Bool), t1) m => HsModuleP -> [PName] -> m HsModuleP
addItemsToExport :: MonadState (([PosToken], Bool), t1) m => HsModuleP -> Maybe PName -> Bool -> Either [String] [HsExportEntP] -> m HsModuleP
addParamsToDecls :: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m) => [HsDeclP] -> PName -> [PName] -> Bool -> m [HsDeclP]
addGuardsToRhs :: MonadState (([PosToken], Bool), (Int, Int)) m => RhsP -> HsExpP -> m RhsP
duplicateDecl :: MonadState (([PosToken], Bool), t1) m => [HsDeclP] -> PName -> String -> m [HsDeclP]
commentOutTypeSig :: MonadState (([PosToken], Bool), t1) m => PName -> [HsDeclP] -> m [HsDeclP]
rmParams :: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m) => PNT -> Int -> HsExpP -> m HsExpP
rmItemsFromExport :: MonadState (([PosToken], Bool), t1) m => HsModuleP -> Either ([ModuleName], [PName]) [HsExportEntP] -> m HsModuleP
rmSubEntsFromExport :: MonadState (([PosToken], Bool), (Int, Int)) m => PName -> HsModuleP -> m HsModuleP
class (Term t, Term t1) => Delete t t1 where
delete :: (MonadPlus m, MonadState (([PosToken], Bool), t2) m) => t -> t1 -> m t1
class (Term t, Term t1) => Update t t1 where
update :: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m) => t -> t -> t1 -> m t1
qualifyPName :: ModuleName -> PName -> PName
rmQualifier :: (MonadState (([PosToken], Bool), t1) m, Term t) => [PName] -> t -> m t
renamePN :: (MonadState (([PosToken], Bool), t1) m, Term t) => PName -> Maybe ModuleName -> String -> Bool -> t -> m t
replaceNameInPN :: Maybe ModuleName -> PName -> String -> PName
autoRenameLocalVar :: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m, Term t) => Bool -> PName -> t -> m t
showEntities :: (Eq t, Term t) => (t -> String) -> [t] -> String
showPNwithLoc :: PName -> String
toRelativeLocs :: Term t => t -> t
rmLocs :: Term t => t -> t
defaultPN :: PName
defaultPNT :: PNT
defaultModName :: ModuleName
defaultExp :: HsExpP
defaultPat :: HsPatP
pNTtoPN :: PNT -> PName
pNTtoName :: PNT -> String
pNtoName :: PName -> String
nameToPNT :: String -> PNT
nameToPN :: String -> PName
pNtoPNT :: PName -> IdTy PId -> PNT
expToPNT :: HsExpP -> PNT
expToPN :: HsExpP -> PName
nameToExp :: String -> HsExpP
pNtoExp :: PName -> HsExpP
patToPNT :: HsPatP -> PNT
patToPN :: HsPatP -> PName
nameToPat :: String -> HsPatP
pNtoPat :: PName -> HsPatP
definingDecls :: [PName] -> [HsDeclP] -> Bool -> Bool -> [HsDeclP]
definedPNs :: HsDeclP -> [PName]
simplifyDecl :: Monad m => HsDeclP -> m HsDeclP
mkNewName :: String -> [String] -> Int -> String
removeFromInts :: (MonadPlus m, Term t) => t -> m t
getDataName :: Term t => t -> String
checkTypes :: Term t => String -> t -> Bool
getPNs :: HsDeclP -> [PName]
getPN :: Term t => t -> PName
getPNPats :: HsExpP -> [PName]
Program Analysis
Imports and exports
inScopeInfo
:: InScopesThe 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
:: StringThe identifier name.
-> InScopesThe inscope relation
-> BoolThe result.
Return True if the identifier is inscope and can be used without a qualifier.
hsQualifier
:: PNTThe identifier.
-> InScopesThe in-scope relation.
-> [ModuleName]The result.
Return all the possible qualifiers for the identifier. The identifier is not inscope if the result is an empty list.
rmPrelude :: HsModuleP -> HsModuleP
exportInfo
:: ExportsThe export relation.
-> [(String, NameSpace, ModuleName)]The result
Process the export relation returned from the parsing and module analysis pass, and return a list of trhee-element tuples. Each tuple contains an identifier name, the identifier's namespace info, and the identifier's define module.
isExported
:: PNTThe identifier.
-> ExportsThe export relation.
-> BoolThe result.
Return True if the identifier is exported either implicitly or explicitly.
isExplicitlyExported
:: PNameThe identifier
-> HsModulePThe AST of the module
-> BoolThe result
Return True if an identifier is explicitly exported by the module.
modIsExported
:: HsModulePThe AST of the module
-> BoolThe result
Return True if the current module is exported either by default or by specifying the module name in the export.
Variable analysis
hsPNs :: Term t => t -> [PName]
Collect the identifiers (in PName format) in a given syntax phrase.
hsPNTs :: Term t => t -> [PNT]
Collect the identifiers (in PNT format) in a given syntax phrase.
hsDataConstrs
:: Term t
=> ModuleNameThe name of the module which t belongs to.
-> tThe given syntax phrase.
-> ([PName], [PName])The result.
Collect those data constructors that occur in the given syntax phrase, say t. In the result, the first list contains the data constructors that are declared in other modules, and the second list contains the data constructors that are declared in the current module.
hsTypeConstrsAndClasses
:: Term t
=> ModuleNameThe name of the module which t belongs to.
-> tThe given syntax phrase.
-> ([PName], [PName])The result.
Collect those type constructors and class names that occur in the given syntax phrase, say t. In the result, the first list contains the type constructor/classes which are declared in other modules, and the second list contains those type constructor/classes that are declared in the current module.
hsTypeVbls :: Term t => t -> ([PName], [PName])
Collect those type variables that are declared in a given syntax phrase t. In the returned result, the first list is always be empty.
hsClassMembers
:: Term t
=> StringThe class name.
-> ModuleNameThe module name.
-> tThe syntax phrase.
-> ([PName], [PName])The result.
Collect the class instances of the spcified class from the given syntax phrase. In the result, the first list contains those class instances which are declared in other modules, and the second list contains those class instances that are declared in the current module.
class Term t => HsDecls t where
The HsDecls class
Methods
hsDecls :: t -> [HsDeclP]
Return the declarations that are directly enclosed in the given syntax phrase.
replaceDecls :: t -> HsDeclsP -> t
Replace the directly enclosed declaration list by the given declaration list. Note: This function does not modify the token stream.
isDeclaredIn :: PName -> t -> Bool
Return True if the specified identifier is declared in the given syntax phrase.
show/hide Instances
HsDecls HsAltP
HsDecls HsDeclP
HsDecls HsDeclsP
HsDecls HsExpP
HsDecls HsMatchP
HsDecls HsModuleP
HsDecls HsStmtP
HsDecls RhsP
HsDecls [HsDeclP]
hsFreeAndDeclaredPNs :: (Term t, MonadPlus m) => t -> m ([PName], [PName])
Collect the free and declared variables (in the PName 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.
hsFreeAndDeclaredNames :: (Term t, MonadPlus m) => t -> m ([String], [String])
The same as hsFreeAndDeclaredPNs except that the returned variables are in the String format.
hsVisiblePNs :: (Term t1, Term t2, FindEntity t1, MonadPlus m) => t1 -> t2 -> m [PName]
Given syntax phrases e and t, if e occurs in t, then return those vairables which are declared in t and accessible to e, otherwise return [].
hsVisibleNames :: (Term t1, Term t2, FindEntity t1, MonadPlus m) => t1 -> t2 -> m [String]
Same as hsVisiblePNs except that the returned identifiers are in String format.
hsFDsFromInside :: (Term t, MonadPlus m) => t -> m ([PName], [PName])
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.
hsFDNamesFromInside :: (Term t, MonadPlus m) => t -> m ([String], [String])
The same as hsFDsFromInside except that the returned variables are in the String format
Property checking
isVarId :: String -> Bool
Return True if a string is a lexically valid variable name.
isConId :: String -> Bool
Return True if a string is a lexically valid constructor name.
isOperator :: String -> Bool
Return True if a string is a lexically valid operator name.
isTopLevelPN :: PName -> Bool
Return True if a PName is a toplevel PName.
isLocalPN :: PName -> Bool
Return True if a PName is a local PName.
isTopLevelPNT :: PNT -> Bool
Return True if an PNT is a toplevel PNT.
isQualifiedPN :: PName -> Bool
Return True if a PName is a qualified PName.
isFunPNT :: Term t => PNT -> t -> Bool
Return True if a PNT is a function name defined in t.
isFunName :: Term t => PName -> t -> Bool
isPatName :: Term t => PName -> t -> Bool
Return True if a PName is a pattern name defined in t.
isFunOrPatName :: Term t => PName -> t -> Bool
Return True if a PName is a function/pattern name defined in t.
isTypeCon :: PNT -> Bool
Return True if a PNT is a type constructor.
isTypeSig :: HsDeclP -> Bool
Return True if a declaration is a type signature declaration.
isFunBind :: HsDeclP -> Bool
Return True if a declaration is a function definition.
isPatBind :: HsDeclP -> Bool
Returns True if a declaration is a pattern binding.
isSimplePatBind :: HsDeclP -> Bool
Return True if a declaration is a pattern binding which only defines a variable value.
isComplexPatBind :: HsDeclP -> Bool
Return True if a declaration is a pattern binding but not a simple one.
isFunOrPatBind :: HsDeclP -> Bool
Return True if a declaration is a function/pattern definition.
isClassDecl :: HsDeclP -> Bool
Return True if a declaration is a Class declaration.
isInstDecl :: HsDeclP -> Bool
Return True if a declaration is a Class instance declaration.
isDirectRecursiveDef :: HsDeclP -> Bool
Return True if a function is a directly recursive function.
usedWithoutQual :: Term t => String -> t -> Bool
Return True is the identifier is unqualifiedly used in the given syntax phrase.
canBeQualified :: Term t => PNT -> t -> Bool
Return True if the identifier can become qualified.
hasFreeVars :: Term t => t -> Bool
Return True if the given syntax phrase contains any free variables.
isUsedInRhs :: Term t => PNT -> t -> Bool
Return True if the identifier is used in the RHS if a function/pattern binding.
findPNT :: Term t => PNT -> t -> Bool
Return True if the identifier(in PNT format) occurs in the given syntax phrase.
findPN :: Term t => PName -> t -> Bool
Return True if the identifier (in PName format) occurs in the given syntax phrase.
findPNs :: Term t => [PName] -> t -> Bool
Return True if any of the specified PNames ocuur in the given syntax phrase.
findEntity :: (FindEntity a, Term b) => a -> b -> Bool
Returns True is a syntax phrase, say a, is part of another syntax phrase, say b.
sameOccurrence :: (Term t, Eq t) => t -> t -> Bool
Return True if syntax phrases t1 and t2 refer to the same one.
defines :: PName -> HsDeclP -> Bool
Return True if the function/pattern binding defines the specified identifier.
definesTypeSig :: PName -> HsDeclP -> Bool
Return True if the declaration defines the type signature of the specified identifier.
isTypeSigOf :: PNT -> HsDeclP -> Bool
Return True if the declaration defines the type signature of the specified identifier.
class Term t => HasModName t where
Methods
hasModName :: t -> Maybe ModuleName
Fetch the module name from an identifier.
show/hide Instances
class HasNameSpace t where
The HasNameSpace class.
Methods
hasNameSpace :: t -> NameSpace
show/hide Instances
Modules and files
clientModsAndFiles :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m [(ModuleName, String)]
Return the client module and file names. The client modules of module, say m, are those modules which import m directly or indirectly.
serverModsAndFiles :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m [(ModuleName, String)]
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.
isAnExistingMod :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => ModuleName -> PFE0MT n i ds ext m Bool
Return True if the given module name exists in the project. isAnExistingMod::( ) =>ModuleName->PFE0MT n i ds ext m Bool
fileNameToModName :: (PFE0_IO err m, IOErr err, HasInfixDecls i ds, QualNames i m1 n, Read n, Show n) => String -> PFE0MT n i ds ext m ModuleName
From file name to module name. fileNameToModName::( )=>String->PFE0MT n i ds ext m ModuleName
strToModName :: String -> ModuleName
Compose ModuleName from String.
modNameToStr :: ModuleName -> String
From ModuleName to string.
Locations
defineLoc :: PNT -> SrcLoc
Return the identifier's defining location.
useLoc :: PNT -> SrcLoc
Return the identifier's source location.
locToPNT
:: Term t
=> StringThe file name
-> (Int, Int)The row and column number
-> tThe syntax phrase
-> PNTThe result
Find the identifier(in PNT format) whose start position is (row,col) in the file specified by the fileName, and returns defaultPNT is such an identifier does not exist.
locToPN :: Term t => String -> (Int, Int) -> t -> PName
The same as locToPNT, except that it returns the identifier in the PName format.
locToExp
:: Term t
=> SimpPosThe start position.
-> SimpPosThe end position.
-> [PosToken]The token stream which should at least contain the tokens for t.
-> tThe syntax phrase.
-> HsExpPThe result.
Given the syntax phrase (and the token stream), find the largest-leftmost expression contained in the region specified by the start and end position. If no expression can be found, then return the defaultExp.
Program transformation
Adding
addDecl :: (MonadState (([PosToken], Bool), (Int, Int)) m, StartEndLoc t, HsDecls t, Printable t) => t -> Maybe PName -> ([HsDeclP], Maybe [PosToken]) -> Bool -> m t
Adding a declaration to the declaration list of the given syntax phrase(so far only adding function/pattern binding has been tested). 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.
addItemsToImport
:: (Term t, MonadState (([PosToken], Bool), t1) m)
=> ModuleNameThe imported module name.
-> Maybe PNameThe condition identifier.
-> Either [String] [EntSpecP]The identifiers to add in either String or EntSpecP format.
-> tThe given syntax phrase.
-> m tThe result.
Add identifiers (given by the third argument) to the explicit entity list in the declaration importing the specified module name. The second argument serves as a condition: if it is like : Just p, then do the adding the if only p occurs in the entity list; if it is Nothing, then do the adding as normal. This function does nothing if the import declaration does not have an explicit entity list.
addHiding
:: MonadState (([PosToken], Bool), t1) m
=> ModuleNameThe imported module name
-> HsModulePThe current module
-> [PName]The items to be added
-> m HsModulePThe result
add items to the hiding list of an import declaration which imports the specified module.
rmItemsFromImport
:: MonadState (([PosToken], Bool), t1) m
=> HsModulePThe module AST
-> [PName]The items to be removed
-> m HsModulePThe result
Remove those specified items from the entity list in the import declaration.
addItemsToExport :: MonadState (([PosToken], Bool), t1) m => HsModuleP -> Maybe PName -> Bool -> Either [String] [HsExportEntP] -> m HsModuleP
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.
addParamsToDecls
:: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m)
=> [HsDeclP]A declaration list where the function is defined and/or used.
-> PNameThe function name.
-> [PName]The parameters to be added.
-> BoolModify the token stream or not.
-> m [HsDeclP]The result.
addGuardsToRhs
:: MonadState (([PosToken], Bool), (Int, Int)) m
=> RhsPThe RHS of the declaration.
-> HsExpPThe guard expression to be added.
-> m RhsPThe result.
Add a guard expression to the RHS of a function/pattern definition. If a guard already exists in the RHS, the new guard will be added to the beginning of the existing one.
duplicateDecl
:: MonadState (([PosToken], Bool), t1) m
=> [HsDeclP]The declaration list
-> PNameThe identifier whose definition is going to be duplicated
-> StringThe new name
-> m [HsDeclP]The result
Duplicate a functon/pattern binding declaration under a new name right after the original one.
Rmoving
commentOutTypeSig
:: MonadState (([PosToken], Bool), t1) m
=> PNameThe identifier.
-> [HsDeclP]The deckaration list.
-> m [HsDeclP]The result.
Comment out the type signature that defines pn's type in the token stream and remove it from the AST.
rmParams
:: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m)
=> PNTThe identifier whose parameters are to be removed.
-> IntNumber of parameters to be removed.
-> HsExpPThe original expression.
-> m HsExpPThe result expression.
Remove the first n parameters of a given identifier in an expression.
rmItemsFromExport
:: MonadState (([PosToken], Bool), t1) m
=> HsModulePThe module AST.
-> Either ([ModuleName], [PName]) [HsExportEntP]The entities to remove.
-> m HsModulePThe result.
Remove the specified entities from the module's exports. The entities can be specified in either of two formats: i.e. either specify the module names and identifier names to be removed, so just given the exact AST for these entities.
rmSubEntsFromExport
:: MonadState (([PosToken], Bool), (Int, Int)) m
=> PNameThe type constructor or class name
-> HsModulePThe module AST
-> m HsModulePThe result
Remove the sub entities of a type constructor or class from the export list.
class (Term t, Term t1) => Delete t t1 where
The Delete class.
Methods
delete
:: (MonadPlus m, MonadState (([PosToken], Bool), t2) m)
=> tThe syntax phrase to delete.
-> t1The contex where the syntax phrase occurs.
-> m t1The result.
Delete the occurrence of a syntax phrase in a given context.
show/hide Instances
Term t => Delete HsExpP t
Term t => Delete HsImportDeclP t
Term t => Delete HsPatP t
Updating
class (Term t, Term t1) => Update t t1 where
The Update class,
Methods
update
:: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m)
=> tThe syntax phrase to be updated.
-> tThe new syntax phrase.
-> t1The contex where the old syntex phrase occurs.
-> m t1The result.
Update the occurrence of one syntax phrase in a given scope by another syntax phrase of the same type.
show/hide Instances
Term t => Update HsDeclP t
Term t => Update HsDeclsP t
Term t => Update HsExpP t
Term t => Update HsExportEntP t
Term t => Update HsImportDeclP t
Term t => Update HsMatchP t
Term t => Update HsPatP t
Term t => Update HsTypeP t
Term t => Update PNT t
Term t => Update [HsDeclP] t
Term t => Update [HsPatP] t
qualifyPName
:: ModuleNameThe qualifier.
-> PNameThe identifier.
-> PNameThe result.
Add a qualifier to an identifier if it is not qualified.
rmQualifier
:: (MonadState (([PosToken], Bool), t1) m, Term t)
=> [PName]The identifiers.
-> tThe syntax phrase.
-> m tThe result.
Remove the qualifier from the given identifiers in the given syntax phrase.
renamePN
:: (MonadState (([PosToken], Bool), t1) m, Term t)
=> PNameThe identifier to be renamed.
-> Maybe ModuleNameThe qualifier
-> StringThe new name
-> BoolTrue means modifying the token stream as well.
-> tThe syntax phrase
-> m t
Rename each occurrences of the identifier in the given syntax phrase with the new name. If the Bool parameter is True, then modify both the AST and the token stream, otherwise only modify the AST.
replaceNameInPN
:: Maybe ModuleNameThe new qualifier
-> PNameThe old PName
-> StringThe new name
-> PNameThe result
Replace the name (and qualifier if specified) by a new name (and qualifier) in a PName. The function does not modify the token stream.
autoRenameLocalVar
:: (MonadPlus m, MonadState (([PosToken], Bool), (Int, Int)) m, Term t)
=> BoolTrue means modfiying the token stream as well.
-> PNameThe identifier.
-> tThe syntax phrase.
-> m tThe result.
Check whether the specified identifier is declared in the given syntax phrase t, if so, rename the identifier by creating a new name automatically. If the Bool parameter is True, the token stream will be modified, otherwise only the AST is modified.
Miscellous
Parsing, writing and showing
showEntities :: (Eq t, Term t) => (t -> String) -> [t] -> String
Show a list of entities, the parameter f is a function that specifies how to format an entity.
showPNwithLoc :: PName -> String
Show a PName in a format like: pn(at row:r, col: c).
Locations
toRelativeLocs :: Term t => t -> t
Change the absolute define locations of local variables to relative ones, so that equality between expressions can be compared via alpha-renaming.
rmLocs :: Term t => t -> t
Remove source location information in the syntax tree.
Default values
defaultPN :: PName
Default identifier in the PName format.
defaultPNT :: PNT
Default identifier in the PNT format.
defaultModName :: ModuleName
Default module name.
defaultExp :: HsExpP
Default expression.
defaultPat :: HsPatP
Default pattern.
Identifiers, expressions, patterns and declarations
pNTtoPN :: PNT -> PName
From PNT to PName.
pNTtoName :: PNT -> String
From PNT to Name. This function ingnores the qualifier.
pNtoName :: PName -> String
From PName to Name. This function ignores the qualifier.
nameToPNT :: String -> PNT
Compose a PNT form a String.
nameToPN :: String -> PName
Compose a PName from String.
pNtoPNT :: PName -> IdTy PId -> PNT
Compose a PNT from a PName and the PName's name space Information
expToPNT :: HsExpP -> PNT
If an expression consists of only one identifier then return this identifier in the PNT format, otherwise return the default PNT.
expToPN :: HsExpP -> PName
If an expression consists of only one identifier then return this identifier in the PName format, otherwise returns the default PName.
nameToExp :: String -> HsExpP
Compose an expression from a String.
pNtoExp :: PName -> HsExpP
Compose an expression from a pName.
patToPNT :: HsPatP -> PNT
If a pattern consists of only one identifier then return this identifier in the PNT format, otherwise returns the default PNT.
patToPN :: HsPatP -> PName
If a pattern consists of only one identifier then returns this identifier in the PName format, otherwise returns the default PName.
nameToPat :: String -> HsPatP
Compose a pattern from a String.
pNtoPat :: PName -> HsPatP
Compose a pattern from a pName.
definingDecls
:: [PName]The specified identifiers.
-> [HsDeclP]A collection of declarations.
-> BoolTrue means to include the type signature.
-> BoolTrue means to look at the local declarations as well.
-> [HsDeclP]The result.
Find those declarations(function/pattern binding and type signature) which define the specified PNames. incTypeSig indicates whether the corresponding type signature will be included.
definedPNs :: HsDeclP -> [PName]
Return the list of identifiers (in PName format) defined by a function/pattern binding.
simplifyDecl :: Monad m => HsDeclP -> m HsDeclP
If a function/pattern binding then convert it into a simple binding using case and/or if-then-else expressions. A simple function/pattern binding should satisfy: a) all the paraneters are simple variables; b). only has one equation; c). the RHS does not have guards. This function DOES NOT modify the token stream not AST.
Others
mkNewName
:: StringThe old name
-> [String]The set of names which the new name cannot take
-> IntThe posfix value
-> StringThe 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.
Typed AST traversals (added by CMB)
Miscellous
removeFromInts :: (MonadPlus m, Term t) => t -> m t
Collect the free and declared variables (in the PName 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.
getDataName :: Term t => t -> String
Takes a [HsDeclP] which is a data type and returns the data type name
checkTypes :: Term t => String -> t -> Bool
CheckTypes takes a string represetation of a type. List types must be supplied in the form | []Int or []a | CheckTypes checks to see whether the type occurs within the syntax phrase | (returns True if an identifier within the syntax phrase is of the type in question
getPNs :: HsDeclP -> [PName]
getPNs take a declaration and returns all the PNames within that declaration
getPN :: Term t => t -> PName
getPN takes a pattern and returns the PName belonging to that Pattern.
getPNPats :: HsExpP -> [PName]
getPNPats takes an expression and returns a list of PNames that occur | within that expression.
Produced by Haddock version 0.7