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

Safe HaskellNone

Language.C.DSL.Decl

Synopsis

Documentation

declSource

Arguments

:: CDeclSpec

The declaration specifier, usually this is a type

-> CDeclr

Equivalent to the name of the object being declared. Often this will make use of the overloaded string instance for CDeclrs

-> Maybe CExpr

The optional init expression

-> CDecl 

A low level way to declare something.

voidTy :: CDeclSpecSource

The CDeclSpec for declarations of type void

charTy :: CDeclSpecSource

The CDeclSpec for declarations of type char

shortTy :: CDeclSpecSource

The CDeclSpec for declarations of type short

intTy :: CDeclSpecSource

The CDeclSpec for declarations of type int

longTy :: CDeclSpecSource

The CDeclSpec for declarations of type long

floatTy :: CDeclSpecSource

The CDeclSpec for declarations of type float

doubleTy :: CDeclSpecSource

The CDeclSpec for declarations of type double

ty :: Ident -> CTypeSpecSource

Turns a string into the corresponding typedefed type.

For example

 struct "foo" [("bar, ty "quux")]

will generate the corresponding

 typedef foo {quux bar;} foo

ptr :: CDeclr -> CDeclrSource

Modifies a declarator to be a pointer. For example ptr someName would be *x in C.

char :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a char.

     char "x" .= 1
     uninit $ char "y"

Would generate

 char x = 1;
 char y;

short :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a short

int :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a int

long :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a long

float :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a float

double :: CDeclr -> Maybe CExpr -> CDeclSource

A short cut for declaring a double

charPtr :: CDeclr -> Maybe CExpr -> CDeclSource

Equivalent to char but wraps the CDeclr in a pointer. This means that uninit $ charPtr someName is equivalent to char *someName;

(.=) :: (Maybe CExpr -> CDecl) -> CExpr -> CDeclSource

Supplies an initializer for an for a declaration. This is meant to be used with the char and friends short cuts

uninit :: (Maybe CExpr -> CDecl) -> CDeclSource

Leave a declaration uninitialized. This is meant to be used with the char and friends declaration

csu :: CStructTag -> String -> [(String, CTypeSpec)] -> CDeclSource

struct :: String -> [(String, CTypeSpec)] -> CDeclSource

Create a structure, for example struct foo [(bar, intTy)] is typedef struct foo {int bar;} foo;

union :: String -> [(String, CTypeSpec)] -> CDeclSource

Equivalent to struct but generates a C union instead.

fun :: [CDeclSpec] -> String -> [Maybe CExpr -> CDecl] -> CStat -> CFunDefSource

Defines a C function. For example

    test =
       fun [intTy] "test"[int "a", int "b"] $ hblock [
           creturn ("a" + "b")
       ]

Would be the equivalent of

   int test(int a, int b)
   {
      return a + b;
   }

annotatedFun :: [CDeclSpec] -> String -> [Maybe CExpr -> CDecl] -> [String] -> CStat -> CFunDefSource

Identical to fun except this annotates the list of attributes given as a list of strings.

transUnit :: [CExtDecl] -> CTranslUnitSource

Exports a series of declarations to a translation unit.