Safe Haskell | None |
---|---|
Language | Haskell2010 |
The FromGHC module provides a way to transform the GHC AST into our AST. This transformation is done in the Ghc monad. The conversion can be performed from the Parsed and the Renamed GHC AST. If the renamed AST is given, additional semantic information is looked up while traversing the AST.
- addTypeInfos :: LHsBinds Id -> Ann Module RangeWithName -> Ghc (Ann Module RangeWithType)
- getTypeVariables :: TyCon -> [Id]
- extractTypes :: LHsBinds Id -> [Id]
- extractExprIds :: LHsBinds Id -> [Located Id]
- trfModule :: Located (HsModule RdrName) -> Trf (Ann Module RangeInfo)
- trfModuleRename :: Module -> Ann Module RangeInfo -> (HsGroup Name, [LImportDecl Name], Maybe [LIE Name], Maybe LHsDocString) -> Located (HsModule RdrName) -> Trf (Ann Module RangeWithName)
- trfModuleHead :: TransformName n r => Maybe (Located ModuleName) -> Maybe (Located [LIE n]) -> Maybe (Located WarningTxt) -> Trf (AnnMaybe ModuleHead r)
- trfFilePragmas :: RangeAnnot a => Trf (AnnList FilePragma a)
- trfLanguagePragma :: RangeAnnot a => Located String -> Trf (Ann FilePragma a)
- trfOptionsPragma :: RangeAnnot a => Located String -> Trf (Ann FilePragma a)
- trfModulePragma :: RangeAnnot a => Maybe (Located WarningTxt) -> Trf (AnnMaybe ModulePragma a)
- trfText' :: RangeAnnot a => StringLiteral -> Trf (StringNode a)
- trfExportList :: TransformName n r => SrcLoc -> Maybe (Located [LIE n]) -> Trf (AnnMaybe ExportSpecList r)
- trfExportList' :: TransformName n r => [LIE n] -> Trf (ExportSpecList r)
- trfExport :: TransformName n r => LIE n -> Trf (Maybe (Ann ExportSpec r))
- trfImports :: TransformName n r => [LImportDecl n] -> Trf (AnnList ImportDecl r)
- trfImport :: forall n r. TransformName n r => LImportDecl n -> Trf (Ann ImportDecl r)
- trfImportSpecs :: TransformName n r => Maybe (Bool, Located [LIE n]) -> Trf (AnnMaybe ImportSpec r)
- trfIESpec :: TransformName n r => LIE n -> Trf (Maybe (Ann IESpec r))
- trfIESpec' :: TransformName n r => IE n -> Trf (Maybe (IESpec r))
- type Trf = ReaderT TrfInput Ghc
- data TrfInput = TrfInput {
- srcMap :: SourceMap
- pragmaComms :: Map String [Located String]
- contRange :: SrcSpan
- localsInScope :: [[Name]]
- defining :: Bool
- definingTypeVars :: Bool
- originalNames :: Map SrcSpan RdrName
- trfInit :: Map ApiAnnKey [SrcSpan] -> Map String [Located String] -> TrfInput
- define :: Trf a -> Trf a
- defineTypeVars :: Trf a -> Trf a
- typeVarTransform :: Trf a -> Trf a
- transformingPossibleVar :: HsHasName n => n -> Trf a -> Trf a
- addToScope :: HsHasName e => e -> Trf a -> Trf a
- addToCurrentScope :: HsHasName e => e -> Trf a -> Trf a
- runTrf :: Map ApiAnnKey [SrcSpan] -> Map String [Located String] -> Trf a -> Ghc a
- setOriginalNames :: Map SrcSpan RdrName -> Trf a -> Trf a
- getOriginalName :: RdrName -> Trf String
- trfOperator :: TransformName name res => Located name -> Trf (Ann Operator res)
- trfOperator' :: TransformName name res => name -> Trf (Operator res)
- trfName :: TransformName name res => Located name -> Trf (Ann Name res)
- trfName' :: TransformName name res => name -> Trf (Name res)
- trfAmbiguousFieldName :: TransformName n res => Located (AmbiguousFieldOcc n) -> Trf (Ann Name res)
- trfAmbiguousFieldName' :: forall n res. TransformName n res => SrcSpan -> AmbiguousFieldOcc n -> Trf (Ann Name res)
- class (DataId n, Eq n, GHCName n) => TransformableName n where
- class (RangeAnnot res, SemanticAnnot res name, SemanticAnnot res Name, TransformableName name, HsHasName name) => TransformName name res
- addNameInfo :: TransformName n r => n -> Ann SimpleName r -> Trf (Ann SimpleName r)
- trfSimpleName :: TransformName name res => Located name -> Trf (Ann SimpleName res)
- trfSimpleName' :: TransformName name res => name -> Trf (SimpleName res)
- trfNameStr :: RangeAnnot a => String -> Trf (AnnList UnqualName a)
- trfNameStr' :: RangeAnnot a => String -> SrcLoc -> [Ann UnqualName a]
- trfModuleName :: RangeAnnot a => Located ModuleName -> Trf (Ann SimpleName a)
- trfModuleName' :: RangeAnnot a => ModuleName -> Trf (SimpleName a)
- trfFastString :: RangeAnnot a => Located FastString -> Trf (Ann StringNode a)
- trfDataKeyword :: RangeAnnot a => NewOrData -> Trf (Ann DataOrNewtypeKeyword a)
- trfCallConv :: RangeAnnot a => Located CCallConv -> Trf (Ann CallConv a)
- trfCallConv' :: RangeAnnot a => CCallConv -> Trf (CallConv a)
- trfSafety :: RangeAnnot a => SrcSpan -> Located Safety -> Trf (AnnMaybe Safety a)
- trfOverlap :: RangeAnnot a => Located OverlapMode -> Trf (Ann OverlapPragma a)
- trfRole :: RangeAnnot a => Located (Maybe Role) -> Trf (Ann Role a)
- trfPhase :: RangeAnnot a => Trf SrcLoc -> Activation -> Trf (AnnMaybe PhaseControl a)
- trfPhaseNum :: RangeAnnot a => PhaseNum -> Trf (Ann PhaseNumber a)
- class HasRange annot => RangeAnnot annot where
- class SemanticAnnot annot n where
- addImportData' :: Ann ImportDecl RangeWithName -> Trf (Ann ImportDecl RangeWithName)
- getImportedNames :: String -> Maybe String -> Trf (Module, [Name])
- checkImportVisible :: GhcMonad m => ImportDecl RangeWithName -> Name -> m Bool
- ieSpecMatches :: GhcMonad m => IESpec RangeWithName -> Name -> m Bool
- nothing :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf (AnnMaybe e a)
- emptyList :: RangeAnnot a => String -> Trf SrcLoc -> Trf (AnnList e a)
- makeList :: RangeAnnot a => String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeListBefore :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeListAfter :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeNonemptyList :: RangeAnnot a => String -> Trf [Ann e a] -> Trf (AnnList e a)
- makeIndentedList :: RangeAnnot a => Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeIndentedListNewlineBefore :: RangeAnnot a => Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeIndentedListBefore :: RangeAnnot a => String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a)
- makeNonemptyIndentedList :: RangeAnnot a => Trf [Ann e a] -> Trf (AnnList e a)
- trfLoc :: RangeAnnot i => (a -> Trf (b i)) -> Located a -> Trf (Ann b i)
- trfMaybe :: RangeAnnot i => String -> String -> (Located a -> Trf (Ann e i)) -> Maybe (Located a) -> Trf (AnnMaybe e i)
- trfMaybeDefault :: RangeAnnot i => String -> String -> (Located a -> Trf (Ann e i)) -> Trf SrcLoc -> Maybe (Located a) -> Trf (AnnMaybe e i)
- trfLocCorrect :: RangeAnnot i => (SrcSpan -> Trf SrcSpan) -> (a -> Trf (b i)) -> Located a -> Trf (Ann b i)
- trfMaybeLoc :: RangeAnnot i => (a -> Trf (Maybe (b i))) -> Located a -> Trf (Maybe (Ann b i))
- trfAnnList :: RangeAnnot i => String -> (a -> Trf (b i)) -> [Located a] -> Trf (AnnList b i)
- trfAnnList' :: RangeAnnot i => String -> (Located a -> Trf (Ann b i)) -> [Located a] -> Trf (AnnList b i)
- nonemptyAnnList :: RangeAnnot i => [Ann e i] -> AnnList e i
- makeJust :: RangeAnnot a => Ann e a -> AnnMaybe e a
- annLoc :: RangeAnnot a => Trf SrcSpan -> Trf (b a) -> Trf (Ann b a)
- focusOn :: SrcSpan -> Trf a -> Trf a
- between :: AnnKeywordId -> AnnKeywordId -> Trf a -> Trf a
- betweenIfPresent :: AnnKeywordId -> AnnKeywordId -> Trf a -> Trf a
- focusAfter :: AnnKeywordId -> Trf a -> Trf a
- focusAfterIfPresent :: AnnKeywordId -> Trf a -> Trf a
- focusBefore :: AnnKeywordId -> Trf a -> Trf a
- focusBeforeIfPresent :: AnnKeywordId -> Trf a -> Trf a
- before :: AnnKeywordId -> Trf SrcLoc
- after :: AnnKeywordId -> Trf SrcLoc
- annFrom :: RangeAnnot a => AnnKeywordId -> Trf (e a) -> Trf (Ann e a)
- atTheStart :: Trf SrcLoc
- atTheEnd :: Trf SrcLoc
- tokenLoc :: AnnKeywordId -> Trf SrcSpan
- allTokenLoc :: AnnKeywordId -> Trf [SrcSpan]
- tokenLocBack :: AnnKeywordId -> Trf SrcSpan
- tokenBefore :: SrcLoc -> AnnKeywordId -> Trf SrcSpan
- tokensLoc :: [AnnKeywordId] -> Trf SrcSpan
- uniqueTokenAnywhere :: AnnKeywordId -> Trf SrcSpan
- annCont :: RangeAnnot a => Trf (e a) -> Trf (Ann e a)
- copyAnnot :: (Ann a i -> b i) -> Trf (Ann a i) -> Trf (Ann b i)
- foldLocs :: [SrcSpan] -> SrcSpan
- advanceStr :: String -> SrcLoc -> SrcLoc
- updateCol :: (Int -> Int) -> SrcLoc -> SrcLoc
- collectLocs :: [Located e] -> SrcSpan
- orderDefs :: RangeAnnot i => [Ann e i] -> [Ann e i]
- orderAnnList :: RangeAnnot i => AnnList e i -> AnnList e i
- trfScopedSequence :: HsHasName d => (d -> Trf e) -> [d] -> Trf [e]
- splitLocated :: Located String -> [Located String]
Documentation
getTypeVariables :: TyCon -> [Id] Source #
trfModuleRename :: Module -> Ann Module RangeInfo -> (HsGroup Name, [LImportDecl Name], Maybe [LIE Name], Maybe LHsDocString) -> Located (HsModule RdrName) -> Trf (Ann Module RangeWithName) Source #
trfModuleHead :: TransformName n r => Maybe (Located ModuleName) -> Maybe (Located [LIE n]) -> Maybe (Located WarningTxt) -> Trf (AnnMaybe ModuleHead r) Source #
trfFilePragmas :: RangeAnnot a => Trf (AnnList FilePragma a) Source #
trfLanguagePragma :: RangeAnnot a => Located String -> Trf (Ann FilePragma a) Source #
trfOptionsPragma :: RangeAnnot a => Located String -> Trf (Ann FilePragma a) Source #
trfModulePragma :: RangeAnnot a => Maybe (Located WarningTxt) -> Trf (AnnMaybe ModulePragma a) Source #
trfText' :: RangeAnnot a => StringLiteral -> Trf (StringNode a) Source #
trfExportList :: TransformName n r => SrcLoc -> Maybe (Located [LIE n]) -> Trf (AnnMaybe ExportSpecList r) Source #
trfExportList' :: TransformName n r => [LIE n] -> Trf (ExportSpecList r) Source #
trfImports :: TransformName n r => [LImportDecl n] -> Trf (AnnList ImportDecl r) Source #
trfImport :: forall n r. TransformName n r => LImportDecl n -> Trf (Ann ImportDecl r) Source #
trfImportSpecs :: TransformName n r => Maybe (Bool, Located [LIE n]) -> Trf (AnnMaybe ImportSpec r) Source #
trfIESpec' :: TransformName n r => IE n -> Trf (Maybe (IESpec r)) Source #
The (immutable) data for the transformation
TrfInput | |
|
defineTypeVars :: Trf a -> Trf a Source #
Perform the transformation taking type variable names as defined.
typeVarTransform :: Trf a -> Trf a Source #
Transform as type variables
transformingPossibleVar :: HsHasName n => n -> Trf a -> Trf a Source #
Transform a name as a type variable if it is one.
addToScope :: HsHasName e => e -> Trf a -> Trf a Source #
Perform the transformation putting the given definition in a new local scope.
addToCurrentScope :: HsHasName e => e -> Trf a -> Trf a Source #
Perform the transformation putting the given definitions in the current scope.
runTrf :: Map ApiAnnKey [SrcSpan] -> Map String [Located String] -> Trf a -> Ghc a Source #
Performs the transformation given the tokens of the source file
getOriginalName :: RdrName -> Trf String Source #
Get the original format of a name (before scoping).
trfOperator :: TransformName name res => Located name -> Trf (Ann Operator res) Source #
trfOperator' :: TransformName name res => name -> Trf (Operator res) Source #
trfName' :: TransformName name res => name -> Trf (Name res) Source #
trfAmbiguousFieldName :: TransformName n res => Located (AmbiguousFieldOcc n) -> Trf (Ann Name res) Source #
trfAmbiguousFieldName' :: forall n res. TransformName n res => SrcSpan -> AmbiguousFieldOcc n -> Trf (Ann Name res) Source #
class (DataId n, Eq n, GHCName n) => TransformableName n where Source #
correctNameString :: n -> Trf String Source #
class (RangeAnnot res, SemanticAnnot res name, SemanticAnnot res Name, TransformableName name, HsHasName name) => TransformName name res Source #
This class allows us to use the same transformation code for multiple variants of the GHC AST.
GHC Name annotated with name
can be transformed to our representation with semantic annotations of res
.
TransformName RdrName RangeInfo Source # | |
(RangeAnnot r, SemanticAnnot r Name) => TransformName Name r Source # | |
addNameInfo :: TransformName n r => n -> Ann SimpleName r -> Trf (Ann SimpleName r) Source #
trfSimpleName :: TransformName name res => Located name -> Trf (Ann SimpleName res) Source #
trfSimpleName' :: TransformName name res => name -> Trf (SimpleName res) Source #
trfNameStr :: RangeAnnot a => String -> Trf (AnnList UnqualName a) Source #
Creates a qualified name from a name string
trfNameStr' :: RangeAnnot a => String -> SrcLoc -> [Ann UnqualName a] Source #
trfModuleName :: RangeAnnot a => Located ModuleName -> Trf (Ann SimpleName a) Source #
trfModuleName' :: RangeAnnot a => ModuleName -> Trf (SimpleName a) Source #
trfFastString :: RangeAnnot a => Located FastString -> Trf (Ann StringNode a) Source #
trfDataKeyword :: RangeAnnot a => NewOrData -> Trf (Ann DataOrNewtypeKeyword a) Source #
trfCallConv :: RangeAnnot a => Located CCallConv -> Trf (Ann CallConv a) Source #
trfCallConv' :: RangeAnnot a => CCallConv -> Trf (CallConv a) Source #
trfOverlap :: RangeAnnot a => Located OverlapMode -> Trf (Ann OverlapPragma a) Source #
trfPhase :: RangeAnnot a => Trf SrcLoc -> Activation -> Trf (AnnMaybe PhaseControl a) Source #
trfPhaseNum :: RangeAnnot a => PhaseNum -> Trf (Ann PhaseNumber a) Source #
class HasRange annot => RangeAnnot annot where Source #
Annotations that is made up from ranges
toNodeAnnot :: SrcSpan -> annot Source #
toListAnnot :: String -> String -> String -> SrcLoc -> annot Source #
toIndentedListAnnot :: String -> String -> String -> SrcLoc -> annot Source #
RangeAnnot (NodeInfo (SemanticInfo n) SpanInfo) Source # | |
class SemanticAnnot annot n where Source #
Annotations that carry semantic information
addSemanticInfo :: SemanticInfo n -> annot -> annot Source #
addScopeData :: annot -> Trf annot Source #
addImportData :: Ann ImportDecl annot -> Trf (Ann ImportDecl annot) Source #
SemanticAnnot RangeWithName Name Source # | |
SemanticAnnot RangeInfo n Source # | |
SemanticAnnot RangeInfo RdrName Source # | |
addImportData' :: Ann ImportDecl RangeWithName -> Trf (Ann ImportDecl RangeWithName) Source #
Adds semantic information to an impord declaration. See ImportInfo.
getImportedNames :: String -> Maybe String -> Trf (Module, [Name]) Source #
Get names that are imported from a given import
checkImportVisible :: GhcMonad m => ImportDecl RangeWithName -> Name -> m Bool Source #
Check is a given name is imported from an import with given import specification.
nothing :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf (AnnMaybe e a) Source #
Creates a place for a missing node with a default location
makeList :: RangeAnnot a => String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
Creates a place for a list of nodes with a default place if the list is empty.
makeListBefore :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
makeListAfter :: RangeAnnot a => String -> String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
makeNonemptyList :: RangeAnnot a => String -> Trf [Ann e a] -> Trf (AnnList e a) Source #
makeIndentedList :: RangeAnnot a => Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
Creates a place for an indented list of nodes with a default place if the list is empty.
makeIndentedListNewlineBefore :: RangeAnnot a => Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
makeIndentedListBefore :: RangeAnnot a => String -> Trf SrcLoc -> Trf [Ann e a] -> Trf (AnnList e a) Source #
makeNonemptyIndentedList :: RangeAnnot a => Trf [Ann e a] -> Trf (AnnList e a) Source #
trfLoc :: RangeAnnot i => (a -> Trf (b i)) -> Located a -> Trf (Ann b i) Source #
Transform a located part of the AST by automatically transforming the location. Sets the source range for transforming children.
trfMaybe :: RangeAnnot i => String -> String -> (Located a -> Trf (Ann e i)) -> Maybe (Located a) -> Trf (AnnMaybe e i) Source #
Transforms a possibly-missing node with the default location of the end of the focus.
trfMaybeDefault :: RangeAnnot i => String -> String -> (Located a -> Trf (Ann e i)) -> Trf SrcLoc -> Maybe (Located a) -> Trf (AnnMaybe e i) Source #
Transforms a possibly-missing node with a default location
trfLocCorrect :: RangeAnnot i => (SrcSpan -> Trf SrcSpan) -> (a -> Trf (b i)) -> Located a -> Trf (Ann b i) Source #
Transform a located part of the AST by automatically transforming the location with correction by applying the given function. Sets the source range for transforming children.
trfMaybeLoc :: RangeAnnot i => (a -> Trf (Maybe (b i))) -> Located a -> Trf (Maybe (Ann b i)) Source #
Transform a located part of the AST by automatically transforming the location. Sets the source range for transforming children.
trfAnnList :: RangeAnnot i => String -> (a -> Trf (b i)) -> [Located a] -> Trf (AnnList b i) Source #
Creates a place for a list of nodes with the default place at the end of the focus if the list is empty.
trfAnnList' :: RangeAnnot i => String -> (Located a -> Trf (Ann b i)) -> [Located a] -> Trf (AnnList b i) Source #
nonemptyAnnList :: RangeAnnot i => [Ann e i] -> AnnList e i Source #
Creates a place for a list of nodes that cannot be empty.
makeJust :: RangeAnnot a => Ann e a -> AnnMaybe e a Source #
Creates an optional node from an existing element
annLoc :: RangeAnnot a => Trf SrcSpan -> Trf (b a) -> Trf (Ann b a) Source #
Annotates a node with the given location and focuses on the given source span.
Focus manipulation
between :: AnnKeywordId -> AnnKeywordId -> Trf a -> Trf a Source #
Focuses the transformation to go between tokens. The tokens must be found inside the current range.
betweenIfPresent :: AnnKeywordId -> AnnKeywordId -> Trf a -> Trf a Source #
Focuses the transformation to go between tokens if they are present
focusAfter :: AnnKeywordId -> Trf a -> Trf a Source #
Focuses the transformation to be performed after the given token. The token must be found inside the current range.
focusAfterIfPresent :: AnnKeywordId -> Trf a -> Trf a Source #
focusBefore :: AnnKeywordId -> Trf a -> Trf a Source #
Focuses the transformation to be performed after the given token. The token must be found inside the current range.
focusBeforeIfPresent :: AnnKeywordId -> Trf a -> Trf a Source #
annFrom :: RangeAnnot a => AnnKeywordId -> Trf (e a) -> Trf (Ann e a) Source #
The element should span from the given token to the end of focus
atTheStart :: Trf SrcLoc Source #
Gets the position at the beginning of the focus
tokenLoc :: AnnKeywordId -> Trf SrcSpan Source #
Searches for a token inside the focus and retrieves its location
allTokenLoc :: AnnKeywordId -> Trf [SrcSpan] Source #
tokenLocBack :: AnnKeywordId -> Trf SrcSpan Source #
Searches for a token backward inside the focus and retrieves its location
tokenBefore :: SrcLoc -> AnnKeywordId -> Trf SrcSpan Source #
tokensLoc :: [AnnKeywordId] -> Trf SrcSpan Source #
Searches for tokens in the given order inside the parent element and returns their combined location
uniqueTokenAnywhere :: AnnKeywordId -> Trf SrcSpan Source #
Searches for a token and retrieves its location anywhere
annCont :: RangeAnnot a => Trf (e a) -> Trf (Ann e a) Source #
Annotates the given element with the current focus as a location.
copyAnnot :: (Ann a i -> b i) -> Trf (Ann a i) -> Trf (Ann b i) Source #
Annotates the element with the same annotation that is on the other element
updateCol :: (Int -> Int) -> SrcLoc -> SrcLoc Source #
Update column information in a source location
collectLocs :: [Located e] -> SrcSpan Source #
Combine source spans of elements into one that contains them all
orderDefs :: RangeAnnot i => [Ann e i] -> [Ann e i] Source #
Rearrange definitions to appear in the order they are defined in the source file.
orderAnnList :: RangeAnnot i => AnnList e i -> AnnList e i Source #
Orders a list of elements to the order they are defined in the source file.