This page summarizes / explains the status of the c-parser related modules of c2hs before the project.
See also: InitialStatusFullDoc
TOC
- Basic Datatypes / Utilities: UName, Attributes, Position, Idents, Errors
- Monadic Parsing: StateTrans , StateBase, !CIO, !State
- C-specific Infrastructure: CAST, !CTokens, !CParserMonad, NameSpaces, CAttrs, CBuiltin
- Lexer/Parser/PP: CLexer, CParser, CPretty
- Other: CTrav
Infrastructure (1) - Basic Datatypes
UName.hs
Provide unique names using unsafePerformIO. Used instead of a name-generating monad.
Attributes.hs
This module provides a facility to store arbitrary attributes for unique references (Names). If a type is an instance of Attributed, it provides an 'attribute identifier' (Attrs) consisting of a source code location and a unique name. Attribute tables map attribute identifiers to attributes. Some attributes provide don't care and undef special values.
Position.hs
Datatype for a source code position (Name, Row, Column).
Uses special values like (-1) or (-2) for row/column to denote special positions like <no-file>, <invalid>, <build-into-compiler> or <internal-error>.
Idents.hs
Datatype of identifiers. Aggregates a hash attribute to speed up equality comparison and a source-code position.
Errors.hs
Provides default error generators (internal compiler error, todo), utilities (showError) and a parse error datatype (error level, position, message).
Infrastructure (2): Monads
StateTrans.hs
The generic monad used for parsing (called !STB). In mtl terms, it provides MonadIO, MonadState? ParserState, MonadState? GenericState, MonadError? (String,String).
StateBase.hs
The actual monad used for parsing (!PreCST). The parser state of STB is instantiated with a datatype carrying raised errors and the name supply, and can be further parametrized with an additional compiler-dependent state. The actual type is 'instance Monad (!PreCST e s)', where e is 'extra compiler state' and s is 'generic state'.
CIO.hs
Lifted IO actions (like !putStrLnCIO :: String -> !PreCST e s ()).
State.hs
Facade for the monad facilities. re-exports !PreCST and !CIO, and provides some extra utility functions.
Infrastructure (3) - C-specific
CAST
The tree structure corresponds to the grammar in Appendix A of K&R. Equality is unique-name equality (using attribute identifiers).
List of all datatypes:
CHeader (a complete C header), CExtDecl (external C declaration), CFunDef (function definition), CStat (C statement), CBlockItem (blocks), CDecl (toplevel, structure, parameters, type names), CDeclSpec and CStorageSpec (declaration specifiers and qualifiers), CTypeSpec, CTypeQual, CStructUnion, CStructTag, CEnum. CDeclr (identifier declarations), CInit (initializers), CDesignator, CExpr, CAssignOp,CBinaryOp,CUnaryOp,CConst.
CTokens
Tokens for the lexer, including Show instance.
CParserMonad
The monad is implemented as (state -> result a). In mtl terms it is a MonadState ParserState and a MonadError ParseError. The parser state comprises the current position, the current input, the previous token, the name supply, the set of typedef'ed identifiers and the set of outer scopes.
NameSpaces
Attribute Maps for global and local variables.
CAttrs
Attributes for the AST nodes. [TODO]
CBuiltin
Build-ins. Currently, only one build-in type name.
