generator: fix absname for fields with only accessor function
authorChristian Linhart <chris@DemoRecorder.com>
Sun, 2 Nov 2014 12:45:12 +0000 (13:45 +0100)
committerChristian Linhart <chris@demorecorder.com>
Mon, 3 Nov 2014 10:23:16 +0000 (11:23 +0100)
commit265d38882cffce597367cc8bb2160b9e2482a80f
treeab98fec2079940108973cf92f6c9627a004caff3
parentfdb291b414a7afc2c2326124b8ca11d6846cd7b9
generator: fix absname for fields with only accessor function

Fix _c_helper_absolute_name for fields which cannot be accessed
as a struct/union member but which can be accessed by an
accessor function.

The fix generates calls to the accessor function in these cases.

Example:
<struct name="AbsnameTest">
<field type="CARD32" name="len" />
<list type="CARD8" name="mylist1">
   <fieldref>len</fieldref>
</list>
<list type="CARD8" name="mylist2">
   <sumof ref="mylist1"/>
</list>
</struct>

The sumof-expression ( <sumof ref="mylist1"/> ) refers to mylist1
which is only acessible by an accessor function.

Previously, sumof was only used inside bitcases,
where such lists are accessible by members of the
deserialized parent struct.
(there is a difference between deserialization of switches
and structs.)

V2 of this patch:
* replaced "!= None" with "is not None" because that's more pythonic.
(according to suggestion from Ran Benita)

V3 of this patch: simplification:
* fixed the recursion in _c_type_setup
  so that _c_helper_absolute_name does not need check
  a gazillion things as a workaround anymore.

* simplified _c_helper_absolute_name
  - remove unneeded check for empty string before
    append of last_sep to prefix_str

  - removed those if-conditions which are not
    needed anymore after fixing the recursion
    in _c_type_setup.

  - extract functionality for checking whether a field
    needs an accessor ( and which type of accessor )
    in functions.
    (also extracted from _c_accessors)

  - rearrange the condition branches and actions for
    more readability.

V3 generates exactly the same *.c and *.h files as V2.

V4 of this patch:
* improve formatting as per suggestions of Ran

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