generator: sumof: support any type, generate explicit code
authorChristian Linhart <chris@DemoRecorder.com>
Sun, 2 Nov 2014 12:45:40 +0000 (13:45 +0100)
committerChristian Linhart <chris@demorecorder.com>
Mon, 3 Nov 2014 10:23:16 +0000 (11:23 +0100)
commit4a915c0dbadf326ea61349e29a0029d29f4bd339
tree4e6b3c351ddb94a461c8eac3fe347a347f6e2b35
parentfda1fb4ed47a705744677a0074d83464af7aa4eb
generator: sumof: support any type, generate explicit code

A sumof-expression now generates explicit code ( for-loop etc )
instead of calling xcb_sumof.

This way, it supports any type which can be added.
Previously, only uint_8 was supported.

Here's an example and the generated code:

xml:
<struct name="SumofTest">
   <field type="CARD32" name="len" />
   <list type="CARD16" name="mylist1">
   <fieldref>len</fieldref>
   </list>
   <list type="CARD8" name="mylist2">
   <sumof ref="mylist1"/>
   </list>
</struct>

declaration of tempvars at the start of enclosing function:
    int xcb_pre_tmp_1; /* sumof length */
    int xcb_pre_tmp_2; /* sumof loop counter */
    int64_t xcb_pre_tmp_3; /* sumof sum */
    const uint16_t* xcb_pre_tmp_4; /* sumof list ptr */

code:
    /* mylist2 */
    /* sumof start */
    xcb_pre_tmp_1 = _aux->len;
    xcb_pre_tmp_3 = 0;
    xcb_pre_tmp_4 = xcb_input_sumof_test_mylist_1(_aux);
    for ( xcb_pre_tmp_2 = 0; xcb_pre_tmp_2 < xcb_pre_tmp_1; xcb_pre_tmp_2++) {
        xcb_pre_tmp_3 += *xcb_pre_tmp_4;
        xcb_pre_tmp_4++;
    }
    /* sumof end. Result is in xcb_pre_tmp_3 */
    xcb_block_len += xcb_pre_tmp_3 * sizeof(uint8_t);

This patch is also a preparation for sumof which can access
fields of lists of struct, etc.

V2: Changed style and formatting according to suggestions from Ran Benita

Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
Reviewed-by: Ran Benita <ran234@gmail.com>
Message-ID: <54562774.8030306@DemoRecorder.com>
Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2
Patch-Set: ListInputDevices
Patch-Number: libxcb 4/9
Patch-Version: V2
src/c_client.py