Commit bba0a978 authored by yoogx's avatar yoogx
Browse files

* Initial support for instanciating record properties

        For ticket #17
parent 175c9d20
...@@ -259,7 +259,8 @@ package body Ocarina.Instances.Processor.Properties is ...@@ -259,7 +259,8 @@ package body Ocarina.Instances.Processor.Properties is
or else Kind (Property_Value) = K_And_Boolean_Term or else Kind (Property_Value) = K_And_Boolean_Term
or else Kind (Property_Value) = K_Or_Boolean_Term or else Kind (Property_Value) = K_Or_Boolean_Term
or else Kind (Property_Value) = K_Parenthesis_Boolean_Term or else Kind (Property_Value) = K_Parenthesis_Boolean_Term
or else Kind (Property_Value) = K_Component_Classifier_Term); or else Kind (Property_Value) = K_Component_Classifier_Term
or else Kind (Property_Value) = K_Record_Term);
Evaluated_Value : Node_Id; Evaluated_Value : Node_Id;
Node : Node_Id; Node : Node_Id;
...@@ -603,6 +604,15 @@ package body Ocarina.Instances.Processor.Properties is ...@@ -603,6 +604,15 @@ package body Ocarina.Instances.Processor.Properties is
(Evaluated_Value, (Evaluated_Value,
Component_Cat (Property_Value)); Component_Cat (Property_Value));
when K_Record_Term =>
-- Simply propagate the list to the instance
Evaluated_Value :=
New_Node (Kind (Property_Value), ATN.Loc (Property_Value));
Set_List_Items
(Evaluated_Value,
ATN.List_Items (Property_Value));
when others => when others =>
raise Program_Error; raise Program_Error;
end case; end case;
......
...@@ -466,11 +466,11 @@ package body Ocarina.Instances.Properties is ...@@ -466,11 +466,11 @@ package body Ocarina.Instances.Properties is
AIN.Property_Association_Value (Property_Association), AIN.Property_Association_Value (Property_Association),
Entity_Instance)); Entity_Instance));
-- IMPORTANT: we use entity instance where the property -- IMPORTANT: we use entity instance where the
-- has been declared, as the reference node to -- property has been declared, as the reference node
-- duplicate the property, and not pointed_instance, -- to duplicate the property, and not
-- which is the node on which the property -- pointed_instance, which is the node on which the
-- applies. Indeed, for properties that are -- property applies. Indeed, for properties that are
-- references, the reference path is set from -- references, the reference path is set from
-- entity_instance. -- entity_instance.
end if; end if;
...@@ -561,6 +561,10 @@ package body Ocarina.Instances.Properties is ...@@ -561,6 +561,10 @@ package body Ocarina.Instances.Properties is
List_Node := List_Node :=
ATN.First_Node (Expanded_Multi_Value (Property_Value)); ATN.First_Node (Expanded_Multi_Value (Property_Value));
else
List_Node :=
ATN.First_Node (Multi_Value (Property_Value));
end if;
while Present (List_Node) loop while Present (List_Node) loop
Append_Node_To_List Append_Node_To_List
...@@ -571,7 +575,7 @@ package body Ocarina.Instances.Properties is ...@@ -571,7 +575,7 @@ package body Ocarina.Instances.Properties is
Multi_Value (Duplicated_Property_Value)); Multi_Value (Duplicated_Property_Value));
List_Node := ATN.Next_Node (List_Node); List_Node := ATN.Next_Node (List_Node);
end loop; end loop;
end if;
end if; end if;
end if; end if;
...@@ -656,7 +660,8 @@ package body Ocarina.Instances.Properties is ...@@ -656,7 +660,8 @@ package body Ocarina.Instances.Properties is
or else Kind (Property_Value) = K_And_Boolean_Term or else Kind (Property_Value) = K_And_Boolean_Term
or else Kind (Property_Value) = K_Or_Boolean_Term or else Kind (Property_Value) = K_Or_Boolean_Term
or else Kind (Property_Value) = K_Parenthesis_Boolean_Term or else Kind (Property_Value) = K_Parenthesis_Boolean_Term
or else Kind (Property_Value) = K_Component_Classifier_Term); or else Kind (Property_Value) = K_Component_Classifier_Term
or else Kind (Property_Value) = K_Record_Term);
pragma Assert (Present (Instance)); pragma Assert (Present (Instance));
Instantiated_Value : Node_Id := No_Node; Instantiated_Value : Node_Id := No_Node;
...@@ -675,7 +680,6 @@ package body Ocarina.Instances.Properties is ...@@ -675,7 +680,6 @@ package body Ocarina.Instances.Properties is
Set_Value (Instantiated_Value, Value (Property_Value)); Set_Value (Instantiated_Value, Value (Property_Value));
when K_Property_Term | K_Enumeration_Term => when K_Property_Term | K_Enumeration_Term =>
Instantiated_Value := Instantiated_Value :=
New_Node (Kind (Property_Value), ATN.Loc (Property_Value)); New_Node (Kind (Property_Value), ATN.Loc (Property_Value));
ATN.Set_Identifier ATN.Set_Identifier
...@@ -800,6 +804,15 @@ package body Ocarina.Instances.Properties is ...@@ -800,6 +804,15 @@ package body Ocarina.Instances.Properties is
(Instantiated_Value, (Instantiated_Value,
Component_Cat (Property_Value)); Component_Cat (Property_Value));
when K_Record_Term =>
-- Simply propagate the list to the instance
Instantiated_Value :=
New_Node (Kind (Property_Value), ATN.Loc (Property_Value));
Set_List_Items
(Instantiated_Value,
ATN.List_Items (Property_Value));
when others => when others =>
raise Program_Error; raise Program_Error;
end case; end case;
......
...@@ -243,10 +243,6 @@ package body Ocarina.Instances.Queries is ...@@ -243,10 +243,6 @@ package body Ocarina.Instances.Queries is
end if; end if;
end Get_Enumeration_Property; end Get_Enumeration_Property;
------------------------------
-- Get_Enumeration_Property --
------------------------------
function Get_Enumeration_Property function Get_Enumeration_Property
(Entity : Node_Id; (Entity : Node_Id;
Name : Name_Id; Name : Name_Id;
...@@ -443,12 +439,14 @@ package body Ocarina.Instances.Queries is ...@@ -443,12 +439,14 @@ package body Ocarina.Instances.Queries is
return No_List; return No_List;
end if; end if;
if Present if No (Expanded_Multi_Value (AIN.Property_Association_Value (Property)))
or else
(Present
(Expanded_Multi_Value (AIN.Property_Association_Value (Property))) (Expanded_Multi_Value (AIN.Property_Association_Value (Property)))
and then No and then No
(ATN.First_Node (ATN.First_Node
(Expanded_Multi_Value (Expanded_Multi_Value
(AIN.Property_Association_Value (Property)))) (AIN.Property_Association_Value (Property)))))
then then
return Multi_Value (AIN.Property_Association_Value (Property)); return Multi_Value (AIN.Property_Association_Value (Property));
end if; end if;
...@@ -642,25 +640,6 @@ package body Ocarina.Instances.Queries is ...@@ -642,25 +640,6 @@ package body Ocarina.Instances.Queries is
PT_Reference; PT_Reference;
end Is_Defined_Reference_Property; end Is_Defined_Reference_Property;
------------------------------------
-- Is_Defined_Classifier_Property --
------------------------------------
function Is_Defined_Classifier_Property
(Entity : Node_Id;
Name : Name_Id;
In_Mode : Name_Id := No_Name) return Boolean
is
Property_Value : constant Node_Id :=
Get_Value_Of_Property_Association (Entity, Name, In_Mode);
begin
return Present (Property_Value)
and then
Get_Type_Of_Property_Value (Property_Value, True) =
PT_Classifier;
end Is_Defined_Classifier_Property;
------------------------------- -------------------------------
-- Is_Defined_Range_Property -- -- Is_Defined_Range_Property --
------------------------------- -------------------------------
...@@ -682,6 +661,46 @@ package body Ocarina.Instances.Queries is ...@@ -682,6 +661,46 @@ package body Ocarina.Instances.Queries is
PT_Range; PT_Range;
end Is_Defined_Range_Property; end Is_Defined_Range_Property;
--------------------------------
-- Is_Defined_Record_Property --
--------------------------------
function Is_Defined_Record_Property
(Entity : Node_Id;
Name : Name_Id;
In_Mode : Name_Id := No_Name) return Boolean
is
Property : constant Node_Id
:= Get_Property_Association (Entity, Name, In_Mode);
begin
return Present (Property)
and then
Get_Type_Of_Property_Value
(ATN.Property_Association_Value
(AIN.Corresponding_Declaration (Property)),
True) = PT_Record;
end Is_Defined_Record_Property;
------------------------------------
-- Is_Defined_Classifier_Property --
------------------------------------
function Is_Defined_Classifier_Property
(Entity : Node_Id;
Name : Name_Id;
In_Mode : Name_Id := No_Name) return Boolean
is
Property_Value : constant Node_Id :=
Get_Value_Of_Property_Association (Entity, Name, In_Mode);
begin
return Present (Property_Value)
and then
Get_Type_Of_Property_Value (Property_Value, True) =
PT_Classifier;
end Is_Defined_Classifier_Property;
------------------------------ ------------------------------
-- Is_Defined_List_Property -- -- Is_Defined_List_Property --
------------------------------ ------------------------------
......
...@@ -107,6 +107,11 @@ package Ocarina.Instances.Queries is ...@@ -107,6 +107,11 @@ package Ocarina.Instances.Queries is
-- Cf. the documentation of -- Cf. the documentation of
-- Ocarina.Analyzer.Queries.Is_Defined_Range_Property -- Ocarina.Analyzer.Queries.Is_Defined_Range_Property
function Is_Defined_Record_Property
(Entity : Node_Id;
Name : Name_Id;
In_Mode : Name_Id := No_Name) return Boolean;
function Is_Defined_List_Property function Is_Defined_List_Property
(Entity : Node_Id; (Entity : Node_Id;
Name : Name_Id; Name : Name_Id;
......
...@@ -203,6 +203,9 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -203,6 +203,9 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
when K_Classifier_Type => when K_Classifier_Type =>
return PT_Classifier; return PT_Classifier;
when K_Record_Type =>
return PT_Record;
when others => when others =>
return PT_Other; return PT_Other;
end case; end case;
...@@ -283,23 +286,26 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -283,23 +286,26 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
if Use_Evaluated_Values then if Use_Evaluated_Values then
if Expanded_Single_Value (Property_Value) /= No_Node then if Expanded_Single_Value (Property_Value) /= No_Node then
Value_Node := Expanded_Single_Value (Property_Value); Value_Node := Expanded_Single_Value (Property_Value);
elsif Expanded_Multi_Value (Property_Value) /= No_List then elsif Expanded_Multi_Value (Property_Value) /= No_List then
Value_Node := Value_Node :=
First_Node (Expanded_Multi_Value (Property_Value)); First_Node (Expanded_Multi_Value (Property_Value));
-- If we are dealing with a list of value, only -- If we are dealing with a list of values, only
-- consider the first value, assuming the other ones -- consider the first value, assuming the other ones
-- are of the same type. -- are of the same type.
else else
Value_Node := No_Node; Value_Node := No_Node;
end if; end if;
-- XXX todo : fix why Property_Association with Range_Term -- XXX todo : fix why Property_Association with
-- Property_Value doesn't have Expanded_Value. -- Range_Term _and_ Record_Term Property_Value doesn't
-- have Expanded_Value.
if No (Value_Node) then if No (Value_Node) then
if Single_Value (Property_Value) /= No_Node then if Single_Value (Property_Value) /= No_Node then
Value_Node := Single_Value (Property_Value); Value_Node := Single_Value (Property_Value);
elsif Multi_Value (Property_Value) /= No_List then elsif Multi_Value (Property_Value) /= No_List then
Value_Node := First_Node (Multi_Value (Property_Value)); Value_Node := First_Node (Multi_Value (Property_Value));
end if; end if;
...@@ -354,6 +360,9 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -354,6 +360,9 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
when K_Component_Classifier_Term => when K_Component_Classifier_Term =>
Value_Type := PT_Classifier; Value_Type := PT_Classifier;
when K_Record_Term =>
Value_Type := PT_Record;
-- XXX add here unit_term and record_term case -- XXX add here unit_term and record_term case
when others => when others =>
...@@ -409,10 +418,6 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -409,10 +418,6 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
return Get_Value_Type (Value (Property_Value)).SVal; return Get_Value_Type (Value (Property_Value)).SVal;
end Get_String_Of_Property_Value; end Get_String_Of_Property_Value;
----------------------------------
-- Get_String_Of_Property_Value --
----------------------------------
function Get_String_Of_Property_Value function Get_String_Of_Property_Value
(Property_Value : Node_Id) return String (Property_Value : Node_Id) return String
is is
...@@ -448,10 +453,6 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -448,10 +453,6 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
end case; end case;
end Get_Enumeration_Of_Property_Value; end Get_Enumeration_Of_Property_Value;
---------------------------------------
-- Get_Enumeration_Of_Property_Value --
---------------------------------------
function Get_Enumeration_Of_Property_Value function Get_Enumeration_Of_Property_Value
(Property_Value : Node_Id) return String (Property_Value : Node_Id) return String
is is
...@@ -512,6 +513,18 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -512,6 +513,18 @@ package body Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
return Get_Referenced_Entity (Property_Value); return Get_Referenced_Entity (Property_Value);
end Get_Classifier_Of_Property_Value; end Get_Classifier_Of_Property_Value;
----------------------------------
-- Get_Record_Of_Property_Value --
----------------------------------
function Get_Record_Of_Property_Value
(Property_Value : Node_Id) return List_Id
is
pragma Unreferenced (Property_Value);
begin
return No_List;
end Get_Record_Of_Property_Value;
--------------------------------------- ---------------------------------------
-- Get_Value_Of_Property_Association -- -- Get_Value_Of_Property_Association --
--------------------------------------- ---------------------------------------
......
...@@ -53,6 +53,7 @@ package Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -53,6 +53,7 @@ package Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
PT_Classifier, PT_Classifier,
PT_Range, PT_Range,
PT_List, PT_List,
Pt_Record,
PT_Other); PT_Other);
type Named_Element is type Named_Element is
...@@ -189,6 +190,10 @@ package Ocarina.ME_AADL.AADL_Tree.Entities.Properties is ...@@ -189,6 +190,10 @@ package Ocarina.ME_AADL.AADL_Tree.Entities.Properties is
function Get_Reference_Of_Property_Value function Get_Reference_Of_Property_Value
(Property_Value : Node_Id) return Node_Id; (Property_Value : Node_Id) return Node_Id;
function Get_Record_Of_Property_Value
(Property_Value : Node_Id) return List_Id;
-- For record, values as stored as a list
function Get_Value_Of_Property_Association function Get_Value_Of_Property_Association
(Property : Node_Id) return Value_Type; (Property : Node_Id) return Value_Type;
......
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