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

Portabilityghc
Stabilityexperimental
Maintainerbenedikt.huber@gmail.com

Language.C.Data

Contents

Description

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

Synopsis

Input stream

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).

Instances

Eq SUERef 
Data SUERef 
Ord SUERef 
Show SUERef 
Typeable SUERef 
Pretty 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 
Typeable Ident 
Pos Ident 
CNode Ident 
Pretty 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 Names starting with nameId 0

Source code positions

data Position

uniform representation of source file positions; the order of the arguments is important as it leads to the desired ordering of source positions

Constructors

Position String !Int !Int 

Instances

Eq Position 
Data Position 
Ord Position 
Read Position 
Show Position 
Typeable Position 

initPos :: FilePath -> Position

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

posFile :: Position -> String

get the source file of the specified position. Fails unless isSourcePos pos.

posRow :: Position -> Int

get the line number of the specified position. Fails unless isSourcePos pos

posColumn :: Position -> Int

get the column of the specified position. Fails unless isSourcePos pos

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

Instances

Eq NodeInfo 
Data NodeInfo 
Ord NodeInfo 
Read NodeInfo 
Show NodeInfo 
Typeable NodeInfo 
Pos NodeInfo 
CNode NodeInfo 

fileOfNode :: CNode a => a -> FilePath

mkNodeInfoOnlyPos :: Position -> NodeInfo

Given only a source position, create a new attribute identifier

mkNodeInfo :: Position -> Name -> NodeInfo

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

Extensible errors