agda-unused-0.1.0: Check for unused code in an Agda project.
Safe HaskellNone
LanguageHaskell2010

Agda.Unused.Types.Context

Description

Definitions and interface for the Context and AccessContext types, which represent namespaces of definitions.

Synopsis

Definitions

data Item Source #

The data associated with a name in context. This includes:

  • Whether the name is a constructor, pattern synonym, or ordinary definition.
  • A list of ranges associated with the name, which includes the site of the original definition, as well as any relevant import or open statements.
  • Alternative syntax for the name, if any.

Instances

Instances details
Show Item Source # 
Instance details

Defined in Agda.Unused.Types.Context

Methods

showsPrec :: Int -> Item -> ShowS #

show :: Item -> String #

showList :: [Item] -> ShowS #

data Module Source #

The data associated with a module in context. This includes:

  • A list of ranges associated with the module, which includes the site of the original definition, as well as any relevant import or open statements.
  • The inner context of the module.

Constructors

Module ![Range] !Context 

Instances

Instances details
Show Module Source # 
Instance details

Defined in Agda.Unused.Types.Context

data AccessModule Source #

Like Module, but also recording whether the module is public or private.

Constructors

AccessModule !Access ![Range] !Context 

Instances

Instances details
Show AccessModule Source # 
Instance details

Defined in Agda.Unused.Types.Context

data Context Source #

A namespace of definitions. Any Agda module produces a Context.

Instances

Instances details
Show Context Source # 
Instance details

Defined in Agda.Unused.Types.Context

Semigroup Context Source #

Prefer values from second context.

Instance details

Defined in Agda.Unused.Types.Context

Monoid Context Source # 
Instance details

Defined in Agda.Unused.Types.Context

data AccessContext Source #

A namespace of definitions, which may be public or private. Any collection of Agda declarations produces an AccessContext, for example.

accessContextUnion :: AccessContext -> AccessContext -> AccessContext Source #

Like (<>), but public items take precedence over private items. This is important when combining contexts from successive declarations; for example:

module M where

  postulate
    A : Set

module N where

  postulate
    A : Set

  open M

x : N.A
x = ?

This code type-checks, and the identifier N.A refers to the postulate declared in the definition of N, not the definition opened from M.

Interface

Lookup

data LookupError where Source #

A description of failure for an AccessContext lookup.

Instances

Instances details
Show LookupError Source # 
Instance details

Defined in Agda.Unused.Types.Context

contextLookup :: QName -> Context -> Maybe [Range] Source #

Get the ranges for the given name, or Nothing if not in context.

contextLookupItem :: QName -> Context -> Maybe Item Source #

Get the item for the given name, or Nothing if not in context.

contextLookupModule :: QName -> Context -> Maybe Module Source #

Get the inner module for the given name, or Nothing if not in context.

accessContextLookup :: QName -> AccessContext -> Either LookupError [Range] Source #

Get the ranges for the given name, or produce a LookupError.

accessContextLookupModule :: QName -> AccessContext -> Either LookupError Module Source #

Get the inner module for the given name, or produce a LookupError.

accessContextLookupDefining :: QName -> AccessContext -> Either LookupError (Bool, [Range]) Source #

Like accessContextLookup, but also return a boolean indicating whether we are currently defining the referenced item.

accessContextLookupSpecial :: QName -> AccessContext -> Maybe Bool Source #

Determine whether a name represents a constructor or pattern synonym. Return Nothing if the name is not in context.

Insert

contextInsertRange :: Name -> Range -> Context -> Context Source #

Insert a range for the given name, if present.

contextInsertRangeModule :: Name -> Range -> Context -> Context Source #

Insert a range for all names in the given module, if present.

contextInsertRangeAll :: Range -> Context -> Context Source #

Insert a range for all names in a context.

accessContextInsertRangeAll :: Range -> AccessContext -> AccessContext Source #

Insert a range for all names in an access context.

Delete

contextDelete :: Name -> Context -> Context Source #

Delete an item from the context.

contextDeleteModule :: Name -> Context -> Context Source #

Delete a module from the context.

Rename

contextRename :: Name -> Name -> Context -> Context Source #

Rename an item, if present.

contextRenameModule :: Name -> Name -> Context -> Context Source #

Rename a module, if present.

Define

accessContextDefine :: Name -> AccessContext -> AccessContext Source #

Mark an existing name as in process of being defined.

Ranges

moduleRanges :: Module -> [Range] Source #

Get all ranges associated with names in the given module, including ranges associated with the module itself.

contextRanges :: Context -> [Range] Source #

Get all ranges associated with names in the given context.

Match

accessContextMatch :: [String] -> AccessContext -> [Name] Source #

Find all operators matching the given list of tokens.

Construction

item :: [Range] -> Maybe Name -> Item Source #

Construct an Item representing an ordinary definition.

itemPattern :: [Range] -> Maybe Name -> Item Source #

Construct an Item representing a pattern synonym.

itemConstructor :: [Range] -> Maybe Name -> Item Source #

Construct an Item representing a constructor.

contextItem :: Name -> Item -> Context Source #

Construct a Context with a single item.

contextModule :: Name -> Module -> Context Source #

Construct a Context with a single module.

accessContextItem :: Name -> Access -> Item -> AccessContext Source #

Construct an AccessContext with a single item, along with the relevant syntax item if applicable.

accessContextModule :: Name -> AccessModule -> AccessContext Source #

Construct an AccessContext with a single access module.

accessContextModule' :: Name -> Access -> [Range] -> AccessContext -> AccessContext Source #

Like accessContextModule, but taking an access context. We convert the given access context to an ordinary context using toContext:

accessContextModule' n a rs c
  = accessContextModule n (AccessModule a rs (toContext c))

accessContextImport :: QName -> Context -> AccessContext Source #

Construct an access context with a single import.

Conversion

fromContext :: Access -> Context -> AccessContext Source #

Convert a Context to AccessContext. Give all items the given access.

toContext :: AccessContext -> Context Source #

Convert an AccessContext to Context. Discard private items and imports.