{-# LANGUAGE DeriveDataTypeable #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Language.C.Data.Position
-- Copyright   :  (c) [1995..2000] Manuel M. T. Chakravarty
--                    [2008..2009] Benedikt Huber
-- License     :  BSD-style
-- Maintainer  :  benedikt.huber@gmail.com
-- Stability   :  experimental
-- Portability :  ghc
--
-- Source code position
-----------------------------------------------------------------------------
module Language.C.Data.Position (
  --
  -- source text positions
  --
  Position(),
  position,
  PosLength,
  posFile,posRow,posColumn,posOffset,posParent,
  initPos, isSourcePos,
  nopos, isNoPos,
  builtinPos, isBuiltinPos,
  internalPos, isInternalPos,
  incPos, retPos,
  incOffset,
  Pos(..),
) where
import Data.Generics hiding (Generic)
import GHC.Generics (Generic)
import Control.DeepSeq (NFData)

-- | file position information
data FilePosition = FilePosition { FilePosition -> String
posSrcFile    :: String,            -- ^ source file
                                   FilePosition -> Maybe Position
posParentFile :: (Maybe Position)   -- ^ including file, if any
                                 }
                    deriving (FilePosition -> FilePosition -> Bool
(FilePosition -> FilePosition -> Bool)
-> (FilePosition -> FilePosition -> Bool) -> Eq FilePosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilePosition -> FilePosition -> Bool
$c/= :: FilePosition -> FilePosition -> Bool
== :: FilePosition -> FilePosition -> Bool
$c== :: FilePosition -> FilePosition -> Bool
Eq, Eq FilePosition
Eq FilePosition =>
(FilePosition -> FilePosition -> Ordering)
-> (FilePosition -> FilePosition -> Bool)
-> (FilePosition -> FilePosition -> Bool)
-> (FilePosition -> FilePosition -> Bool)
-> (FilePosition -> FilePosition -> Bool)
-> (FilePosition -> FilePosition -> FilePosition)
-> (FilePosition -> FilePosition -> FilePosition)
-> Ord FilePosition
FilePosition -> FilePosition -> Bool
FilePosition -> FilePosition -> Ordering
FilePosition -> FilePosition -> FilePosition
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FilePosition -> FilePosition -> FilePosition
$cmin :: FilePosition -> FilePosition -> FilePosition
max :: FilePosition -> FilePosition -> FilePosition
$cmax :: FilePosition -> FilePosition -> FilePosition
>= :: FilePosition -> FilePosition -> Bool
$c>= :: FilePosition -> FilePosition -> Bool
> :: FilePosition -> FilePosition -> Bool
$c> :: FilePosition -> FilePosition -> Bool
<= :: FilePosition -> FilePosition -> Bool
$c<= :: FilePosition -> FilePosition -> Bool
< :: FilePosition -> FilePosition -> Bool
$c< :: FilePosition -> FilePosition -> Bool
compare :: FilePosition -> FilePosition -> Ordering
$ccompare :: FilePosition -> FilePosition -> Ordering
$cp1Ord :: Eq FilePosition
Ord, Typeable, Typeable FilePosition
DataType
Constr
Typeable FilePosition =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> FilePosition -> c FilePosition)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FilePosition)
-> (FilePosition -> Constr)
-> (FilePosition -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FilePosition))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c FilePosition))
-> ((forall b. Data b => b -> b) -> FilePosition -> FilePosition)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FilePosition -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FilePosition -> r)
-> (forall u. (forall d. Data d => d -> u) -> FilePosition -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FilePosition -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition)
-> Data FilePosition
FilePosition -> DataType
FilePosition -> Constr
(forall b. Data b => b -> b) -> FilePosition -> FilePosition
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FilePosition -> c FilePosition
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FilePosition
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FilePosition -> u
forall u. (forall d. Data d => d -> u) -> FilePosition -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FilePosition
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FilePosition -> c FilePosition
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FilePosition)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FilePosition)
$cFilePosition :: Constr
$tFilePosition :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
gmapMp :: (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
gmapM :: (forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FilePosition -> m FilePosition
gmapQi :: Int -> (forall d. Data d => d -> u) -> FilePosition -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FilePosition -> u
gmapQ :: (forall d. Data d => d -> u) -> FilePosition -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FilePosition -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FilePosition -> r
gmapT :: (forall b. Data b => b -> b) -> FilePosition -> FilePosition
$cgmapT :: (forall b. Data b => b -> b) -> FilePosition -> FilePosition
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FilePosition)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FilePosition)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c FilePosition)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FilePosition)
dataTypeOf :: FilePosition -> DataType
$cdataTypeOf :: FilePosition -> DataType
toConstr :: FilePosition -> Constr
$ctoConstr :: FilePosition -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FilePosition
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FilePosition
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FilePosition -> c FilePosition
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FilePosition -> c FilePosition
$cp1Data :: Typeable FilePosition
Data, (forall x. FilePosition -> Rep FilePosition x)
-> (forall x. Rep FilePosition x -> FilePosition)
-> Generic FilePosition
forall x. Rep FilePosition x -> FilePosition
forall x. FilePosition -> Rep FilePosition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilePosition x -> FilePosition
$cfrom :: forall x. FilePosition -> Rep FilePosition x
Generic)

instance NFData FilePosition

-- | uniform representation of source file positions
data Position = Position { Position -> Int
posOffset :: {-# UNPACK #-} !Int  -- ^ absolute offset in the preprocessed file
                         , Position -> Int
posRow :: {-# UNPACK #-} !Int     -- ^ row (line)  in the original file. Affected by #LINE pragmas.
                         , Position -> Int
posColumn :: {-# UNPACK #-} !Int  -- ^ column in the preprocessed file. Inaccurate w.r.t. to the original
                                                             --   file in the presence of preprocessor macros.
                         , Position -> FilePosition
posFileInfo :: FilePosition       -- ^ position in source file, including files
                         }
              | NoPosition
              | BuiltinPosition
              | InternalPosition
                deriving (Position -> Position -> Bool
(Position -> Position -> Bool)
-> (Position -> Position -> Bool) -> Eq Position
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Position -> Position -> Bool
$c/= :: Position -> Position -> Bool
== :: Position -> Position -> Bool
$c== :: Position -> Position -> Bool
Eq, Eq Position
Eq Position =>
(Position -> Position -> Ordering)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Position)
-> (Position -> Position -> Position)
-> Ord Position
Position -> Position -> Bool
Position -> Position -> Ordering
Position -> Position -> Position
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Position -> Position -> Position
$cmin :: Position -> Position -> Position
max :: Position -> Position -> Position
$cmax :: Position -> Position -> Position
>= :: Position -> Position -> Bool
$c>= :: Position -> Position -> Bool
> :: Position -> Position -> Bool
$c> :: Position -> Position -> Bool
<= :: Position -> Position -> Bool
$c<= :: Position -> Position -> Bool
< :: Position -> Position -> Bool
$c< :: Position -> Position -> Bool
compare :: Position -> Position -> Ordering
$ccompare :: Position -> Position -> Ordering
$cp1Ord :: Eq Position
Ord, Typeable, Typeable Position
DataType
Constr
Typeable Position =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Position -> c Position)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Position)
-> (Position -> Constr)
-> (Position -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Position))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Position))
-> ((forall b. Data b => b -> b) -> Position -> Position)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Position -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Position -> r)
-> (forall u. (forall d. Data d => d -> u) -> Position -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Position -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Position -> m Position)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Position -> m Position)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Position -> m Position)
-> Data Position
Position -> DataType
Position -> Constr
(forall b. Data b => b -> b) -> Position -> Position
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Position -> c Position
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Position
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Position -> u
forall u. (forall d. Data d => d -> u) -> Position -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Position -> m Position
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Position -> m Position
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Position
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Position -> c Position
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Position)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Position)
$cInternalPosition :: Constr
$cBuiltinPosition :: Constr
$cNoPosition :: Constr
$cPosition :: Constr
$tPosition :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Position -> m Position
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Position -> m Position
gmapMp :: (forall d. Data d => d -> m d) -> Position -> m Position
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Position -> m Position
gmapM :: (forall d. Data d => d -> m d) -> Position -> m Position
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Position -> m Position
gmapQi :: Int -> (forall d. Data d => d -> u) -> Position -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Position -> u
gmapQ :: (forall d. Data d => d -> u) -> Position -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Position -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Position -> r
gmapT :: (forall b. Data b => b -> b) -> Position -> Position
$cgmapT :: (forall b. Data b => b -> b) -> Position -> Position
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Position)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Position)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Position)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Position)
dataTypeOf :: Position -> DataType
$cdataTypeOf :: Position -> DataType
toConstr :: Position -> Constr
$ctoConstr :: Position -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Position
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Position
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Position -> c Position
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Position -> c Position
$cp1Data :: Typeable Position
Data, (forall x. Position -> Rep Position x)
-> (forall x. Rep Position x -> Position) -> Generic Position
forall x. Rep Position x -> Position
forall x. Position -> Rep Position x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Position x -> Position
$cfrom :: forall x. Position -> Rep Position x
Generic)

instance NFData Position

posFile :: Position -> String
posFile :: Position -> String
posFile = FilePosition -> String
posSrcFile (FilePosition -> String)
-> (Position -> FilePosition) -> Position -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Position -> FilePosition
posFileInfo

posParent :: Position -> (Maybe Position)
posParent :: Position -> Maybe Position
posParent = FilePosition -> Maybe Position
posParentFile (FilePosition -> Maybe Position)
-> (Position -> FilePosition) -> Position -> Maybe Position
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Position -> FilePosition
posFileInfo

-- | Position and length of a token
type PosLength = (Position,Int)

instance Show Position where
  showsPrec :: Int -> Position -> ShowS
showsPrec _ (Position _ row :: Int
row _ (FilePosition fname :: String
fname mparent :: Maybe Position
mparent)) =
    String -> ShowS
showString "(" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec 0 String
fname ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString ": line " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec 0 Int
row ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    ShowS -> (Position -> ShowS) -> Maybe Position -> ShowS
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ShowS
forall a. a -> a
id (\p :: Position
p -> String -> ShowS
showString ", in file included from " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Position -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec 0 Position
p) Maybe Position
mparent ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    String -> ShowS
showString ")"
  showsPrec _  NoPosition                     = String -> ShowS
showString "<no file>"
  showsPrec _  BuiltinPosition                = String -> ShowS
showString "<builtin>"
  showsPrec _ InternalPosition                = String -> ShowS
showString "<internal>"

-- | @position absoluteOffset fileName lineNumber columnNumber@ initializes a @Position@ using the given arguments
position :: Int -> String -> Int -> Int -> Maybe Position -> Position
position :: Int -> String -> Int -> Int -> Maybe Position -> Position
position offset :: Int
offset fname :: String
fname row :: Int
row col :: Int
col mparent :: Maybe Position
mparent = Int -> Int -> Int -> FilePosition -> Position
Position Int
offset Int
row Int
col (String -> Maybe Position -> FilePosition
FilePosition String
fname Maybe Position
mparent)

-- | class of type which aggregate a source code location
class Pos a where
    posOf :: a -> Position

-- | initialize a Position to the start of the translation unit starting in the given file
initPos :: FilePath -> Position
initPos :: String -> Position
initPos file :: String
file = Int -> Int -> Int -> FilePosition -> Position
Position 0 1 1 (String -> Maybe Position -> FilePosition
FilePosition String
file Maybe Position
forall a. Maybe a
Nothing)

-- | returns @True@ if the given position refers to an actual source file
isSourcePos :: Position -> Bool
isSourcePos :: Position -> Bool
isSourcePos (Position _ _ _ _) = Bool
True
isSourcePos _                  = Bool
False

-- | no position (for unknown position information)
nopos :: Position
nopos :: Position
nopos  = Position
NoPosition

-- | returns @True@ if the there is no position information available
isNoPos :: Position -> Bool
isNoPos :: Position -> Bool
isNoPos NoPosition = Bool
True
isNoPos _          = Bool
False

-- | position attached to built-in objects
--
builtinPos :: Position
builtinPos :: Position
builtinPos  = Position
BuiltinPosition

-- | returns @True@ if the given position refers to a builtin definition
isBuiltinPos :: Position -> Bool
isBuiltinPos :: Position -> Bool
isBuiltinPos BuiltinPosition = Bool
True
isBuiltinPos _               = Bool
False

-- | position used for internal errors
internalPos :: Position
internalPos :: Position
internalPos = Position
InternalPosition

-- | returns @True@ if the given position is internal
isInternalPos :: Position -> Bool
isInternalPos :: Position -> Bool
isInternalPos InternalPosition = Bool
True
isInternalPos _                = Bool
False

{-# INLINE incPos #-}
-- | advance column
incPos :: Position -> Int -> Position
incPos :: Position -> Int -> Position
incPos (Position offs :: Int
offs row :: Int
row col :: Int
col fpos :: FilePosition
fpos) n :: Int
n = Int -> Int -> Int -> FilePosition -> Position
Position (Int
offs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) Int
row (Int
col Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) FilePosition
fpos
incPos p :: Position
p _                             = Position
p

{-# INLINE retPos #-}
-- | advance to next line
retPos :: Position -> Position
retPos :: Position -> Position
retPos (Position offs :: Int
offs row :: Int
row _ fpos :: FilePosition
fpos) = Int -> Int -> Int -> FilePosition -> Position
Position (Int
offsInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) (Int
row Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1) 1 FilePosition
fpos
retPos p :: Position
p                           = Position
p

{-# INLINE incOffset #-}
-- | advance just the offset
incOffset :: Position -> Int -> Position
incOffset :: Position -> Int -> Position
incOffset (Position o :: Int
o r :: Int
r c :: Int
c f :: FilePosition
f) n :: Int
n = Int -> Int -> Int -> FilePosition -> Position
Position (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) Int
r Int
c FilePosition
f
incOffset pos :: Position
pos _             = Position
pos