zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
250 stars 37 forks source link

String representation of anonymous bitfield in units #1660

Open awelzel opened 9 months ago

awelzel commented 9 months ago
module Test;

import spicy;

public type Header = unit {

  : bitfield(16) {
    fin: 0;
    rsv: 1..3;
    opcode: 4..7;
    remaining: 8..15;
  } &bit-order=spicy::BitOrder::MSB0;

  on %done {
    print "fin", self.fin, "opcode", self.opcode;

    print self;
  }
};

$ printf "\x82\xff" | spicy-driver  ./test.spicy 
fin, 1, opcode, 2
[$<anon>=(1, 0, 2, 255)]

As discussed in Slack, it's a bit surprising that the "lifted" fields are not shown in the string representation of the unit and instead the $<anon> part shows up.

rsmmr commented 9 months ago

I would have sworn that we were lifting this up now after the recent changes, but indeed I do see this in our baselines, too:

spicy.types.bitfield.anonymous-field:

[$<anon>=(15, 15), $<anon>=(not set)]

spicy-dump does lift it up. From the same test:

Test::Foo {
  x: 15
  y: 15
}