camfort-1.0.1: CamFort - Cambridge Fortran infrastructure
Safe HaskellNone
LanguageHaskell2010

Language.Fortran.Model.Translate

Description

Provides translation from a subset of the dynamically typed Fortran syntax (Language.Fortran.AST) to the strongly typed expression language (Language.Fortran.Model).

Synopsis

Types

Fortran Expressions

type FortranExpr = HFree CoreOp FortranVar Source #

The type of strongly-typed Fortran expressions.

Existentials

data Some f where Source #

An existential type containing f a for some type a.

Constructors

Some :: f a -> Some f 

Instances

Instances details
Pretty1 f => Show (Some f) Source # 
Instance details

Defined in Camfort.Helpers.TypeLevel

Methods

showsPrec :: Int -> Some f -> ShowS #

show :: Some f -> String #

showList :: [Some f] -> ShowS #

Pretty1 f => Pretty (Some f) Source # 
Instance details

Defined in Camfort.Helpers.TypeLevel

Methods

pretty :: Some f -> String

prettysPrec :: Int -> Some f -> ShowS

type SomeVar = Some FortranVar Source #

A Fortran variable with an existential type.

type SomeExpr = Some (PairOf D FortranExpr) Source #

A Fortran expression with an existential type.

type SomeType = Some D Source #

An existential Fortran type.

Semantics

newtype KindSelector Source #

A function mapping numeric kind annotations from Fortran programs to actual precision, for a particular basic type bt.

Constructors

KindSelector 

data FortranSemantics Source #

A (currently very incomplete) specification of the semantics of a particular version of Fortran, needed when translating.

defaultSemantics :: FortranSemantics Source #

Kinds

The default semantics has sensible defaults for kind 0 (unspecified). Otherwise, the kind is the number of bytes used for the type's representation. Only power-of-two values up to 8 are valid. Characters only allow single byte precision. Reals only allow 4- or 8-byte precision.

Translation Monad

Environment

data TranslateEnv Source #

In order to translate Fortran expressions, we require some information about the environment. That information is capture in this record.

Constructors

TranslateEnv 

Fields

Instances

Instances details
Monad m => MonadReader TranslateEnv (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Errors

data TranslateError Source #

Constructors

ErrUnsupportedItem Text

Tried to translate a part of the language that is not (yet) supported.

ErrBadLiteral

Found a literal value that we didn't know how to translate. May or may not be valid Fortran.

ErrUnexpectedType Text SomeType SomeType

ErrUnexpectedType message expected actual: tried to translate a Fortran language part into the wrong expression type, and it wasn't coercible to the correct type.

ErrInvalidOpApplication (Some (Rec D))

Tried to apply an operator to arguments with the wrong types.

ErrVarNotInScope Name

Reference to a variable that's not currently in scope

ErrInvalidKind Text Integer

ErrInvalidKind baseTypeName givenKind: tried to interpret a type with the given kind which is not valid under the semantics.

Monad

newtype TranslateT m a Source #

Instances

Instances details
MonadLogger e w m => MonadLogger e w (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

setDefaultSourceFile :: FilePath -> TranslateT m () Source #

getDefaultSourceFile :: TranslateT m FilePath Source #

recordLogMessage :: SomeMessage e w -> TranslateT m () Source #

logError :: Origin -> e -> TranslateT m () Source #

logError' :: Spanned a => a -> e -> TranslateT m () Source #

logWarn :: Origin -> w -> TranslateT m () Source #

logWarn' :: Spanned a => a -> w -> TranslateT m () Source #

logInfo :: Origin -> Text -> TranslateT m () Source #

logInfo' :: Spanned a => a -> Text -> TranslateT m () Source #

logInfoNoOrigin :: Text -> TranslateT m () Source #

logDebug :: Origin -> Text -> TranslateT m () Source #

logDebug' :: Spanned a => a -> Text -> TranslateT m () Source #

Monad m => MonadReader TranslateEnv (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Monad m => MonadError TranslateError (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Monad m => Monad (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

(>>=) :: TranslateT m a -> (a -> TranslateT m b) -> TranslateT m b #

(>>) :: TranslateT m a -> TranslateT m b -> TranslateT m b #

return :: a -> TranslateT m a #

Functor m => Functor (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

fmap :: (a -> b) -> TranslateT m a -> TranslateT m b #

(<$) :: a -> TranslateT m b -> TranslateT m a #

MonadFail m => MonadFail (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

fail :: String -> TranslateT m a #

Monad m => Applicative (TranslateT m) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

pure :: a -> TranslateT m a #

(<*>) :: TranslateT m (a -> b) -> TranslateT m a -> TranslateT m b #

liftA2 :: (a -> b -> c) -> TranslateT m a -> TranslateT m b -> TranslateT m c #

(*>) :: TranslateT m a -> TranslateT m b -> TranslateT m b #

(<*) :: TranslateT m a -> TranslateT m b -> TranslateT m a #

Translating Expressions

translateExpression :: (Monad m, MonadFail m) => Expression (Analysis ann) -> TranslateT m SomeExpr Source #

Translate an expression with an unknown type. The return value existentially captures the type of the result.

translateExpression' :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (FortranExpr a) Source #

Translate an expression with a known type. Fails if the actual type does not match.

translateCoerceExpression :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (HFree MetaOp FortranExpr a) Source #

Translate an expression and try to coerce it to a particular type. Fails if the actual type cannot be coerced to the given type.

Translating Types

TypeInfo

data TypeInfo ann Source #

The different ways of specifying Fortran types are complicated. This record contains information about all the different things that might contribute to a type.

Instances

Instances details
Functor TypeInfo Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

fmap :: (a -> b) -> TypeInfo a -> TypeInfo b #

(<$) :: a -> TypeInfo b -> TypeInfo a #

Show ann => Show (TypeInfo ann) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

showsPrec :: Int -> TypeInfo ann -> ShowS #

show :: TypeInfo ann -> String #

showList :: [TypeInfo ann] -> ShowS #

Spanned (TypeInfo ann) Source # 
Instance details

Defined in Language.Fortran.Model.Translate

Methods

getSpan :: TypeInfo ann -> SrcSpan

setSpan :: SrcSpan -> TypeInfo ann -> TypeInfo ann

typeInfo :: TypeSpec ann -> TypeInfo ann Source #

Create a simple TypeInfo from an TypeSpec. Many use cases will need to add more information to fully specify the type.

Translation

translateTypeInfo :: (Monad m, MonadFail m, Show ann) => TypeInfo ann -> TranslateT m SomeType Source #

Convert a TypeInfo to its corresponding strong type.

Lenses

FortranSemantics

TranslateEnv

TypeInfo

tiSrcSpan :: forall ann. Lens' (TypeInfo ann) SrcSpan Source #

tiBaseType :: forall ann. Lens' (TypeInfo ann) BaseType Source #

tiSelectorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #

tiSelectorKind :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #

tiDeclaratorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #

tiDimensionDeclarators :: forall ann. Lens' (TypeInfo ann) (Maybe (AList DimensionDeclarator ann)) Source #

tiAttributes :: forall ann. Lens' (TypeInfo ann) (Maybe (AList Attribute ann)) Source #