------------------------------------------------ -------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . B U I L D E R . N A M E S P A C E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, 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; package body Ocarina.Builder.Namespaces is ---------------------------------- -- Initialize_Unnamed_Namespace -- ---------------------------------- function Initialize_Unnamed_Namespace (Loc : Locations.Location) return Types.Node_Id is use Ocarina.Nodes; use Ocarina.Nutils; use Types; Specification : constant Node_Id := New_Node (K_AADL_Specification, Loc); Entity_Scop : constant Node_Id := New_Node (K_Scope_Definition, Loc); begin Set_Entity_Scope (Specification, Entity_Scop); Set_Scoped_Identifiers (Entity_Scop, No_Node); Set_Corresponding_Entity (Entity_Scop, Specification); Set_Declarations (Specification, New_List (K_AADL_Declarations_List, Loc)); return Specification; end Initialize_Unnamed_Namespace; ------------------------------ -- Add_Property_Association -- ------------------------------ function Add_Property_Association (Pack : Types.Node_Id; Property_Association : Types.Node_Id) return Boolean is use Locations; use Ocarina.Nodes; use Types; use Ocarina.Nutils; pragma Assert (Pack /= No_Node and then Kind (Pack) = K_Package_Specification); pragma Assert (Property_Association /= No_Node and then Kind (Property_Association) = K_Property_Association); begin if Is_Empty (Ocarina.Nodes.Properties (Pack)) then Set_Properties (Pack, New_List (K_List_Id, Loc (Property_Association))); end if; Append_Node_To_List (Property_Association, Ocarina.Nodes.Properties (Pack)); return True; end Add_Property_Association; --------------------- -- Add_Declaration -- --------------------- function Add_Declaration (Namespace : Types.Node_Id; Element : Types.Node_Id) return Boolean is use Ocarina.Nodes; use Types; use Ocarina.Nutils; pragma Assert (Namespace /= No_Node and then (Kind (Namespace) = K_Package_Specification or else Kind (Namespace) = K_AADL_Specification)); pragma Assert (Element /= No_Node); begin case Kind (Namespace) is when K_Package_Specification => case Kind (Element) is when K_Port_Group_Type | K_Annex_Library | K_Component_Type | K_Component_Implementation => if Is_Empty (Declarations (Namespace)) then Set_Declarations (Namespace, New_List (K_List_Id, Loc (Element))); end if; Append_Node_To_List (Element, Declarations (Namespace)); if Is_Private (Element) then Set_Has_Private_Part (Namespace, True); else Set_Has_Public_Part (Namespace, True); end if; return True; when others => raise Program_Error; end case; when K_AADL_Specification => case Kind (Element) is when K_Port_Group_Type | K_Component_Type | K_Component_Implementation | K_Property_Set | K_Package_Specification => if Is_Empty (Declarations (Namespace)) then Set_Declarations (Namespace, New_List (K_List_Id, Loc (Element))); end if; Append_Node_To_List (Element, Declarations (Namespace)); return True; when others => raise Program_Error; end case; when others => raise Program_Error; end case; end Add_Declaration; --------------------- -- Add_New_Package -- --------------------- function Add_New_Package (Loc : Locations.Location; Pack_Name : Types.Node_Id; Namespace : Types.Node_Id) return Types.Node_Id is use Ocarina.Nutils; use Ocarina.Nodes; use Types; pragma Assert (Pack_Name /= No_Node and then Kind (Pack_Name) = K_Identifier); pragma Assert (Namespace /= No_Node and then Kind (Namespace) = K_AADL_Specification); Node : constant Node_Id := New_Node (K_Package_Specification, Loc); Success : Boolean := True; Entity_Scop : constant Node_Id := New_Node (K_Scope_Definition, Loc); Property_Scop : constant Node_Id := New_Node (K_Scope_Definition, Loc); begin Set_Identifier (Node, Pack_Name); Set_Corresponding_Entity (Pack_Name, Node); 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_Declarations (Node, No_List); Set_Properties (Node, No_List); Set_Has_Private_Part (Node, False); Set_Has_Public_Part (Node, False); Success := Add_Declaration (Namespace => Namespace, Element => Node); if Success then return Node; else return No_Node; end if; end Add_New_Package; end Ocarina.Builder.Namespaces;