c-dsl-0.3.1: A higher level DSL on top of language-c

Safe HaskellNone
LanguageHaskell2010

Language.C.DSL.Exp

Description

This module contians the DSL for writing CExprs. It doesn't export the orphan instance for IsString CExpr which can be found in Language.C.DSL.StringLike.

Synopsis

Documentation

str :: String -> CExpr Source

Lift a Haskell string into a literal C string.

(==:) :: CExpr -> CExpr -> CExpr Source

Equality test, a ==: b is equivalent to a == b

(/=:) :: CExpr -> CExpr -> CExpr Source

Inequality test, a /=: b is equivalent to a != b

(<:) :: CExpr -> CExpr -> CExpr Source

Less-than test, a <: b is equivalent to a < b

(>:) :: CExpr -> CExpr -> CExpr Source

Greater-than test, a >: b is equivalent to a > b

(<=:) :: CExpr -> CExpr -> CExpr Source

Less than or equal to, a <=: b is equivalent to a <= b

(>=:) :: CExpr -> CExpr -> CExpr Source

Greater than or equal to, a >=: b is equivalent to a >= b

ternary :: CExpr -> CExpr -> CExpr -> CExpr Source

The ternary operator in C. ternary a b c will turn into a ? b : c.

var :: Ident -> CExpr Source

A function mapping identifier in C to be used as variables. Normally this can be avoided since Language.C.DSL.StringLike provides an IsString instance.

(#) :: CExpr -> [CExpr] -> CExpr Source

Function calls, f#[a, b, c] will become f(a, b, c). Note that f is also an expression.

(<--) :: CExpr -> CExpr -> CExpr infixl 3 Source

The assignment operator. var <-- value will become var = value; in C.

assign :: CAssignOp -> CExpr -> CExpr -> CExpr Source

This is the more generalized version of '(<--)'. It allows any CAssignOp to be passed in to facilitate writing a += b and similar.

data UnOp Source

A simplified unary operator type. It can be converted to Cs version using toCUnaryOp.

Constructors

PlusPlus 
MinusMinus 
Minus 
Plus 
Not 
Addr

The address of operator &.

Ind

The dereferencing operator in C *.

Instances

toCUnaryOp :: UnOp -> CUnaryOp Source

Convert a UnOp to the corresponding CUnaryOp.

pre :: UnOp -> CExpr -> CExpr Source

Apply a unary operator prefix, op pre exp will transform into something like op exp in C. This only matters for PlusPlus and MinusMinus.

post :: CExpr -> UnOp -> CExpr Source

The postfix equivalent of pre.

star :: CExpr -> CExpr Source

A quick wrapper of pre Ind exp since it's so common.

comma :: [CExpr] -> CExpr Source

The C comma operator, comma [a, b, c] is equivalent to a, b, c in C.

castTo :: CExpr -> CDecl -> CExpr Source

Implements C style casts for expressions.

sizeOfDecl :: CDecl -> CExpr Source

size of for types.

sizeOf :: CExpr -> CExpr Source

size of for expressions. Carefully note that sizeOf "someType" will incorrectly treat someType as a variable, not a type.

(&) :: CExpr -> String -> CExpr infixl 8 Source

Access a field of a struct, this C's . operator.

(&*) :: CExpr -> String -> CExpr infixl 8 Source

The automatic dereferencing -> in C.

(!) :: CExpr -> CExpr -> CExpr infixl 8 Source

This is the indexing operator in C, a ! i is a[i].