ocarina-backends-xml_common-mapping.adb 5.22 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--  O C A R I N A . B A C K E N D S . X M L _ C O M M O N . M A P P I N G   --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--       Copyright (C) 2009 Telecom ParisTech, 2010-2015 ESA & ISAE.        --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31
--                                                                          --
------------------------------------------------------------------------------

32 33
with Ocarina.ME_AADL.AADL_Instances.Nodes;

34
with Ocarina.Backends.XML_Values;
35
with Ocarina.Backends.XML_Tree.Nodes;
36 37 38 39
with Ocarina.Backends.XML_Tree.Nutils;

package body Ocarina.Backends.XML_Common.Mapping is

40
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
41
   use Ocarina.Backends.XML_Tree.Nutils;
42 43
   use Ocarina.Backends.XML_Tree.Nodes;
   package XV renames Ocarina.Backends.XML_Values;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

   --------------
   -- Map_Time --
   --------------

   function Map_Time (T : Time_Type) return Node_Id is
      Time : Unsigned_Long_Long;
   begin
      case T.U is
         when Picosecond =>
            --  Our framework only support microseconds
            --  Picosecond and Nanosecond are ignored
            if T.T mod 1_000_000 = 0 then
               Time := T.T / 1_000_000;
            else
               return No_Node;
            end if;

         when Nanosecond =>
            if T.T mod 1000 = 0 then
               Time := T.T / 1000;
            else
               return No_Node;
            end if;

         when Microsecond =>
            Time := T.T;

         when Millisecond =>
            Time := T.T;

         when Second =>
            Time := T.T;

         when Minute =>
            Time := T.T;

         when Hour =>
            --  Convert it into minutes

            Time := T.T * 60;
      end case;

      return Make_Literal (XV.New_Numeric_Value (Time, 1, 10));
   end Map_Time;

90 91 92 93
   ---------------------
   -- Map_To_XML_Node --
   ---------------------

94 95 96 97
   function Map_To_XML_Node
     (Name  : String;
      Value : Unsigned_Long_Long) return Node_Id
   is
98 99 100 101 102 103 104 105 106
      N, V : Node_Id;
   begin
      N := Make_XML_Node (Name);
      V := Make_Literal (XV.New_Numeric_Value (Value, 1, 10));
      Append_Node_To_List (V, Subitems (N));

      return N;
   end Map_To_XML_Node;

107
   function Map_To_XML_Node (Name : String; Value : Name_Id) return Node_Id is
108 109 110 111 112 113 114 115 116 117 118 119 120 121
      N, V : Node_Id;
   begin
      N := Make_XML_Node (Name);
      V := Make_Defining_Identifier (Value);
      Append_Node_To_List (V, Subitems (N));

      return N;
   end Map_To_XML_Node;

   -------------------------------------
   -- Map_Node_Identifier_To_XML_Node --
   -------------------------------------

   function Map_Node_Identifier_To_XML_Node
122 123
     (Name     : String;
      The_Node : Node_Id) return Node_Id
124 125 126 127
   is
      N, V : Node_Id;
   begin
      N := Make_XML_Node (Name);
128 129 130
      V :=
        Make_Defining_Identifier
          (To_XML_Name (Display_Name (Identifier (The_Node))));
131 132 133 134 135
      Append_Node_To_List (V, Subitems (N));

      return N;
   end Map_Node_Identifier_To_XML_Node;

136
   function Map_Node_Identifier_To_XML_Node
137 138
     (Name     : String;
      The_Node : Name_Id) return Node_Id
139 140 141 142 143 144 145 146 147 148
   is
      N, V : Node_Id;
   begin
      N := Make_XML_Node (Name);
      V := Make_Defining_Identifier (The_Node);
      Append_Node_To_List (V, Subitems (N));

      return N;
   end Map_Node_Identifier_To_XML_Node;

149
end Ocarina.Backends.XML_Common.Mapping;