Skip to content

Commit

Permalink
Add support for Opaque attribute on sequences
Browse files Browse the repository at this point in the history
Ref. #1021
  • Loading branch information
treiher committed May 18, 2022
1 parent 9b9bb4d commit f9ee0b5
Show file tree
Hide file tree
Showing 242 changed files with 7,093 additions and 242 deletions.
19 changes: 19 additions & 0 deletions doc/Language-Reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ A declared variable must have a type and can be optionally initialized using an
// * Aggregates [§S-D-V-E-A]
// * Valid Attributes [§S-D-V-E-VAT]
// * Opaque Attributes [§S-D-V-E-OAT]
// * Size Attributes [§S-D-V-E-SAT]
// * Head Attributes [§S-D-V-E-HAT]
// * Has_Data Attributes [§S-D-V-E-HDAT]
// * Selected Expressions [§S-D-V-E-S]
Expand Down Expand Up @@ -667,6 +668,7 @@ A local declaration must not hide a global declaration.
// * Aggregates [§S-S-D-V-E-A]
// * Valid Attributes [§S-S-D-V-E-VAT]
// * Opaque Attributes [§S-S-D-V-E-OAT]
// * Size Attributes [§S-S-D-V-E-SAT]
// * Head Attributes [§S-S-D-V-E-HAT]
// * Has_Data Attributes [§S-S-D-V-E-HDAT]
// * Selected Expressions [§S-S-D-V-E-S]
Expand Down Expand Up @@ -708,6 +710,7 @@ State transitions define the conditions for the change to subsequent states. An
// * Aggregates [§S-S-T-A]
// * Valid Attributes [§S-S-T-VAT]
// * Opaque Attributes [§S-S-T-OAT]
// * Size Attributes [§S-S-T-SAT]
// * Head Attributes [§S-S-T-HAT]
// * Has_Data Attributes [§S-S-T-HDAT]
// * Selected Expressions [§S-S-T-S]
Expand Down Expand Up @@ -764,6 +767,7 @@ An assignment sets the value of variable.
// * Aggregates [§S-S-A-A-A]
// * Valid Attributes [§S-S-A-A-VAT]
// * Opaque Attributes [§S-S-A-A-OAT]
// * Size Attributes [§S-S-A-A-SAT]
// * Head Attributes [§S-S-A-A-HAT]
// * Has_Data Attributes [§S-S-A-A-HDAT]
// * Selected Expressions [§S-S-A-A-S]
Expand Down Expand Up @@ -809,6 +813,7 @@ An element is added to the end of a sequence using the Append attribute.
// * Aggregates [§S-S-A-AP-A]
// * Valid Attributes [§S-S-A-AP-VAT]
// * Opaque Attributes [§S-S-A-AP-OAT]
// * Size Attributes [§S-S-AP-SAT]
// * Head Attributes [§S-S-A-AP-HAT]
// * Has_Data Attributes [§S-S-A-AP-HDAT]
// * Selected Expressions [§S-S-A-AP-S]
Expand Down Expand Up @@ -854,6 +859,7 @@ The Extend attributes adds a sequence of elements to the end of a sequence.
// * Aggregates [§S-S-A-EX-A]
// * Valid Attributes [§S-S-A-EX-VAT]
// * Opaque Attributes [§S-S-A-EX-OAT]
// * Size Attributes [§S-S-A-EX-SAT]
// * Head Attributes [§S-S-A-EX-HAT]
// * Has_Data Attributes [§S-S-A-EX-HDAT]
// * Selected Expressions [§S-S-A-EX-S]
Expand Down Expand Up @@ -901,6 +907,7 @@ When resetting a parameterized message, the intended values for the parameters o
// * Aggregates [§S-S-A-RS-A]
// * Valid Attributes [§S-S-A-RS-VAT]
// * Opaque Attributes [§S-S-A-RS-OAT]
// * Size Attributes [§S-S-A-RS-SAT]
// * Head Attributes [§S-S-A-RS-HAT]
// * Has_Data Attributes [§S-S-A-RS-HDAT]
// * Selected Expressions [§S-S-A-RS-S]
Expand Down Expand Up @@ -946,6 +953,7 @@ The read attribute statement is used to retrieve a message from a channel.
// * Aggregates [§S-S-A-RD-A]
// * Valid Attributes [§S-S-A-RD-VAT]
// * Opaque Attributes [§S-S-A-RD-OAT]
// * Size Attributes [§S-S-A-RD-SAT]
// * Head Attributes [§S-S-A-RD-HAT]
// * Has_Data Attributes [§S-S-A-RD-HDAT]
// * Selected Expressions [§S-S-A-RD-S]
Expand Down Expand Up @@ -987,6 +995,7 @@ A message can be sent through a channel using a write attribute statement.
// * Aggregates [§S-S-A-WR-A]
// * Valid Attributes [§S-S-A-WR-VAT]
// * Opaque Attributes [§S-S-A-WR-OAT]
// * Size Attributes [§S-S-A-WR-SAT]
// * Head Attributes [§S-S-A-WR-HAT]
// * Has_Data Attributes [§S-S-A-WR-HDAT]
// * Selected Expressions [§S-S-A-WR-S]
Expand Down Expand Up @@ -1099,6 +1108,7 @@ An aggregate is a collection of elements.
// * Aggregates [§S-E-A-E-A]
// * Valid Attributes [§S-E-A-E-VAT]
// * Opaque Attributes [§S-E-A-E-OAT]
// * Size Attributes [§S-E-A-E-SAT]
// * Head Attributes [§S-E-A-E-HAT]
// * Has_Data Attributes [§S-E-A-E-HDAT]
// * Selected Expressions [§S-E-A-E-S]
Expand Down Expand Up @@ -1148,6 +1158,7 @@ The Valid attribute allows to determine the validity of a message or sequence.
// * Aggregates [§S-E-AT-V-A]
// * Valid Attributes [§S-E-AT-V-VAT]
// * Opaque Attributes [§S-E-AT-V-OAT]
// * Size Attributes [§S-E-AT-V-SAT]
// * Head Attributes [§S-E-AT-V-HAT]
// * Has_Data Attributes [§S-E-AT-V-HDAT]
// * Selected Expressions [§S-E-AT-V-S]
Expand Down Expand Up @@ -1199,6 +1210,7 @@ The Head attribute allows to get the first element of a sequence.
// * Aggregates [§S-E-AT-H-A]
// * Valid Attributes [§S-E-AT-H-VAT]
// * Opaque Attributes [§S-E-AT-H-OAT]
// * Size Attributes [§S-E-AT-H-SAT]
// * Head Attributes [§S-E-AT-H-HAT]
// * Has_Data Attributes [§S-E-AT-H-HDAT]
// * Selected Expressions [§S-E-AT-H-S]
Expand All @@ -1222,6 +1234,7 @@ Whether a channel contains data can be checked with the Has_Data attribute.
// * Aggregates [§S-E-AT-HD-A]
// * Valid Attributes [§S-E-AT-HD-VAT]
// * Opaque Attributes [§S-E-AT-HD-OAT]
// * Size Attributes [§S-E-AT-HD-SAT]
// * Head Attributes [§S-E-AT-HD-HAT]
// * Has_Data Attributes [§S-E-AT-HD-HDAT]
// * Selected Expressions [§S-E-AT-HD-S]
Expand Down Expand Up @@ -1267,6 +1280,7 @@ The Selected expression is used to get a value of a message field.
// * Aggregates [§S-E-S-A]
// * Valid Attributes [§S-E-S-VAT]
// * Opaque Attributes [§S-E-S-OAT]
// * Size Attributes [§S-E-S-SAT]
// * Head Attributes [§S-E-S-HAT]
// * Has_Data Attributes [§S-E-S-HDAT]
// * Selected Expressions [§S-E-S-S]
Expand Down Expand Up @@ -1355,6 +1369,7 @@ A binding can be used to name a subexpression and enables the use of a subexpres
// * Aggregates [§S-E-B-A]
// * Valid Attributes [§S-E-B-VAT]
// * Opaque Attributes [§S-E-B-OAT]
// * Size Attributes [§S-E-B-SAT]
// * Head Attributes [§S-E-B-HAT]
// * Has_Data Attributes [§S-E-B-HDAT]
// * Selected Expressions [§S-E-B-S]
Expand Down Expand Up @@ -1403,6 +1418,7 @@ Quantified expressions enable reasoning about properties of sequences.
// * Aggregates [§S-E-Q-I-A]
// * Valid Attributes [§S-E-Q-I-VAT]
// * Opaque Attributes [§S-E-Q-I-OAT]
// * Size Attributes [§S-E-Q-I-SAT]
// * Head Attributes [§S-E-Q-I-HAT]
// * Has_Data Attributes [§S-E-Q-I-HDAT]
// * Selected Expressions [§S-E-Q-I-S]
Expand All @@ -1422,6 +1438,7 @@ Quantified expressions enable reasoning about properties of sequences.
// * Aggregates [§S-E-Q-P-A]
// * Valid Attributes [§S-E-Q-P-VAT]
// * Opaque Attributes [§S-E-Q-P-OAT]
// * Size Attributes [§S-E-Q-P-SAT]
// * Head Attributes [§S-E-Q-P-HAT]
// * Has_Data Attributes [§S-E-Q-P-HDAT]
// * Selected Expressions [§S-E-Q-P-S]
Expand Down Expand Up @@ -1464,6 +1481,7 @@ All functions which are declared in the session parameters can be called.
// * Aggregates [§S-E-CL-A]
// * Valid Attributes [§S-E-CL-VAT]
// * Opaque Attributes [§S-E-CL-OAT]
// * Size Attributes [§S-E-CL-SAT]
// * Head Attributes [§S-E-CL-HAT]
// * Has_Data Attributes [§S-E-CL-HDAT]
// * Selected Expressions [§S-E-CL-S]
Expand Down Expand Up @@ -1507,6 +1525,7 @@ A conversion is only allowed if a refinement for the message field and the inten
// * Aggregates [§S-E-CV-A]
// * Valid Attributes [§S-E-CV-VAT]
// * Opaque Attributes [§S-E-CV-OAT]
// * Size Attributes [§S-E-CV-SAT]
// * Head Attributes [§S-E-CV-HAT]
// * Has_Data Attributes [§S-E-CV-HDAT]
// * Selected Expressions [§S-E-CV-S]
Expand Down
2 changes: 1 addition & 1 deletion rflx/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ def __init__(self, prefix: Union[StrID, Expr], negative: bool = False) -> None:
self.type_ = rty.OPAQUE

def _check_type_subexpr(self) -> RecordFluxError:
return self.prefix.check_type_instance(rty.Message)
return self.prefix.check_type_instance((rty.Sequence, rty.Message))


class Val(Attribute):
Expand Down
2 changes: 1 addition & 1 deletion rflx/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def __create_message(self, message: Message) -> None:
self._executor.submit(message_generator.create_byte_size_function),
self._executor.submit(message_generator.create_message_last_function),
self._executor.submit(message_generator.create_written_last_function),
self._executor.submit(message_generator.create_message_data_procedure),
self._executor.submit(message_generator.create_data_procedure),
self._executor.submit(
message_generator.create_valid_value_function, message, scalar_fields, self.__prefix
),
Expand Down
4 changes: 2 additions & 2 deletions rflx/generator/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,9 +2134,9 @@ def create_written_last_function() -> UnitPart:
)


def create_message_data_procedure() -> UnitPart:
def create_data_procedure() -> UnitPart:
specification = ProcedureSpecification(
"Message_Data",
"Data",
[Parameter(["Ctx"], "Context"), OutParameter(["Data"], const.TYPES_BYTES)],
)

Expand Down
50 changes: 27 additions & 23 deletions rflx/generator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ def _assign_to_call( # pylint: disable = too-many-locals
elif (
isinstance(a, expr.Opaque)
and isinstance(a.prefix, expr.Variable)
and isinstance(a.prefix.type_, rty.Message)
and isinstance(a.prefix.type_, (rty.Message, rty.Sequence))
):
self._session_context.used_types_body.append(const.TYPES_LENGTH)
argument_name = f"RFLX_{call_expr.identifier}_Arg_{i}_{a.prefix}"
Expand Down Expand Up @@ -2966,15 +2966,20 @@ def _assign_to_call( # pylint: disable = too-many-locals
self._raise_exception_if(
Not(
Call(
type_identifier * "Structural_Valid_Message",
type_identifier
* (
"Structural_Valid_Message"
if isinstance(a.prefix.type_, rty.Message)
else "Valid"
),
[Variable(message_context)],
)
),
f'invalid message "{message_context}"',
exception_handler,
),
CallStatement(
type_identifier * "Message_Data",
type_identifier * "Data",
[
Variable(message_context),
argument.ada_expr(),
Expand Down Expand Up @@ -3159,19 +3164,20 @@ def check(
]

if isinstance(append.type_.element, (rty.Integer, rty.Enumeration)):
assert isinstance(append.parameter, expr.Variable)
if isinstance(append.parameter, (expr.Variable, expr.Number)):
sequence_type = ID(append.type_.identifier)
sequence_context = context_id(append.identifier, is_global)
element_type = ID(append.type_.element.identifier)

sequence_type = ID(append.type_.identifier)
sequence_context = context_id(append.identifier, is_global)
element_type = ID(append.type_.element.identifier)
return [
*check(sequence_type, Size(element_type)),
CallStatement(
sequence_type * "Append_Element",
[Variable(sequence_context), append.parameter.ada_expr()],
),
]

return [
*check(sequence_type, Size(element_type)),
CallStatement(
sequence_type * "Append_Element",
[Variable(sequence_context), append.parameter.ada_expr()],
),
]
_unsupported_expression(append.parameter, "in Append statement")

if isinstance(append.type_.element, rty.Message):
sequence_type = ID(append.type_.identifier)
Expand Down Expand Up @@ -3461,7 +3467,7 @@ def func(expression: expr.Expr) -> expr.Expr:
if (
isinstance(expression.prefix.type_, rty.AnyInteger)
or (
isinstance(expression.prefix.type_, (rty.Sequence, rty.Aggregate))
isinstance(expression.prefix.type_, rty.Aggregate)
and isinstance(expression.prefix.type_.element, rty.AnyInteger)
)
or (
Expand Down Expand Up @@ -3503,14 +3509,12 @@ def func(expression: expr.Expr) -> expr.Expr:
)

if isinstance(expression, expr.Opaque):
assert expression.type_ == rty.OPAQUE
if isinstance(expression.prefix, expr.Variable):
assert expression.type_ == rty.OPAQUE
assert isinstance(expression.prefix.type_, rty.Message)
message_type = ID(expression.prefix.type_.identifier)
message_context = context_id(expression.prefix.identifier, is_global)
return expr.Call(
message_type * "Message_Data", [expr.Variable(message_context)]
)
if isinstance(expression.prefix.type_, (rty.Message, rty.Sequence)):
type_ = ID(expression.prefix.type_.identifier)
context = context_id(expression.prefix.identifier, is_global)
return expr.Call(type_ * "Data", [expr.Variable(context)])

_unsupported_expression(expression.prefix, "in Opaque attribute")

Expand Down Expand Up @@ -4085,7 +4089,7 @@ def _set_opaque_field_to_message(
),
get_statements=[
CallStatement(
message_type * "Message_Data",
message_type * "Data",
[
Variable(message_context),
Variable("Data"),
Expand Down
9 changes: 9 additions & 0 deletions rflx/templates/rflx_message_sequence.adb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ is
end if;
end Update;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) is
begin
if Data'Length > 0 then
Data := Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Sequence_Last));
else
Data := Ctx.Buffer.all (1 .. 0);
end if;
end Data;

end {prefix}RFLX_Message_Sequence;
6 changes: 6 additions & 0 deletions rflx/templates/rflx_message_sequence.ads
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ is

function Byte_Size (Ctx : Context) return RFLX_Types.Length;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) with
Pre =>
(Has_Buffer (Ctx)
and then Valid (Ctx)
and then Data'Length = Byte_Size (Ctx));

private

-- ISSUE: Componolit/Workarounds#24
Expand Down
9 changes: 9 additions & 0 deletions rflx/templates/rflx_scalar_sequence.adb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ is
Ctx.Sequence_Last := Ctx.Sequence_Last + {prefix}RFLX_Types.Bit_Index (Element_Size);
end Append_Element;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) is
begin
if Data'Length > 0 then
Data := Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Sequence_Last));
else
Data := Ctx.Buffer.all (1 .. 0);
end if;
end Data;

end {prefix}RFLX_Scalar_Sequence;
6 changes: 6 additions & 0 deletions rflx/templates/rflx_scalar_sequence.ads
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ is

function Byte_Size (Ctx : Context) return RFLX_Types.Length;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) with
Pre =>
(Has_Buffer (Ctx)
and then Valid (Ctx)
and then Data'Length = Byte_Size (Ctx));

private

-- ISSUE: Componolit/Workarounds#24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ is
end if;
end Update;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) is
begin
if Data'Length > 0 then
Data := Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Sequence_Last));
else
Data := Ctx.Buffer.all (1 .. 0);
end if;
end Data;

end RFLX.RFLX_Message_Sequence;
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ is

function Byte_Size (Ctx : Context) return RFLX_Types.Length;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) with
Pre =>
(Has_Buffer (Ctx)
and then Valid (Ctx)
and then Data'Length = Byte_Size (Ctx));

private

pragma Warnings (Off, "use clause for package * has no effect");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ is
Ctx.Sequence_Last := Ctx.Sequence_Last + RFLX.RFLX_Types.Bit_Index (Element_Size);
end Append_Element;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) is
begin
if Data'Length > 0 then
Data := Ctx.Buffer.all (RFLX_Types.To_Index (Ctx.First) .. RFLX_Types.To_Index (Ctx.Sequence_Last));
else
Data := Ctx.Buffer.all (1 .. 0);
end if;
end Data;

end RFLX.RFLX_Scalar_Sequence;
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ is

function Byte_Size (Ctx : Context) return RFLX_Types.Length;

procedure Data (Ctx : Context; Data : out RFLX_Types.Bytes) with
Pre =>
(Has_Buffer (Ctx)
and then Valid (Ctx)
and then Data'Length = Byte_Size (Ctx));

private

pragma Warnings (Off, "use clause for package * has no effect");
Expand Down
Loading

0 comments on commit f9ee0b5

Please sign in to comment.