Skip to content

Commit

Permalink
Ensure initialization of all session context components
Browse files Browse the repository at this point in the history
This is required to prove the initialization of a session context which
is declared as a package variable.

Ref. #954
  • Loading branch information
treiher committed Apr 4, 2022
1 parent f81d80f commit 9c895fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion rflx/generator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,13 @@ def _create_context_type(
[
Component("Next_State", "State", Variable(f"S_{initial_state}")),
*[
Component(identifier, type_identifier, expression)
Component(
identifier,
type_identifier,
expression
if expression is not None or type_identifier.name == ID("Context")
else First(type_identifier),
)
for identifier, (
type_identifier,
expression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ is
pragma Assert (Ctx.P.Slots.Slot_Ptr_1 = null);
goto Finalize_Process;
end if;
Ctx.P.Global := Local + 20;
Ctx.P.Uninitialized_Global := Local;
Ctx.P.Global := Ctx.P.Uninitialized_Global + 20;
if RFLX_Types.To_First_Bit_Index (Ctx.P.Message_Ctx.Buffer_Last) - RFLX_Types.To_First_Bit_Index (Ctx.P.Message_Ctx.Buffer_First) + 1 >= 32 then
Universal.Message.Reset (Ctx.P.Message_Ctx, RFLX_Types.To_First_Bit_Index (Ctx.P.Message_Ctx.Buffer_First), RFLX_Types.To_First_Bit_Index (Ctx.P.Message_Ctx.Buffer_First) + 32 - 1);
Universal.Message.Set_Message_Type (Ctx.P.Message_Ctx, Universal.MT_Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private
record
Next_State : State := S_Start;
Global : Universal.Value := 11;
Uninitialized_Global : Universal.Value := Universal.Value'First;
Message_Ctx : Universal.Message.Context;
Slots : Test.Session_Allocator.Slots;
Memory : Test.Session_Allocator.Memory;
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/session_variable_initialization/test.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package Test is
Final => Terminated
is
Global : Universal::Value := 11; -- §S-D-V-T-SC, §S-D-V-E-L
Uninitialized_Global : Universal::Value; -- §S-D-V-T-SC, §S-D-V-E-N
Message : Universal::Message; -- §S-D-V-T-M, §S-D-V-E-N
begin
state Start is
Expand All @@ -22,7 +23,8 @@ package Test is
Local : Universal::Value := 2; -- §S-S-D-V-T-SC, §S-S-D-V-E-L
begin
Local := Local + Message.Value; -- §S-S-A-A-ME, §S-S-A-A-L, §S-S-A-A-S, §S-S-A-A-V, §S-E-S-V
Global := Local + 20; -- §S-S-A-A-ME, §S-S-A-A-L, §S-S-A-A-V
Uninitialized_Global := Local; -- §S-S-A-A-V
Global := Uninitialized_Global + 20; -- §S-S-A-A-ME, §S-S-A-A-L, §S-S-A-A-V
-- §S-S-A-A-MA
Message := Universal::Message'(Message_Type => Universal::MT_Value,
Length => Universal::Value'Size / 8,
Expand Down

0 comments on commit 9c895fb

Please sign in to comment.