ghc-8.2.2: The GHC API

Safe Haskell | None
Language | Haskell2010

SrcLoc

Contents

- SrcLoc
  - Constructing SrcLoc
  - Unsafely deconstructing SrcLoc
- SrcSpan
  - Constructing SrcSpan
  - Deconstructing SrcSpan
  - Unsafely deconstructing SrcSpan
  - Predicates on SrcSpan
- Located
  - Constructing Located
  - Deconstructing Located
  - Combining and comparing Located values

Description

This module contains types that relate to the positions of things in source files, and allow tagging of those things with locations

Synopsis

- data RealSrcLoc
- data SrcLoc
  - = RealSrcLoc !RealSrcLoc
  - | UnhelpfulLoc FastString
- mkSrcLoc :: FastString -> Int -> Int -> SrcLoc
- mkRealSrcLoc :: FastString -> Int -> Int -> RealSrcLoc
- mkGeneralSrcLoc :: FastString -> SrcLoc
- noSrcLoc :: SrcLoc
- generatedSrcLoc :: SrcLoc
- interactiveSrcLoc :: SrcLoc
- advanceSrcLoc :: RealSrcLoc -> Char -> RealSrcLoc
- srcLocFile :: RealSrcLoc -> FastString
- srcLocLine :: RealSrcLoc -> Int
- srcLocCol :: RealSrcLoc -> Int
- data RealSrcSpan
- data SrcSpan
  - = RealSrcSpan !RealSrcSpan
  - | UnhelpfulSpan !FastString
- mkGeneralSrcSpan :: FastString -> SrcSpan
- mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan
- mkRealSrcSpan :: RealSrcLoc -> RealSrcLoc -> RealSrcSpan
- noSrcSpan :: SrcSpan
- wiredInSrcSpan :: SrcSpan
- interactiveSrcSpan :: SrcSpan
- srcLocSpan :: SrcLoc -> SrcSpan
- realSrcLocSpan :: RealSrcLoc -> RealSrcSpan
- combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
- srcSpanFirstCharacter :: SrcSpan -> SrcSpan
- srcSpanStart :: SrcSpan -> SrcLoc
- srcSpanEnd :: SrcSpan -> SrcLoc
- realSrcSpanStart :: RealSrcSpan -> RealSrcLoc
- realSrcSpanEnd :: RealSrcSpan -> RealSrcLoc
- srcSpanFileName_maybe :: SrcSpan -> Maybe FastString
- pprUserRealSpan :: Bool -> RealSrcSpan -> SDoc
- srcSpanFile :: RealSrcSpan -> FastString
- srcSpanStartLine :: RealSrcSpan -> Int
- srcSpanEndLine :: RealSrcSpan -> Int
- srcSpanStartCol :: RealSrcSpan -> Int
- srcSpanEndCol :: RealSrcSpan -> Int
- isGoodSrcSpan :: SrcSpan -> Bool
- isOneLineSpan :: SrcSpan -> Bool
- containsSpan :: RealSrcSpan -> RealSrcSpan -> Bool
- type Located e = GenLocated SrcSpan e
- type RealLocated e = GenLocated RealSrcSpan e
- data GenLocated l e = L l e
- noLoc :: e -> Located e
- mkGeneralLocated :: String -> e -> Located e
- getLoc :: GenLocated l e -> l
- unLoc :: GenLocated l e -> e
- eqLocated :: Eq a => Located a -> Located a -> Bool
- cmpLocated :: Ord a => Located a -> Located a -> Ordering
- combineLocs :: Located a -> Located b -> SrcSpan
- addCLoc :: Located a -> Located b -> c -> Located c
- leftmost_smallest :: SrcSpan -> SrcSpan -> Ordering
- leftmost_largest :: SrcSpan -> SrcSpan -> Ordering
- rightmost :: SrcSpan -> SrcSpan -> Ordering
- spans :: SrcSpan -> (Int, Int) -> Bool
- isSubspanOf :: SrcSpan -> SrcSpan -> Bool
- sortLocated :: [Located a] -> [Located a]

# SrcLoc

data RealSrcLoc Source #

Real Source Location

Represents a single point within a file

Instances

Eq RealSrcLoc # |
Methods (==) :: RealSrcLoc -> RealSrcLoc -> Bool # (/=) :: RealSrcLoc -> RealSrcLoc -> Bool #
Ord RealSrcLoc # |
Methods compare :: RealSrcLoc -> RealSrcLoc -> Ordering # (<) :: RealSrcLoc -> RealSrcLoc -> Bool # (<=) :: RealSrcLoc -> RealSrcLoc -> Bool # (>) :: RealSrcLoc -> RealSrcLoc -> Bool # (>=) :: RealSrcLoc -> RealSrcLoc -> Bool # max :: RealSrcLoc -> RealSrcLoc -> RealSrcLoc # min :: RealSrcLoc -> RealSrcLoc -> RealSrcLoc #
Show RealSrcLoc # |
Methods showsPrec :: Int -> RealSrcLoc -> ShowS Source # show :: RealSrcLoc -> String Source # showList :: [RealSrcLoc] -> ShowS Source #
Outputable RealSrcLoc # |
Methods ppr :: RealSrcLoc -> SDoc Source # pprPrec :: Rational -> RealSrcLoc -> SDoc Source #

data SrcLoc Source #

Source Location

Constructors

RealSrcLoc !RealSrcLoc |
UnhelpfulLoc FastString |

Instances

Eq SrcLoc # |
Methods (==) :: SrcLoc -> SrcLoc -> Bool # (/=) :: SrcLoc -> SrcLoc -> Bool #
Ord SrcLoc # |
Methods compare :: SrcLoc -> SrcLoc -> Ordering # (<) :: SrcLoc -> SrcLoc -> Bool # (<=) :: SrcLoc -> SrcLoc -> Bool # (>) :: SrcLoc -> SrcLoc -> Bool # (>=) :: SrcLoc -> SrcLoc -> Bool # max :: SrcLoc -> SrcLoc -> SrcLoc # min :: SrcLoc -> SrcLoc -> SrcLoc #
Show SrcLoc # |
Methods showsPrec :: Int -> SrcLoc -> ShowS Source # show :: SrcLoc -> String Source # showList :: [SrcLoc] -> ShowS Source #
Outputable SrcLoc # |
Methods ppr :: SrcLoc -> SDoc Source # pprPrec :: Rational -> SrcLoc -> SDoc Source #

## Constructing SrcLoc

mkSrcLoc :: FastString -> Int -> Int -> SrcLoc Source #

mkRealSrcLoc :: FastString -> Int -> Int -> RealSrcLoc Source #

mkGeneralSrcLoc :: FastString -> SrcLoc Source #

Creates a "bad" `SrcLoc` that has no detailed information about its location

noSrcLoc :: SrcLoc Source #

Built-in "bad" `SrcLoc` values for particular locations

generatedSrcLoc :: SrcLoc Source #

Built-in "bad" `SrcLoc` values for particular locations

interactiveSrcLoc :: SrcLoc Source #

Built-in "bad" `SrcLoc` values for particular locations

advanceSrcLoc :: RealSrcLoc -> Char -> RealSrcLoc Source #

Move the `SrcLoc` down by one line if the character is a newline, to the next 8-char tabstop if it is a tab, and across by one character in any other case

## Unsafely deconstructing SrcLoc

srcLocFile :: RealSrcLoc -> FastString Source #

Gives the filename of the `RealSrcLoc`

srcLocLine :: RealSrcLoc -> Int Source #

Raises an error when used on a "bad" `SrcLoc`

srcLocCol :: RealSrcLoc -> Int Source #

Raises an error when used on a "bad" `SrcLoc`

# SrcSpan

data RealSrcSpan Source #

A `RealSrcSpan` delimits a portion of a text file. It could be represented by a pair of (line,column) coordinates, but in fact we optimise slightly by using more compact representations for single-line and zero-length spans, both of which are quite common.

The end position is defined to be the column after the end of the span. That is, a span of (1,1)-(1,2) is one character long, and a span of (1,1)-(1,1) is zero characters long.

Real Source Span

Instances

Eq RealSrcSpan # |
Methods (==) :: RealSrcSpan -> RealSrcSpan -> Bool # (/=) :: RealSrcSpan -> RealSrcSpan -> Bool #
Data RealSrcSpan # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RealSrcSpan -> c RealSrcSpan Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RealSrcSpan Source # toConstr :: RealSrcSpan -> Constr Source # dataTypeOf :: RealSrcSpan -> DataType Source # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c RealSrcSpan) Source # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RealSrcSpan) Source # gmapT :: (forall b. Data b => b -> b) -> RealSrcSpan -> RealSrcSpan Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RealSrcSpan -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RealSrcSpan -> r Source # gmapQ :: (forall d. Data d => d -> u) -> RealSrcSpan -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> RealSrcSpan -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RealSrcSpan -> m RealSrcSpan Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RealSrcSpan -> m RealSrcSpan Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RealSrcSpan -> m RealSrcSpan Source #
Ord RealSrcSpan # |
Methods compare :: RealSrcSpan -> RealSrcSpan -> Ordering # (<) :: RealSrcSpan -> RealSrcSpan -> Bool # (<=) :: RealSrcSpan -> RealSrcSpan -> Bool # (>) :: RealSrcSpan -> RealSrcSpan -> Bool # (>=) :: RealSrcSpan -> RealSrcSpan -> Bool # max :: RealSrcSpan -> RealSrcSpan -> RealSrcSpan # min :: RealSrcSpan -> RealSrcSpan -> RealSrcSpan #
Show RealSrcSpan # |
Methods showsPrec :: Int -> RealSrcSpan -> ShowS Source # show :: RealSrcSpan -> String Source # showList :: [RealSrcSpan] -> ShowS Source #
Outputable RealSrcSpan # |
Methods ppr :: RealSrcSpan -> SDoc Source # pprPrec :: Rational -> RealSrcSpan -> SDoc Source #
ToJson RealSrcSpan # |
Methods json :: RealSrcSpan -> JsonDoc Source #

data SrcSpan Source #

Source Span

A `SrcSpan` identifies either a specific portion of a text file or a human-readable description of a location.

Constructors

RealSrcSpan !RealSrcSpan |
UnhelpfulSpan !FastString |

Instances

Eq SrcSpan # |
Methods (==) :: SrcSpan -> SrcSpan -> Bool # (/=) :: SrcSpan -> SrcSpan -> Bool #
Data SrcSpan # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SrcSpan -> c SrcSpan Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SrcSpan Source # toConstr :: SrcSpan -> Constr Source # dataTypeOf :: SrcSpan -> DataType Source # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SrcSpan) Source # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan) Source # gmapT :: (forall b. Data b => b -> b) -> SrcSpan -> SrcSpan Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r Source # gmapQ :: (forall d. Data d => d -> u) -> SrcSpan -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcSpan -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source #
Ord SrcSpan # |
Methods compare :: SrcSpan -> SrcSpan -> Ordering # (<) :: SrcSpan -> SrcSpan -> Bool # (<=) :: SrcSpan -> SrcSpan -> Bool # (>) :: SrcSpan -> SrcSpan -> Bool # (>=) :: SrcSpan -> SrcSpan -> Bool # max :: SrcSpan -> SrcSpan -> SrcSpan # min :: SrcSpan -> SrcSpan -> SrcSpan #
Show SrcSpan # |
Methods showsPrec :: Int -> SrcSpan -> ShowS Source # show :: SrcSpan -> String Source # showList :: [SrcSpan] -> ShowS Source #
NFData SrcSpan # |
Methods rnf :: SrcSpan -> () Source #
Outputable SrcSpan # |
Methods ppr :: SrcSpan -> SDoc Source # pprPrec :: Rational -> SrcSpan -> SDoc Source #
ToJson SrcSpan # |
Methods json :: SrcSpan -> JsonDoc Source #
Binary SrcSpan # |
Methods put_ :: BinHandle -> SrcSpan -> IO () Source # put :: BinHandle -> SrcSpan -> IO (Bin * SrcSpan) Source # get :: BinHandle -> IO SrcSpan Source #
Binary a => Binary (GenLocated SrcSpan a) # |
Methods put_ :: BinHandle -> GenLocated SrcSpan a -> IO () Source # put :: BinHandle -> GenLocated SrcSpan a -> IO (Bin * (GenLocated SrcSpan a)) Source # get :: BinHandle -> IO (GenLocated SrcSpan a) Source #

## Constructing SrcSpan

mkGeneralSrcSpan :: FastString -> SrcSpan Source #

Create a "bad" `SrcSpan` that has not location information

mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan Source #

Create a `SrcSpan` between two points in a file

mkRealSrcSpan :: RealSrcLoc -> RealSrcLoc -> RealSrcSpan Source #

Create a `SrcSpan` between two points in a file

noSrcSpan :: SrcSpan Source #

Built-in "bad" `SrcSpan`s for common sources of location uncertainty

wiredInSrcSpan :: SrcSpan Source #

Built-in "bad" `SrcSpan`s for common sources of location uncertainty

interactiveSrcSpan :: SrcSpan Source #

Built-in "bad" `SrcSpan`s for common sources of location uncertainty

srcLocSpan :: SrcLoc -> SrcSpan Source #

Create a `SrcSpan` corresponding to a single point

realSrcLocSpan :: RealSrcLoc -> RealSrcSpan Source #

combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan Source #

Combines two `SrcSpan` into one that spans at least all the characters within both spans. Assumes the "file" part is the same in both inputs

srcSpanFirstCharacter :: SrcSpan -> SrcSpan Source #

Convert a SrcSpan into one that represents only its first character

## Deconstructing SrcSpan

srcSpanStart :: SrcSpan -> SrcLoc Source #

Returns the location at the start of the `SrcSpan` or a "bad" `SrcSpan` if that is unavailable

srcSpanEnd :: SrcSpan -> SrcLoc Source #

Returns the location at the end of the `SrcSpan` or a "bad" `SrcSpan` if that is unavailable

realSrcSpanStart :: RealSrcSpan -> RealSrcLoc Source #

realSrcSpanEnd :: RealSrcSpan -> RealSrcLoc Source #

srcSpanFileName_maybe :: SrcSpan -> Maybe FastString Source #

Obtains the filename for a `SrcSpan` if it is "good"

pprUserRealSpan :: Bool -> RealSrcSpan -> SDoc Source #

## Unsafely deconstructing SrcSpan

srcSpanFile :: RealSrcSpan -> FastString Source #

srcSpanStartLine :: RealSrcSpan -> Int Source #

srcSpanEndLine :: RealSrcSpan -> Int Source #

srcSpanStartCol :: RealSrcSpan -> Int Source #

srcSpanEndCol :: RealSrcSpan -> Int Source #

## Predicates on SrcSpan

isGoodSrcSpan :: SrcSpan -> Bool Source #

Test if a `SrcSpan` is "good", i.e. has precise location information

isOneLineSpan :: SrcSpan -> Bool Source #

True if the span is known to straddle only one line. For "bad" `SrcSpan`, it returns False

containsSpan :: RealSrcSpan -> RealSrcSpan -> Bool Source #

Tests whether the first span "contains" the other span, meaning that it covers at least as much source code. True where spans are equal.

# Located

type Located e = GenLocated SrcSpan e Source #

type RealLocated e = GenLocated RealSrcSpan e Source #

data GenLocated l e Source #

We attach SrcSpans to lots of things, so let's have a datatype for it.

Constructors

L l e |

Instances

Functor (GenLocated l) # |
Methods fmap :: (a -> b) -> GenLocated l a -> GenLocated l b Source # (<$) :: a -> GenLocated l b -> GenLocated l a Source #
Foldable (GenLocated l) # |
Methods fold :: Monoid m => GenLocated l m -> m Source # foldMap :: Monoid m => (a -> m) -> GenLocated l a -> m Source # foldr :: (a -> b -> b) -> b -> GenLocated l a -> b Source # foldr' :: (a -> b -> b) -> b -> GenLocated l a -> b Source # foldl :: (b -> a -> b) -> b -> GenLocated l a -> b Source # foldl' :: (b -> a -> b) -> b -> GenLocated l a -> b Source # foldr1 :: (a -> a -> a) -> GenLocated l a -> a Source # foldl1 :: (a -> a -> a) -> GenLocated l a -> a Source # toList :: GenLocated l a -> [a] Source # null :: GenLocated l a -> Bool Source # length :: GenLocated l a -> Int Source # elem :: Eq a => a -> GenLocated l a -> Bool Source # maximum :: Ord a => GenLocated l a -> a Source # minimum :: Ord a => GenLocated l a -> a Source # sum :: Num a => GenLocated l a -> a Source # product :: Num a => GenLocated l a -> a Source #
Traversable (GenLocated l) # |
Methods traverse :: Applicative f => (a -> f b) -> GenLocated l a -> f (GenLocated l b) Source # sequenceA :: Applicative f => GenLocated l (f a) -> f (GenLocated l a) Source # mapM :: Monad m => (a -> m b) -> GenLocated l a -> m (GenLocated l b) Source # sequence :: Monad m => GenLocated l (m a) -> m (GenLocated l a) Source #
(Eq e, Eq l) => Eq (GenLocated l e) # |
Methods (==) :: GenLocated l e -> GenLocated l e -> Bool # (/=) :: GenLocated l e -> GenLocated l e -> Bool #
(Data e, Data l) => Data (GenLocated l e) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GenLocated l e -> c (GenLocated l e) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (GenLocated l e) Source # toConstr :: GenLocated l e -> Constr Source # dataTypeOf :: GenLocated l e -> DataType Source # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (GenLocated l e)) Source # dataCast2 :: Typeable (* -> * -> *) t => (forall d a. (Data d, Data a) => c (t d a)) -> Maybe (c (GenLocated l e)) Source # gmapT :: (forall b. Data b => b -> b) -> GenLocated l e -> GenLocated l e Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GenLocated l e -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GenLocated l e -> r Source # gmapQ :: (forall d. Data d => d -> u) -> GenLocated l e -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> GenLocated l e -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> GenLocated l e -> m (GenLocated l e) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GenLocated l e -> m (GenLocated l e) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GenLocated l e -> m (GenLocated l e) Source #
(Ord e, Ord l) => Ord (GenLocated l e) # |
Methods compare :: GenLocated l e -> GenLocated l e -> Ordering # (<) :: GenLocated l e -> GenLocated l e -> Bool # (<=) :: GenLocated l e -> GenLocated l e -> Bool # (>) :: GenLocated l e -> GenLocated l e -> Bool # (>=) :: GenLocated l e -> GenLocated l e -> Bool # max :: GenLocated l e -> GenLocated l e -> GenLocated l e # min :: GenLocated l e -> GenLocated l e -> GenLocated l e #
(Outputable l, Outputable e) => Outputable (GenLocated l e) # |
Methods ppr :: GenLocated l e -> SDoc Source # pprPrec :: Rational -> GenLocated l e -> SDoc Source #
Binary a => Binary (GenLocated SrcSpan a) # |
Methods put_ :: BinHandle -> GenLocated SrcSpan a -> IO () Source # put :: BinHandle -> GenLocated SrcSpan a -> IO (Bin * (GenLocated SrcSpan a)) Source # get :: BinHandle -> IO (GenLocated SrcSpan a) Source #
NamedThing e => NamedThing (GenLocated l e) # |
Methods getOccName :: GenLocated l e -> OccName Source # getName :: GenLocated l e -> Name Source #

## Constructing Located

noLoc :: e -> Located e Source #

mkGeneralLocated :: String -> e -> Located e Source #

## Deconstructing Located

getLoc :: GenLocated l e -> l Source #

unLoc :: GenLocated l e -> e Source #

## Combining and comparing Located values

eqLocated :: Eq a => Located a -> Located a -> Bool Source #

Tests whether the two located things are equal

cmpLocated :: Ord a => Located a -> Located a -> Ordering Source #

Tests the ordering of the two located things

combineLocs :: Located a -> Located b -> SrcSpan Source #

addCLoc :: Located a -> Located b -> c -> Located c Source #

Combine locations from two `Located` things and add them to a third thing

leftmost_smallest :: SrcSpan -> SrcSpan -> Ordering Source #

Alternative strategies for ordering `SrcSpan`s

leftmost_largest :: SrcSpan -> SrcSpan -> Ordering Source #

Alternative strategies for ordering `SrcSpan`s

rightmost :: SrcSpan -> SrcSpan -> Ordering Source #

Alternative strategies for ordering `SrcSpan`s

spans :: SrcSpan -> (Int, Int) -> Bool Source #

Determines whether a span encloses a given line and column index

isSubspanOf Source #

Arguments

:: SrcSpan | The span that may be enclosed by the other
-> SrcSpan | The span it may be enclosed by
-> Bool |

Determines whether a span is enclosed by another one

sortLocated :: [Located a] -> [Located a] Source #