Language.C.Data

language-c-0.4.5: Analysis and generation of C code

Copyright | (c) 2008 Benedikt Huber
License | BSD-style
Maintainer | benedikt.huber@gmail.com
Stability | experimental
Portability | ghc
Safe Haskell | None
Language | Haskell98

Language.C.Data

Contents

- Input stream
- Identifiers
- Unqiue names
- Source code positions
- Syntax tree nodes
- Extensible errors

Description

Common data types for Language.C: Identifiers, unique names, source code locations, ast node attributes and extensible errors.

Synopsis

- module Language.C.Data.InputStream
- data SUERef
  - = AnonymousRef Name
  - | NamedRef Ident
- isAnonymousRef :: SUERef -> Bool
- data Ident
- mkIdent :: Position -> String -> Name -> Ident
- identToString :: Ident -> String
- internalIdent :: String -> Ident
- isInternalIdent :: Ident -> Bool
- builtinIdent :: String -> Ident
- newtype Name = Name {
  - nameId :: Int
  }
- newNameSupply :: [Name]
- data Position
- class Pos a where
  - posOf :: a -> Position
- initPos :: FilePath -> Position
- nopos :: Position
- builtinPos :: Position
- internalPos :: Position
- isSourcePos :: Position -> Bool
- isBuiltinPos :: Position -> Bool
- isInternalPos :: Position -> Bool
- data NodeInfo
  - = OnlyPos Position !PosLength
  - | NodeInfo Position !PosLength !Name
- class CNode a where
  - nodeInfo :: a -> NodeInfo
- fileOfNode :: CNode a => a -> Maybe FilePath
- posOfNode :: NodeInfo -> Position
- nameOfNode :: NodeInfo -> Maybe Name
- undefNode :: NodeInfo
- mkNodeInfoOnlyPos :: Position -> NodeInfo
- mkNodeInfo :: Position -> Name -> NodeInfo
- internalNode :: NodeInfo
- module Language.C.Data.Error

# Input stream

module Language.C.Data.InputStream

# Identifiers

data SUERef

References uniquely determining a struct, union or enum type. Those are either identified by an string identifier, or by a unique name (anonymous types).

Constructors

AnonymousRef Name |
NamedRef Ident |

Instances

Eq SUERef |
Data SUERef |
Ord SUERef |
Show SUERef |
Pretty SUERef |
Typeable * SUERef |

isAnonymousRef :: SUERef -> Bool

Return true if the struct/union/enum reference is anonymous.

data Ident

C identifiers

Instances

Eq Ident |
Data Ident |
Ord Ident |
Show Ident |
Pos Ident |
CNode Ident |
Pretty Ident |
Typeable * Ident |

mkIdent :: Position -> String -> Name -> Ident

build an identifier from a string.

- only minimal error checking, e.g., the characters of the identifier are not checked for being alphanumerical only; the correct lexis of the identifier should be ensured by the caller, e.g., the scanner.
- for reasons of simplicity the complete lexeme is hashed.

identToString :: Ident -> String

string of an identifier

internalIdent :: String -> Ident

returns an internal identifier (has internal position and no unique name)

isInternalIdent :: Ident -> Bool

return `True` if the given identifier is internal

builtinIdent :: String -> Ident

returns a builtin identifier (has builtin position and no unique name)

# Unqiue names

newtype Name

Name is a unique identifier

Constructors

Name |
Fields nameId :: Int

Instances

Enum Name |
Eq Name |
Data Name |
Ord Name |
Read Name |
Show Name |
Ix Name |
Typeable * Name |

newNameSupply :: [Name]

return an infinite stream of `Name`s starting with `nameId` 0

# Source code positions

data Position

uniform representation of source file positions

Instances

Eq Position |
Data Position |
Ord Position |
Show Position |
Typeable * Position |

class Pos a where

class of type which aggregate a source code location

Methods

posOf :: a -> Position

Instances

Pos NodeInfo |
Pos Ident |
Pos Attr |
Pos Enumerator |
Pos EnumType |
Pos CompType |
Pos EnumTypeRef |
Pos CompTypeRef |
Pos TypeDefRef |
Pos TypeDef |
Pos MemberDecl |
Pos ParamDecl |
Pos FunDef |
Pos ObjDef |
Pos Decl |
Pos DeclEvent |
Pos IdentDecl |
Pos TagDef |
Pos a => Pos [a] |
CNode t1 => Pos (CStringLiteral t1) |
CNode t1 => Pos (CConstant t1) |
CNode t1 => Pos (CBuiltinThing t1) |
CNode t1 => Pos (CExpression t1) |
CNode t1 => Pos (CAttribute t1) |
CNode t1 => Pos (CPartDesignator t1) |
CNode t1 => Pos (CInitializer t1) |
CNode t1 => Pos (CEnumeration t1) |
CNode t1 => Pos (CStructureUnion t1) |
CNode t1 => Pos (CTypeQualifier t1) |
CNode t1 => Pos (CTypeSpecifier t1) |
CNode t1 => Pos (CStorageSpecifier t1) |
CNode t1 => Pos (CDeclarationSpecifier t1) |
CNode t1 => Pos (CCompoundBlockItem t1) |
CNode t1 => Pos (CAssemblyOperand t1) |
CNode t1 => Pos (CAssemblyStatement t1) |
CNode t1 => Pos (CStatement t1) |
CNode t1 => Pos (CDerivedDeclarator t1) |
CNode t1 => Pos (CDeclarator t1) |
CNode t1 => Pos (CDeclaration t1) |
CNode t1 => Pos (CFunctionDef t1) |
CNode t1 => Pos (CExternalDeclaration t1) |
CNode t1 => Pos (CTranslationUnit t1) |

initPos :: FilePath -> Position

initialize a Position to the start of the translation unit starting in the given file

nopos :: Position

no position (for unknown position information)

builtinPos :: Position

position attached to built-in objects

internalPos :: Position

position used for internal errors

isSourcePos :: Position -> Bool

returns `True` if the given position refers to an actual source file

isBuiltinPos :: Position -> Bool

returns `True` if the given position refers to a builtin definition

isInternalPos :: Position -> Bool

returns `True` if the given position is internal

# Syntax tree nodes

data NodeInfo

Parsed entity attribute

Constructors

OnlyPos Position !PosLength |
NodeInfo Position !PosLength !Name |

Instances

Eq NodeInfo |
Data NodeInfo |
Ord NodeInfo |
Show NodeInfo |
Pos NodeInfo |
CNode NodeInfo |
Pretty CStrLit |
Pretty CConst |
Pretty CBuiltin |
Pretty CExpr |
Pretty CAttr |
Pretty CDesignator |
Pretty CInit |
Pretty CEnum |
Pretty CStructUnion |
Pretty CTypeQual |
Pretty CTypeSpec |
Pretty CStorageSpec |
Pretty CDeclSpec |
Pretty CBlockItem |
Pretty CAsmOperand |
Pretty CAsmStmt |
Pretty CStat |
Pretty CArrSize |
Pretty CDeclr |
Pretty CDecl |
Pretty CFunDef |
Pretty CExtDecl |
Pretty CTranslUnit |
Typeable * NodeInfo |

class CNode a where

a class for convenient access to the attributes of an attributed object

Methods

nodeInfo :: a -> NodeInfo

Instances

CNode NodeInfo |
CNode Ident |
CNode Attr |
CNode Enumerator |
CNode EnumType |
CNode CompType |
CNode EnumTypeRef |
CNode CompTypeRef |
CNode TypeDefRef |
CNode TypeDef |
CNode MemberDecl |
CNode ParamDecl |
CNode FunDef |
CNode ObjDef |
CNode Decl |
CNode DeclEvent |
CNode IdentDecl |
CNode TagDef |
CNode TagFwdDecl |
CNode t1 => CNode (CStringLiteral t1) |
CNode t1 => CNode (CConstant t1) |
CNode t1 => CNode (CBuiltinThing t1) |
CNode t1 => CNode (CExpression t1) |
CNode t1 => CNode (CAttribute t1) |
CNode t1 => CNode (CPartDesignator t1) |
CNode t1 => CNode (CInitializer t1) |
CNode t1 => CNode (CEnumeration t1) |
CNode t1 => CNode (CStructureUnion t1) |
CNode t1 => CNode (CTypeQualifier t1) |
CNode t1 => CNode (CTypeSpecifier t1) |
CNode t1 => CNode (CStorageSpecifier t1) |
CNode t1 => CNode (CDeclarationSpecifier t1) |
CNode t1 => CNode (CCompoundBlockItem t1) |
CNode t1 => CNode (CAssemblyOperand t1) |
CNode t1 => CNode (CAssemblyStatement t1) |
CNode t1 => CNode (CStatement t1) |
CNode t1 => CNode (CDerivedDeclarator t1) |
CNode t1 => CNode (CDeclarator t1) |
CNode t1 => CNode (CDeclaration t1) |
CNode t1 => CNode (CFunctionDef t1) |
CNode t1 => CNode (CExternalDeclaration t1) |
CNode t1 => CNode (CTranslationUnit t1) |
(CNode a, CNode b) => CNode (Either a b) |

fileOfNode :: CNode a => a -> Maybe FilePath

posOfNode :: NodeInfo -> Position

nameOfNode :: NodeInfo -> Maybe Name

undefNode :: NodeInfo

create a node with neither name nor positional information

mkNodeInfoOnlyPos :: Position -> NodeInfo

| Given only a source position, create a new node attribute

mkNodeInfo :: Position -> Name -> NodeInfo

Given a source position and a unique name, create a new attribute identifier

internalNode :: NodeInfo

Deprecated: use undefNode instead

# Extensible errors

module Language.C.Data.Error