language-c-0.9.2: Analysis and generation of C code
Copyright(c) 2008 Benedikt Huber
LicenseBSD-style
Maintainerbenedikt.huber@gmail.com
Stabilityalpha
Portabilityghc
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.C.Analysis.DeclAnalysis

Description

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

Synopsis

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] -> TypeSpecAnalysis -> [CDerivedDeclr] -> [CDecl] -> m Type Source #

translate a type

tDirectType :: MonadTrav m => Bool -> NodeInfo -> [CTypeQual] -> TypeSpecAnalysis -> m Type Source #

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

tNumType :: MonadCError 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.

mergeOldStyle :: MonadCError 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

data NumBaseType Source #

Instances

Instances details
Eq NumBaseType Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

(==) :: NumBaseType -> NumBaseType -> Bool

(/=) :: NumBaseType -> NumBaseType -> Bool

Ord NumBaseType Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

data SignSpec Source #

Constructors

NoSignSpec 
Signed 
Unsigned 

Instances

Instances details
Eq SignSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

(==) :: SignSpec -> SignSpec -> Bool

(/=) :: SignSpec -> SignSpec -> Bool

Ord SignSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

compare :: SignSpec -> SignSpec -> Ordering

(<) :: SignSpec -> SignSpec -> Bool

(<=) :: SignSpec -> SignSpec -> Bool

(>) :: SignSpec -> SignSpec -> Bool

(>=) :: SignSpec -> SignSpec -> Bool

max :: SignSpec -> SignSpec -> SignSpec

min :: SignSpec -> SignSpec -> SignSpec

data SizeMod Source #

Instances

Instances details
Eq SizeMod Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

(==) :: SizeMod -> SizeMod -> Bool

(/=) :: SizeMod -> SizeMod -> Bool

Ord SizeMod Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

compare :: SizeMod -> SizeMod -> Ordering

(<) :: SizeMod -> SizeMod -> Bool

(<=) :: SizeMod -> SizeMod -> Bool

(>) :: SizeMod -> SizeMod -> Bool

(>=) :: SizeMod -> SizeMod -> Bool

max :: SizeMod -> SizeMod -> SizeMod

min :: SizeMod -> SizeMod -> SizeMod

data StorageSpec Source #

Instances

Instances details
Read StorageSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

readsPrec :: Int -> ReadS StorageSpec

readList :: ReadS [StorageSpec]

readPrec :: ReadPrec StorageSpec

readListPrec :: ReadPrec [StorageSpec]

Show StorageSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

showsPrec :: Int -> StorageSpec -> ShowS

show :: StorageSpec -> String

showList :: [StorageSpec] -> ShowS

Eq StorageSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Methods

(==) :: StorageSpec -> StorageSpec -> Bool

(/=) :: StorageSpec -> StorageSpec -> Bool

Ord StorageSpec Source # 
Instance details

Defined in Language.C.Analysis.DeclAnalysis

Helpers

tAttr :: (MonadCError m, MonadSymtab m) => CAttr -> m Attr Source #

translate attribute annotations TODO: This is a unwrap and wrap stub

mkVarName :: (MonadCError m, MonadSymtab m) => NodeInfo -> Maybe Ident -> Maybe AsmName -> m VarName Source #

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

analyseVarDecl :: MonadTrav m => Bool -> [CStorageSpec] -> [CAttr] -> [CTypeQual] -> TypeSpecAnalysis -> [CFunSpec] -> CDeclr -> [CDecl] -> Maybe CInit -> m VarDeclInfo Source #

analyse declarators

analyseVarDecl' :: MonadTrav m => Bool -> [CDeclSpec] -> CDeclr -> [CDecl] -> Maybe CInit -> m VarDeclInfo Source #