Skip to content

cxx fixes - #190

Open
hchataing wants to merge 4 commits into
mainfrom
cxx-fixes
Open

hchataing wants to merge 4 commits into
mainfrom
cxx-fixes

Conversation

@hchataing

Copy link
Copy Markdown
Collaborator
  • cxx: Fix the generation of code for the Android PDL grammars
  • cxx: Align the accessor naming with generate_cxx_backend.py
  • tests: Add canonical test cases for the C++ backend fixes
  • tests: Add a script checking that the generated C++ code compiles

The C++ backend generated invalid code, or failed, for most of the
grammars found in the Android repository (Bluetooth, NFC, UWB, ...):

- Closed enum fields extracted from the same chunk all declared a local
  variable `raw_value`. The variables are now named after the field.
- The `span` variable was not declared in the parser of packet views
  without fields, but used to check for trailing bytes.
- Children of packets without payload (specialized by constraints only)
  referenced the inexistent `payload_` member of the parent view.
- The payload size fields of the parent packets were declared as
  members of the child views and builders, conflicting with the payload
  size field of the child packet.
- The count, size, and element size values of parent array fields were
  not copied to the child views.
- Builders computed the payload size of parent packets from the fields
  of the leaf packet only, or from the leaf payload when the leaf packet
  declares a payload. The size of all the fields between the parent
  packet and the leaf packet is now accounted for. This bug produced
  invalid packets for any hierarchy with more than two levels, e.g. the
  HCI Command Status events.
- Range tags were not declared in the generated enums, and the default
  value of enum fields used the first tag even when this tag was a range
  or default tag. Range tags are now declared with `_MIN` and `_MAX`
  bounds, followed by the tags declared inside the range.
- Struct and packet declarations were generated in source order, but
  C++ requires types to be defined before use. The declarations are now
  generated in dependency order.
- The payload field of structs was assigned a slice instead of a byte
  vector.
- The generator panicked when a field of unknown size was followed by
  fields of non-static size (UWB TestSrRxNtf). The typedef field is now
  parsed from the remaining span, like the Rust backend does.
- The span of a typedef field of unknown size followed by static fields
  was not advanced past the parsed field.
The accessors were named with heck::ToUpperCamelCase, which does not
capitalize letters following a digit (ch3c_shape -> GetCh3cShape), while
generate_cxx_backend.py and generate_cxx_backend_tests.py use the Python
str.title() convention (ch3c_shape -> GetCh3CShape). Use the same
convention to keep the generated code compatible with the code written
against the headers generated by generate_cxx_backend.py.
Add test cases for the issues fixed in the C++ backend:

- Packet_Enum_Field_Packed: multiple closed enum fields packed in the
  same bit field chunk.
- ScalarGrandChild_C: three levels of inheritance with fields declared at
  every level, the payload size of the root packet accounts for all the
  fields.
- ScalarChild_D: child packet declaring a payload size field, when the
  parent packet also declares one.
- ConstrainedChild_A, ConstrainedChild_B: children of a packet without
  payload, specialized by constraints only.

The Java backend fails to generate ConstrainedParent, and the Java tests
generator sets the constrained fields of grandparent packets; these
declarations are excluded from the Java tests.
cxx_compile_check.py generates the C++ backend for a list of PDL files,
generates stub implementations for the declared custom fields and
checksums, and compiles the generated headers with -fsyntax-only.
The script reports the generator failures and compilation errors, and is
used to validate the C++ backend against the PDL grammars of the Android
repository:

    ./tests/cxx_compile_check.py --pdlc ../target/release/pdlc \
        $(find $ANDROID_BUILD_TOP -name '*.pdl')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant