------------------------------- ------------------------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . B U I L D E R . C O M P O N E N T 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.Builder.Namespaces; package body Ocarina.Builder.Components is --------------- -- Add_Annex -- --------------- function Add_Annex (Component : node_id; Annex : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation or else Kind (Component) = k_component_type or else Kind (Component) = k_port_group_type); pragma assert (Present (Annex)); begin if Is_Empty (Annexes (Component)) then Set_Annexes (Component, New_List (k_list_id, Loc (Annex))); end if; Append_Node_To_List (Annex, Annexes (Component)); return True; end Add_Annex; -------------------- -- Add_Connection -- -------------------- function Add_Connection (Component : node_id; Connection : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Present (Component) and then Kind (Component) = k_component_implementation); pragma assert (Present (Connection)); begin if Connections (Component) = No_List then Set_Connections (Component, New_List (k_list_id, Loc (Connection))); end if; Append_Node_To_List (Connection, Connections (Component)); Set_Container_Component (Connection, Component); return True; end Add_Connection; ----------------- -- Add_Feature -- ----------------- function Add_Feature (Component : node_id; Feature : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_type or else Kind (Component) = k_port_group_type); pragma assert (Present (Feature)); begin if Features (Component) = No_List then Set_Features (Component, New_List (k_list_id, Loc (Feature))); end if; Append_Node_To_List (Feature, Features (Component)); Set_Container_Component (Feature, Component); return True; end Add_Feature; ---------------------- -- Add_Refined_Type -- ---------------------- function Add_Refined_Type (Component : node_id; Refined_Type : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (Refined_Type)); begin if Refines_Type (Component) = No_List then Set_Refines_Type (Component, New_List (k_list_id, Loc (Refined_Type))); end if; Append_Node_To_List (Refined_Type, Refines_Type (Component)); return True; end Add_Refined_Type; ---------------------- -- Add_Subcomponent -- ---------------------- function Add_Subcomponent (Component : node_id; Subcomponent : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (Subcomponent)); begin if Subcomponents (Component) = No_List then Set_Subcomponents (Component, New_List (k_list_id, Loc (Subcomponent))); end if; Append_Node_To_List (Subcomponent, Subcomponents (Component)); Set_Container_Component (Subcomponent, Component); return True; end Add_Subcomponent; ---------------------------------- -- Add_Subprogram_Call_Sequence -- ---------------------------------- function Add_Subprogram_Call_Sequence (Component : node_id; Call_Sequence : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (Call_Sequence)); begin if Calls (Component) = No_List then Set_Calls (Component, New_List (k_list_id, Loc (Call_Sequence))); end if; Append_Node_To_List (Call_Sequence, Calls (Component)); Set_Container_Component (Call_Sequence, Component); return True; end Add_Subprogram_Call_Sequence; ------------------- -- Add_Flow_Spec -- ------------------- function Add_Flow_Spec (Component : node_id; Flow_Spec : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_type); pragma assert (Present (Flow_Spec)); begin if Flows (Component) = No_List then Set_Flows (Component, New_List (k_list_id, Loc (Flow_Spec))); end if; Append_Node_To_List (Flow_Spec, Flows (Component)); Set_Container_Component (Flow_Spec, Component); return True; end Add_Flow_Spec; ----------------------------- -- Add_Flow_Implementation -- ----------------------------- function Add_Flow_Implementation (Component : node_id; Flow_Impl : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (Flow_Impl)); begin if Flows (Component) = No_List then Set_Flows (Component, New_List (k_list_id, Loc (Flow_Impl))); end if; Append_Node_To_List (Flow_Impl, Flows (Component)); Set_Container_Component (Flow_Impl, Component); return True; end Add_Flow_Implementation; ------------------------------ -- Add_End_To_End_Flow_Spec -- ------------------------------ function Add_End_To_End_Flow_Spec (Component : node_id; End_To_End_Flow : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (End_To_End_Flow)); begin if Flows (Component) = No_List then Set_Flows (Component, New_List (k_list_id, Loc (End_To_End_Flow))); end if; Append_Node_To_List (End_To_End_Flow, Flows (Component)); Set_Container_Component (End_To_End_Flow, Component); return True; end Add_End_To_End_Flow_Spec; -------------- -- Add_Mode -- -------------- function Add_Mode (Component : node_id; Mode : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation); pragma assert (Present (Mode)); begin if Ocarina.Nodes.Modes (Component) = No_List then Set_Modes (Component, New_List (k_list_id, Loc (Mode))); end if; Append_Node_To_List (Mode, Ocarina.Nodes.Modes (Component)); Set_Container_Component (Mode, Component); return True; end Add_Mode; ------------------------------ -- Add_Property_Association -- ------------------------------ function Add_Property_Association (Component : node_id; Property_Association : node_id) return Boolean is use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Kind (Component) = k_component_implementation or else Kind (Component) = k_component_type or else Kind (Component) = k_port_group_type); pragma assert (Present (Property_Association)); begin if Is_Empty (Ocarina.Nodes.Properties (Component)) then Set_Properties (Component, New_List (k_list_id, Loc (Property_Association))); end if; Append_Node_To_List (Property_Association, Ocarina.Nodes.Properties (Component)); return True; end Add_Property_Association; ---------------------------- -- Add_New_Component_Type -- ---------------------------- function Add_New_Component_Type (Loc : location; Identifier : node_id; Namespace : node_id; Component_Type : Ocarina.Entities.Components.component_category; Is_Private : Boolean := False) return node_id is use Ocarina.Nodes; use Ocarina.Nutils; use Ocarina.Entities.Components; use Ocarina.Builder.Namespaces; pragma assert (Present (Identifier)); pragma assert (Kind (Namespace) = k_package_specification or else Kind (Namespace) = k_aadl_specification); Node : constant node_id := New_Node (k_component_type, Loc); Entity_Scop : constant node_id := New_Node (k_scope_definition, Loc); Property_Scop : constant node_id := New_Node (k_scope_definition, Loc); Success : Boolean := True; begin Set_Category (Node, component_category'pos (Component_Type)); Set_Identifier (Node, Identifier); Set_Corresponding_Entity (Identifier, Node); Set_Instances (Node, No_List); Set_Namespace (Node, Namespace); Set_Features (Node, No_List); Set_Flows (Node, No_List); Set_Properties (Node, No_List); Set_Annexes (Node, No_List); Set_Entity_Scope (Node, Entity_Scop); Set_Property_Scope (Node, Property_Scop); Set_Corresponding_Entity (Entity_Scop, Node); Set_Corresponding_Entity (Property_Scop, Node); Set_Scoped_Identifiers (Entity_Scop, No_Node); Set_Scoped_Identifiers (Property_Scop, No_Node); Set_Is_Private (Node, Is_Private); Success := Add_Declaration (Namespace => Namespace, Element => Node); if Success then return Node; else return No_Node; end if; end Add_New_Component_Type; -------------------------------------- -- Add_New_Component_Implementation -- -------------------------------------- function Add_New_Component_Implementation (Loc : location; Identifier : node_id; Namespace : node_id; Component_Type : Ocarina.Entities.Components.component_category; Is_Private : Boolean := False) return node_id is use Ocarina.Nodes; use Ocarina.Nutils; use Ocarina.Entities.Components; use Ocarina.Builder.Namespaces; pragma assert (Present (Identifier)); pragma assert (Kind (Namespace) = k_package_specification or else Kind (Namespace) = k_aadl_specification); Entity_Scop : constant node_id := New_Node (k_scope_definition, Loc); Property_Scop : constant node_id := New_Node (k_scope_definition, Loc); Node : constant node_id := New_Node (k_component_implementation, Loc); Success : Boolean := True; begin Set_Category (Node, component_category'pos (Component_Type)); Set_Parent (Node, No_Node); Set_Identifier (Node, Identifier); Set_Corresponding_Entity (Identifier, Node); Set_Instances (Node, No_List); Set_Namespace (Node, Namespace); Set_Refines_Type (Node, No_List); Set_Subcomponents (Node, No_List); Set_Calls (Node, No_List); Set_Connections (Node, No_List); Set_Flows (Node, No_List); Set_Modes (Node, No_List); Set_Properties (Node, No_List); Set_Annexes (Node, No_List); Set_Entity_Scope (Node, Entity_Scop); Set_Property_Scope (Node, Property_Scop); Set_Corresponding_Entity (Entity_Scop, Node); Set_Corresponding_Entity (Property_Scop, Node); Set_Scoped_Identifiers (Entity_Scop, No_Node); Set_Scoped_Identifiers (Property_Scop, No_Node); Set_Is_Private (Node, Is_Private); Success := Add_Declaration (Namespace => Namespace, Element => Node); if Success then return Node; else return No_Node; end if; end Add_New_Component_Implementation; ------------------------ -- Add_New_Port_Group -- ------------------------ function Add_New_Port_Group (Loc : location; Name : node_id; Namespace : node_id; Is_Private : Boolean := False) 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_package_specification or else Kind (Namespace) = k_aadl_specification); Node : constant node_id := New_Node (k_port_group_type, Loc); Property_Scop : constant node_id := New_Node (k_scope_definition, Loc); Entity_Scop : constant node_id := New_Node (k_scope_definition, Loc); Success : Boolean := True; begin Set_Identifier (Node, Name); Set_Corresponding_Entity (Name, Node); Set_Features (Node, No_List); Set_Inverse_Of (Node, No_Node); Set_Properties (Node, No_List); Set_Annexes (Node, No_List); Set_Namespace (Node, Namespace); Set_Entity_Scope (Node, Entity_Scop); Set_Property_Scope (Node, Property_Scop); Set_Scoped_Identifiers (Entity_Scop, No_Node); Set_Scoped_Identifiers (Property_Scop, No_Node); Set_Corresponding_Entity (Entity_Scop, Node); Set_Corresponding_Entity (Property_Scop, Node); Set_Parent (Node, No_Node); Set_Is_Private (Node, Is_Private); Success := Add_Declaration (Namespace, Node); if Success then return Node; else return No_Node; end if; end Add_New_Port_Group; end Ocarina.Builder.Components;