----------------------------------------- --------------------------------------- -- -- -- 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;