Copyright | (c) [1999..2007] Manuel M T Chakravarty (c) 2008 Benedikt Huber |
---|---|
License | BSD-style |
Maintainer | benedikt.huber@gmail.com |
Stability | experimental |
Portability | ghc |
Safe Haskell | None |
Language | Haskell98 |
Abstract syntax of C source and header files.
The tree structure is based on the grammar in Appendix A of K&R. The abstract syntax simplifies the concrete syntax by merging similar concrete constructs into a single type of abstract tree structure: declarations are merged with structure declarations, parameter declarations and type names, and declarators are merged with abstract declarators.
With K&R we refer to ``The C Programming Language'', second edition, Brain W. Kernighan and Dennis M. Ritchie, Prentice Hall, 1988. The AST supports all of C99 http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf and several GNU extensions http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html.
Synopsis
- type CTranslUnit = CTranslationUnit NodeInfo
- type CExtDecl = CExternalDeclaration NodeInfo
- data CTranslationUnit a = CTranslUnit [CExternalDeclaration a] a
- data CExternalDeclaration a
- = CDeclExt (CDeclaration a)
- | CFDefExt (CFunctionDef a)
- | CAsmExt (CStringLiteral a) a
- type CFunDef = CFunctionDef NodeInfo
- type CDecl = CDeclaration NodeInfo
- type CStructUnion = CStructureUnion NodeInfo
- type CEnum = CEnumeration NodeInfo
- data CFunctionDef a = CFunDef [CDeclarationSpecifier a] (CDeclarator a) [CDeclaration a] (CStatement a) a
- data CDeclaration a
- = CDecl [CDeclarationSpecifier a] [(Maybe (CDeclarator a), Maybe (CInitializer a), Maybe (CExpression a))] a
- | CStaticAssert (CExpression a) (CStringLiteral a) a
- data CStructTag
- data CStructureUnion a = CStruct CStructTag (Maybe Ident) (Maybe [CDeclaration a]) [CAttribute a] a
- data CEnumeration a = CEnum (Maybe Ident) (Maybe [(Ident, Maybe (CExpression a))]) [CAttribute a] a
- type CDeclSpec = CDeclarationSpecifier NodeInfo
- partitionDeclSpecs :: [CDeclarationSpecifier a] -> ([CStorageSpecifier a], [CAttribute a], [CTypeQualifier a], [CTypeSpecifier a], [CFunctionSpecifier a], [CAlignmentSpecifier a])
- type CStorageSpec = CStorageSpecifier NodeInfo
- type CTypeSpec = CTypeSpecifier NodeInfo
- isSUEDef :: CTypeSpecifier a -> Bool
- type CTypeQual = CTypeQualifier NodeInfo
- type CFunSpec = CFunctionSpecifier NodeInfo
- type CAlignSpec = CAlignmentSpecifier NodeInfo
- type CAttr = CAttribute NodeInfo
- data CFunctionSpecifier a
- = CInlineQual a
- | CNoreturnQual a
- data CDeclarationSpecifier a
- = CStorageSpec (CStorageSpecifier a)
- | CTypeSpec (CTypeSpecifier a)
- | CTypeQual (CTypeQualifier a)
- | CFunSpec (CFunctionSpecifier a)
- | CAlignSpec (CAlignmentSpecifier a)
- data CStorageSpecifier a
- data CTypeSpecifier a
- = CVoidType a
- | CCharType a
- | CShortType a
- | CIntType a
- | CLongType a
- | CFloatType a
- | CDoubleType a
- | CSignedType a
- | CUnsigType a
- | CBoolType a
- | CComplexType a
- | CInt128Type a
- | CFloatNType Int Bool a
- | CSUType (CStructureUnion a) a
- | CEnumType (CEnumeration a) a
- | CTypeDef Ident a
- | CTypeOfExpr (CExpression a) a
- | CTypeOfType (CDeclaration a) a
- | CAtomicType (CDeclaration a) a
- data CAlignmentSpecifier a
- = CAlignAsType (CDeclaration a) a
- | CAlignAsExpr (CExpression a) a
- data CTypeQualifier a
- = CConstQual a
- | CVolatQual a
- | CRestrQual a
- | CAtomicQual a
- | CAttrQual (CAttribute a)
- | CNullableQual a
- | CNonnullQual a
- | CClRdOnlyQual a
- | CClWrOnlyQual a
- data CAttribute a = CAttr Ident [CExpression a] a
- type CDeclr = CDeclarator NodeInfo
- type CDerivedDeclr = CDerivedDeclarator NodeInfo
- type CArrSize = CArraySize NodeInfo
- data CDeclarator a = CDeclr (Maybe Ident) [CDerivedDeclarator a] (Maybe (CStringLiteral a)) [CAttribute a] a
- data CDerivedDeclarator a
- = CPtrDeclr [CTypeQualifier a] a
- | CArrDeclr [CTypeQualifier a] (CArraySize a) a
- | CFunDeclr (Either [Ident] ([CDeclaration a], Bool)) [CAttribute a] a
- data CArraySize a
- = CNoArrSize Bool
- | CArrSize Bool (CExpression a)
- type CInit = CInitializer NodeInfo
- type CInitList = CInitializerList NodeInfo
- type CDesignator = CPartDesignator NodeInfo
- data CInitializer a
- = CInitExpr (CExpression a) a
- | CInitList (CInitializerList a) a
- type CInitializerList a = [([CPartDesignator a], CInitializer a)]
- data CPartDesignator a
- = CArrDesig (CExpression a) a
- | CMemberDesig Ident a
- | CRangeDesig (CExpression a) (CExpression a) a
- type CStat = CStatement NodeInfo
- type CBlockItem = CCompoundBlockItem NodeInfo
- type CAsmStmt = CAssemblyStatement NodeInfo
- type CAsmOperand = CAssemblyOperand NodeInfo
- data CStatement a
- = CLabel Ident (CStatement a) [CAttribute a] a
- | CCase (CExpression a) (CStatement a) a
- | CCases (CExpression a) (CExpression a) (CStatement a) a
- | CDefault (CStatement a) a
- | CExpr (Maybe (CExpression a)) a
- | CCompound [Ident] [CCompoundBlockItem a] a
- | CIf (CExpression a) (CStatement a) (Maybe (CStatement a)) a
- | CSwitch (CExpression a) (CStatement a) a
- | CWhile (CExpression a) (CStatement a) Bool a
- | CFor (Either (Maybe (CExpression a)) (CDeclaration a)) (Maybe (CExpression a)) (Maybe (CExpression a)) (CStatement a) a
- | CGoto Ident a
- | CGotoPtr (CExpression a) a
- | CCont a
- | CBreak a
- | CReturn (Maybe (CExpression a)) a
- | CAsm (CAssemblyStatement a) a
- data CCompoundBlockItem a
- = CBlockStmt (CStatement a)
- | CBlockDecl (CDeclaration a)
- | CNestedFunDef (CFunctionDef a)
- data CAssemblyStatement a = CAsmStmt (Maybe (CTypeQualifier a)) (CStringLiteral a) [CAssemblyOperand a] [CAssemblyOperand a] [CStringLiteral a] a
- data CAssemblyOperand a = CAsmOperand (Maybe Ident) (CStringLiteral a) (CExpression a) a
- type CExpr = CExpression NodeInfo
- data CExpression a
- = CComma [CExpression a] a
- | CAssign CAssignOp (CExpression a) (CExpression a) a
- | CCond (CExpression a) (Maybe (CExpression a)) (CExpression a) a
- | CBinary CBinaryOp (CExpression a) (CExpression a) a
- | CCast (CDeclaration a) (CExpression a) a
- | CUnary CUnaryOp (CExpression a) a
- | CSizeofExpr (CExpression a) a
- | CSizeofType (CDeclaration a) a
- | CAlignofExpr (CExpression a) a
- | CAlignofType (CDeclaration a) a
- | CComplexReal (CExpression a) a
- | CComplexImag (CExpression a) a
- | CIndex (CExpression a) (CExpression a) a
- | CCall (CExpression a) [CExpression a] a
- | CMember (CExpression a) Ident Bool a
- | CVar Ident a
- | CConst (CConstant a)
- | CCompoundLit (CDeclaration a) (CInitializerList a) a
- | CGenericSelection (CExpression a) [(Maybe (CDeclaration a), CExpression a)] a
- | CStatExpr (CStatement a) a
- | CLabAddrExpr Ident a
- | CBuiltinExpr (CBuiltinThing a)
- data CAssignOp
- data CBinaryOp
- data CUnaryOp
- = CPreIncOp
- | CPreDecOp
- | CPostIncOp
- | CPostDecOp
- | CAdrOp
- | CIndOp
- | CPlusOp
- | CMinOp
- | CCompOp
- | CNegOp
- type CBuiltin = CBuiltinThing NodeInfo
- data CBuiltinThing a
- = CBuiltinVaArg (CExpression a) (CDeclaration a) a
- | CBuiltinOffsetOf (CDeclaration a) [CPartDesignator a] a
- | CBuiltinTypesCompatible (CDeclaration a) (CDeclaration a) a
- | CBuiltinConvertVector (CExpression a) (CDeclaration a) a
- type CConst = CConstant NodeInfo
- type CStrLit = CStringLiteral NodeInfo
- cstringOfLit :: CStringLiteral a -> CString
- liftStrLit :: CStringLiteral a -> CConstant a
- data CConstant a
- = CIntConst CInteger a
- | CCharConst CChar a
- | CFloatConst CFloat a
- | CStrConst CString a
- data CStringLiteral a = CStrLit CString a
- class Functor ast => Annotated ast where
- annotation :: ast a -> a
- amap :: (a -> a) -> ast a -> ast a
C translation units
type CTranslUnit = CTranslationUnit NodeInfo Source #
Complete C tranlsation unit (C99 6.9, K&R A10)
A complete C translation unit, for example representing a C header or source file. It consists of a list of external (i.e. toplevel) declarations.
type CExtDecl = CExternalDeclaration NodeInfo Source #
External C declaration (C99 6.9, K&R A10)
Either a toplevel declaration, function definition or external assembler.
data CTranslationUnit a Source #
Instances
data CExternalDeclaration a Source #
CDeclExt (CDeclaration a) | |
CFDefExt (CFunctionDef a) | |
CAsmExt (CStringLiteral a) a |
Instances
Declarations
type CFunDef = CFunctionDef NodeInfo Source #
C function definition (C99 6.9.1, K&R A10.1)
A function definition is of the form CFunDef specifiers declarator decllist? stmt
.
specifiers
are the type and storage-class specifiers of the function. The only storage-class specifiers allowed are extern and static.- The
declarator
must be such that the declared identifier has function type. The return type shall be void or an object type other than array type. - The optional declaration list
decllist
is for old-style function declarations. - The statement
stmt
is a compound statement.
type CDecl = CDeclaration NodeInfo Source #
C declarations (K&R A8, C99 6.7), including structure declarations, parameter declarations and type names.
A declaration is of the form CDecl specifiers init-declarator-list
, where the form of the declarator list's
elements depends on the kind of declaration:
1) Toplevel declarations (K&R A8, C99 6.7 declaration)
- C99 requires that there is at least one specifier, though this is merely a syntactic restriction
- at most one storage class specifier is allowed per declaration
- the elements of the non-empty
init-declarator-list
are of the form(Just declr, init?, Nothing)
. The declaratordeclr
has to be present and non-abstract and the initialization expression is optional.
2) Structure declarations (K&R A8.3, C99 6.7.2.1 struct-declaration)
Those are the declarations of a structure's members.
- do not allow storage specifiers
- in strict C99, the list of declarators has to be non-empty
- the elements of
init-declarator-list
are either of the form(Just declr, Nothing, size?)
, representing a member with optional bit-field size, or of the form(Nothing, Nothing, Just size)
, for unnamed bitfields.declr
has to be non-abstract. - no member of a structure shall have incomplete type
3) Parameter declarations (K&R A8.6.3, C99 6.7.5 parameter-declaration)
init-declarator-list
must contain at most one triple of the form(Just declr, Nothing, Nothing)
, i.e. consist of a single declarator, which is allowed to be abstract (i.e. unnamed).
4) Type names (A8.8, C99 6.7.6)
- do not allow storage specifiers
init-declarator-list
must contain at most one triple of the form(Just declr, Nothing, Nothing)
. wheredeclr
is an abstract declarator (i.e. doesn't contain a declared identifier)
type CStructUnion = CStructureUnion NodeInfo Source #
C structure or union specifiers (K&R A8.3, C99 6.7.2.1)
CStruct tag identifier struct-decls c-attrs
represents a struct or union specifier (depending on tag
).
- either
identifier
or the declaration liststruct-decls
(or both) have to be present.
Example: in struct foo x;
, the identifier is present, in struct { int y; } x
the declaration list, and
in struct foo { int y; } x;
both of them.
c-attrs
is a list ofattribute
annotations associated with the struct or union specifier
type CEnum = CEnumeration NodeInfo Source #
C enumeration specifier (K&R A8.4, C99 6.7.2.2)
CEnum identifier enumerator-list attrs
represent as enum specifier
- Either the identifier or the enumerator-list (or both) have to be present.
- If
enumerator-list
is present, it has to be non-empty. - The enumerator list is of the form
(enumeration-constant, enumeration-value?)
, where the latter is an optional constant integral expression. attrs
is a list ofattribute
annotations associated with the enumeration specifier
data CFunctionDef a Source #
CFunDef [CDeclarationSpecifier a] (CDeclarator a) [CDeclaration a] (CStatement a) a |
Instances
data CDeclaration a Source #
CDecl [CDeclarationSpecifier a] [(Maybe (CDeclarator a), Maybe (CInitializer a), Maybe (CExpression a))] a | |
CStaticAssert (CExpression a) (CStringLiteral a) a |
Instances
data CStructTag Source #
A tag to determine wheter we refer to a struct
or union
, see CStructUnion
.
Instances
data CStructureUnion a Source #
CStruct CStructTag (Maybe Ident) (Maybe [CDeclaration a]) [CAttribute a] a |
Instances
data CEnumeration a Source #
CEnum (Maybe Ident) (Maybe [(Ident, Maybe (CExpression a))]) [CAttribute a] a |
Instances
Declaration attributes
type CDeclSpec = CDeclarationSpecifier NodeInfo Source #
C declaration specifiers and qualifiers
Declaration specifiers include at most one storage-class specifier (C99 6.7.1), type specifiers (6.7.2) and type qualifiers (6.7.3).
partitionDeclSpecs :: [CDeclarationSpecifier a] -> ([CStorageSpecifier a], [CAttribute a], [CTypeQualifier a], [CTypeSpecifier a], [CFunctionSpecifier a], [CAlignmentSpecifier a]) Source #
Separate the declaration specifiers
attribute
of a declaration qualify declarations or declarators (but not types),
and are therefore separated as well.
type CStorageSpec = CStorageSpecifier NodeInfo Source #
C storage class specifier (and typedefs) (K&R A8.1, C99 6.7.1)
type CTypeSpec = CTypeSpecifier NodeInfo Source #
C type specifier (K&R A8.2, C99 6.7.2)
Type specifiers are either basic types such as char
or int
,
struct
, union
or enum
specifiers or typedef names.
As a GNU extension, a typeof
expression also is a type specifier.
isSUEDef :: CTypeSpecifier a -> Bool Source #
returns True
if the given typespec is a struct, union or enum definition
type CTypeQual = CTypeQualifier NodeInfo Source #
C type qualifiers (K&R A8.2, C99 6.7.3) and attributes.
const
, volatile
and restrict
type qualifiers
Additionally, attribute
annotations for declarations and declarators, and
function specifiers
type CFunSpec = CFunctionSpecifier NodeInfo Source #
C function specifiers (C99 6.7.4)
function specifiers inline
and _Noreturn
type CAlignSpec = CAlignmentSpecifier NodeInfo Source #
C alignment specifiers (C99 6.7.5)
type CAttr = CAttribute NodeInfo Source #
attribute
annotations
Those are of the form CAttr attribute-name attribute-parameters
,
and serve as generic properties of some syntax tree elements.
data CFunctionSpecifier a Source #
Instances
data CDeclarationSpecifier a Source #
CStorageSpec (CStorageSpecifier a) | storage-class specifier or typedef |
CTypeSpec (CTypeSpecifier a) | type name |
CTypeQual (CTypeQualifier a) | type qualifier |
CFunSpec (CFunctionSpecifier a) | function specifier |
CAlignSpec (CAlignmentSpecifier a) | alignment specifier |
Instances
data CStorageSpecifier a Source #
CAuto a | auto |
CRegister a | register |
CStatic a | static |
CExtern a | extern |
CTypedef a | typedef |
CThread a | C11/GNUC thread local storage |
CClKernel a | OpenCL kernel function |
CClGlobal a | OpenCL __global variable |
CClLocal a | OpenCL __local variable |
Instances
data CTypeSpecifier a Source #
CVoidType a | |
CCharType a | |
CShortType a | |
CIntType a | |
CLongType a | |
CFloatType a | |
CDoubleType a | |
CSignedType a | |
CUnsigType a | |
CBoolType a | |
CComplexType a | |
CInt128Type a | |
CFloatNType Int Bool a | IEC 60227: width (32,64,128), extended flag |
CSUType (CStructureUnion a) a | Struct or Union specifier |
CEnumType (CEnumeration a) a | Enumeration specifier |
CTypeDef Ident a | Typedef name |
CTypeOfExpr (CExpression a) a | typeof(expr) |
CTypeOfType (CDeclaration a) a | typeof(type) |
CAtomicType (CDeclaration a) a | _Atomic(type) |
Instances
data CAlignmentSpecifier a Source #
CAlignAsType (CDeclaration a) a | _Alignas(type) |
CAlignAsExpr (CExpression a) a | _Alignas(expr) |
Instances
data CTypeQualifier a Source #
CConstQual a | |
CVolatQual a | |
CRestrQual a | |
CAtomicQual a | |
CAttrQual (CAttribute a) | |
CNullableQual a | |
CNonnullQual a | |
CClRdOnlyQual a | |
CClWrOnlyQual a |
Instances
data CAttribute a Source #
CAttr Ident [CExpression a] a |
Instances
Declarators
type CDeclr = CDeclarator NodeInfo Source #
C declarator (K&R A8.5, C99 6.7.5) and abstract declarator (K&R A8.8, C99 6.7.6)
A declarator declares a single object, function, or type. It is always associated with
a declaration (CDecl
), which specifies the declaration's type and the additional storage qualifiers and
attributes, which apply to the declared object.
A declarator is of the form CDeclr name? indirections asm-name? attrs _
, where
name
is the name of the declared object (missing for abstract declarators),
declquals
is a set of additional declaration specifiers,
asm-name
is the optional assembler name and attributes is a set of
attrs is a set of attribute
annotations for the declared object.
indirections
is a set of pointer, array and function declarators, which modify the type of the declared object as
described below. If the declaration specifies the non-derived type T
,
and we have indirections = [D1, D2, ..., Dn]
than the declared object has type
(D1
, whereindirect
(D2 indirect
... (Dn indirect
T)))
(CPtrDeclr attrs)
is attributed pointer to Tindirect
T(CFunDeclr attrs)
is attributed function returning Tindirect
T(CArrayDeclr attrs)
is attributed array of elemements of type Tindirect
T
Examples (simplified attributes):
- x is an int
int x; CDeclr "x" []
- x is a restrict pointer to a const pointer to int
const int * const * restrict x; CDeclr "x" [CPtrDeclr [restrict], CPtrDeclr [const]]
- f is an function return a constant pointer to int
int* const f(); CDeclr "f" [CFunDeclr [],CPtrDeclr [const]]
- f is a constant pointer to a function returning int
int (* const f)(); ==> CDeclr "f" [CPtrDeclr [const], CFunDeclr []]
type CDerivedDeclr = CDerivedDeclarator NodeInfo Source #
Derived declarators, see CDeclr
Indirections are qualified using type-qualifiers and generic attributes, and additionally
- The size of an array is either a constant expression, variable length (
*
) or missing; in the last case, the type of the array is incomplete. The qualifier static is allowed for function arguments only, indicating that the supplied argument is an array of at least the given size. - New style parameter lists have the form
Right (declarations, isVariadic)
, old style parameter lists have the formLeft (parameter-names)
type CArrSize = CArraySize NodeInfo Source #
Size of an array
data CDeclarator a Source #
CDeclr (Maybe Ident) [CDerivedDeclarator a] (Maybe (CStringLiteral a)) [CAttribute a] a |
Instances
data CDerivedDeclarator a Source #
CPtrDeclr [CTypeQualifier a] a | Pointer declarator |
CArrDeclr [CTypeQualifier a] (CArraySize a) a | Array declarator |
CFunDeclr (Either [Ident] ([CDeclaration a], Bool)) [CAttribute a] a | Function declarator |
Instances
data CArraySize a Source #
CNoArrSize Bool | CUnknownSize isCompleteType |
CArrSize Bool (CExpression a) | CArrSize isStatic expr |
Instances
Initialization
type CInit = CInitializer NodeInfo Source #
C initialization (K&R A8.7, C99 6.7.8)
Initializers are either assignment expressions or initializer lists (surrounded in curly braces), whose elements are themselves initializers, paired with an optional list of designators.
type CInitList = CInitializerList NodeInfo Source #
Initializer List
The members of an initializer list are of the form (designator-list,initializer)
.
The designator-list
specifies one member of the compound type which is initialized.
It is allowed to be empty - in this case the initializer refers to the
'next'
member of the compound type (see C99 6.7.8).
Examples (simplified expressions and identifiers):
-- int x[3][4] = { [0][3] = 4, [2] = 5, 8 }; -- corresponds to the assignments -- x[0][3] = 4; x[2][0] = 5; x[2][1] = 8; let init1 = ([CArrDesig 0, CArrDesig 3], CInitExpr 4) init2 = ([CArrDesig 2] , CInitExpr 5) init3 = ([] , CInitExpr 8) in CInitList [init1, init2, init3]
-- struct { struct { int a[2]; int b[2]; int c[2]; } s; } x = { .s = { {2,3} , .c[0] = 1 } }; -- corresponds to the assignments -- x.s.a[0] = 2; x.s.a[1] = 3; x.s.c[0] = 1; let init_s_0 = CInitList [ ([], CInitExpr 2), ([], CInitExpr 3)] init_s = CInitList [ ([], init_s_0), ([CMemberDesig "c", CArrDesig 0], CInitExpr 1) ] in CInitList [(CMemberDesig "s", init_s)]
type CDesignator = CPartDesignator NodeInfo Source #
Designators
A designator specifies a member of an object, either an element or range of an array, or the named member of a struct / union.
data CInitializer a Source #
CInitExpr (CExpression a) a | assignment expression |
CInitList (CInitializerList a) a | initialization list (see |
Instances
type CInitializerList a = [([CPartDesignator a], CInitializer a)] Source #
data CPartDesignator a Source #
CArrDesig (CExpression a) a | array position designator |
CMemberDesig Ident a | member designator |
CRangeDesig (CExpression a) (CExpression a) a | array range designator |
Instances
Statements
type CStat = CStatement NodeInfo Source #
C statement (K&R A9, C99 6.8)
type CBlockItem = CCompoundBlockItem NodeInfo Source #
C99 Block items
Things that may appear in compound statements: either statements, declarations or nested function definitions.
type CAsmStmt = CAssemblyStatement NodeInfo Source #
GNU Assembler statement
CAssemblyStatement type-qual? asm-expr out-ops in-ops clobbers _
is an inline assembler statement.
The only type-qualifier (if any) allowed is volatile.
asm-expr
is the actual assembler epxression (a string), out-ops
and in-ops
are the input
and output operands of the statement.
clobbers
is a list of registers which are clobbered when executing the assembler statement
type CAsmOperand = CAssemblyOperand NodeInfo Source #
Assembler operand
CAsmOperand argName? constraintExpr arg
specifies an operand for an assembler
statement.
data CStatement a Source #
CLabel Ident (CStatement a) [CAttribute a] a | An (attributed) label followed by a statement |
CCase (CExpression a) (CStatement a) a | A statement of the form |
CCases (CExpression a) (CExpression a) (CStatement a) a | A case range of the form |
CDefault (CStatement a) a | The default case |
CExpr (Maybe (CExpression a)) a | A simple statement, that is in C: evaluating an expression with side-effects and discarding the result. |
CCompound [Ident] [CCompoundBlockItem a] a | compound statement |
CIf (CExpression a) (CStatement a) (Maybe (CStatement a)) a | conditional statement |
CSwitch (CExpression a) (CStatement a) a | switch statement |
CWhile (CExpression a) (CStatement a) Bool a | while or do-while statement |
CFor (Either (Maybe (CExpression a)) (CDeclaration a)) (Maybe (CExpression a)) (Maybe (CExpression a)) (CStatement a) a | for statement |
CGoto Ident a | goto statement |
CGotoPtr (CExpression a) a | computed goto |
CCont a | continue statement |
CBreak a | break statement |
CReturn (Maybe (CExpression a)) a | return statement |
CAsm (CAssemblyStatement a) a | assembly statement |
Instances
data CCompoundBlockItem a Source #
CBlockStmt (CStatement a) | A statement |
CBlockDecl (CDeclaration a) | A local declaration |
CNestedFunDef (CFunctionDef a) | A nested function (GNU C) |
Instances
data CAssemblyStatement a Source #
CAsmStmt (Maybe (CTypeQualifier a)) (CStringLiteral a) [CAssemblyOperand a] [CAssemblyOperand a] [CStringLiteral a] a |
Instances
data CAssemblyOperand a Source #
CAsmOperand (Maybe Ident) (CStringLiteral a) (CExpression a) a |
Instances
Expressions
type CExpr = CExpression NodeInfo Source #
C expression (K&R A7)
- these can be arbitrary expression, as the argument of
sizeof
can be arbitrary, even if appearing in a constant expression - GNU C extensions:
alignof
,__real
,__imag
,({ stmt-expr })
,&& label
and built-ins
data CExpression a Source #
CComma [CExpression a] a | |
CAssign CAssignOp (CExpression a) (CExpression a) a | |
CCond (CExpression a) (Maybe (CExpression a)) (CExpression a) a | |
CBinary CBinaryOp (CExpression a) (CExpression a) a | |
CCast (CDeclaration a) (CExpression a) a | |
CUnary CUnaryOp (CExpression a) a | |
CSizeofExpr (CExpression a) a | |
CSizeofType (CDeclaration a) a | |
CAlignofExpr (CExpression a) a | |
CAlignofType (CDeclaration a) a | |
CComplexReal (CExpression a) a | |
CComplexImag (CExpression a) a | |
CIndex (CExpression a) (CExpression a) a | |
CCall (CExpression a) [CExpression a] a | |
CMember (CExpression a) Ident Bool a | |
CVar Ident a | |
CConst (CConstant a) | integer, character, floating point and string constants |
CCompoundLit (CDeclaration a) (CInitializerList a) a | C99 compound literal |
CGenericSelection (CExpression a) [(Maybe (CDeclaration a), CExpression a)] a | C11 generic selection |
CStatExpr (CStatement a) a | GNU C compound statement as expr |
CLabAddrExpr Ident a | GNU C address of label |
CBuiltinExpr (CBuiltinThing a) | builtin expressions, see |
Instances
C assignment operators (K&R A7.17)
CAssignOp | |
CMulAssOp | |
CDivAssOp | |
CRmdAssOp | remainder and assignment |
CAddAssOp | |
CSubAssOp | |
CShlAssOp | |
CShrAssOp | |
CAndAssOp | |
CXorAssOp | |
COrAssOp |
Instances
Eq CAssignOp Source # | |
Data CAssignOp Source # | |
Defined in Language.C.Syntax.Ops gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CAssignOp -> c CAssignOp # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CAssignOp # toConstr :: CAssignOp -> Constr # dataTypeOf :: CAssignOp -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CAssignOp) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CAssignOp) # gmapT :: (forall b. Data b => b -> b) -> CAssignOp -> CAssignOp # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CAssignOp -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CAssignOp -> r # gmapQ :: (forall d. Data d => d -> u) -> CAssignOp -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CAssignOp -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CAssignOp -> m CAssignOp # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CAssignOp -> m CAssignOp # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CAssignOp -> m CAssignOp # | |
Ord CAssignOp Source # | |
Defined in Language.C.Syntax.Ops | |
Show CAssignOp Source # | |
Generic CAssignOp Source # | |
NFData CAssignOp Source # | |
Defined in Language.C.Syntax.Ops | |
Pretty CAssignOp Source # | |
type Rep CAssignOp Source # | |
Defined in Language.C.Syntax.Ops type Rep CAssignOp = D1 ('MetaData "CAssignOp" "Language.C.Syntax.Ops" "language-c-0.9-inplace" 'False) (((C1 ('MetaCons "CAssignOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CMulAssOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CDivAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CRmdAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CAddAssOp" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "CSubAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CShlAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CShrAssOp" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "CAndAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CXorAssOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "COrAssOp" 'PrefixI 'False) (U1 :: Type -> Type))))) |
C binary operators (K&R A7.6-15)
CMulOp | |
CDivOp | |
CRmdOp | remainder of division |
CAddOp | |
CSubOp | |
CShlOp | shift left |
CShrOp | shift right |
CLeOp | less |
CGrOp | greater |
CLeqOp | less or equal |
CGeqOp | greater or equal |
CEqOp | equal |
CNeqOp | not equal |
CAndOp | bitwise and |
CXorOp | exclusive bitwise or |
COrOp | inclusive bitwise or |
CLndOp | logical and |
CLorOp | logical or |
Instances
Eq CBinaryOp Source # | |
Data CBinaryOp Source # | |
Defined in Language.C.Syntax.Ops gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CBinaryOp -> c CBinaryOp # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CBinaryOp # toConstr :: CBinaryOp -> Constr # dataTypeOf :: CBinaryOp -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CBinaryOp) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CBinaryOp) # gmapT :: (forall b. Data b => b -> b) -> CBinaryOp -> CBinaryOp # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CBinaryOp -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CBinaryOp -> r # gmapQ :: (forall d. Data d => d -> u) -> CBinaryOp -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CBinaryOp -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CBinaryOp -> m CBinaryOp # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CBinaryOp -> m CBinaryOp # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CBinaryOp -> m CBinaryOp # | |
Ord CBinaryOp Source # | |
Defined in Language.C.Syntax.Ops | |
Show CBinaryOp Source # | |
Generic CBinaryOp Source # | |
NFData CBinaryOp Source # | |
Defined in Language.C.Syntax.Ops | |
Pretty CBinaryOp Source # | |
type Rep CBinaryOp Source # | |
Defined in Language.C.Syntax.Ops type Rep CBinaryOp = D1 ('MetaData "CBinaryOp" "Language.C.Syntax.Ops" "language-c-0.9-inplace" 'False) ((((C1 ('MetaCons "CMulOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CDivOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CRmdOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CAddOp" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "CSubOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CShlOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CShrOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CLeOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CGrOp" 'PrefixI 'False) (U1 :: Type -> Type))))) :+: (((C1 ('MetaCons "CLeqOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CGeqOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CEqOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CNeqOp" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "CAndOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CXorOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "COrOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CLndOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CLorOp" 'PrefixI 'False) (U1 :: Type -> Type)))))) |
C unary operator (K&R A7.3-4)
CPreIncOp | prefix increment operator |
CPreDecOp | prefix decrement operator |
CPostIncOp | postfix increment operator |
CPostDecOp | postfix decrement operator |
CAdrOp | address operator |
CIndOp | indirection operator |
CPlusOp | prefix plus |
CMinOp | prefix minus |
CCompOp | one's complement |
CNegOp | logical negation |
Instances
Eq CUnaryOp Source # | |
Data CUnaryOp Source # | |
Defined in Language.C.Syntax.Ops gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CUnaryOp -> c CUnaryOp # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CUnaryOp # toConstr :: CUnaryOp -> Constr # dataTypeOf :: CUnaryOp -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CUnaryOp) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CUnaryOp) # gmapT :: (forall b. Data b => b -> b) -> CUnaryOp -> CUnaryOp # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CUnaryOp -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CUnaryOp -> r # gmapQ :: (forall d. Data d => d -> u) -> CUnaryOp -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CUnaryOp -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CUnaryOp -> m CUnaryOp # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CUnaryOp -> m CUnaryOp # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CUnaryOp -> m CUnaryOp # | |
Ord CUnaryOp Source # | |
Defined in Language.C.Syntax.Ops | |
Show CUnaryOp Source # | |
Generic CUnaryOp Source # | |
NFData CUnaryOp Source # | |
Defined in Language.C.Syntax.Ops | |
Pretty CUnaryOp Source # | |
type Rep CUnaryOp Source # | |
Defined in Language.C.Syntax.Ops type Rep CUnaryOp = D1 ('MetaData "CUnaryOp" "Language.C.Syntax.Ops" "language-c-0.9-inplace" 'False) (((C1 ('MetaCons "CPreIncOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CPreDecOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CPostIncOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CPostDecOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CAdrOp" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "CIndOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CPlusOp" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CMinOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CCompOp" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CNegOp" 'PrefixI 'False) (U1 :: Type -> Type))))) |
type CBuiltin = CBuiltinThing NodeInfo Source #
GNU Builtins, which cannot be typed in C99
data CBuiltinThing a Source #
CBuiltinVaArg (CExpression a) (CDeclaration a) a | (expr, type) |
CBuiltinOffsetOf (CDeclaration a) [CPartDesignator a] a | (type, designator-list) |
CBuiltinTypesCompatible (CDeclaration a) (CDeclaration a) a | (type,type) |
CBuiltinConvertVector (CExpression a) (CDeclaration a) a | (expr, type) |
Instances
Constants
type CStrLit = CStringLiteral NodeInfo Source #
Attributed string literals
cstringOfLit :: CStringLiteral a -> CString Source #
liftStrLit :: CStringLiteral a -> CConstant a Source #
Lift a string literal to a C constant
Instances
data CStringLiteral a Source #
Instances
Annoated type class
class Functor ast => Annotated ast where Source #
All AST nodes are annotated. Inspired by the Annotated
class of Niklas Broberg's haskell-src-exts package.
In principle, we could have Copointed superclass instead
of ann
, for the price of another dependency.
annotation :: ast a -> a Source #
get the annotation of an AST node
amap :: (a -> a) -> ast a -> ast a Source #
change the annotation (non-recursively) of an AST node. Use fmap for recursively modifying the annotation.