language-objc-0.4.2.5: Analysis and generation of Objective C code

Portabilityghc
Stabilityalpha
Maintainerjwlato@gmail.com
Safe HaskellNone

Language.ObjC.Analysis.SemRep

Contents

Description

This module contains definitions for representing C translation units. In contrast to AST, the representation tries to express the semantics of of a translation unit.

Synopsis

Sums of tags and identifiers

data TagDef Source

Composite type definitions (tags)

typeOfTagDef :: TagDef -> TypeNameSource

return the type corresponding to a tag definition

class Declaration n whereSource

All datatypes aggregating a declaration are instances of Declaration

Methods

getVarDecl :: n -> VarDeclSource

get the name, type and declaration attributes of a declaration or definition

declIdent :: Declaration n => n -> IdentSource

get the variable identifier of a declaration (only safe if the the declaration is known to have a name)

declName :: Declaration n => n -> VarNameSource

get the variable name of a Declaration

declType :: Declaration n => n -> TypeSource

get the type of a Declaration

declAttrs :: Declaration n => n -> DeclAttrsSource

get the declaration attributes of a Declaration

data IdentDecl Source

identifiers, typedefs and enumeration constants (namespace sum)

Constructors

Declaration Decl

object or function declaration

ObjectDef ObjDef

object definition

FunctionDef FunDef

function definition

EnumeratorDef Enumerator

definition of an enumerator

objKindDescr :: IdentDecl -> StringSource

textual description of the kind of an object

splitIdentDecls :: Bool -> Map Ident IdentDecl -> (Map Ident Decl, (Map Ident Enumerator, Map Ident ObjDef, Map Ident FunDef))Source

splitIdentDecls includeAllDecls splits a map of object, function and enumerator declarations and definitions into one map holding declarations, and three maps for object definitions, enumerator definitions and function definitions. If includeAllDecls is True all declarations are present in the first map, otherwise only those where no corresponding definition is available.

Global definitions

data GlobalDecls Source

global declaration/definition table returned by the analysis

Instances

emptyGlobalDecls :: GlobalDeclsSource

empty global declaration table

filterGlobalDecls :: (DeclEvent -> Bool) -> GlobalDecls -> GlobalDeclsSource

filter global declarations

mergeGlobalDecls :: GlobalDecls -> GlobalDecls -> GlobalDeclsSource

merge global declarations

Events for visitors

data DeclEvent Source

Declaration events

Those events are reported to callbacks, which are executed during the traversal.

Constructors

TagEvent TagDef

file-scope struct/union/enum event

DeclEvent IdentDecl

file-scope declaration or definition

ParamEvent ParamDecl

parameter declaration

LocalEvent IdentDecl

local variable declaration or definition

TypeDefEvent TypeDef

a type definition

AsmEvent AsmBlock

assembler block

Declarations and definitions

data Decl Source

Declarations, which aren't definitions

Constructors

Decl VarDecl NodeInfo 

data ObjDef Source

Object Definitions

An object definition is a declaration together with an initializer.

If the initializer is missing, it is a tentative definition, i.e. a definition which might be overriden later on.

isTentative :: ObjDef -> BoolSource

Returns True if the given object definition is tentative.

data FunDef Source

Function definitions

A function definition is a declaration together with a statement (the function body).

Constructors

FunDef VarDecl Stmt NodeInfo 

data MemberDecl Source

Struct/Union member declaration

Constructors

MemberDecl VarDecl (Maybe Expr) NodeInfo
MemberDecl vardecl bitfieldsize node
AnonBitField Type Expr NodeInfo
AnonBitField typ size

data TypeDef Source

typedef definitions.

The identifier is a new name for the given type.

identOfTypeDef :: TypeDef -> IdentSource

return the idenitifier of a typedef

data VarDecl Source

Generic variable declarations

Declaration attributes

data DeclAttrs Source

Declaration attributes of the form DeclAttrs isInlineFunction storage linkage attrs

They specify the storage and linkage of a declared object.

Constructors

DeclAttrs Bool Storage Attributes
DeclAttrs inline storage attrs

data Storage Source

Storage duration and linkage of a variable

Constructors

NoStorage

no storage

Auto Register

automatic storage (optional: register)

Static Linkage ThreadLocal

static storage, linkage spec and thread local specifier (gnu c)

FunLinkage Linkage

function, either internal or external linkage

declStorage :: Declaration d => d -> StorageSource

get the Storage of a declaration

data Linkage Source

Linkage: Either no linkage, internal to the translation unit or external

hasLinkage :: Storage -> BoolSource

return True if the object has linkage

declLinkage :: Declaration d => d -> LinkageSource

Get the linkage of a definition

Types

data FunType Source

Function types are of the form FunType return-type params isVariadic.

If the parameter types aren't yet known, the function has type FunTypeIncomplete type attrs.

data ArraySize Source

An array type may either have unknown size or a specified array size, the latter either variable or constant. Furthermore, when used as a function parameters, the size may be qualified as static. In a function prototype, the size may be `Unspecified variable size' ([*]).

Constructors

UnknownArraySize Bool
UnknownArraySize is-starred
ArraySize Bool Expr
FixedSizeArray is-static size-expr

data TypeDefRef Source

typdef references If the actual type is known, it is attached for convenience

data BuiltinType Source

Builtin type (va_list, anything)

Constructors

TyVaList 
TyAny 

data FloatType Source

floating point type (C99 6.7.2.2)

Constructors

TyFloat 
TyDouble 
TyLDouble 

class HasSUERef a whereSource

accessor class : struct/union/enum names

Methods

sueRef :: a -> SUERefSource

class HasCompTyKind a whereSource

accessor class : composite type tags (struct or union)

Methods

compTag :: a -> CompTyKindSource

typeOfCompDef :: CompType -> TypeNameSource

return the type of a composite type definition

data CompTyKind Source

a tag to determine wheter we refer to a struct or union, see CompType.

Constructors

StructTag 
UnionTag 

data EnumType Source

Representation of C enumeration types

Constructors

EnumType SUERef [Enumerator] Attributes NodeInfo
EnumType name enumeration-constants attrs node

typeOfEnumDef :: EnumType -> TypeNameSource

return the type of an enum definition

data Enumerator Source

An Enumerator consists of an identifier, a constant expressions and the link to its type

data TypeQuals Source

Type qualifiers: constant, volatile, proto, and restrict

Constructors

TypeQuals 

noTypeQuals :: TypeQualsSource

no type qualifiers

mergeTypeQuals :: TypeQuals -> TypeQuals -> TypeQualsSource

merge (&&) two type qualifier sets

mergeProtoQuals :: ProtoQuals -> ProtoQuals -> ProtoQualsSource

merge (&&) two protocol qualifier sets

protoFromAST :: ObjCProtoQualifier a -> ProtoQualsSource

Convert protocol qualifier from AST representation

Variable names

data VarName Source

VarName name assembler-name is a name of an declared object

Constructors

VarName Ident (Maybe AsmName) 
NoName 

type AsmName = CStrLitSource

Assembler name (alias for CStrLit)

Attributes (STUB, not yet analyzed)

data Attr Source

__attribute__ annotations

Those are of the form Attr attribute-name attribute-parameters, and serve as generic properties of some syntax tree elements.

Some examples:

  • labels can be attributed with unused to indicate that their not used
  • struct definitions can be attributed with packed to tell the compiler to use the most compact representation
  • declarations can be attributed with deprecated
  • function declarations can be attributes with noreturn to tell the compiler that the function will never return,
  • or with const to indicate that it is a pure function

TODO: ultimatively, we want to parse attributes and represent them in a typed way

Constructors

Attr Ident [Expr] NodeInfo 

noAttributes :: AttributesSource

Empty attribute list

mergeAttributes :: Attributes -> Attributes -> AttributesSource

Merge attribute lists TODO: currently does not remove duplicates

Statements and Expressions (STUB, aliases to Syntax)

type Stmt = CStatSource

Stmt is an alias for CStat (Syntax)

type Expr = CExprSource

Expr is currently an alias for CExpr (Syntax)

type Initializer = CInitSource

Initializer is currently an alias for CInit.

We're planning a normalized representation, but this depends on the implementation of constant expression evaluation

type AsmBlock = CStrLitSource

Top level assembler block (alias for CStrLit)