Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines the notion of a scope and operations on scopes.
- data Scope = Scope {}
- data NameSpaceId
- type ScopeNameSpaces = [(NameSpaceId, NameSpace)]
- localNameSpace :: Access -> NameSpaceId
- nameSpaceAccess :: NameSpaceId -> Access
- scopeNameSpace :: NameSpaceId -> Scope -> NameSpace
- updateScopeNameSpaces :: (ScopeNameSpaces -> ScopeNameSpaces) -> Scope -> Scope
- updateScopeNameSpacesM :: Functor m => (ScopeNameSpaces -> m ScopeNameSpaces) -> Scope -> m Scope
- data ScopeInfo = ScopeInfo {}
- type LocalVars = AssocList Name LocalVar
- data LocalVar = LocalVar {
- localVar :: Name
- localLetBound :: Bool
- localShadowedBy :: [AbstractName]
- shadowLocal :: [AbstractName] -> LocalVar -> LocalVar
- notShadowedLocal :: LocalVar -> Maybe Name
- notShadowedLocals :: LocalVars -> AssocList Name Name
- updateScopeLocals :: (LocalVars -> LocalVars) -> ScopeInfo -> ScopeInfo
- setScopeLocals :: LocalVars -> ScopeInfo -> ScopeInfo
- mapScopeInfo :: (Scope -> Scope) -> ScopeInfo -> ScopeInfo
- data NameSpace = NameSpace {}
- type ThingsInScope a = Map Name [a]
- type NamesInScope = ThingsInScope AbstractName
- type ModulesInScope = ThingsInScope AbstractModule
- type InScopeSet = Set QName
- data InScopeTag a where
- class Eq a => InScope a where
- inNameSpace :: forall a. InScope a => NameSpace -> ThingsInScope a
- data KindOfName
- allKindsOfNames :: [KindOfName]
- data WhyInScope
- data AbstractName = AbsName {}
- data AbstractModule = AbsModule {}
- lensAnameName :: Functor m => (QName -> m QName) -> AbstractName -> m AbstractName
- lensAmodName :: Functor m => (ModuleName -> m ModuleName) -> AbstractModule -> m AbstractModule
- mergeNames :: Eq a => ThingsInScope a -> ThingsInScope a -> ThingsInScope a
- emptyNameSpace :: NameSpace
- mapNameSpace :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> NameSpace -> NameSpace
- zipNameSpace :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> NameSpace -> NameSpace -> NameSpace
- mapNameSpaceM :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> NameSpace -> m NameSpace
- emptyScope :: Scope
- emptyScopeInfo :: ScopeInfo
- mapScope :: (NameSpaceId -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScope_ :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScope' :: NameSpaceId -> (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScopeM :: Applicative m => (NameSpaceId -> NamesInScope -> m NamesInScope) -> (NameSpaceId -> ModulesInScope -> m ModulesInScope) -> (NameSpaceId -> InScopeSet -> m InScopeSet) -> Scope -> m Scope
- mapScopeM_ :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> Scope -> m Scope
- zipScope :: (NameSpaceId -> NamesInScope -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope
- zipScope_ :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope
- recomputeInScopeSets :: Scope -> Scope
- filterScope :: (Name -> Bool) -> (Name -> Bool) -> Scope -> Scope
- allNamesInScope :: InScope a => Scope -> ThingsInScope a
- allNamesInScope' :: InScope a => Scope -> ThingsInScope (a, Access)
- exportedNamesInScope :: InScope a => Scope -> ThingsInScope a
- namesInScope :: InScope a => [NameSpaceId] -> Scope -> ThingsInScope a
- allThingsInScope :: Scope -> NameSpace
- thingsInScope :: [NameSpaceId] -> Scope -> NameSpace
- mergeScope :: Scope -> Scope -> Scope
- mergeScopes :: [Scope] -> Scope
- setScopeAccess :: NameSpaceId -> Scope -> Scope
- setNameSpace :: NameSpaceId -> NameSpace -> Scope -> Scope
- modifyNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> Scope -> Scope
- addNamesToScope :: NameSpaceId -> Name -> [AbstractName] -> Scope -> Scope
- addNameToScope :: NameSpaceId -> Name -> AbstractName -> Scope -> Scope
- removeNameFromScope :: NameSpaceId -> Name -> Scope -> Scope
- addModuleToScope :: NameSpaceId -> Name -> AbstractModule -> Scope -> Scope
- type UsingOrHiding = Either Using [ImportedName]
- usingOrHiding :: ImportDirective -> UsingOrHiding
- applyImportDirective :: ImportDirective -> Scope -> Scope
- renameCanonicalNames :: Map QName QName -> Map ModuleName ModuleName -> Scope -> Scope
- restrictPrivate :: Scope -> Scope
- restrictLocalPrivate :: ModuleName -> Scope -> Scope
- removeOnlyQualified :: Scope -> Scope
- inScopeBecause :: (WhyInScope -> WhyInScope) -> Scope -> Scope
- publicModules :: ScopeInfo -> Map ModuleName Scope
- publicNames :: ScopeInfo -> Set AbstractName
- everythingInScope :: ScopeInfo -> NameSpace
- flattenScope :: [[Name]] -> ScopeInfo -> Map QName [AbstractName]
- concreteNamesInScope :: ScopeInfo -> Set QName
- scopeLookup :: InScope a => QName -> ScopeInfo -> [a]
- scopeLookup' :: forall a. InScope a => QName -> ScopeInfo -> [(a, Access)]
- data AllowAmbiguousNames
- isNameInScope :: QName -> ScopeInfo -> Bool
- inverseScopeLookup :: Either ModuleName QName -> ScopeInfo -> [QName]
- inverseScopeLookup' :: AllowAmbiguousNames -> Either ModuleName QName -> ScopeInfo -> [QName]
- recomputeInverseScopeMaps :: ScopeInfo -> ScopeInfo
- inverseScopeLookupName :: QName -> ScopeInfo -> [QName]
- inverseScopeLookupName' :: AllowAmbiguousNames -> QName -> ScopeInfo -> [QName]
- inverseScopeLookupModule :: ModuleName -> ScopeInfo -> [QName]
- prettyNameSpace :: NameSpace -> [Doc]
- blockOfLines :: Doc -> [Doc] -> [Doc]
Scope representation
A scope is a named collection of names partitioned into public and private names.
data NameSpaceId Source #
See Access
.
PrivateNS | Things not exported by this module. |
PublicNS | Things defined and exported by this module. |
ImportedNS | Things from open public, exported by this module. |
OnlyQualifiedNS | Visible (as qualified) from outside, but not exported when opening the module. Used for qualified constructors. |
type ScopeNameSpaces = [(NameSpaceId, NameSpace)] Source #
localNameSpace :: Access -> NameSpaceId Source #
nameSpaceAccess :: NameSpaceId -> Access Source #
scopeNameSpace :: NameSpaceId -> Scope -> NameSpace Source #
updateScopeNameSpaces :: (ScopeNameSpaces -> ScopeNameSpaces) -> Scope -> Scope Source #
A lens for scopeNameSpaces
updateScopeNameSpacesM :: Functor m => (ScopeNameSpaces -> m ScopeNameSpaces) -> Scope -> m Scope Source #
`Monadic'
lens (Functor sufficient).
The complete information about the scope at a particular program point includes the scope stack, the local variables, and the context precedence.
A local variable can be shadowed by an import. In case of reference to a shadowed variable, we want to report a scope error.
LocalVar | |
|
shadowLocal :: [AbstractName] -> LocalVar -> LocalVar Source #
Shadow a local name by a non-empty list of imports.
notShadowedLocals :: LocalVars -> AssocList Name Name Source #
Get all locals that are not shadowed by imports.
updateScopeLocals :: (LocalVars -> LocalVars) -> ScopeInfo -> ScopeInfo Source #
Lens for scopeLocals
.
Name spaces
A NameSpace
contains the mappings from concrete names that the user can
write to the abstract fully qualified names that the type checker wants to
read.
NameSpace | |
|
type ThingsInScope a = Map Name [a] Source #
type NamesInScope = ThingsInScope AbstractName Source #
type InScopeSet = Set QName Source #
data InScopeTag a where Source #
Set of types consisting of exactly AbstractName
and AbstractModule
.
A GADT just for some dependent-types trickery.
class Eq a => InScope a where Source #
Type class for some dependent-types trickery.
inScopeTag :: InScopeTag a Source #
inNameSpace :: forall a. InScope a => NameSpace -> ThingsInScope a Source #
inNameSpace
selects either the name map or the module name map from
a NameSpace
. What is selected is determined by result type
(using the dependent-type trickery).
Decorated names
data KindOfName Source #
For the sake of parsing left-hand sides, we distinguish constructor and record field names from defined names.
ConName | Constructor name. |
FldName | Record field name. |
DefName | Ordinary defined name. |
PatternSynName | Name of a pattern synonym. |
MacroName | Name of a macro |
QuotableName | A name that can only be quoted. |
allKindsOfNames :: [KindOfName] Source #
A list containing all name kinds.
data WhyInScope Source #
Where does a name come from?
This information is solely for reporting to the user,
see whyInScope
.
Defined | Defined in this module. |
Opened QName WhyInScope | Imported from another module. |
Applied QName WhyInScope | Imported by a module application. |
data AbstractName Source #
A decoration of QName
.
AbsName | |
|
data AbstractModule Source #
A decoration of abstract syntax module names.
AbsModule | |
|
lensAnameName :: Functor m => (QName -> m QName) -> AbstractName -> m AbstractName Source #
Van Laarhoven lens on anameName
.
lensAmodName :: Functor m => (ModuleName -> m ModuleName) -> AbstractModule -> m AbstractModule Source #
Van Laarhoven lens on amodName
.
Operations on name and module maps.
mergeNames :: Eq a => ThingsInScope a -> ThingsInScope a -> ThingsInScope a Source #
Operations on name spaces
emptyNameSpace :: NameSpace Source #
The empty name space.
mapNameSpace :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> NameSpace -> NameSpace Source #
Map functions over the names and modules in a name space.
zipNameSpace :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> NameSpace -> NameSpace -> NameSpace Source #
Zip together two name spaces.
mapNameSpaceM :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> NameSpace -> m NameSpace Source #
Map monadic function over a namespace.
General operations on scopes
emptyScope :: Scope Source #
The empty scope.
emptyScopeInfo :: ScopeInfo Source #
The empty scope info.
mapScope :: (NameSpaceId -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet) -> Scope -> Scope Source #
Map functions over the names and modules in a scope.
mapScope_ :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope Source #
Same as mapScope
but applies the same function to all name spaces.
mapScope' :: NameSpaceId -> (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope Source #
Same as mapScope
but applies the function only on the given name space.
mapScopeM :: Applicative m => (NameSpaceId -> NamesInScope -> m NamesInScope) -> (NameSpaceId -> ModulesInScope -> m ModulesInScope) -> (NameSpaceId -> InScopeSet -> m InScopeSet) -> Scope -> m Scope Source #
Map monadic functions over the names and modules in a scope.
mapScopeM_ :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> Scope -> m Scope Source #
Same as mapScopeM
but applies the same function to both the public and
private name spaces.
zipScope :: (NameSpaceId -> NamesInScope -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope Source #
Zip together two scopes. The resulting scope has the same name as the first scope.
zipScope_ :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope Source #
Same as zipScope
but applies the same function to both the public and
private name spaces.
recomputeInScopeSets :: Scope -> Scope Source #
Recompute the inScope sets of a scope.
filterScope :: (Name -> Bool) -> (Name -> Bool) -> Scope -> Scope Source #
Filter a scope keeping only concrete names matching the predicates. The first predicate is applied to the names and the second to the modules.
allNamesInScope :: InScope a => Scope -> ThingsInScope a Source #
Return all names in a scope.
allNamesInScope' :: InScope a => Scope -> ThingsInScope (a, Access) Source #
exportedNamesInScope :: InScope a => Scope -> ThingsInScope a Source #
Returns the scope's non-private names.
namesInScope :: InScope a => [NameSpaceId] -> Scope -> ThingsInScope a Source #
allThingsInScope :: Scope -> NameSpace Source #
thingsInScope :: [NameSpaceId] -> Scope -> NameSpace Source #
mergeScope :: Scope -> Scope -> Scope Source #
Merge two scopes. The result has the name of the first scope.
mergeScopes :: [Scope] -> Scope Source #
Merge a non-empty list of scopes. The result has the name of the first scope in the list.
Specific operations on scopes
setScopeAccess :: NameSpaceId -> Scope -> Scope Source #
Move all names in a scope to the given name space (except never move from Imported to Public).
setNameSpace :: NameSpaceId -> NameSpace -> Scope -> Scope Source #
Update a particular name space.
modifyNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> Scope -> Scope Source #
Modify a particular name space.
addNamesToScope :: NameSpaceId -> Name -> [AbstractName] -> Scope -> Scope Source #
Add names to a scope.
addNameToScope :: NameSpaceId -> Name -> AbstractName -> Scope -> Scope Source #
Add a name to a scope.
removeNameFromScope :: NameSpaceId -> Name -> Scope -> Scope Source #
Remove a name from a scope. Caution: does not update the nsInScope set. This is only used by rebindName and in that case we add the name right back (but with a different kind).
addModuleToScope :: NameSpaceId -> Name -> AbstractModule -> Scope -> Scope Source #
Add a module to a scope.
type UsingOrHiding = Either Using [ImportedName] Source #
applyImportDirective :: ImportDirective -> Scope -> Scope Source #
Apply an ImportDirective
to a scope.
renameCanonicalNames :: Map QName QName -> Map ModuleName ModuleName -> Scope -> Scope Source #
Rename the abstract names in a scope.
restrictPrivate :: Scope -> Scope Source #
Remove private name space of a scope.
Should be a right identity for exportedNamesInScope
.
exportedNamesInScope . restrictPrivate == exportedNamesInScope
.
restrictLocalPrivate :: ModuleName -> Scope -> Scope Source #
Remove private things from the given module from a scope.
removeOnlyQualified :: Scope -> Scope Source #
Remove names that can only be used qualified (when opening a scope)
inScopeBecause :: (WhyInScope -> WhyInScope) -> Scope -> Scope Source #
Add an explanation to why things are in scope.
publicModules :: ScopeInfo -> Map ModuleName Scope Source #
Get the public parts of the public modules of a scope
publicNames :: ScopeInfo -> Set AbstractName Source #
flattenScope :: [[Name]] -> ScopeInfo -> Map QName [AbstractName] Source #
Compute a flattened scope. Only include unqualified names or names qualified by modules in the first argument.
concreteNamesInScope :: ScopeInfo -> Set QName Source #
Get all concrete names in scope. Includes bound variables.
Inverse look-up
data AllowAmbiguousNames Source #
AmbiguousAnything | Used for instance arguments to check whether a name is in scope, but we do not care whether is is ambiguous |
AmbiguousConProjs | Ambiguous constructors or projections. |
AmbiguousNothing |
inverseScopeLookup :: Either ModuleName QName -> ScopeInfo -> [QName] Source #
Find the concrete names that map (uniquely) to a given abstract name. Sort by length, shortest first.
inverseScopeLookup' :: AllowAmbiguousNames -> Either ModuleName QName -> ScopeInfo -> [QName] Source #
inverseScopeLookupName :: QName -> ScopeInfo -> [QName] Source #
Find the concrete names that map (uniquely) to a given abstract qualified name. Sort by length, shortest first.
inverseScopeLookupName' :: AllowAmbiguousNames -> QName -> ScopeInfo -> [QName] Source #
inverseScopeLookupModule :: ModuleName -> ScopeInfo -> [QName] Source #
Find the concrete names that map (uniquely) to a given abstract module name. Sort by length, shortest first.
(Debug) printing
prettyNameSpace :: NameSpace -> [Doc] Source #