----------------------------------------------- --------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . E N T I 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 Namet; with Ocarina.Nodes; with Ocarina.Nutils; with Ocarina.Entities.Messages; package body Ocarina.Entities is ------------------------- -- Get_Entity_Category -- ------------------------- function Get_Entity_Category (Node : Types.node_id) return entity_category is use Ocarina.Nodes; begin case Kind (Node) is when k_subcomponent => return ec_subcomponent; when k_flow_spec => return ec_flow_spec; when k_flow_implementation | k_end_to_end_flow_spec | k_flow_implementation_refinement | k_end_to_end_flow_refinement => return ec_flow_implementation; when k_mode | k_mode_transition => return ec_mode; when k_connection => return ec_connection; when k_property_association => return ec_property_association; when k_subprogram_call_sequence => return ec_call_sequence; when k_subprogram_call => return ec_subprogram_call; when k_port_spec | k_port_group_spec | k_subprogram_spec | k_parameter | k_subcomponent_access => return ec_feature; when k_component_type | k_component_implementation => return ec_component; when k_port_group_type => return ec_port_group_type; when k_package_specification => return ec_package; when k_property_set => return ec_property_set; when k_property_name_declaration => return ec_property_name; when k_property_type_declaration => return ec_property_type; when k_annex_library | k_annex_subclause => return ec_annex; when others => return ec_undefined; end case; end Get_Entity_Category; ------------------------ -- Get_Name_Of_Entity -- ------------------------ function Get_Name_Of_Entity (Entity : Types.node_id; Get_Display_Name : Boolean := True) return Types.name_id is use Ocarina.Nodes; use Ocarina.Entities.Messages; use Types; pragma assert (Kind (Entity) = k_component_implementation or else Kind (Entity) = k_component_type or else Kind (Entity) = k_port_group_type or else Kind (Entity) = k_subcomponent or else Kind (Entity) = k_mode or else Kind (Entity) = k_connection or else Kind (Entity) = k_flow_spec or else Kind (Entity) = k_flow_implementation or else Kind (Entity) = k_flow_implementation_refinement or else Kind (Entity) = k_end_to_end_flow_spec or else Kind (Entity) = k_end_to_end_flow_refinement or else Kind (Entity) = k_subprogram_call or else Kind (Entity) = k_subprogram_call_sequence or else Kind (Entity) = k_port_spec or else Kind (Entity) = k_port_group_spec or else Kind (Entity) = k_parameter or else Kind (Entity) = k_subcomponent_access or else Kind (Entity) = k_subprogram_spec or else Kind (Entity) = k_property_association or else Kind (Entity) = k_property_type_declaration or else Kind (Entity) = k_property_name_declaration or else Kind (Entity) = k_package_specification or else Kind (Entity) = k_aadl_specification or else Kind (Entity) = k_property_set or else Kind (Entity) = k_annex_subclause or else Kind (Entity) = k_annex_library or else Kind (Entity) = k_subcomponent_instance or else Kind (Entity) = k_call_instance or else Kind (Entity) = k_call_sequence_instance or else Kind (Entity) = k_port_spec_instance or else Kind (Entity) = k_port_group_spec_instance or else Kind (Entity) = k_parameter_instance or else Kind (Entity) = k_subcomponent_access_instance or else Kind (Entity) = k_subprogram_spec_instance or else Kind (Entity) = k_connection_instance or else Kind (Entity) = k_component_instance or else Kind (Entity) = k_mode_instance or else Kind (Entity) = k_namespace_instance or else DNKE (Entity)); begin if Kind (Entity) /= k_aadl_specification and then Identifier (Entity) /= No_Node then if Get_Display_Name then return Display_Name (Identifier (Entity)); else return Name (Identifier (Entity)); end if; else return No_Name; end if; end Get_Name_Of_Entity; ------------------------ -- Get_Name_Of_Entity -- ------------------------ function Get_Name_Of_Entity (Entity : Types.node_id; Get_Display_Name : Boolean := True) return String is use Types; use Namet; Name : constant name_id := Get_Name_Of_Entity (Entity, Get_Display_Name); begin if Name /= No_Name then return Get_Name_String (Name); else return ""; end if; end Get_Name_Of_Entity; ---------------------------------- -- Get_Name_Of_Entity_Reference -- ---------------------------------- function Get_Name_Of_Entity_Reference (Entity_Ref : Types.node_id; Get_Display_Name : Boolean := True) return Types.name_id is use Types; use Namet; use Ocarina.Nodes; use Ocarina.Entities.Messages; pragma assert (Kind (Entity_Ref) = k_entity_reference or else Kind (Entity_Ref) = k_property_term or else Kind (Entity_Ref) = k_reference_term or else DNKE (Entity_Ref)); begin if Identifier (Entity_Ref) /= No_Node then if Namespace_Identifier (Entity_Ref) /= No_Node then if Get_Display_Name then Get_Name_String (Display_Name (Namespace_Identifier (Entity_Ref))); Add_Str_To_Name_Buffer ("::"); Get_Name_String_And_Append (Display_Name (Identifier (Entity_Ref))); return Name_Find; else Get_Name_String (Name (Namespace_Identifier (Entity_Ref))); Add_Str_To_Name_Buffer ("::"); Get_Name_String_And_Append (Name (Identifier (Entity_Ref))); return Name_Find; end if; else if Get_Display_Name then return Display_Name (Identifier (Entity_Ref)); else return Name (Identifier (Entity_Ref)); end if; end if; else return No_Name; end if; end Get_Name_Of_Entity_Reference; ---------------------------------- -- Get_Name_Of_Entity_Reference -- ---------------------------------- function Get_Name_Of_Entity_Reference (Entity_Ref : Types.node_id; Get_Display_Name : Boolean := True) return String is use Namet; use Types; Name : constant name_id := Get_Name_Of_Entity_Reference (Entity_Ref, Get_Display_Name); begin if Name /= No_Name then return Get_Name_String (Name); else return ""; end if; end Get_Name_Of_Entity_Reference; --------------------------- -- Get_Referenced_Entity -- --------------------------- function Get_Referenced_Entity (Entity_Ref : Types.node_id) return Types.node_id is use Ocarina.Nodes; use Types; use Ocarina.Entities.Messages; pragma assert (Kind (Entity_Ref) = k_entity_reference or else Kind (Entity_Ref) = k_reference_term or else Kind (Entity_Ref) = k_property_term or else Kind (Entity_Ref) = k_unique_property_const_identifier or else Kind (Entity_Ref) = k_unique_property_type_identifier or else Kind (Entity_Ref) = k_component_classifier_term or else Kind (Entity_Ref) = k_entity_reference_instance or else DNKE (Entity_Ref)); begin if Kind (Entity_Ref) = k_entity_reference_instance then return Item (Last_Node (Path (Entity_Ref))); elsif Kind (Entity (Entity_Ref)) = k_subprogram_spec and then Present (Ocarina.Nodes.Entity_Ref (Entity (Entity_Ref))) then return Entity (Ocarina.Nodes.Entity_Ref (Entity (Entity_Ref))); else return Entity (Entity_Ref); end if; end Get_Referenced_Entity; --------------------------- -- Set_Referenced_Entity -- --------------------------- procedure Set_Referenced_Entity (Entity_Ref, Entity : Types.node_id) is use Ocarina.Nodes; use Types; use Ocarina.Entities.Messages; pragma assert (Entity_Ref /= No_Node and then (Kind (Entity_Ref) = k_entity_reference or else Kind (Entity_Ref) = k_reference_term or else Kind (Entity_Ref) = k_property_term or else Kind (Entity_Ref) = k_unique_property_const_identifier or else Kind (Entity_Ref) = k_unique_property_type_identifier or else Kind (Entity_Ref) = k_component_classifier_term or else DNKE (Entity_Ref))); begin Set_Entity (Entity_Ref, Entity); end Set_Referenced_Entity; ------------------------------------------ -- Add_Path_Element_To_Entity_Reference -- ------------------------------------------ procedure Add_Path_Element_To_Entity_Reference (Entity_Ref, Item : Types.node_id) is use Types; use Ocarina.Nodes; use Ocarina.Nutils; use Ocarina.Entities.Messages; pragma assert (Entity_Ref /= No_Node and then (Kind (Entity_Ref) = k_entity_reference_instance or else Kind (Entity_Ref) = k_entity_reference or else Kind (Entity_Ref) = k_reference_term or else DNKE (Entity_Ref))); pragma assert (Item /= No_Node); begin if Path (Entity_Ref) = No_List then Set_Path (Entity_Ref, New_List (k_list_id, Loc (Item))); end if; Append_Node_To_List (New_Node (k_node_container, Loc (Item)), Path (Entity_Ref)); Set_Item (Last_Node (Path (Entity_Ref)), Item); end Add_Path_Element_To_Entity_Reference; ------------------------------------------------ -- Entity_Reference_Path_Has_Several_Elements -- ------------------------------------------------ function Entity_Reference_Path_Has_Several_Elements (Entity_Ref : Types.node_id) return Boolean is use Types; use Ocarina.Nodes; use Ocarina.Nutils; pragma assert (Entity_Ref /= No_Node and then (Kind (Entity_Ref) = k_entity_reference_instance or else Kind (Entity_Ref) = k_entity_reference)); begin return Path (Entity_Ref) /= No_List and then First_Node (Path (Entity_Ref)) /= No_Node and then Next_Node (First_Node (Path (Entity_Ref))) /= No_Node; end Entity_Reference_Path_Has_Several_Elements; -------------------------- -- Duplicate_Identifier -- -------------------------- function Duplicate_Identifier (Identifier : Types.node_id) return Types.node_id is use Ocarina.Nodes; use Types; use Ocarina.Nutils; pragma assert (Identifier = No_Node or else Kind (Identifier) = k_identifier); Duplicate : node_id; begin if Identifier = No_Node then return No_Node; else Duplicate := New_Node (k_identifier, Loc (Identifier)); Set_Name (Duplicate, Name (Identifier)); Set_Display_Name (Duplicate, Display_Name (Identifier)); Set_Corresponding_Entity (Duplicate, Corresponding_Entity (Identifier)); return Duplicate; end if; end Duplicate_Identifier; end Ocarina.Entities;