Skip to content

Commit

Permalink
Fix code generation for array with imported element type
Browse files Browse the repository at this point in the history
Ref. #349
  • Loading branch information
treiher committed Jul 17, 2020
1 parent 43fe72f commit 584299f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion generated/rflx-arrays-av_enumeration_vector.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Scalar_Sequence;
with RFLX.Arrays;
with RFLX.RFLX_Types;

package RFLX.Arrays.AV_Enumeration_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, AV_Enumeration, AV_Enumeration_Base, Valid, To_Actual, To_Base);
package RFLX.Arrays.AV_Enumeration_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, RFLX.Arrays.AV_Enumeration, RFLX.Arrays.AV_Enumeration_Base, RFLX.Arrays.Valid, RFLX.Arrays.To_Actual, RFLX.Arrays.To_Base);
2 changes: 1 addition & 1 deletion generated/rflx-arrays-enumeration_vector.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Scalar_Sequence;
with RFLX.Arrays;
with RFLX.RFLX_Types;

package RFLX.Arrays.Enumeration_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, Enumeration, Enumeration_Base, Valid, To_Actual, To_Base);
package RFLX.Arrays.Enumeration_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, RFLX.Arrays.Enumeration, RFLX.Arrays.Enumeration_Base, RFLX.Arrays.Valid, RFLX.Arrays.To_Actual, RFLX.Arrays.To_Base);
2 changes: 1 addition & 1 deletion generated/rflx-arrays-inner_messages.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Message_Sequence;
with RFLX.Arrays.Inner_Message;
with RFLX.RFLX_Types;

package RFLX.Arrays.Inner_Messages is new RFLX_Message_Sequence (RFLX.RFLX_Types, Inner_Message.Context, Inner_Message.Initialize, Inner_Message.Take_Buffer, Inner_Message.Has_Buffer, Inner_Message.Message_Last, Inner_Message.Initialized, Inner_Message.Structural_Valid_Message);
package RFLX.Arrays.Inner_Messages is new RFLX.RFLX_Message_Sequence (RFLX.RFLX_Types, RFLX.Arrays.Inner_Message.Context, RFLX.Arrays.Inner_Message.Initialize, RFLX.Arrays.Inner_Message.Take_Buffer, RFLX.Arrays.Inner_Message.Has_Buffer, RFLX.Arrays.Inner_Message.Message_Last, RFLX.Arrays.Inner_Message.Initialized, RFLX.Arrays.Inner_Message.Structural_Valid_Message);
2 changes: 1 addition & 1 deletion generated/rflx-arrays-modular_vector.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Scalar_Sequence;
with RFLX.Arrays;
with RFLX.RFLX_Types;

package RFLX.Arrays.Modular_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, Modular_Integer, Modular_Integer, Valid, To_Actual, To_Base);
package RFLX.Arrays.Modular_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, RFLX.Arrays.Modular_Integer, RFLX.Arrays.Modular_Integer, RFLX.Arrays.Valid, RFLX.Arrays.To_Actual, RFLX.Arrays.To_Base);
2 changes: 1 addition & 1 deletion generated/rflx-arrays-range_vector.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Scalar_Sequence;
with RFLX.Arrays;
with RFLX.RFLX_Types;

package RFLX.Arrays.Range_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, Range_Integer, Range_Integer_Base, Valid, To_Actual, To_Base);
package RFLX.Arrays.Range_Vector is new RFLX.RFLX_Scalar_Sequence (RFLX.RFLX_Types, RFLX.Arrays.Range_Integer, RFLX.Arrays.Range_Integer_Base, RFLX.Arrays.Valid, RFLX.Arrays.To_Actual, RFLX.Arrays.To_Base);
2 changes: 1 addition & 1 deletion generated/rflx-ipv4-options.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ with RFLX.RFLX_Message_Sequence;
with RFLX.IPv4.Option;
with RFLX.RFLX_Types;

package RFLX.IPv4.Options is new RFLX_Message_Sequence (RFLX.RFLX_Types, Option.Context, Option.Initialize, Option.Take_Buffer, Option.Has_Buffer, Option.Message_Last, Option.Initialized, Option.Structural_Valid_Message);
package RFLX.IPv4.Options is new RFLX.RFLX_Message_Sequence (RFLX.RFLX_Types, RFLX.IPv4.Option.Context, RFLX.IPv4.Option.Initialize, RFLX.IPv4.Option.Take_Buffer, RFLX.IPv4.Option.Has_Buffer, RFLX.IPv4.Option.Message_Last, RFLX.IPv4.Option.Initialized, RFLX.IPv4.Option.Structural_Valid_Message);
36 changes: 20 additions & 16 deletions rflx/generator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,37 +2203,41 @@ def __create_array_unit(self, array_type: Array, package_name: ID) -> None:
]
array_package = GenericPackageInstantiation(
self.prefix * array_type.identifier,
const.MESSAGE_SEQUENCE_PACKAGE,
self.prefix * const.MESSAGE_SEQUENCE_PACKAGE,
[
self.prefix * const.TYPES_PACKAGE,
f"{element_type.name}.Context",
f"{element_type.name}.Initialize",
f"{element_type.name}.Take_Buffer",
f"{element_type.name}.Has_Buffer",
f"{element_type.name}.Message_Last",
f"{element_type.name}.Initialized",
f"{element_type.name}.Structural_Valid_Message",
self.prefix * element_type.identifier * "Context",
self.prefix * element_type.identifier * "Initialize",
self.prefix * element_type.identifier * "Take_Buffer",
self.prefix * element_type.identifier * "Has_Buffer",
self.prefix * element_type.identifier * "Message_Last",
self.prefix * element_type.identifier * "Initialized",
self.prefix * element_type.identifier * "Structural_Valid_Message",
],
)
elif isinstance(element_type, Scalar):
array_context = [
Pragma("SPARK_Mode"),
WithClause(self.prefix * const.SCALAR_SEQUENCE_PACKAGE),
WithClause(self.prefix * package_name),
WithClause(self.prefix * element_type.package.name),
WithClause(self.prefix * const.TYPES_PACKAGE),
]
array_package = GenericPackageInstantiation(
self.prefix * package_name * array_type.name,
self.prefix * const.SCALAR_SEQUENCE_PACKAGE,
[
self.prefix * const.TYPES_PACKAGE,
element_type.name,
common.base_type_name(element_type)
if not isinstance(element_type, ModularInteger)
else element_type.name,
"Valid",
"To_Actual",
"To_Base",
self.prefix * element_type.identifier,
self.prefix
* element_type.package.name
* (
common.base_type_name(element_type)
if not isinstance(element_type, ModularInteger)
else element_type.name
),
self.prefix * element_type.package.name * "Valid",
self.prefix * element_type.package.name * "To_Actual",
self.prefix * element_type.package.name * "To_Base",
],
)
else:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,49 @@ def test_potential_name_conflicts_fields_literals() -> None:
end Test;
"""
)


def test_array_with_imported_element_type_scalar() -> None:
p = Parser()
p.parse_string(
"""
with Test;
package Array_Test is
type T is array of Test.T;
end Array_Test;
"""
)
p.parse_string(
"""
package Test is
type T is mod 256;
end Test;
"""
)
_assert_compilable_code(p)


def test_array_with_imported_element_type_message() -> None:
p = Parser()
p.parse_string(
"""
with Test;
package Array_Test is
type T is array of Test.M;
end Array_Test;
"""
)
p.parse_string(
"""
package Test is
type M is
message
null
then A
with Length => 8;
A : Opaque;
end message;
end Test;
"""
)
_assert_compilable_code(p)

0 comments on commit 584299f

Please sign in to comment.