| language-c-0.3.2: Analysis and generation of C code | Source code | Contents | Index

Language.C.Analysis.DeclAnalysis

Portability | ghc
Stability | alpha
Maintainer | benedikt.huber@gmail.com

Contents

Translating types
Dissecting type specs
Helpers

Description
This module performs the analysis of declarations and the translation of type specifications in the AST.
Synopsis

analyseTypeDecl :: MonadTrav m => CDecl -> m Type
tType :: MonadTrav m => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> [CDerivedDeclr] -> [CDecl] -> m Type
tDirectType :: MonadTrav m => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> m Type
tNumType :: MonadTrav m => NumTypeSpec -> m (Either (FloatType, Bool) IntType)
tArraySize :: MonadTrav m => CArrSize -> m ArraySize
tTypeQuals :: MonadTrav m => [CTypeQual] -> m (TypeQuals, Attributes)
mergeOldStyle :: MonadTrav m => NodeInfo -> [CDecl] -> [CDerivedDeclr] -> m [CDerivedDeclr]
canonicalTypeSpec :: MonadTrav m => [CTypeSpec] -> m TypeSpecAnalysis

data NumBaseType

= NoBaseType
| BaseChar
| BaseInt
| BaseFloat
| BaseDouble

data SignSpec

= NoSignSpec
| Signed
| Unsigned

data SizeMod

= NoSizeMod
| ShortMod
| LongMod
| LongLongMod

data NumTypeSpec = NumTypeSpec {

base :: NumBaseType
signSpec :: SignSpec
sizeMod :: SizeMod
isComplex :: Bool

}

data TypeSpecAnalysis

= TSNone
| TSVoid
| TSBool
| TSNum NumTypeSpec
| TSNonBasic CTypeSpec

canonicalStorageSpec :: MonadTrav m => [CStorageSpec] -> m StorageSpec

data StorageSpec

= NoStorageSpec
| AutoSpec
| RegSpec
| ThreadSpec
| StaticSpec Bool
| ExternSpec Bool

hasThreadLocalSpec :: StorageSpec -> Bool
data VarDeclInfo = VarDeclInfo VarName Bool StorageSpec Attributes Type NodeInfo
tAttr :: MonadTrav m => CAttr -> m Attr
mkVarName :: MonadTrav m => NodeInfo -> Maybe Ident -> Maybe AsmName -> m VarName
getOnlyDeclr :: MonadTrav m => CDecl -> m CDeclr
nameOfDecl :: MonadTrav m => CDecl -> m Ident

Translating types

analyseTypeDecl :: MonadTrav m => CDecl -> m Type | Source

get the type of a type declaration

A type declaration `T` may appear in thre forms:

-     typeof(T)

- as abstract declarator in a function prototype, as in `f(int)`
- in a declaration without declarators, as in `struct x { int a } ;`

Currently, `analyseTypeDecl` is exlusively used for analysing types for GNU's `typeof(T)`.

We move attributes to the type, as they have no meaning for the abstract declarator

tType :: MonadTrav m => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> [CDerivedDeclr] -> [CDecl] -> m Type | Source

translate a type

tDirectType :: MonadTrav m => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> m Type | Source

translate a type without (syntactic) indirections Due to the GNU `typeof` extension and typeDefs, this can be an arbitrary type

tNumType :: MonadTrav m => NumTypeSpec -> m (Either (FloatType, Bool) IntType) | Source

Mapping from num type specs to C types (C99 6.7.2-2), ignoring the complex qualifier.

tArraySize :: MonadTrav m => CArrSize -> m ArraySize | Source

tTypeQuals :: MonadTrav m => [CTypeQual] -> m (TypeQuals, Attributes) | Source

mergeOldStyle :: MonadTrav m => NodeInfo -> [CDecl] -> [CDerivedDeclr] -> m [CDerivedDeclr] | Source

convert old style parameters

This requires matching parameter names and declarations, as in the following example:

     int f(d,c,a,b)
     char a,*b;
     int c;
     { }

is converted to

     int f(int d, int c, char a, char* b)

TODO: This could be moved to syntax, as it operates on the AST only

Dissecting type specs

canonicalTypeSpec :: MonadTrav m => [CTypeSpec] -> m TypeSpecAnalysis | Source

data NumBaseType | Source

Constructors

NoBaseType |
BaseChar |
BaseInt |
BaseFloat |
BaseDouble |

Instances

Eq NumBaseType
Ord NumBaseType

data SignSpec | Source

Constructors

NoSignSpec |
Signed |
Unsigned |

Instances

Eq SignSpec
Ord SignSpec

data SizeMod | Source

Constructors

NoSizeMod |
ShortMod |
LongMod |
LongLongMod |

Instances

Eq SizeMod
Ord SizeMod

data NumTypeSpec | Source

Constructors

NumTypeSpec |

base :: NumBaseType |
signSpec :: SignSpec |
sizeMod :: SizeMod |
isComplex :: Bool |

data TypeSpecAnalysis | Source

Constructors

TSNone |
TSVoid |
TSBool |
TSNum NumTypeSpec |
TSNonBasic CTypeSpec |

canonicalStorageSpec :: MonadTrav m => [CStorageSpec] -> m StorageSpec | Source

data StorageSpec | Source

Constructors

NoStorageSpec |
AutoSpec |
RegSpec |
ThreadSpec |
StaticSpec Bool |
ExternSpec Bool |

Instances

Eq StorageSpec
Ord StorageSpec
Read StorageSpec
Show StorageSpec

hasThreadLocalSpec :: StorageSpec -> Bool | Source

Helpers

data VarDeclInfo | Source

Constructors

VarDeclInfo VarName Bool StorageSpec Attributes Type NodeInfo |

tAttr :: MonadTrav m => CAttr -> m Attr | Source

translate `__attribute__` annotations TODO: This is a unwrap and wrap stub

mkVarName :: MonadTrav m => NodeInfo -> Maybe Ident -> Maybe AsmName -> m VarName | Source

construct a name for a variable TODO: more or less bogus

getOnlyDeclr :: MonadTrav m => CDecl -> m CDeclr | Source

nameOfDecl :: MonadTrav m => CDecl -> m Ident | Source

Produced by Haddock version 2.4.2