RecordFlux icon indicating copy to clipboard operation
RecordFlux copied to clipboard

incorrect code generation for size of scalar sequences

Open kanigsson opened this issue 4 years ago • 5 comments

messages.rflx.txt test.rflx.txt

On the attached file, RFLX issues this error message:

test.rflx:26:46: parser: error: Expected 'for', got 'First'

The file contains neither "for" nor "First", so what is this about? I probably did something wrong, what's the proper syntax for such sequence comprehensions?

kanigsson avatar Jan 26 '22 08:01 kanigsson

The error messages of the specification parser are unfortunately quite bad. That is a known issue: Componolit/RecordFlux-parser#28. The parser complains about the sequence aggregate in:

         Out_Msg := Messages::Msg_Seq'(A => [In_Msg.C, In_Msg.D]);

The reason is that sequence aggregates only support numeric literals as elements (sequence aggregates were introduced for comparing opaque fields with a fixed sequence of bytes). There is already a ticket for changing that: #488. For now, the intended action can be specified as follows:

      state Copy is
         Seq : Messages::Seq;
      begin
         Seq'Append (In_Msg.C);
         Seq'Append (In_Msg.D);
         Out_Msg := Messages::Msg_Seq'(A => Seq);

As there are already tickets for all related issues, I'm closing this ticket.

treiher avatar Jan 26 '22 09:01 treiher

Thanks for the quick answer!

kanigsson avatar Jan 26 '22 09:01 kanigsson

I'm reopening the issue because your code is accepted by Recordflux, but:

  1. It triggers the assertion at generator/session.py, line 2495 (because the expression is a Selected, not a Variable; this is only visible when running with assertions obviously, e.g. via the testsuite)
  2. The generated code doesn't compile:
rflx-test-session.adb:63:45: error: "In_Msg" is undefined (more references follow)
rflx-test-session.adb:81:10: error: "Seq" is not visible (more references follow)
rflx-test-session.adb:81:10: error: non-visible declaration at rflx-messages-seq.ads:18

Any idea how the code should be written to be accepted?

kanigsson avatar Jan 26 '22 09:01 kanigsson

  1. can be solved by using variables instead of the `Selected´ expression directly:
      state Copy is
         Seq : Messages::Seq;
         C : Messages::Integer;
         D : Messages::Integer;
      begin
         C := In_Msg.C;
         D := In_Msg.D;
         Seq'Append (C);
         Seq'Append (D);
         Out_Msg := Messages::Msg_Seq'(A => Seq);

We could make the unsupported expression clearer by calling _unsupported_expression, if no variable is used.

  1. points to an actual bug:
rflx-test-session.adb:103:10: error: "Seq" is not visible (more references follow)
rflx-test-session.adb:103:10: error: non-visible declaration at rflx-messages-seq.ads:10
103          Seq'Size <= 32768
104          and then Seq'Size mod RFLX_Types.Byte'Size = 0

Seq'Size should be substituted by Messages.Seq.Size (Seq_Ctx). The fix is probably quite simple: Handling that specific case in _substitution in rflx/generator/session.py.

Do you think you can fix that?

treiher avatar Jan 26 '22 10:01 treiher

Sure, I can try.

kanigsson avatar Jan 26 '22 10:01 kanigsson