binPAC : more than one &require attribute on a field

Hi all,

I'm a Bro beginner. I got a small problem when writing binPAC. See below.

I'm using master branch of binPAC.

In the binPAC grammar, nothing prevents from applying many &requires attributes to the same field.
However, in such a case the generated C++ code is incorrect.

type MyArray = record {
     b: uint16;
} &let {
     c : uint16 = b * 2;
     d : uint16 = b * 3;
};

The generated code is :
     // Parse "a"
     // Parse "b"
     b_ = FixByteOrder(t_byteorder, *((uint16 const *) ((t_begin_of_data + 2))));
     // Evaluate 'let' and 'withinput' fields
     d_ = b() * 3;
     a_ = FixByteOrder(t_byteorder, *((uint16 const *) (t_begin_of_data)));
     // Evaluate 'let' and 'withinput' fields

     // Evaluate 'let' and 'withinput' fields
     c_ = b() * 2;

In pac_types.cc, only the last &requires attribute is kept, the previous ones are forgotten.
Replacing attr_requires_ of type Expr with a ListExpr solves the problem and produces the (expected) C++ code below :

     // Parse "a"
     // Parse "b"
     b_ = FixByteOrder(t_byteorder, *((uint16 const *) ((t_begin_of_data + 2))));
     // Evaluate 'let' and 'withinput' fields
     c_ = b() * 2;
     d_ = b() * 3;
     a_ = FixByteOrder(t_byteorder, *((uint16 const *) (t_begin_of_data)));

I have written a small patch for this problem. I can submit it if you agree with my changes.

Thank you.

Hi François,

Thanks for reporting this. I'll need to think through some of the
implications a bit more closely.

If you'd be willing to share your patch, I'd be happy to take a look.
Thanks,

  --Vlad

François Pennaneach <francois.pennaneach@free.fr> writes: