Commit e1a73dc0 authored by julien.delange's avatar julien.delange
Browse files

add the ASN1 CHOICE alternative

begin to generate packet contents



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@687 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent ddd7046f
......@@ -86,6 +86,8 @@ package body Ocarina.Backends.ASN1.Deployment is
Port_Id : Unsigned_Long_Long := 0;
-- The port identifier. This is unique for each port.
Msg_Choices : List_Id;
Module_Node : Node_Id;
-----------
......@@ -120,8 +122,9 @@ package body Ocarina.Backends.ASN1.Deployment is
Get_String_Name ("POHIC-DEPLOYMENT"));
Module_Node := ASN1N.Module_Node (ASN1_Root);
Thread_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Port_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Thread_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Port_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Msg_Choices := New_List (ASN1N.K_Enumerated_Value_List);
Visit (Root_System (E));
......@@ -147,25 +150,35 @@ package body Ocarina.Backends.ASN1.Deployment is
Append_Node_To_List
(Make_Sequence_Member
(Get_String_Name ("sender-thread"),
Get_String_Name ("THREAD-ID")),
Make_Defining_Identifier
(Get_String_Name ("THREAD-ID"))),
Pkt_Contents);
Append_Node_To_List
(Make_Sequence_Member
(Get_String_Name ("sender-port"),
Get_String_Name ("PORT-ID")),
Make_Defining_Identifier
(Get_String_Name ("PORT-ID"))),
Pkt_Contents);
Append_Node_To_List
(Make_Sequence_Member
(Get_String_Name ("receiver-thread"),
Get_String_Name ("THREAD-ID")),
Make_Defining_Identifier
(Get_String_Name ("THREAD-ID"))),
Pkt_Contents);
Append_Node_To_List
(Make_Sequence_Member
(Get_String_Name ("receiver-port"),
Get_String_Name ("PORT-ID")),
Make_Defining_Identifier
(Get_String_Name ("PORT-ID"))),
Pkt_Contents);
Append_Node_To_List
(Make_Sequence_Member
(Get_String_Name ("msg"),
Make_Choice (Msg_Choices)),
Pkt_Contents);
Packet_Type :=
......
......@@ -60,6 +60,9 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
procedure Generate_Enumerated_Value (N : Node_Id);
procedure Generate_Sequence (N : Node_Id);
procedure Generate_Sequence_Member (N : Node_Id);
procedure Generate_Choice (N : Node_Id);
procedure Generate_Choice_Member (N : Node_Id);
procedure Generate_Defining_Identifier (N : Node_Id);
-----------
-- Write --
......@@ -108,6 +111,15 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
when K_Sequence_Member =>
Generate_Sequence_Member (N);
when K_Choice =>
Generate_Choice (N);
when K_Choice_Member =>
Generate_Choice_Member (N);
when K_Defining_Identifier =>
Generate_Defining_Identifier (N);
when others =>
Display_Error ("other element in generator", Fatal => False);
null;
......@@ -163,7 +175,6 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
Write_Name (Name (N));
Write_Space;
Write_Str (" ::= ");
Write_Eol;
Generate (Declaration (N));
end Generate_Type_Definition;
......@@ -175,6 +186,9 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
P : Node_Id;
begin
Write_Str (" ENUMERATED {");
Write_Eol;
Increment_Indentation;
Write_Indentation;
if not Is_Empty (Values (N)) then
P := First_Node (Values (N));
while Present (P) loop
......@@ -182,10 +196,16 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
P := Next_Node (P);
if P /= No_Node then
Write_Char (',');
Write_Eol;
Write_Indentation;
end if;
end loop;
end if;
Write_Eol;
Write_Indentation;
Write_Line ("}");
Decrement_Indentation;
Write_Indentation;
end Generate_Enumerated;
-------------------------------
......@@ -210,16 +230,22 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
P : Node_Id;
begin
Write_Line (" SEQUENCE {");
Increment_Indentation;
if not Is_Empty (Values (N)) then
P := First_Node (Values (N));
while Present (P) loop
Write_Indentation;
Generate (P);
P := Next_Node (P);
if P /= No_Node then
Write_Char (',');
Write_Eol;
end if;
end loop;
end if;
Write_Eol;
Decrement_Indentation;
Write_Indentation;
Write_Line ("}");
end Generate_Sequence;
......@@ -231,7 +257,54 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
begin
Write_Name (Member_Name (N));
Write_Space;
Write_Name (Member_Type (N));
Generate (Member_Type (N));
end Generate_Sequence_Member;
---------------------
-- Generate_Choice --
---------------------
procedure Generate_Choice (N : Node_Id) is
P : Node_Id;
begin
Write_Line (" CHOICE {");
Increment_Indentation;
Write_Indentation (-1);
if not Is_Empty (Values (N)) then
P := First_Node (Values (N));
while Present (P) loop
Generate (P);
P := Next_Node (P);
if P /= No_Node then
Write_Char (',');
Write_Eol;
Write_Indentation;
end if;
end loop;
end if;
Decrement_Indentation;
Write_Indentation;
Write_Line ("}");
end Generate_Choice;
------------------------------
-- Generate_Choice_Member --
------------------------------
procedure Generate_Choice_Member (N : Node_Id) is
begin
Write_Name (Member_Name (N));
Write_Space;
Generate (Member_Type (N));
end Generate_Choice_Member;
----------------------------------
-- Generate_Defining_Identifier --
----------------------------------
procedure Generate_Defining_Identifier (N : Node_Id) is
begin
Write_Name (Name (N));
end Generate_Defining_Identifier;
end Ocarina.Backends.ASN1_Tree.Generator;
......@@ -82,7 +82,18 @@ module Ocarina::Backends::ASN1_Tree::Nodes {
interface Sequence_Member : Node_Id
{
Name_Id Member_Name;
Name_Id Member_Type;
Node_Id Member_Type;
};
interface Choice : Node_Id
{
List_Id Values;
};
interface Choice_Member : Node_Id
{
Name_Id Member_Name;
Node_Id Member_Type;
};
interface Literal : Node_Id {
......
......@@ -554,7 +554,7 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
--------------------------
function Make_Sequence_Member
(Member_Name : Name_Id; Member_Type : Name_Id) return Node_Id
(Member_Name : Name_Id; Member_Type : Node_Id) return Node_Id
is
N : Node_Id;
begin
......@@ -564,6 +564,34 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
return N;
end Make_Sequence_Member;
-----------------
-- Make_Choice --
-----------------
function Make_Choice (Choice_Members : List_Id) return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Choice);
Set_Values (N, Choice_Members);
return N;
end Make_Choice;
------------------------
-- Make_Choice_Member --
------------------------
function Make_Choice_Member
(Member_Name : Name_Id; Member_Type : Node_Id) return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Choice_Member);
Set_Member_Name (N, Member_Name);
Set_Member_Type (N, Member_Type);
return N;
end Make_Choice_Member;
------------------
-- Make_Literal --
------------------
......
......@@ -199,8 +199,16 @@ package Ocarina.Backends.ASN1_Tree.Nutils is
-- Make a sequence that contains the members given in parameter.
function Make_Sequence_Member
(Member_Name : Name_Id; Member_Type : Name_Id) return Node_Id;
(Member_Name : Name_Id; Member_Type : Node_Id) return Node_Id;
-- Make a sequence member identified by Member_Name which has the
-- type Member_Type.
function Make_Choice (Choice_Members : List_Id) return Node_Id;
-- Make a choice that contains the members given in parameter.
function Make_Choice_Member
(Member_Name : Name_Id; Member_Type : Node_Id) return Node_Id;
-- Make a choice member identified by Member_Name which has the
-- type Member_Type.
end Ocarina.Backends.ASN1_Tree.Nutils;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment