--------------------------------------------------- ----------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- OCARINA.DIA.PARSER.TRANSLATE.COMPONENTS -- -- -- -- 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 Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Fixed; with Types; use Types; with Namet; with Ocarina.Dia.Parser.Core.Nodes; with Ocarina.Nodes; with Ocarina.Builder; with Ocarina.Builder.Components; with Ocarina.Dia.Parser.Translate.Features; with Ocarina.Dia.Parser.Translate.Misc; package body Ocarina.Dia.Parser.Translate.Components is ----------------------- -- Create_Component -- ----------------------- function Create_Component (Dia_Node : Ocarina.Dia.Parser.Core.node; Ocarina_Root : Types.node_id; Category : Ocarina.Entities.Components.component_category; NL : node_list) return Types.node_id is use Ocarina.Dia.Parser.Core.Nodes; use Ocarina.Dia.Parser.Translate.Features; use Ocarina.Nodes; Ocarina_Node : Types.node_id; Name : name_id; Identifier : Types.node_id; begin -- Is this component an implementation ? if Is_Implementation (Dia_Node, NL) then Put_Line ("Implementation " & Get_Node_Name (Dia_Node)); -- Create the component Namet.Set_Str_To_Name_Buffer (Get_Node_Name (Dia_Node)); Name := Namet.Name_Find; Identifier := Get_Identifier (No_Node, Name); Set_Name (Identifier, Name); Namet.Set_Str_To_Name_Buffer (Get_Node_Name (Dia_Node)); Name := Namet.Name_Find; Set_Display_Name (Identifier, Name); Ocarina_Node := Add_New_Component_Implementation (Identifier, Ocarina_Root, Category); -- Link it with the corresponding Component Type Set_Component_Type_Identifier (Ocarina_Node, Get_Impl_Source_Identifier (Dia_Node)); -- ports ignored when implementation else Put_Line ("Type " & Get_Node_Name (Dia_Node)); Namet.Set_Str_To_Name_Buffer (Get_Node_Name (Dia_Node)); Name := Namet.Name_Find; Identifier := Get_Identifier (No_Node, Name); -- todo verify this Set_Name (Identifier, Name); Namet.Set_Str_To_Name_Buffer (Get_Node_Name (Dia_Node)); Name := Namet.Name_Find; Set_Display_Name (Identifier, Name); -- end todo Ocarina_Node := Add_New_Component_Type (Identifier, Ocarina_Root, Category); if Ocarina_Node = No_Node then Put_Line ("Component type wrong created"); end if; -- keep track of it OAppend (Get_Node_Name (Dia_Node), Identifier); -- Ports Create_Ports (Ocarina_Node, Dia_Node); end if; return Ocarina_Node; end Create_Component; ------------------------------ -- Add_New_Component_Type -- ------------------------------ function Add_New_Component_Type (Identifier : Types.node_id; Namespace : Types.node_id; Component_Type : Ocarina.Entities.Components.component_category) return Types.node_id is begin return Ocarina.Builder.Components.Add_New_Component_Type (L, Identifier, Namespace, Component_Type); end Add_New_Component_Type; --------------------------------------- -- Add_New_Component_Implementation -- --------------------------------------- function Add_New_Component_Implementation (Identifier : Types.node_id; Namespace : Types.node_id; Component_Type : Ocarina.Entities.Components.component_category) return Types.node_id is begin return Ocarina.Builder.Components.Add_New_Component_Implementation (L, Identifier, Namespace, Component_Type); end Add_New_Component_Implementation; ----------------------- -- Is_Implementation -- ----------------------- function Is_Implementation (N : node; List : node_list) return Boolean is use Ocarina.Dia.Parser.Core.Nodes; use Ada.Strings.Fixed; M : node; begin M := Has_Implementation_Arrow (N, List); if M = null then return False; else if Index (Get_Node_Name (N), Get_Node_Name (M)) /= 0 then return True; else return False; end if; end if; end Is_Implementation; ---------------------------------- -- Get_Impl_Source_Identifier -- ---------------------------------- function Get_Impl_Source_Identifier (DN : node) return Types.node_id is use Ada.Strings.Fixed; use Ocarina.Dia.Parser.Core.Nodes; use Ocarina.Dia.Parser.Translate.Misc; use Namet; ONN : String (1 .. 30); OID : Types.node_id; begin for I in 0 .. (OLength - 1) loop ONN := OItemName (I); OID := OItemId (I); -- if Ocarina.Nodes.Name (ON) = 0 then -- Put_Line ("Name_Id not found !"); -- Put_Line ("OC Node id : " & Types.Node_Id'Image (ON)); -- ok -- Put_Line ("DiaNode Name : " & Get_Node_Name (DN)); -- ok -- Put_Line ("Name_id " & Name_Id'Image (Ocarina.Nodes.Name (ON))); -- this one doesn't work ! -- else -- if Index (Get_Node_Name (DN), -- Get_Name_String (Ocarina.Nodes.Name (ON))) /= 0 then -- Put_Line ("Type of implementation found"); -- return Ocarina.Nodes.Identifier (ON); -- end if; -- end if; if Index (Get_Node_Name (DN), Stripped_Name (ONN)) /= 0 then Put_Line ("Type of implementation found"); return OID; end if; end loop; Put_Line ("Could not find the type of the implementation !"); return No_Node; end Get_Impl_Source_Identifier; end Ocarina.Dia.Parser.Translate.Components;