Skip to content

Commit

Permalink
Improve check message in case of wrong instantation
Browse files Browse the repository at this point in the history
Ref. #292
  • Loading branch information
treiher committed Jul 27, 2021
1 parent 7e34e6f commit cab5dd4
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rflx/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,29 @@ def __create_write_procedure() -> UnitPart:
Variable("Length"),
],
),
# ISSUE: Componolit/Workarounds#39
# Improve the check message in case of a wrong instantiation of "Write".
PragmaStatement(
"Assert",
[
LessEqual(
Variable("Length"),
Length(
Indexed(
Variable("Ctx.Buffer.all"),
ValueRange(
Call(const.TYPES_TO_INDEX, [Variable("Ctx.First")]),
Call(const.TYPES_TO_INDEX, [Variable("Ctx.Last")]),
),
)
),
),
String(
"Length <= Buffer'Length is not ensured by postcondition of"
' "Write"'
),
],
),
CallStatement(
"Reset",
[
Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-derivation-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-enumeration-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-ethernet-frame.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-expression-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-fixed_size-simple_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-icmp-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-ipv4-option.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-ipv4-packet.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-sequence-inner_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-sequence-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-sequence-messages_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-tlv-message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down
1 change: 1 addition & 0 deletions tests/spark/generated/rflx-udp-datagram.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ is
Length : RFLX_Types.Length;
begin
Write (Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last)), Length);
pragma Assert (Length <= Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Last))'Length, "Length <= Buffer'Length is not ensured by postcondition of ""Write""");
Reset (Ctx, Ctx.First, RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (RFLX_Types.To_Index (Ctx.First)) + Length - 1));
end Write;

Expand Down

0 comments on commit cab5dd4

Please sign in to comment.