free-compiler-0.3.0.0: A Haskell to Coq compiler.

Safe HaskellSafe
LanguageHaskell2010

FreeC.IR.SrcSpan

Contents

Description

This module contains the definition of a source span data type that is used by the AST of the intermediate language to store for every node the corresponding portion of the source code.

Source spans can be pretty printed and are used by the error reporting engine of the compiler to point the user to the relevant piece of code when an error occurs.

Synopsis

Source Files

data SrcFile Source #

Data type that contains the name and contents of source files.

The contents of the source file are stored as a string for parsing and as a list of lines for error messages.

Constructors

SrcFile 

Fields

NoSrcFile

A source file whose contents are unknown.

Fields

Instances
Eq SrcFile Source # 
Instance details

Defined in FreeC.IR.SrcSpan

Show SrcFile Source # 
Instance details

Defined in FreeC.IR.SrcSpan

Pretty SrcFile Source #

Pretty instance for a source file that displays the filename.

Instance details

Defined in FreeC.IR.SrcSpan

Methods

pretty :: SrcFile -> Doc #

prettyList :: [SrcFile] -> Doc #

mkSrcFile :: FilePath -> String -> SrcFile Source #

Smart constructor for SrcFile that automatically splits the file contents into lines.

hasSrcFileContents :: SrcFile -> Bool Source #

Tests whether the contents of the given source file are known.

Source File Maps

type SrcFileMap = [(FilePath, SrcFile)] Source #

Type for a map that associates source files with their filename.

mkSrcFileMap :: [SrcFile] -> SrcFileMap Source #

Smart constructor for SrcFileMap for the given SrcFiles.

lookupSrcFile :: FilePath -> SrcFileMap -> SrcFile Source #

Looks up a SrcFile in a SrcFileMap.

Returns NoSrcFile if the map does not contain such a source file.

Source Spans

data SrcSpan Source #

Describes the portion of the source code that caused a message to be reported.

In contrast to the source spans provided by the haskell-src-exts package this source span provides access to the lines of code that contain the source span.

Constructors

SrcSpan 

Fields

NoSrcSpan

Indicates that no location information is available.

FileSpan

Points to an unknown location in the given file.

Fields

Instances
Eq SrcSpan Source # 
Instance details

Defined in FreeC.IR.SrcSpan

Show SrcSpan Source # 
Instance details

Defined in FreeC.IR.SrcSpan

Pretty SrcSpan Source #

Pretty instance for a source span that displays the filename and the start and end position of the source span.

If the source span spans only a single line, the end position is omitted.

Instance details

Defined in FreeC.IR.SrcSpan

Methods

pretty :: SrcSpan -> Doc #

prettyList :: [SrcSpan] -> Doc #

TransformSrcSpan SrcSpan

Converts a source span to an HST source span.

Instance details

Defined in FreeC.Frontend.Haskell.PatternMatching

Methods

transformSrcSpan :: SrcSpan -> SrcSpan0 (HSE SrcSpan)

TransformSrcSpan SrcSpan

Extracts the actual source span from an HST source span.

Instance details

Defined in FreeC.Frontend.Haskell.PatternMatching

Methods

transformSrcSpan :: SrcSpan0 (HSE SrcSpan) -> SrcSpan

Selectors

srcSpanCodeLines :: SrcSpan -> [String] Source #

Gets the lines of source code spanned by the given source span.

Returns an empty list if the given source span does not satisfy the hasSourceCode predicate.

Predicates

hasSrcSpanFile :: SrcSpan -> Bool Source #

Tests whether the given SrcSpan contains information about the file that is spanned (i.e., there is a field srcSpanFile).

hasSourceCode :: SrcSpan -> Bool Source #

Tests whether the given source span has attached source code.

spansMultipleLines :: SrcSpan -> Bool Source #

Tests whether the given source span spans multiple lines.

Conversion

class ConvertibleSrcSpan ss where Source #

Type class for source spans from other packages that can be converted to SrcSpans for pretty printing of messages.

Methods

convertSrcSpan :: SrcFileMap -> ss -> SrcSpan Source #

Converts the given third party source span to a SrcSpan by attaching the corresponding line of source code.

Instances
ConvertibleSrcSpan SourcePos Source #

Converts a Parsec SourcePos to a SrcSpan.

Instance details

Defined in FreeC.Util.Parsec

ConvertibleSrcSpan SrcLoc Source #

Converts a SrcLoc by creating a zero width source span and applying the conversion for SrcSpans.

Instance details

Defined in FreeC.Frontend.Haskell.SrcSpanConverter

Methods

convertSrcSpan :: SrcFileMap -> SrcLoc -> SrcSpan Source #

ConvertibleSrcSpan SrcSpan Source #

Directly converts a SrcSpan to a SrcSpan by looking up the corresponding line of code in the provided map.

Instance details

Defined in FreeC.Frontend.Haskell.SrcSpanConverter

Methods

convertSrcSpan :: SrcFileMap -> SrcSpan -> SrcSpan0 Source #

ConvertibleSrcSpan SrcSpanInfo Source #

Converts a SrcSpanInfo by removing additional information and applying the conversion for SrcSpans.

Instance details

Defined in FreeC.Frontend.Haskell.SrcSpanConverter

Methods

convertSrcSpan :: SrcFileMap -> SrcSpanInfo -> SrcSpan Source #