------------------------------------------------ -------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . B U I L D E R . P R O P E R T I E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2007, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Ocarina.Nodes; with Ocarina.Nutils; with Ocarina.Entities.Properties; with Ocarina.Builder.Namespaces; with Ocarina.Builder.Components; with Ocarina.Builder.Components.Subcomponents; with Ocarina.Builder.Components.Features; with Ocarina.Builder.Components.Connections; with Ocarina.Builder.Components.Flows; with Ocarina.Builder.Components.Modes; with Ocarina.Builder.Components.Subprogram_Calls; package body Ocarina.Builder.Properties is function Add_Property_Type_Declaration (Property_Set : node_id; Property_Type_Declaration : node_id) return Boolean; function Add_Property_Name_Declaration (Property_Set : node_id; Property_Name_Declaration : node_id) return Boolean; function Add_Property_Constant_Declaration (Property_Set : node_id; Property_Constant_Declaration : node_id) return Boolean; ----------------------------------- -- Add_Property_Name_Declaration -- ----------------------------------- function Add_Property_Name_Declaration (Property_Set : node_id; Property_Name_Declaration : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Property_Set) = k_property_set); pragma assert (Kind (Property_Name_Declaration) = k_property_name_declaration); begin if Is_Empty (Declarations (Property_Set)) then Set_Declarations (Property_Set, New_List (k_list_id, Loc (Property_Name_Declaration))); end if; Append_Node_To_List (Property_Name_Declaration, Declarations (Property_Set)); return True; end Add_Property_Name_Declaration; ----------------------------------- -- Add_Property_Type_Declaration -- ----------------------------------- function Add_Property_Type_Declaration (Property_Set : node_id; Property_Type_Declaration : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Property_Set) = k_property_set); pragma assert (Kind (Property_Type_Declaration) = k_property_type_declaration); begin if Is_Empty (Declarations (Property_Set)) then Set_Declarations (Property_Set, New_List (k_list_id, Loc (Property_Type_Declaration))); end if; Append_Node_To_List (Property_Type_Declaration, Declarations (Property_Set)); return True; end Add_Property_Type_Declaration; --------------------------------------- -- Add_Property_Constant_Declaration -- --------------------------------------- function Add_Property_Constant_Declaration (Property_Set : node_id; Property_Constant_Declaration : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Property_Set) = k_property_set); pragma assert (Kind (Property_Constant_Declaration) = k_constant_property_declaration); begin if Is_Empty (Declarations (Property_Set)) then Set_Declarations (Property_Set, New_List (k_list_id, Loc (Property_Constant_Declaration))); end if; Append_Node_To_List (Property_Constant_Declaration, Declarations (Property_Set)); return True; end Add_Property_Constant_Declaration; -------------------------- -- Add_New_Property_Set -- -------------------------- function Add_New_Property_Set (Loc : location; Name : node_id; Namespace : node_id) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; use Ocarina.Builder.Namespaces; pragma assert (Kind (Name) = k_identifier); pragma assert (Kind (Namespace) = k_aadl_specification); Node : node_id; Success : Boolean := True; begin Node := New_Node (k_property_set, Loc); Set_Identifier (Node, Name); Set_Corresponding_Entity (Name, Node); Set_Entity_Scope (Node, New_Node (k_scope_definition, Loc)); Set_Corresponding_Entity (Entity_Scope (Node), Node); Set_Declarations (Node, No_List); Success := Add_Declaration (Namespace, Node); if Success then return Node; else return No_Node; end if; end Add_New_Property_Set; ------------------------------------------- -- Add_New_Property_Constant_Declaration -- ------------------------------------------- function Add_New_Property_Constant_Declaration (Loc : location; Name : node_id; Property_Set : node_id; Constant_Type : node_id; Unit_Identifier : node_id; Single_Value : node_id; Multiple_Values : list_id) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; pragma assert (Kind (Name) = k_identifier); pragma assert (Kind (Property_Set) = k_property_set); pragma assert (No (Unit_Identifier) or else Kind (Unit_Identifier) = k_unique_property_type_identifier); pragma assert (No (Single_Value) or else Is_Empty (Multiple_Values)); pragma assert (Kind (Constant_Type) = k_integer_type or else Kind (Constant_Type) = k_real_type or else Kind (Constant_Type) = k_string_type or else Kind (Constant_Type) = k_boolean_type or else Kind (Constant_Type) = k_unique_property_type_identifier); Node : constant node_id := New_Node (k_constant_property_declaration, Loc); Value_Node : constant node_id := New_Node (k_property_value, Loc); Success : Boolean := True; begin Set_Single_Value (Value_Node, Single_Value); Set_Multi_Value (Value_Node, Multiple_Values); Set_Constant_Value (Node, Value_Node); Set_Identifier (Node, Name); Set_Corresponding_Entity (Name, Node); Set_Constant_Type (Node, Constant_Type); Set_Unique_Unit_Identifier (Node, Unit_Identifier); Set_Value_Container (Value_Node, Property_Set); Set_Single_Value (Value_Node, Single_Value); Set_Multi_Value (Value_Node, Multiple_Values); Success := Add_Property_Constant_Declaration (Property_Set, Node); if Success then return Node; else return No_Node; end if; end Add_New_Property_Constant_Declaration; --------------------------------------- -- Add_New_Property_Type_Declaration -- --------------------------------------- function Add_New_Property_Type_Declaration (Loc : location; Name : node_id; Property_Set : node_id; Type_Designator : node_id) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; pragma assert (Kind (Name) = k_identifier); pragma assert (Kind (Property_Set) = k_property_set); Node : node_id; Success : Boolean := True; begin Node := New_Node (k_property_type_declaration, Loc); Set_Identifier (Node, Name); Set_Corresponding_Entity (Name, Node); Set_Property_Type_Designator (Node, Type_Designator); Success := Add_Property_Type_Declaration (Property_Set, Node); if Success then return Node; else return No_Node; end if; end Add_New_Property_Type_Declaration; --------------------------------------- -- Add_New_Property_Name_Declaration -- --------------------------------------- function Add_New_Property_Name_Declaration (Loc : location; Name : node_id; Property_Set : node_id; Is_Inherit : Boolean; Is_Access : Boolean; Single_Default_Value : node_id; Multiple_Default_Value : list_id; Property_Name_Type : node_id; Property_Type_Is_A_List : Boolean; Applies_To_All : Boolean; Applies_To : list_id) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; pragma assert (Kind (Name) = k_identifier); pragma assert (Kind (Property_Set) = k_property_set); pragma assert (Safe_XOR (Applies_To_All, (not Is_Empty (Applies_To)))); Node : node_id; Success : Boolean := True; begin Node := New_Node (k_property_name_declaration, Loc); Set_Identifier (Node, Name); Set_Corresponding_Entity (Name, Node); Set_Is_Inherit (Node, Is_Inherit); Set_Is_Access (Node, Is_Access); Set_Applies_To (Node, New_Node (k_applies_to, Loc)); Set_Is_All (Ocarina.Nodes.Applies_To (Node), Applies_To_All); Set_Owner_Categories (Ocarina.Nodes.Applies_To (Node), Applies_To); Set_Property_Name_Type (Node, New_Node (k_property_type, Loc)); Set_Property_Type_Designator (Ocarina.Nodes.Property_Name_Type (Node), Property_Name_Type); Set_Is_List (Ocarina.Nodes.Property_Name_Type (Node), Property_Type_Is_A_List); if Multiple_Default_Value = No_List and then Single_Default_Value = No_Node then Set_Default_Value (Node, No_Node); else Set_Default_Value (Node, New_Node (k_property_value, Loc)); Set_Single_Value (Default_Value (Node), Single_Default_Value); Set_Multi_Value (Default_Value (Node), Multiple_Default_Value); Set_Value_Container (Default_Value (Node), Property_Set); end if; Success := Add_Property_Name_Declaration (Property_Set, Node); if Success then return Node; else return No_Node; end if; end Add_New_Property_Name_Declaration; ---------------------------------- -- Add_New_Property_Association -- ---------------------------------- function Add_New_Property_Association (Loc : location; Name : node_id; Property_Name : node_id; Container : node_id; In_Binding : node_id; In_Modes : node_id; Property_Value : node_id; Is_Constant : Boolean; Is_Access : Boolean; Is_Additive : Boolean; Applies_To : list_id; Check_For_Conflicts : Boolean := False; Override : Boolean := False) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; use Ocarina.Entities.Properties; use Ocarina.Builder.Components; use Ocarina.Builder.Components.Features; use Ocarina.Builder.Components.Connections; use Ocarina.Builder.Components.Flows; use Ocarina.Builder.Components.Modes; use Ocarina.Builder.Components.Subprogram_Calls; use Ocarina.Builder.Components.Subcomponents; use Ocarina.Builder.Namespaces; pragma assert (Kind (Name) = k_identifier); pragma assert (Kind (Property_Name) = k_entity_reference and then Identifier (Property_Name) /= No_Node); pragma assert (Kind (Container) = k_component_type or else Kind (Container) = k_component_implementation or else Kind (Container) = k_subcomponent or else Kind (Container) = k_mode or else Kind (Container) = k_flow_spec or else Kind (Container) = k_flow_implementation or else Kind (Container) = k_flow_implementation_refinement or else Kind (Container) = k_end_to_end_flow_spec or else Kind (Container) = k_end_to_end_flow_refinement or else Kind (Container) = k_port_group_type or else Kind (Container) = k_connection or else Kind (Container) = k_subprogram_call or else Kind (Container) = k_subprogram_spec or else Kind (Container) = k_port_spec or else Kind (Container) = k_parameter or else Kind (Container) = k_port_group_spec or else Kind (Container) = k_subcomponent_access or else Kind (Container) = k_package_specification); Node, Existing_Node : node_id := No_Node; Value_Of_Association : constant node_id := New_Node (k_property_value, Loc); Success : Boolean := True; Property_List : list_id; begin if Check_For_Conflicts then Property_List := Ocarina.Nodes.Properties (Container); Existing_Node := Find_Property_Association_From_Name (Property_List, Ocarina.Nodes.Name (Name)); end if; if Existing_Node = No_Node or else Override then Node := New_Node (k_property_association, Loc); Set_Identifier (Node, Name); Set_Corresponding_Entity (Identifier (Node), Node); Set_Property_Name (Node, Property_Name); Set_Is_Constant (Node, Is_Constant); Set_Is_Additive_Association (Node, Is_Additive); Set_Is_Access (Node, Is_Access); Set_Applies_To_Prop (Node, Applies_To); Set_In_Binding (Node, In_Binding); Set_In_Modes (Node, In_Modes); Set_Is_Private (Node, False); Set_Property_Association_Value (Node, Value_Of_Association); Set_Value_Container (Value_Of_Association, Container); if Property_Value /= No_Node then if Kind (Property_Value) = k_property_list_value then Set_Single_Value (Value_Of_Association, No_Node); Set_Multi_Value (Value_Of_Association, list_id (Property_Value)); else Set_Single_Value (Value_Of_Association, Property_Value); Set_Multi_Value (Value_Of_Association, No_List); end if; else Set_Single_Value (Value_Of_Association, No_Node); Set_Multi_Value (Value_Of_Association, No_List); end if; case Kind (Container) is when k_component_type | k_component_implementation | k_port_group_type => Success := Ocarina.Builder.Components.Add_Property_Association (Container, Node); when k_subcomponent => Success := Ocarina.Builder.Components.Subcomponents .Add_Property_Association (Container, Node); when k_mode => Success := Ocarina.Builder.Components.Modes.Add_Property_Association (Container, Node); when k_flow_spec | k_flow_implementation | k_flow_implementation_refinement | k_end_to_end_flow_spec | k_end_to_end_flow_refinement => Success := Ocarina.Builder.Components.Flows.Add_Property_Association (Container, Node); when k_connection => Success := Ocarina.Builder.Components.Connections .Add_Property_Association (Container, Node); when k_subprogram_call => Success := Ocarina.Builder.Components.Subprogram_Calls .Add_Property_Association (Container, Node); when k_package_specification => Success := Ocarina.Builder.Namespaces.Add_Property_Association (Container, Node); when k_subprogram_spec | k_port_spec | k_port_group_spec | k_parameter | k_subcomponent_access => Success := Ocarina.Builder.Components.Features.Add_Property_Association (Container, Node); when others => raise Program_Error; end case; else Success := False; end if; if Existing_Node /= No_Node and then Override then Remove_Node_From_List (Existing_Node, Property_List); end if; if Success then return Node; else return Existing_Node; end if; end Add_New_Property_Association; end Ocarina.Builder.Properties;