cgen.py, templates: use new `_CompoundOp` for structure fields
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 8 Sep 2020 20:05:42 +0000 (16:05 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 8 Sep 2020 20:15:06 +0000 (16:15 -0400)
commit2394a4b42a97b7d8c62ee34d469c13ac9cb7b9cc
tree40351ad9e18de107974a3c649a204a640dff017e
parent634084f6abbf93a68bc35eb93a4368cd0d637375
cgen.py, templates: use new `_CompoundOp` for structure fields

This patch adds the `_CompoundOp` class which inherits `_Op`. It also
makes `_AlignOp` and `_WriteOp` inherit a new `_LeadOf` class. The final
operation class hierarchy is:

    _Op
      _CompoundOp
      _LeafOp
        _AlignOp
        _WriteOp

A compound operation is a simple container of suboperations (compound or
leaf). It is expected that a compound field type leads to a compound
operation.

As of this version, the only "real" compound field type is the structure
field type.

`_OpsBuilder` becomes `_OpBuilder` and does not accumulate operations
anymore: it still has a state, but its build_for_root_ft() method
returns a `_CompoundOp` object for a given root structure field type.

The returned compound operation can contain an "align" operation for the
structure field itself as its first suboperation.

Because an `_OpBuilder` doesn't accumulate operations anymore, there's
no need to copy operations anymore.

For a structure field type, _OpBuilder._build_for_ft() returns a single
compound operation having the new serialization and size templates
`serialize-write-struct-statements.j2` and
`size-write-struct-statements.j2`. Those templates contain a C comment
and a simple loop to render the appropriate template for each
suboperation, forwarding the `stream_type` and `ev_type` context
variables.

`barectf.c.j2` is changed to render a single template for any compound
operation. This removes many loops.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/cgen.py
barectf/templates/c/barectf.c.j2
barectf/templates/c/serialize-write-struct-statements.j2 [new file with mode: 0644]
barectf/templates/c/size-write-struct-statements.j2 [new file with mode: 0644]
This page took 0.023389 seconds and 4 git commands to generate.