[C2hs] Re: c2hs / Language.C feature to discover cdecl / stdcall

Benedikt Huber benjovi at gmx.net
Thu Apr 2 06:09:44 EDT 2009


On 02.04.2009, at 11:34, Duncan Coutts wrote:
> It was pointed out to me yesterday that it would be rather useful if
> c2hs could automatically work out if the ffi import for a {# call/ 
> fun #}
> hook should be ccall or stdcall calling convention
> ...
> So the first job would be for Language.C to keep the __attribute__'s  
> in
> the abstract syntax tree. They already get parsed, but at least last
> time I looked they were not entered into the AST.
Hi Duncan,

language.c records attributes already :) (implemented during SoC last  
year).

See: http://hackage.haskell.org/packages/archive/language-c/0.3.1.1/doc/html/Language-C-Syntax-AST.html#t%3ACAttr

examples $ cat test.i
__attribute__((__stdcall__)) int f();
examples $ ./ParseAndPrint test.i
__attribute__((__stdcall__)) int f();

In the AST, this kind of attribute is recorded like this:

* CDecl
   * declspecs-list
     + CTypeQual
        + CAttrQual
            * CAttr "__stdcall__" [] nodeinfo
   *  declr-list
   *  nodeinfo

> The attribute syntax
> is pretty uniform so a generic representation in the AST would be  
> fine.
> Any code that interpreted the attributes would just have to match on
> known string values.
Right, it is easy to check whether the "stdcall" attribute is present.
Is the current language.c support sufficient for implementing this  
request ?

benedikt




More information about the C2hs mailing list