Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested lists in property values #284

Merged
merged 5 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/backends/aadl_pp/ocarina-be_aadl-properties.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -291,6 +291,36 @@ package body Ocarina.BE_AADL.Properties is
Write_Eol;
end Print_Property_Type_Declaration;

-------------------------------
-- Print_Property_List_Value --
-------------------------------

procedure Print_Property_List_Value (Node : Node_Id) is
pragma Assert (Kind (Node) = K_Property_List_Value);

List_Node : Node_Id;
begin
Print_Token (T_Left_Parenthesis);
List_Node := First_Node (Property_Values (Node));

while Present (List_Node) loop
if List_Node /= First_Node (Property_Values (Node)) then
Print_Token (T_Comma);
Write_Space;
end if;

if Kind (List_Node) = K_Property_List_Value then
Print_Property_List_Value (List_Node);
else
Print_Property_Value (List_Node);
end if;

List_Node := Next_Node (List_Node);
end loop;

Print_Token (T_Right_Parenthesis);
end Print_Property_List_Value;

---------------------------
-- Print_Property_Values --
---------------------------
Expand All @@ -300,25 +330,15 @@ package body Ocarina.BE_AADL.Properties is
(Present (Node)
and then (Kind (Node) = K_Property_Value or else DNKE (Node)));

List_Node : Node_Id;
Prop_List_Value_Node : Node_Id;
begin
if Single_Value (Node) = No_Node then
-- Print Property_List_Value with new line and indents

Print_Token (T_Left_Parenthesis);
List_Node := First_Node (Multi_Value (Node));
-- Print Property_List_Value

while Present (List_Node) loop
if List_Node /= First_Node (Multi_Value (Node)) then
Print_Token (T_Comma);
Write_Space;
end if;

Print_Property_Value (List_Node);
List_Node := Next_Node (List_Node);
end loop;

Print_Token (T_Right_Parenthesis);
Prop_List_Value_Node :=
New_Node (K_Property_List_Value, Loc (Node));
Set_Property_Values (Prop_List_Value_Node, Multi_Value (Node));
Print_Property_List_Value (Prop_List_Value_Node);
else
-- Print Property_Expression without new line

Expand Down
27 changes: 26 additions & 1 deletion src/core/instance/ocarina-instances-processor-properties.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2005-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -248,6 +248,7 @@ package body Ocarina.Instances.Processor.Properties is
(No (Property_Value)
or else Kind (Property_Value) = K_Literal
or else Kind (Property_Value) = K_Property_Term
or else Kind (Property_Value) = K_Property_List_Value
or else Kind (Property_Value) = K_Enumeration_Term
or else Kind (Property_Value) = K_Number_Range_Term
or else Kind (Property_Value) = K_Reference_Term
Expand Down Expand Up @@ -629,6 +630,30 @@ package body Ocarina.Instances.Processor.Properties is
(Evaluated_Value,
ATN.List_Items (Property_Value));

when K_Property_List_Value =>
declare
Items : List_Id;
Item : Node_Id;
New_Evaluated_Node : Node_Id;
begin
Items :=
New_List (K_List_Id, ATN.Loc (Property_Value));
Item :=
ATN.First_Node (Property_Values (Property_Value));
while Item /= No_Node loop
New_Evaluated_Node :=
Evaluate_Property_Value
(Instance_Root, Container, Item);
Append_Node_To_List (New_Evaluated_Node, Items);
Item := ATN.Next_Node (Item);
end loop;
Evaluated_Value :=
New_Node
(K_Property_List_Value,
ATN.Loc (Property_Value));
Set_Property_Values (Evaluated_Value, Items);
end;

when others =>
raise Program_Error;
end case;
Expand Down
23 changes: 22 additions & 1 deletion src/core/instance/ocarina-instances-properties.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2005-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -649,6 +649,7 @@ package body Ocarina.Instances.Properties is
(No (Property_Value)
or else Kind (Property_Value) = K_Literal
or else Kind (Property_Value) = K_Property_Term
or else Kind (Property_Value) = K_Property_List_Value
or else Kind (Property_Value) = K_Enumeration_Term
or else Kind (Property_Value) = K_Number_Range_Term
or else Kind (Property_Value) = K_Reference_Term
Expand All @@ -664,6 +665,7 @@ package body Ocarina.Instances.Properties is

Instantiated_Value : Node_Id := No_Node;
List_Node : Node_Id := No_Node;
Items : List_Id;
Node : Node_Id;

begin
Expand Down Expand Up @@ -811,6 +813,25 @@ package body Ocarina.Instances.Properties is
(Instantiated_Value,
ATN.List_Items (Property_Value));

when K_Property_List_Value =>
-- nested lists
Items := New_List (K_List_Id, ATN.Loc (Property_Value));
List_Node :=
ATN.First_Node (Property_Values (Property_Value));

while Present (List_Node) loop
Append_Node_To_List
(Instantiate_Property_Value
(Instance_Root, List_Node, Instance),
Items);
List_Node := ATN.Next_Node (List_Node);
end loop;
Instantiated_Value :=
New_Node
(K_Property_List_Value,
ATN.Loc (Property_Value));
Set_Property_Values (Instantiated_Value, Items);

when others =>
raise Program_Error;
end case;
Expand Down
107 changes: 84 additions & 23 deletions src/core/model/ocarina-analyzer-aadl-semantics.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -180,6 +180,17 @@ package body Ocarina.Analyzer.AADL.Semantics is
(Property_Type : Node_Id;
Property_Value : Node_Id) return Boolean;

function Check_Values_Of_Property_List_Value
(Property_Association : Node_Id;
Property_Value : Node_Id;
Property_Name : Node_Id;
Property_Type_Multiplicity : Int;
Property_Value_Layer : Int) return Boolean;
-- Check whether the values in the property value that is a
-- K_Property_List_Value node and the depth of the nested lists are
-- conformant with the type associated with the corresponding
-- property name.

------------------------------------
-- Check_Classifier_Matching_Rule --
------------------------------------
Expand Down Expand Up @@ -2048,30 +2059,21 @@ package body Ocarina.Analyzer.AADL.Semantics is
No_List
then
if Type_Of_Property_Is_A_List (Property_Name) then
List_Node :=
First_Node
(Expanded_Multi_Value
(Property_Association_Value (Property_Association)));
-- Wrap the list in a K_Property_List_Value node for checks

while Present (List_Node) loop
Types_Are_Compatible :=
Test_Property_Type_Equivalence
(Type_Of_Property_Name,
Get_Type_Of_Property_Value (List_Node))
and then Test_Property_Value_Validity
(Property_Name_Type (Property_Name),
List_Node);

if not Types_Are_Compatible then
Display_Incompatible_Property_Types
(Property_Association => Property_Association,
Property_Value => List_Node,
Property_Name => Property_Name);
Success := False;
end if;
List_Node := New_Node
(K_Property_List_Value,
Loc (Property_Association_Value (Property_Association)));
Set_Property_Values (List_Node, Expanded_Multi_Value
(Property_Association_Value (Property_Association)));

List_Node := Next_Node (List_Node);
end loop;
Success :=
Check_Values_Of_Property_List_Value
(Property_Association,
List_Node,
Property_Name,
Multiplicity (Property_Name_Type (Property_Name)),
1);

else
-- Single value properties cannot have a list as
Expand Down Expand Up @@ -2665,4 +2667,63 @@ package body Ocarina.Analyzer.AADL.Semantics is
and then Check_Property_Value (Type_Designator, Property_Value);
end Test_Property_Value_Validity;

-----------------------------------------
-- Check_Values_Of_Property_List_Value --
-----------------------------------------

function Check_Values_Of_Property_List_Value
(Property_Association : Node_Id;
Property_Value : Node_Id;
Property_Name : Node_Id;
Property_Type_Multiplicity : Int;
Property_Value_Layer : Int) return Boolean
is
pragma Assert (Kind (Property_Value) = K_Property_List_Value);

List_Node : Node_Id;
Types_Are_Compatible : Boolean;
Success : Boolean;
begin

List_Node :=
First_Node
(Property_Values
(Property_Value));
while Present (List_Node) loop
if Kind (List_Node) = K_Property_List_Value then
Types_Are_Compatible :=
Check_Values_Of_Property_List_Value
(Property_Association,
List_Node,
Property_Name,
Property_Type_Multiplicity,
Property_Value_Layer + 1);
if not Types_Are_Compatible then
Success := False;
end if;
else
Types_Are_Compatible :=
Test_Property_Type_Equivalence
(Get_Type_Of_Property (Property_Name),
Get_Type_Of_Property_Value (List_Node))
and then Test_Property_Value_Validity
(Property_Name_Type (Property_Name),
List_Node);

if not Types_Are_Compatible then
Display_Incompatible_Property_Types
(Property_Association => Property_Association,
Property_Value => List_Node,
Property_Name => Property_Name);
Success := False;
end if;

end if;

List_Node := Next_Node (List_Node);
end loop;

return Success;
end Check_Values_Of_Property_List_Value;

end Ocarina.Analyzer.AADL.Semantics;
4 changes: 2 additions & 2 deletions src/core/model/ocarina-builder-aadl-properties.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -418,7 +418,7 @@ package body Ocarina.Builder.AADL.Properties is
Set_Single_Value (Value_Of_Association, No_Node);
Set_Multi_Value
(Value_Of_Association,
List_Id (Property_Value));
Property_Values (Property_Value));
else
Set_Single_Value (Value_Of_Association, Property_Value);
Set_Multi_Value (Value_Of_Association, No_List);
Expand Down
28 changes: 27 additions & 1 deletion src/core/model/ocarina-processor-properties.adb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2005-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -513,6 +513,11 @@ package body Ocarina.Processor.Properties is
Append_List_To_List
(List_Id (Computed_Value),
Expanded_List);
elsif Kind (Computed_Value) = K_Property_List_Value then
-- nested lists
Append_Node_To_List
(Computed_Value,
Expanded_List);
else
Expanded_List_Node := Computed_Value;

Expand Down Expand Up @@ -564,6 +569,7 @@ package body Ocarina.Processor.Properties is
or else Kind (Property_Value) = K_Component_Classifier_Term
or else Kind (Property_Value) = K_Unique_Property_Const_Identifier
or else Kind (Property_Value) = K_Record_Term
or else Kind (Property_Value) = K_Property_List_Value
or else Ocarina.ME_AADL.AADL_Tree.Entities.DNKE (Property_Value));

pragma Assert (Reference_Property /= No_Node);
Expand All @@ -575,6 +581,26 @@ package body Ocarina.Processor.Properties is
Evaluated_Value := No_Node;
else
case Kind (Property_Value) is
when K_Property_List_Value =>
declare
Items : List_Id;
Item : Node_Id;
New_Evaluated_Node : Node_Id;
begin
Items := New_List (K_List_Id, Loc (Property_Value));
Item := First_Node (Property_Values (Property_Value));
while Item /= No_Node loop
New_Evaluated_Node :=
Evaluate_Property_Value (Item, Reference_Property);
Append_Node_To_List (New_Evaluated_Node, Items);
Item := Next_Node (Item);
end loop;

Evaluated_Value :=
New_Node (K_Property_List_Value, Loc (Property_Value));
Set_Property_Values (Evaluated_Value, Items);
end;

when K_Enumeration_Term =>
Evaluated_Value :=
New_Node (Kind (Property_Value), Loc (Property_Value));
Expand Down
Loading