[Bro] binPAC : more than one &require attribute on a field

François Pennaneach francois.pennaneach at free.fr
Wed Nov 2 17:19:45 PDT 2016


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 {
     a: uint16 &requires(c) &requires(d);
     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.



More information about the Bro mailing list