Commit 61425ccb authored by yoogx's avatar yoogx

* Continue code refactoring

parent 44e8768d
......@@ -14,12 +14,6 @@ property set Deployment is
Port_Number : aadlinteger applies to (process, device);
-- IP port number of a process (BSD_Sockets specific)
Process_ID : aadlinteger applies to (process, device);
-- Process identifier (SpaceWire specific)
Channel_Address : aadlinteger applies to (process, device);
-- Communication channel address (SpaceWire specific)
Protocol_Type : type enumeration (iiop, diop);
-- Supported communication protocols
Protocol : Deployment::Protocol_Type applies to (system);
......
......@@ -31,10 +31,17 @@
-- --
------------------------------------------------------------------------------
with Ocarina.Backends.Messages;
with Ocarina.Instances.Queries;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.Namet;
package body Ocarina.Backends.Properties.Utils is
use Ocarina.Backends.Messages;
use Ocarina.Instances.Queries;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.Namet;
----------------------------
-- Check_And_Get_Property --
......@@ -79,6 +86,19 @@ package body Ocarina.Backends.Properties.Utils is
end if;
end Check_And_Get_Property;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
Default_Value : List_Id := No_List)
return List_Id is
begin
if Is_Defined_List_Property (E, Property_Name) then
return Get_List_Property (E, Property_Name);
else
return Default_Value;
end if;
end Check_And_Get_Property;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
......@@ -92,4 +112,31 @@ package body Ocarina.Backends.Properties.Utils is
end if;
end Check_And_Get_Property;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
Names : Name_Array;
Default_Value : Int := Int'First)
return Int
is
P_Name : Name_Id;
begin
if not Is_Defined_Enumeration_Property (E, Property_Name) then
return Default_Value;
end if;
P_Name := Get_Enumeration_Property (E, Property_Name);
for J in Names'Range loop
if P_Name = Names (J) then
return J;
end if;
end loop;
Display_Located_Error
(Loc (E),
"Unknown enumerator " & Get_Name_String (P_Name),
Fatal => True);
return Default_Value;
end Check_And_Get_Property;
end Ocarina.Backends.Properties.Utils;
......@@ -51,12 +51,25 @@ package Ocarina.Backends.Properties.Utils is
Default_Value : Node_Id := No_Node)
return Node_Id;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
Default_Value : List_Id := No_List)
return List_Id;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
Default_Value : Boolean := False)
return Boolean;
function Check_And_Get_Property
(E : Node_Id;
Property_Name : Name_Id;
Names : Name_Array;
Default_Value : Int := Int'First)
return Int;
-- Check Property_Name is set on node E, if so returns its value
-- otherwise return the default value.
......
......@@ -658,14 +658,9 @@ package body Ocarina.Backends.Properties is
-------------------
function Get_Base_Type (D : Node_Id) return List_Id is
begin
pragma Assert (AINU.Is_Data (D));
if Is_Defined_List_Property (D, Base_Type) then
return Get_List_Property (D, Base_Type);
else
return No_List;
end if;
begin
return Check_And_Get_Property (D, Base_Type);
end Get_Base_Type;
------------------
......@@ -947,27 +942,26 @@ package body Ocarina.Backends.Properties is
function Get_IEEE754_Precision
(D : Node_Id) return Supported_IEEE754_Precision
is
P_Name : Name_Id;
begin
pragma Assert (AINU.Is_Data (D));
if Is_Defined_Enumeration_Property (D, IEEE754_Precision) then
P_Name := Get_Enumeration_Property (D, IEEE754_Precision);
IEEE754_Names : constant Name_Array
(Supported_IEEE754_Precision'Pos (Supported_IEEE754_Precision'First) ..
Supported_IEEE754_Precision'Pos (Supported_IEEE754_Precision'Last))
:= (Supported_IEEE754_Precision'Pos (Precision_Simple)
=> Precision_Simple_Name,
Supported_IEEE754_Precision'Pos (Precision_Double)
=> Precision_Double_Name,
Supported_IEEE754_Precision'Pos (Precision_None)
=> No_Name
);
if P_Name = Precision_Simple_Name then
return Precision_Simple;
elsif P_Name = Precision_Double_Name then
return Precision_Double;
else
Display_Located_Error
(AIN.Loc (D),
"Unknown floating point precision",
Fatal => True);
return Precision_None;
end if;
else
return Precision_None;
end if;
begin
return Supported_IEEE754_Precision'Val
(Check_And_Get_Property
(D,
IEEE754_Precision,
IEEE754_Names,
Supported_IEEE754_Precision'Pos (Precision_None)));
end Get_IEEE754_Precision;
-----------------------
......
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