Exemplo n.º 1
0
    def create_verify_message_procedure(
            message: Message, context_invariant: Sequence[Expr]) -> UnitPart:
        specification = ProcedureSpecification(
            "Verify_Message", [InOutParameter(["Ctx"], "Context")])

        return UnitPart(
            [
                SubprogramDeclaration(
                    specification,
                    [
                        Postcondition(
                            And(
                                Equal(
                                    Call("Has_Buffer", [Variable("Ctx")]),
                                    Old(Call("Has_Buffer", [Variable("Ctx")])),
                                ),
                                *context_invariant,
                            )),
                    ],
                )
            ],
            [
                SubprogramBody(
                    specification,
                    [],
                    [
                        CallStatement(
                            "Verify",
                            [Variable("Ctx"),
                             Variable(f.affixed_name)]) for f in message.fields
                    ],
                )
            ],
        )
Exemplo n.º 2
0
 def setter_postconditions(
     self, message: Message, field: Field, field_type: Type
 ) -> Sequence[Expr]:
     return [
         *[
             Call("Invalid", [Name("Ctx"), Name(p.affixed_name)])
             for p in message.successors(field)
             if p != FINAL
         ],
         *self.common.valid_path_to_next_field_condition(message, field, field_type),
         *[
             Equal(e, Old(e))
             for e in [
                 Selected("Ctx", "Buffer_First"),
                 Selected("Ctx", "Buffer_Last"),
                 Selected("Ctx", "First"),
                 Call("Predecessor", [Name("Ctx"), Name(field.affixed_name)]),
                 Call("Valid_Next", [Name("Ctx"), Name(field.affixed_name)]),
             ]
             + [
                 Call(f"Get_{p.name}", [Name("Ctx")])
                 for p in message.definite_predecessors(field)
                 if isinstance(message.types[p], Scalar)
             ]
         ],
     ]
Exemplo n.º 3
0
def test_attribute() -> None:
    assert isinstance(Size("X"), Attribute)
    assert isinstance(Length("X"), Attribute)
    assert isinstance(First("X"), Attribute)
    assert isinstance(Last("X"), Attribute)
    assert isinstance(Range("X"), Attribute)
    assert isinstance(Old("X"), Attribute)
    assert isinstance(Result("X"), Attribute)
    assert isinstance(Constrained("X"), Attribute)
    assert First("X") == First(Variable("X"))
    assert First("X") == First(ID("X"))
    assert First("X") == First(Variable(ID("X")))
Exemplo n.º 4
0
 def create_internal_functions(
     self, message: Message, scalar_fields: Mapping[Field, Scalar]
 ) -> UnitPart:
     return UnitPart(
         [],
         [
             SubprogramBody(
                 ProcedureSpecification(
                     "Set_Field_Value",
                     [
                         InOutParameter(["Ctx"], "Context"),
                         Parameter(["Val"], "Field_Dependent_Value"),
                         OutParameter(["Fst", "Lst"], self.types.bit_index),
                     ],
                 ),
                 [
                     *self.common.field_bit_location_declarations(Selected("Val", "Fld")),
                     *self.common.field_byte_location_declarations(),
                 ],
                 [
                     Assignment("Fst", Name("First")),
                     Assignment("Lst", Name("Last")),
                     CaseStatement(
                         Selected("Val", "Fld"),
                         [
                             (
                                 Name(f.affixed_name),
                                 [
                                     CallStatement(
                                         "Insert",
                                         [
                                             Selected("Val", f"{f.name}_Value"),
                                             Slice(
                                                 Selected(Selected("Ctx", "Buffer"), "all"),
                                                 Name("Buffer_First"),
                                                 Name("Buffer_Last"),
                                             ),
                                             Name("Offset"),
                                         ],
                                     )
                                     if f in scalar_fields
                                     else NullStatement()
                                 ],
                             )
                             for f in message.all_fields
                         ],
                     ),
                 ],
                 [
                     Precondition(
                         AndThen(
                             Not(Constrained("Ctx")),
                             Call("Has_Buffer", [Name("Ctx")]),
                             In(Selected("Val", "Fld"), Range("Field")),
                             Call("Valid_Next", [Name("Ctx"), Selected("Val", "Fld")]),
                             self.common.sufficient_space_for_field_condition(
                                 Selected("Val", "Fld")
                             ),
                             ForAllIn(
                                 "F",
                                 Range("Field"),
                                 If(
                                     [
                                         (
                                             Call(
                                                 "Structural_Valid",
                                                 [
                                                     Indexed(
                                                         Selected("Ctx", "Cursors"), Name("F"),
                                                     )
                                                 ],
                                             ),
                                             LessEqual(
                                                 Selected(
                                                     Indexed(
                                                         Selected("Ctx", "Cursors"), Name("F"),
                                                     ),
                                                     "Last",
                                                 ),
                                                 Call(
                                                     "Field_Last",
                                                     [Name("Ctx"), Selected("Val", "Fld")],
                                                 ),
                                             ),
                                         )
                                     ]
                                 ),
                             ),
                         )
                     ),
                     Postcondition(
                         And(
                             Call("Has_Buffer", [Name("Ctx")]),
                             Equal(
                                 Name("Fst"),
                                 Call("Field_First", [Name("Ctx"), Selected("Val", "Fld")]),
                             ),
                             Equal(
                                 Name("Lst"),
                                 Call("Field_Last", [Name("Ctx"), Selected("Val", "Fld")]),
                             ),
                             GreaterEqual(Name("Fst"), Selected("Ctx", "First")),
                             LessEqual(Name("Fst"), Add(Name("Lst"), Number(1))),
                             LessEqual(
                                 Call(self.types.byte_index, [Name("Lst")]),
                                 Selected("Ctx", "Buffer_Last"),
                             ),
                             ForAllIn(
                                 "F",
                                 Range("Field"),
                                 If(
                                     [
                                         (
                                             Call(
                                                 "Structural_Valid",
                                                 [
                                                     Indexed(
                                                         Selected("Ctx", "Cursors"), Name("F"),
                                                     )
                                                 ],
                                             ),
                                             LessEqual(
                                                 Selected(
                                                     Indexed(
                                                         Selected("Ctx", "Cursors"), Name("F"),
                                                     ),
                                                     "Last",
                                                 ),
                                                 Name("Lst"),
                                             ),
                                         )
                                     ]
                                 ),
                             ),
                             *[
                                 Equal(e, Old(e))
                                 for e in [
                                     Selected("Ctx", "Buffer_First"),
                                     Selected("Ctx", "Buffer_Last"),
                                     Selected("Ctx", "First"),
                                     Selected("Ctx", "Cursors"),
                                 ]
                             ],
                         )
                     ),
                 ],
             )
         ],
     )
Exemplo n.º 5
0
    def create_scalar_setter_procedures(
        self, message: Message, scalar_fields: Mapping[Field, Scalar]
    ) -> UnitPart:
        def specification(field: Field, field_type: Type) -> ProcedureSpecification:
            type_name = (
                field_type.enum_name
                if isinstance(field_type, Enumeration) and field_type.always_valid
                else field_type.name
            )
            return ProcedureSpecification(
                f"Set_{field.name}",
                [
                    InOutParameter(["Ctx"], "Context"),
                    Parameter(["Val"], f"{message.package}.{type_name}"),
                ],
            )

        return UnitPart(
            [
                SubprogramDeclaration(
                    specification(f, t),
                    [
                        Precondition(
                            AndThen(
                                *self.setter_preconditions(f),
                                Call(
                                    "Field_Condition",
                                    [
                                        Name("Ctx"),
                                        Aggregate(
                                            Name(f.affixed_name),
                                            Name("Val")
                                            if not isinstance(t, Enumeration)
                                            else Call("Convert", [Name("Val")]),
                                        ),
                                    ],
                                ),
                                Call("Valid", [Name("Val")])
                                if not isinstance(t, Enumeration)
                                else TRUE,
                                self.common.sufficient_space_for_field_condition(
                                    Name(f.affixed_name)
                                ),
                            )
                        ),
                        Postcondition(
                            And(
                                VALID_CONTEXT,
                                Call("Has_Buffer", [Name("Ctx")]),
                                Call("Valid", [Name("Ctx"), Name(f.affixed_name)]),
                                Equal(
                                    Call(f"Get_{f.name}", [Name("Ctx")]),
                                    Aggregate(TRUE, Name("Val"))
                                    if isinstance(t, Enumeration) and t.always_valid
                                    else Name("Val"),
                                ),
                                *self.setter_postconditions(message, f, t),
                                *[
                                    Equal(
                                        Call("Cursor", [Name("Ctx"), Name(p.affixed_name)]),
                                        Old(Call("Cursor", [Name("Ctx"), Name(p.affixed_name)])),
                                    )
                                    for p in message.predecessors(f)
                                ],
                            )
                        ),
                    ],
                )
                for f, t in scalar_fields.items()
            ],
            [
                SubprogramBody(
                    specification(f, t),
                    [
                        ObjectDeclaration(
                            ["Field_Value"],
                            "Field_Dependent_Value",
                            Aggregate(
                                Name(f.affixed_name),
                                Name("Val")
                                if not isinstance(t, Enumeration)
                                else Call("Convert", [Name("Val")]),
                            ),
                            True,
                        ),
                        ObjectDeclaration(["First", "Last"], self.types.bit_index),
                    ],
                    [
                        CallStatement(
                            "Reset_Dependent_Fields", [Name("Ctx"), Name(f.affixed_name)],
                        ),
                        CallStatement(
                            "Set_Field_Value",
                            [Name("Ctx"), Name("Field_Value"), Name("First"), Name("Last")],
                        ),
                        Assignment(
                            "Ctx",
                            Aggregate(
                                Selected("Ctx", "Buffer_First"),
                                Selected("Ctx", "Buffer_Last"),
                                Selected("Ctx", "First"),
                                Name("Last"),
                                Selected("Ctx", "Buffer"),
                                Selected("Ctx", "Cursors"),
                            ),
                        ),
                        Assignment(
                            Indexed(Selected("Ctx", "Cursors"), Name(f.affixed_name)),
                            NamedAggregate(
                                ("State", Name("S_Valid")),
                                ("First", Name("First")),
                                ("Last", Name("Last")),
                                ("Value", Name("Field_Value")),
                                (
                                    "Predecessor",
                                    Selected(
                                        Indexed(Selected("Ctx", "Cursors"), Name(f.affixed_name)),
                                        "Predecessor",
                                    ),
                                ),
                            ),
                        ),
                        Assignment(
                            Indexed(
                                Selected("Ctx", "Cursors"),
                                Call("Successor", [Name("Ctx"), Name(f.affixed_name)]),
                            ),
                            NamedAggregate(
                                ("State", Name("S_Invalid")), ("Predecessor", Name(f.affixed_name)),
                            ),
                        ),
                    ],
                )
                for f, t in scalar_fields.items()
            ],
        )
Exemplo n.º 6
0
    def create_verify_procedure(self, message: Message,
                                context_invariant: Sequence[Expr]) -> UnitPart:
        specification = ProcedureSpecification(
            "Verify",
            [InOutParameter(["Ctx"], "Context"),
             Parameter(["Fld"], "Field")])

        valid_field_condition = And(
            Call(
                "Valid_Value",
                [Variable("Value")],
            ),
            Call(
                "Field_Condition",
                [
                    Variable("Ctx"),
                    Variable("Value"),
                    *([
                        Call(
                            "Field_Length",
                            [Variable("Ctx"), Variable("Fld")])
                    ] if common.length_dependent_condition(message) else []),
                ],
            ),
        )

        set_cursors_statements = [
            IfStatement(
                [(
                    Call("Composite_Field", [Variable("Fld")]),
                    [
                        Assignment(
                            Indexed(Variable("Ctx.Cursors"), Variable("Fld")),
                            NamedAggregate(
                                ("State", Variable("S_Structural_Valid")),
                                (
                                    "First",
                                    Call("Field_First",
                                         [Variable("Ctx"),
                                          Variable("Fld")]),
                                ),
                                (
                                    "Last",
                                    Call("Field_Last",
                                         [Variable("Ctx"),
                                          Variable("Fld")]),
                                ),
                                ("Value", Variable("Value")),
                                (
                                    "Predecessor",
                                    Selected(
                                        Indexed(Variable("Ctx.Cursors"),
                                                Variable("Fld")),
                                        "Predecessor",
                                    ),
                                ),
                            ),
                        )
                    ],
                )],
                [
                    Assignment(
                        Indexed(Variable("Ctx.Cursors"), Variable("Fld")),
                        NamedAggregate(
                            ("State", Variable("S_Valid")),
                            ("First",
                             Call("Field_First",
                                  [Variable("Ctx"),
                                   Variable("Fld")])),
                            ("Last",
                             Call("Field_Last",
                                  [Variable("Ctx"),
                                   Variable("Fld")])),
                            ("Value", Variable("Value")),
                            (
                                "Predecessor",
                                Selected(
                                    Indexed(Variable("Ctx.Cursors"),
                                            Variable("Fld")), "Predecessor"),
                            ),
                        ),
                    )
                ],
            ),
            # WORKAROUND:
            # Limitation of GNAT Community 2019 / SPARK Pro 20.0
            # Provability of predicate is increased by adding part of
            # predicate as assert
            PragmaStatement("Assert", [
                str(common.message_structure_invariant(message, self.prefix))
            ]),
            # WORKAROUND:
            # Limitation of GNAT Community 2019 / SPARK Pro 20.0
            # Provability of predicate is increased by splitting
            # assignment in multiple statements
            IfStatement([(
                Equal(Variable("Fld"), Variable(f.affixed_name)),
                [
                    Assignment(
                        Indexed(
                            Variable("Ctx.Cursors"),
                            Call("Successor",
                                 [Variable("Ctx"),
                                  Variable("Fld")]),
                        ),
                        NamedAggregate(
                            ("State", Variable("S_Invalid")),
                            ("Predecessor", Variable("Fld")),
                        ),
                    )
                ],
            ) for f in message.fields]),
        ]

        return UnitPart(
            [
                SubprogramDeclaration(
                    specification,
                    [
                        Postcondition(
                            And(
                                Equal(
                                    Call("Has_Buffer", [Variable("Ctx")]),
                                    Old(Call("Has_Buffer", [Variable("Ctx")])),
                                ),
                                *context_invariant,
                            )),
                    ],
                )
            ],
            [
                SubprogramBody(
                    specification,
                    [ObjectDeclaration(["Value"], "Field_Dependent_Value")],
                    [
                        IfStatement([(
                            AndThen(
                                Call("Has_Buffer", [Variable("Ctx")]),
                                Call(
                                    "Invalid",
                                    [
                                        Indexed(Variable("Ctx.Cursors"),
                                                Variable("Fld"))
                                    ],
                                ),
                                Call("Valid_Predecessor",
                                     [Variable("Ctx"),
                                      Variable("Fld")]),
                                Call("Path_Condition",
                                     [Variable("Ctx"),
                                      Variable("Fld")]),
                            ),
                            [
                                IfStatement(
                                    [(
                                        Call(
                                            "Sufficient_Buffer_Length",
                                            [Variable("Ctx"),
                                             Variable("Fld")],
                                        ),
                                        [
                                            Assignment(
                                                "Value",
                                                Call(
                                                    "Get_Field_Value",
                                                    [
                                                        Variable("Ctx"),
                                                        Variable("Fld")
                                                    ],
                                                ),
                                            ),
                                            IfStatement(
                                                [(
                                                    valid_field_condition,
                                                    set_cursors_statements,
                                                )],
                                                [
                                                    Assignment(
                                                        Indexed(
                                                            Variable(
                                                                "Ctx.Cursors"),
                                                            Variable("Fld"),
                                                        ),
                                                        NamedAggregate(
                                                            (
                                                                "State",
                                                                Variable(
                                                                    "S_Invalid"
                                                                ),
                                                            ),
                                                            (
                                                                "Predecessor",
                                                                Variable(
                                                                    FINAL.
                                                                    affixed_name
                                                                ),
                                                            ),
                                                        ),
                                                    )
                                                ],
                                            ),
                                        ],
                                    )],
                                    [
                                        Assignment(
                                            Indexed(Variable("Ctx.Cursors"),
                                                    Variable("Fld")),
                                            NamedAggregate(
                                                ("State",
                                                 Variable("S_Incomplete")),
                                                (
                                                    "Predecessor",
                                                    Variable(
                                                        FINAL.affixed_name),
                                                ),
                                            ),
                                        )
                                    ],
                                )
                            ],
                        )], )
                    ],
                )
            ],
        )
Exemplo n.º 7
0
 def create_internal_functions(
         self, message: Message,
         scalar_fields: Mapping[Field, Scalar]) -> UnitPart:
     return UnitPart(
         [],
         [
             SubprogramBody(
                 ProcedureSpecification(
                     "Set_Field_Value",
                     [
                         InOutParameter(["Ctx"], "Context"),
                         Parameter(["Val"], "Field_Dependent_Value"),
                         OutParameter(["Fst", "Lst"],
                                      const.TYPES_BIT_INDEX),
                     ],
                 ),
                 [
                     *common.field_bit_location_declarations(
                         Variable("Val.Fld")),
                     *common.field_byte_location_declarations(),
                     *unique(
                         self.insert_function(common.full_base_type_name(t))
                         for t in message.types.values()
                         if isinstance(t, Scalar)),
                 ],
                 [
                     Assignment("Fst", Variable("First")),
                     Assignment("Lst", Variable("Last")),
                     CaseStatement(
                         Variable("Val.Fld"),
                         [(
                             Variable(f.affixed_name),
                             [
                                 CallStatement(
                                     "Insert",
                                     [
                                         Variable(f"Val.{f.name}_Value"),
                                         Slice(
                                             Variable("Ctx.Buffer.all"),
                                             Variable("Buffer_First"),
                                             Variable("Buffer_Last"),
                                         ),
                                         Variable("Offset"),
                                     ],
                                 )
                                 if f in scalar_fields else NullStatement()
                             ],
                         ) for f in message.all_fields],
                     ),
                 ],
                 [
                     Precondition(
                         AndThen(
                             Not(Constrained("Ctx")),
                             Call("Has_Buffer", [Variable("Ctx")]),
                             In(Variable("Val.Fld"), Range("Field")),
                             Call("Valid_Next",
                                  [Variable("Ctx"),
                                   Variable("Val.Fld")]),
                             common.sufficient_space_for_field_condition(
                                 Variable("Val.Fld")),
                             ForAllIn(
                                 "F",
                                 Range("Field"),
                                 If([(
                                     Call(
                                         "Structural_Valid",
                                         [
                                             Indexed(
                                                 Variable("Ctx.Cursors"),
                                                 Variable("F"),
                                             )
                                         ],
                                     ),
                                     LessEqual(
                                         Selected(
                                             Indexed(
                                                 Variable("Ctx.Cursors"),
                                                 Variable("F"),
                                             ),
                                             "Last",
                                         ),
                                         Call(
                                             "Field_Last",
                                             [
                                                 Variable("Ctx"),
                                                 Variable("Val.Fld")
                                             ],
                                         ),
                                     ),
                                 )]),
                             ),
                         )),
                     Postcondition(
                         And(
                             Call("Has_Buffer", [Variable("Ctx")]),
                             Equal(
                                 Variable("Fst"),
                                 Call(
                                     "Field_First",
                                     [Variable("Ctx"),
                                      Variable("Val.Fld")]),
                             ),
                             Equal(
                                 Variable("Lst"),
                                 Call(
                                     "Field_Last",
                                     [Variable("Ctx"),
                                      Variable("Val.Fld")]),
                             ),
                             GreaterEqual(Variable("Fst"),
                                          Variable("Ctx.First")),
                             LessEqual(Variable("Fst"),
                                       Add(Variable("Lst"), Number(1))),
                             LessEqual(
                                 Call(const.TYPES_BYTE_INDEX,
                                      [Variable("Lst")]),
                                 Variable("Ctx.Buffer_Last"),
                             ),
                             ForAllIn(
                                 "F",
                                 Range("Field"),
                                 If([(
                                     Call(
                                         "Structural_Valid",
                                         [
                                             Indexed(
                                                 Variable("Ctx.Cursors"),
                                                 Variable("F"),
                                             )
                                         ],
                                     ),
                                     LessEqual(
                                         Selected(
                                             Indexed(
                                                 Variable("Ctx.Cursors"),
                                                 Variable("F"),
                                             ),
                                             "Last",
                                         ),
                                         Variable("Lst"),
                                     ),
                                 )]),
                             ),
                             *[
                                 Equal(e, Old(e)) for e in [
                                     Variable("Ctx.Buffer_First"),
                                     Variable("Ctx.Buffer_Last"),
                                     Variable("Ctx.First"),
                                     Variable("Ctx.Cursors"),
                                 ]
                             ],
                         )),
                 ],
             )
         ] if scalar_fields else [],
     )
Exemplo n.º 8
0
    def create_scalar_setter_procedures(
            self, message: Message,
            scalar_fields: Mapping[Field, Scalar]) -> UnitPart:
        def specification(field: Field,
                          field_type: Type) -> ProcedureSpecification:
            if field_type.package == BUILTINS_PACKAGE:
                type_name = ID(field_type.name)
            elif isinstance(field_type,
                            Enumeration) and field_type.always_valid:
                type_name = common.prefixed_type_name(
                    common.full_enum_name(field_type), self.prefix)
            else:
                type_name = common.prefixed_type_name(field_type.identifier,
                                                      self.prefix)

            return ProcedureSpecification(
                f"Set_{field.name}",
                [
                    InOutParameter(["Ctx"], "Context"),
                    Parameter(["Val"], type_name)
                ],
            )

        return UnitPart(
            [
                SubprogramDeclaration(
                    specification(f, t),
                    [
                        Precondition(
                            AndThen(
                                *self.setter_preconditions(f),
                                Call(
                                    "Field_Condition",
                                    [
                                        Variable("Ctx"),
                                        Aggregate(
                                            Variable(f.affixed_name),
                                            Call("To_Base", [Variable("Val")]),
                                        ),
                                    ],
                                ),
                                Call("Valid",
                                     [Call("To_Base", [Variable("Val")])])
                                if not isinstance(t, Enumeration) else TRUE,
                                common.sufficient_space_for_field_condition(
                                    Variable(f.affixed_name)),
                            )),
                        Postcondition(
                            And(
                                Call("Has_Buffer", [Variable("Ctx")]),
                                Call("Valid", [
                                    Variable("Ctx"),
                                    Variable(f.affixed_name)
                                ]),
                                Equal(
                                    Call(f"Get_{f.name}", [Variable("Ctx")]),
                                    Aggregate(TRUE, Variable("Val"))
                                    if isinstance(t, Enumeration)
                                    and t.always_valid else Variable("Val"),
                                ),
                                *self.setter_postconditions(message, f),
                                *[
                                    Equal(
                                        Call(
                                            "Context_Cursor",
                                            [
                                                Variable("Ctx"),
                                                Variable(p.affixed_name)
                                            ],
                                        ),
                                        Old(
                                            Call(
                                                "Context_Cursor",
                                                [
                                                    Variable("Ctx"),
                                                    Variable(p.affixed_name)
                                                ],
                                            )),
                                    ) for p in message.predecessors(f)
                                ],
                            )),
                    ],
                ) for f, t in scalar_fields.items()
            ],
            [
                SubprogramBody(
                    specification(f, t),
                    [
                        ObjectDeclaration(
                            ["Field_Value"],
                            "Field_Dependent_Value",
                            Aggregate(
                                Variable(f.affixed_name),
                                Call("To_Base", [Variable("Val")]),
                            ),
                            True,
                        ),
                        ObjectDeclaration(["First", "Last"],
                                          const.TYPES_BIT_INDEX),
                    ],
                    [
                        CallStatement(
                            "Reset_Dependent_Fields",
                            [Variable("Ctx"),
                             Variable(f.affixed_name)],
                        ),
                        CallStatement(
                            "Set_Field_Value",
                            [
                                Variable("Ctx"),
                                Variable("Field_Value"),
                                Variable("First"),
                                Variable("Last"),
                            ],
                        ),
                        Assignment(
                            "Ctx",
                            Aggregate(
                                Variable("Ctx.Buffer_First"),
                                Variable("Ctx.Buffer_Last"),
                                Variable("Ctx.First"),
                                Variable("Last"),
                                Variable("Ctx.Buffer"),
                                Variable("Ctx.Cursors"),
                            ),
                        ),
                        Assignment(
                            Indexed(Variable("Ctx.Cursors"),
                                    Variable(f.affixed_name)),
                            NamedAggregate(
                                ("State", Variable("S_Valid")),
                                ("First", Variable("First")),
                                ("Last", Variable("Last")),
                                ("Value", Variable("Field_Value")),
                                (
                                    "Predecessor",
                                    Selected(
                                        Indexed(Variable("Ctx.Cursors"),
                                                Variable(f.affixed_name)),
                                        "Predecessor",
                                    ),
                                ),
                            ),
                        ),
                        Assignment(
                            Indexed(
                                Variable("Ctx.Cursors"),
                                Call("Successor", [
                                    Variable("Ctx"),
                                    Variable(f.affixed_name)
                                ]),
                            ),
                            NamedAggregate(
                                ("State", Variable("S_Invalid")),
                                ("Predecessor", Variable(f.affixed_name)),
                            ),
                        ),
                    ],
                ) for f, t in scalar_fields.items()
            ],
        )