HieUtils

ghc-8.8.0.20190424: The GHC API

Safe Haskell | None
Language | Haskell2010

HieUtils

Synopsis

- generateReferencesMap :: Foldable f => f (HieAST a) -> Map Identifier [(Span, IdentifierDetails a)]
- renderHieType :: DynFlags -> HieTypeFix -> String
- resolveVisibility :: Type -> [Type] -> [(Bool, Type)]
- foldType :: (HieType a -> a) -> HieTypeFix -> a
- hieTypeToIface :: HieTypeFix -> IfaceType
- data HieTypeState = HTS {
  - tyMap :: !(TypeMap TypeIndex)
  - htyTable :: !(IntMap HieTypeFlat)
  - freshIndex :: !TypeIndex
  }
- initialHTS :: HieTypeState
- freshTypeIndex :: State HieTypeState TypeIndex
- compressTypes :: HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
- recoverFullType :: TypeIndex -> Array TypeIndex HieTypeFlat -> HieTypeFix
- getTypeIndex :: Type -> State HieTypeState TypeIndex
- resolveTyVarScopes :: Map FastString (HieAST a) -> Map FastString (HieAST a)
- resolveTyVarScopeLocal :: HieAST a -> Map FastString (HieAST a) -> HieAST a
- getNameBinding :: Name -> Map FastString (HieAST a) -> Maybe Span
- getNameScope :: Name -> Map FastString (HieAST a) -> Maybe [Scope]
- getNameBindingInClass :: Name -> Span -> Map FastString (HieAST a) -> Maybe Span
- getNameScopeAndBinding :: Name -> Map FastString (HieAST a) -> Maybe ([Scope], Maybe Span)
- getScopeFromContext :: ContextInfo -> Maybe [Scope]
- getBindSiteFromContext :: ContextInfo -> Maybe Span
- flattenAst :: HieAST a -> [HieAST a]
- smallestContainingSatisfying :: Span -> (HieAST a -> Bool) -> HieAST a -> Maybe (HieAST a)
- selectLargestContainedBy :: Span -> HieAST a -> Maybe (HieAST a)
- selectSmallestContaining :: Span -> HieAST a -> Maybe (HieAST a)
- definedInAsts :: Map FastString (HieAST a) -> Name -> Bool
- isOccurrence :: ContextInfo -> Bool
- scopeContainsSpan :: Scope -> Span -> Bool
- combineAst :: HieAST Type -> HieAST Type -> HieAST Type
- insertAst :: HieAST Type -> [HieAST Type] -> [HieAST Type]
- combineNodeInfo :: NodeInfo Type -> NodeInfo Type -> NodeInfo Type
- mergeAsts :: [HieAST Type] -> [HieAST Type] -> [HieAST Type]
- rightOf :: Span -> Span -> Bool
- leftOf :: Span -> Span -> Bool
- startsRightOf :: Span -> Span -> Bool
- mergeSortAsts :: [HieAST Type] -> [HieAST Type]
- simpleNodeInfo :: FastString -> FastString -> NodeInfo a
- locOnly :: SrcSpan -> [HieAST a]
- mkScope :: SrcSpan -> Scope
- mkLScope :: Located a -> Scope
- combineScopes :: Scope -> Scope -> Scope
- makeNode :: (Applicative m, Data a) => a -> SrcSpan -> m [HieAST b]
- makeTypeNode :: (Applicative m, Data a) => a -> SrcSpan -> Type -> m [HieAST Type]

# Documentation

generateReferencesMap :: Foldable f => f (HieAST a) -> Map Identifier [(Span, IdentifierDetails a)] Source #

renderHieType :: DynFlags -> HieTypeFix -> String Source #

resolveVisibility :: Type -> [Type] -> [(Bool, Type)] Source #

foldType :: (HieType a -> a) -> HieTypeFix -> a Source #

hieTypeToIface :: HieTypeFix -> IfaceType Source #

data HieTypeState Source #

Constructors

HTS |
Fields tyMap :: !(TypeMap TypeIndex) htyTable :: !(IntMap HieTypeFlat) freshIndex :: !TypeIndex

initialHTS :: HieTypeState Source #

freshTypeIndex :: State HieTypeState TypeIndex Source #

compressTypes :: HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat) Source #

recoverFullType :: TypeIndex -> Array TypeIndex HieTypeFlat -> HieTypeFix Source #

getTypeIndex :: Type -> State HieTypeState TypeIndex Source #

resolveTyVarScopes :: Map FastString (HieAST a) -> Map FastString (HieAST a) Source #

resolveTyVarScopeLocal :: HieAST a -> Map FastString (HieAST a) -> HieAST a Source #

getNameBinding :: Name -> Map FastString (HieAST a) -> Maybe Span Source #

getNameScope :: Name -> Map FastString (HieAST a) -> Maybe [Scope] Source #

getNameBindingInClass :: Name -> Span -> Map FastString (HieAST a) -> Maybe Span Source #

getNameScopeAndBinding :: Name -> Map FastString (HieAST a) -> Maybe ([Scope], Maybe Span) Source #

getScopeFromContext :: ContextInfo -> Maybe [Scope] Source #

getBindSiteFromContext :: ContextInfo -> Maybe Span Source #

flattenAst :: HieAST a -> [HieAST a] Source #

smallestContainingSatisfying :: Span -> (HieAST a -> Bool) -> HieAST a -> Maybe (HieAST a) Source #

selectLargestContainedBy :: Span -> HieAST a -> Maybe (HieAST a) Source #

selectSmallestContaining :: Span -> HieAST a -> Maybe (HieAST a) Source #

definedInAsts :: Map FastString (HieAST a) -> Name -> Bool Source #

isOccurrence :: ContextInfo -> Bool Source #

scopeContainsSpan :: Scope -> Span -> Bool Source #

combineAst :: HieAST Type -> HieAST Type -> HieAST Type Source #

One must contain the other. Leaf nodes cannot contain anything

insertAst :: HieAST Type -> [HieAST Type] -> [HieAST Type] Source #

Insert an AST in a sorted list of disjoint Asts

combineNodeInfo :: NodeInfo Type -> NodeInfo Type -> NodeInfo Type Source #

Merge two nodes together.

Precondition and postcondition: elements in `nodeType` are ordered.

mergeAsts :: [HieAST Type] -> [HieAST Type] -> [HieAST Type] Source #

Merge two sorted, disjoint lists of ASTs, combining when necessary.

In the absence of position-altering pragmas (ex: `# line "file.hs" 3`), different nodes in an AST tree should either have disjoint spans (in which case you can say for sure which one comes first) or one span should be completely contained in the other (in which case the contained span corresponds to some child node).

However, since Haskell does have position-altering pragmas it is possible for spans to be overlapping. Here is an example of a source file in which `foozball` and `quuuuuux` have overlapping spans:

    module Baz where

    # line 3 "Baz.hs"
    foozball :: Int
    foozball = 0

    # line 3 "Baz.hs"
    bar, quuuuuux :: Int
    bar = 1
    quuuuuux = 2

In these cases, we just do our best to produce sensible `HieAST`'s. The blame should be laid at the feet of whoever wrote the line pragmas in the first place (usually the C preprocessor...).

rightOf :: Span -> Span -> Bool Source #

leftOf :: Span -> Span -> Bool Source #

startsRightOf :: Span -> Span -> Bool Source #

mergeSortAsts :: [HieAST Type] -> [HieAST Type] Source #

combines and sorts ASTs using a merge sort

simpleNodeInfo :: FastString -> FastString -> NodeInfo a Source #

locOnly :: SrcSpan -> [HieAST a] Source #

mkScope :: SrcSpan -> Scope Source #

mkLScope :: Located a -> Scope Source #

combineScopes :: Scope -> Scope -> Scope Source #

makeNode Source #

Arguments

:: (Applicative m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpan | return an empty list if this is unhelpful
-> m [HieAST b] |

makeTypeNode Source #

Arguments

:: (Applicative m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpan | return an empty list if this is unhelpful
-> Type | type to associate with the node
-> m [HieAST Type] |