Skip to content

Commit

Permalink
Suppress false warnings about always False precondition
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Jan 15, 2021
1 parent 2bc3465 commit 0b75e0c
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 10 deletions.
5 changes: 4 additions & 1 deletion rflx/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,8 @@ def __create_successor_function(message: Message) -> UnitPart:
return UnitPart(
[],
[
# WORKAROUND: Componolit/Workarounds#31
Pragma("Warnings", [Variable("Off"), String("precondition is always False")]),
ExpressionFunctionDeclaration(
specification,
Case(
Expand Down Expand Up @@ -1299,7 +1301,8 @@ def __create_successor_function(message: Message) -> UnitPart:
)
)
],
)
),
Pragma("Warnings", [Variable("On"), String("precondition is always False")]),
],
)

Expand Down
25 changes: 16 additions & 9 deletions rflx/generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
Or,
Parameter,
Postcondition,
Pragma,
PragmaStatement,
Precondition,
ProcedureSpecification,
Result,
ReturnStatement,
Selected,
Slice,
String,
Subprogram,
SubprogramBody,
SubprogramDeclaration,
Expand Down Expand Up @@ -652,15 +654,20 @@ def result(field: Field) -> Expr:

return UnitPart(
[
SubprogramDeclaration(
specification(f, t),
[
Precondition(
Call("Valid", [Variable("Ctx"), Variable(f.affixed_name)]),
)
],
)
for f, t in scalar_fields.items()
# WORKAROUND: Componolit/Workarounds#31
Pragma("Warnings", [Variable("Off"), String("precondition is always False")]),
*[
SubprogramDeclaration(
specification(f, t),
[
Precondition(
Call("Valid", [Variable("Ctx"), Variable(f.affixed_name)]),
)
],
)
for f, t in scalar_fields.items()
],
Pragma("Warnings", [Variable("On"), String("precondition is always False")]),
],
[
ExpressionFunctionDeclaration(specification(f, t), result(f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Header =>
Expand All @@ -111,6 +113,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Header (Ctx : Context) return RFLX.Arrays.Enumeration with
Pre =>
Valid (Ctx, F_Header);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Vector (Vector : Types.Bytes);
procedure Get_Vector (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-arrays-generic_inner_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Length =>
Expand All @@ -111,6 +113,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-arrays-generic_inner_message.ads
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Length (Ctx : Context) return RFLX.Arrays.Length with
Pre =>
Valid (Ctx, F_Length);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Payload (Payload : Types.Bytes);
procedure Get_Payload (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-arrays-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Length =>
Expand All @@ -177,6 +179,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-arrays-generic_message.ads
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,14 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Length (Ctx : Context) return RFLX.Arrays.Length with
Pre =>
Valid (Ctx, F_Length);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Modular_Vector (Modular_Vector : Types.Bytes);
procedure Get_Modular_Vector (Ctx : Context) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Length =>
Expand All @@ -111,6 +113,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Length (Ctx : Context) return RFLX.Arrays.Length with
Pre =>
Valid (Ctx, F_Length);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Messages (Messages : Types.Bytes);
procedure Get_Messages (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-enumeration-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Priority =>
Expand All @@ -85,6 +87,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-enumeration-generic_message.ads
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Priority (Ctx : Context) return RFLX.Enumeration.Priority with
Pre =>
Valid (Ctx, F_Priority);

pragma Warnings (On, "precondition is always False");

procedure Set_Priority (Ctx : in out Context; Val : RFLX.Enumeration.Priority_Enum) with
Pre =>
not Ctx'Constrained
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-ethernet-generic_frame.adb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Destination =>
Expand Down Expand Up @@ -282,6 +284,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-ethernet-generic_frame.ads
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Destination (Ctx : Context) return RFLX.Ethernet.Address with
Pre =>
Valid (Ctx, F_Destination);
Expand All @@ -221,6 +223,8 @@ is
Pre =>
Valid (Ctx, F_Type_Length);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Payload (Payload : Types.Bytes);
procedure Get_Payload (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-expression-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Payload =>
Expand All @@ -92,6 +94,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-expression-generic_message.ads
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Payload (Payload : Types.Bytes);
procedure Get_Payload (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-icmp-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Tag =>
Expand Down Expand Up @@ -564,6 +566,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-icmp-generic_message.ads
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Tag (Ctx : Context) return RFLX.ICMP.Tag with
Pre =>
Valid (Ctx, F_Tag);
Expand Down Expand Up @@ -275,6 +277,8 @@ is
Pre =>
Valid (Ctx, F_Transmit_Timestamp);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Data (Data : Types.Bytes);
procedure Get_Data (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-ipv4-generic_option.adb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Copied =>
Expand Down Expand Up @@ -246,6 +248,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-ipv4-generic_option.ads
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ is

function Incomplete_Message (Ctx : Context) return Boolean;

pragma Warnings (Off, "precondition is always False");

function Get_Copied (Ctx : Context) return Boolean with
Pre =>
Valid (Ctx, F_Copied);
Expand All @@ -212,6 +214,8 @@ is
Pre =>
Valid (Ctx, F_Option_Length);

pragma Warnings (On, "precondition is always False");

generic
with procedure Process_Option_Data (Option_Data : Types.Bytes);
procedure Get_Option_Data (Ctx : Context) with
Expand Down
4 changes: 4 additions & 0 deletions tests/spark/generated/rflx-ipv4-generic_packet.adb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ is
when others =>
Ctx.Cursors (Fld).Predecessor));

pragma Warnings (Off, "precondition is always False");

function Successor (Ctx : Context; Fld : Field) return Virtual_Field is
((case Fld is
when F_Version =>
Expand Down Expand Up @@ -461,6 +463,8 @@ is
and Structural_Valid (Ctx, Fld)
and Valid_Predecessor (Ctx, Fld);

pragma Warnings (On, "precondition is always False");

function Valid_Predecessor (Ctx : Context; Fld : Virtual_Field) return Boolean is
((case Fld is
when F_Initial =>
Expand Down
Loading

0 comments on commit 0b75e0c

Please sign in to comment.