Commit e5c29d42 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Make connection parsing return option type

parent b3b89882
...@@ -8,7 +8,7 @@ package Option_Type is ...@@ -8,7 +8,7 @@ package Option_Type is
type Option is tagged private; type Option is tagged private;
function Just (I : T) return Option; function Just (I : T) return Option;
function Nothing return Option; function Nothing return Option;
-- function Just (O : Option) return T; function Unsafe_Just (O : Option) return T;
-- function Value (O : Option) return T renames Just; -- function Value (O : Option) return T renames Just;
function Value_Or (O : Option; Default : T) return T; function Value_Or (O : Option; Default : T) return T;
function Has_Value (O : Option) return Boolean; function Has_Value (O : Option) return Boolean;
...@@ -27,7 +27,7 @@ private ...@@ -27,7 +27,7 @@ private
function Nothing return Option is function Nothing return Option is
(Present => False, others => <>); (Present => False, others => <>);
-- function Just (O : Option) return T is (O.Value); function Unsafe_Just (O : Option) return T is (O.Value);
function Value_Or (O : Option; Default : T) return T is function Value_Or (O : Option; Default : T) return T is
(if O.Present then O.Value else Default); (if O.Present then O.Value else Default);
......
...@@ -411,25 +411,33 @@ package body Parser_Utils is ...@@ -411,25 +411,33 @@ package body Parser_Utils is
Current_Function : Node_Id; Current_Function : Node_Id;
-- Parse a connection -- Parse a connection
function Parse_Connection (Conn : Node_Id) return Connection is function Parse_Connection (Conn : Node_Id) return Optional_Connection is
use Option_Connection;
Caller : constant Node_Id := AIN.Item (AIN.First_Node Caller : constant Node_Id := AIN.Item (AIN.First_Node
(AIN.Path (AIN.Destination (Conn)))); (AIN.Path (AIN.Destination (Conn))));
Callee : constant Node_Id := AIN.Item (AIN.First_Node Callee : constant Node_Id := AIN.Item (AIN.First_Node
(AIN.Path (AIN.Source (Conn)))); (AIN.Path (AIN.Source (Conn))));
PI_Name : constant Name_Id := Get_Interface_Name PI_Name : Name_Id; -- None in case of cyclic interface
(Get_Referenced_Entity (AIN.Source (Conn)));
RI_Name : constant Name_Id := Get_Interface_Name RI_Name : constant Name_Id := Get_Interface_Name
(Get_Referenced_Entity (AIN.Destination (Conn))); (Get_Referenced_Entity (AIN.Destination (Conn)));
begin begin
-- Put_Line (AIN.Node_Kind'Image (Kind (Caller))); -- Put_Line (AIN.Node_Kind'Image (Kind (Caller)));
return Connection'(Caller => -- Filter out connections if the PI is cyclic (not a connection!)
if Get_RCM_Operation_Kind (Caller) = Cyclic_Operation then
return Nothing;
end if;
PI_Name := Get_Interface_Name
(Get_Referenced_Entity (AIN.Source (Conn)));
return Just (Connection'(Caller =>
(if Kind (Caller) = K_Subcomponent_Access_Instance then US ("_env") (if Kind (Caller) = K_Subcomponent_Access_Instance then US ("_env")
else US (AIN_Case (Caller))), else US (AIN_Case (Caller))),
Callee => Callee =>
(if Kind (Callee) = K_Subcomponent_Access_Instance then US ("_env") (if Kind (Callee) = K_Subcomponent_Access_Instance then US ("_env")
else US (AIN_Case (Callee))), else US (AIN_Case (Callee))),
PI_Name => US (Get_Name_String (PI_Name)), PI_Name => US (Get_Name_String (PI_Name)),
RI_Name => US (Get_Name_String (RI_Name))); RI_Name => US (Get_Name_String (RI_Name))));
end Parse_Connection; end Parse_Connection;
-- Create a vector of connections for a given system -- Create a vector of connections for a given system
...@@ -438,13 +446,18 @@ package body Parser_Utils is ...@@ -438,13 +446,18 @@ package body Parser_Utils is
function Parse_System_Connections (System : Node_Id) function Parse_System_Connections (System : Node_Id)
return Channels.Vector return Channels.Vector
is is
Conn : Node_Id; use Option_Connection;
Result : Channels.Vector; Conn : Node_Id;
Result : Channels.Vector;
Opt_Conn : Optional_Connection;
begin begin
if Present (AIN.Connections (System)) then if Present (AIN.Connections (System)) then
Conn := AIN.First_Node (AIN.Connections (System)); Conn := AIN.First_Node (AIN.Connections (System));
while Present (Conn) loop while Present (Conn) loop
Result := Result & Parse_Connection (Conn); Opt_Conn := Parse_Connection (Conn);
if Opt_Conn.Has_Value then
Result := Result & Opt_Conn.Unsafe_Just;
end if;
Conn := AIN.Next_Node (Conn); Conn := AIN.Next_Node (Conn);
end loop; end loop;
end if; end if;
......
...@@ -172,7 +172,10 @@ package Parser_Utils is ...@@ -172,7 +172,10 @@ package Parser_Utils is
Callee : Unbounded_String; Callee : Unbounded_String;
RI_Name : Unbounded_String; RI_Name : Unbounded_String;
PI_Name : Unbounded_String; PI_Name : Unbounded_String;
end record; end record;
package Option_Connection is new Option_Type (Connection);
subtype Optional_Connection is Option_Connection.Option;
package Channels is new Indefinite_Vectors (Natural, Connection); package Channels is new Indefinite_Vectors (Natural, Connection);
package Connection_Maps is new Indefinite_Ordered_Maps (String, package Connection_Maps is new Indefinite_Ordered_Maps (String,
......
package Parser_Version is package Parser_Version is
Parser_Release : constant String := Parser_Release : constant String :=
"2c4ef76 ; Commit Date: Sat Jul 15 18:25:37 2017 "; "b3b8988 ; Commit Date: Sun Jul 16 19:13:52 2017 ";
Ocarina_Version : constant String := Ocarina_Version : constant String :=
"Ocarina 2017.x (Working Copy from r0338d89)"; "Ocarina 2017.x (Working Copy from r0338d89)";
end Parser_Version; end Parser_Version;
\ No newline at end of file
AADL_PARSER=../../aadl_parser AADL_PARSER=../../aadl_parser
all: build all: test-parse
test-parse: test-parse:
$(AADL_PARSER) -glue -i interfaceview.aadl -c deploymentview.aadl -d dataview.aadl ../common/ocarina_components.aadl ../common/TASTE_DV_Properties.aadl $(AADL_PARSER) -glue -i interfaceview.aadl -c deploymentview.aadl -d dataview.aadl ../common/ocarina_components.aadl ../common/TASTE_DV_Properties.aadl
......
AADL_PARSER=../../aadl_parser AADL_PARSER=../../aadl_parser
all: build all: test-parse
test-parse: test-parse:
$(AADL_PARSER) -gw -i InterfaceView.aadl -d DataView.aadl ../common/TASTE_IV_Properties.aadl $(AADL_PARSER) -gw -i InterfaceView.aadl -d DataView.aadl ../common/TASTE_IV_Properties.aadl
......
Supports Markdown
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