----------------------------------------- --------------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P A R S E R . T R A N S L A T E -- -- -- -- B o d y -- -- -- -- Copyright (C) 2004-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 Ada.Text_IO; use Ada.Text_IO; with Types; with Locations; with Ocarina.Dia.Parser.Core.Nodes; with Ocarina.Dia.Parser.Translate.Components; with Ocarina.Builder.Namespaces; with Ocarina.Nodes; with Ocarina.Analyzer; with Ocarina.Nutils; package body Ocarina.Dia.Parser.Translate is -- List : Item function OItemName (Index : Integer) return String is begin if Index <= ONL.Last then return ONL.ItemsName (Index); else return ""; end if; end OItemName; function OItemId (Index : Integer) return Types.node_id is begin if Index <= ONL.Last then return ONL.ItemsId (Index); else return No_Node; end if; end OItemId; -- List : Length function OLength return Integer is begin Put_Line ("Taille " & Integer'image (ONL.Last + 1)); return ONL.Last + 1; end OLength; -- Ocarina_Node_List : Append procedure OAppend (S : String; I : Types.node_id) is OldName : constant ocarina_node_name_array_access := ONL.ItemsName; OldId : constant ocarina_node_id_array_access := ONL.ItemsId; begin if OldName = null or else OldName'last = ONL.Last then ONL.ItemsName := new ocarina_node_name_array (0 .. ONL.Last + 5); ONL.ItemsId := new ocarina_node_id_array (0 .. ONL.Last + 5); if OldName /= null then ONL.ItemsName (0 .. ONL.Last) := OldName.all; ONL.ItemsId (0 .. ONL.Last) := OldId.all; -- Free (Old); end if; end if; ONL.Last := ONL.Last + 1; ONL.ItemsName (ONL.Last) := S; for J in S'length + 1 .. 30 loop ONL.ItemsName (ONL.Last) (J) := ' '; end loop; ONL.ItemsId (ONL.Last) := I; end OAppend; ----------------- -- Translate -- ----------------- -- This function translates the internal representation of the -- AADL tree from a Dia document into the Ocarina representation. -- Returns the Root Node_Id function Translate (NL : Ocarina.Dia.Parser.Core.node_list) return Types.node_id is use Ocarina.Dia.Parser.Core; use Ocarina.Dia.Parser.Core.Nodes; use Ocarina.Builder.Namespaces; use Ocarina.Entities.Components; use Ocarina.Dia.Parser.Translate.Components; Ocarina_Root, Ocarina_Node : Types.node_id; Dia_Node : node; Category : Ocarina.Entities.Components.component_category; Valid : Boolean; pragma warnings (Off, Ocarina_Node); begin -- Build the tree Ocarina_Root := Initialize_Unnamed_Namespace (L); for I in 0 .. (Length (NL) - 1) loop Put_Line ("--Treating Object " & Integer'image (I) & "--"); Dia_Node := Item (NL, I); Category := CC_Node_Type (Dia_Node.Node_Type_Arg); if Category /= Ocarina.Entities.Components.cc_unknown then -- We have a component Ocarina_Node := Create_Component (Dia_Node, Ocarina_Root, Category, NL); elsif Dia_Node.Node_Type_Arg = Ocarina.Dia.Parser.Core.link then -- todo Put_Line ("Link"); else Put_Line ("Component Unknown"); end if; end loop; -- check the tree Put_Line ("Checking the tree"); Valid := Ocarina.Analyzer.Analyze_Tree (Ocarina_Root, Ocarina.Analyzer.Default_Analyzer_Options); if Valid then Put_Line ("Ocarina Tree valid"); else Put_Line ("Ocarina Tree is NOT valid !"); end if; return Ocarina_Root; end Translate; -------------------- -- CC_Node_Type -- -------------------- -- returns the Entity_Category associated with the Node_Type function CC_Node_Type (Node_Type_Arg : Ocarina.Dia.Parser.Core.node_type) return Ocarina.Entities.Components.component_category is use Ocarina.Dia.Parser.Core; use Ocarina.Entities.Components; begin case Node_Type_Arg is when process => return cc_process; when thread => return cc_thread; when data => return cc_data; when processor => return cc_processor; when memory => return cc_memory; when bus => return cc_bus; when system => return cc_system; when subprogram => return cc_subprogram; when thread_group => return cc_threadgroup; when device => return cc_device; when link => return cc_unknown; -- todo when void => return cc_unknown; end case; end CC_Node_Type; ---------------------- -- Get_Identifier -- ---------------------- -- gets an identifier function Get_Identifier (Entity : node_id; Name : name_id) return node_id is use Ocarina.Nutils; use Ocarina.Nodes; pragma unreferenced (Entity); Node : constant node_id := New_Node (k_identifier, Locations.No_Location); begin Set_Name (Node, Name); Set_Display_Name (Node, Name); return Node; end Get_Identifier; end Ocarina.Dia.Parser.Translate;