ocarina-be_aadl-components-modes.adb 7.19 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--     O C A R I N A . B E _ A A D L . C O M P O N E N T S . M O D E S      --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE.      --
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--                                                                          --
-- 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
with Ocarina.Output;
33 34 35 36 37 38 39 40 41

with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Nodes; use Ocarina.ME_AADL.AADL_Tree.Nodes;

with Ocarina.BE_AADL.Properties;
with Ocarina.BE_AADL.Identifiers;

package body Ocarina.BE_AADL.Components.Modes is

42
   use Ocarina.Output;
43 44 45
   use Ocarina.ME_AADL.AADL_Tree.Nutils;
   use Ocarina.BE_AADL.Identifiers;

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
   procedure Print_Trigger (Node : Node_Id);
   --  Displays a mode transition trigger

   -------------------
   -- Print_Trigger --
   -------------------

   procedure Print_Trigger (Node : Node_Id) is
   begin
      case Kind (Node) is
         when K_Entity_Reference =>
            Print_Entity_Reference (Node);

         when K_Identifier =>
            Print_Identifier (Node);

         when K_Mode_Transition_Trigger =>
            if Ocarina.ME_AADL.AADL_Tree.Nodes.Is_Self (Node) then
               Print_Token (T_Self);
               Print_Token (T_Dot);
            elsif Ocarina.ME_AADL.AADL_Tree.Nodes.Is_Processor (Node) then
               Print_Token (T_Processor);
               Print_Token (T_Dot);
            end if;

            Print_Trigger (Identifier (Node));
         when others =>
            raise Program_Error
              with "Error when displaying a mode transition trigger";
      end case;
   end Print_Trigger;

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
   --------------------
   -- Print_In_Modes --
   --------------------

   procedure Print_In_Modes (Node : Node_Id) is
      List_Node : Node_Id;
      Mode_List : List_Id;

   begin
      if Present (Node) then
         Increment_Indentation;
         Write_Eol;
         Write_Indentation;
         Print_Tokens ((T_In, T_Modes, T_Left_Parenthesis));

         Mode_List := Ocarina.ME_AADL.AADL_Tree.Nodes.Modes (Node);

         if Is_Empty (Mode_List) then
            Print_Token (T_None);
         else
            List_Node := First_Node (Mode_List);

            while Present (List_Node) loop
               case Kind (List_Node) is
                  when K_Entity_Reference =>
                     Print_Entity_Reference (List_Node);
                  when K_Pair_Of_Entity_References =>
                     Print_Token (T_Left_Parenthesis);
                     Print_Entity_Reference (First_Reference (List_Node));
                     Write_Space;
                     Print_Token (T_Direct_Connection);
                     Write_Space;
                     Print_Entity_Reference (Second_Reference (List_Node));
                     Print_Token (T_Right_Parenthesis);
                  when others =>
                     raise Program_Error;
               end case;

               exit when No (Next_Node (List_Node));
               Print_Token (T_Comma);
               Write_Space;

               List_Node := Next_Node (List_Node);
            end loop;

            Decrement_Indentation;
         end if;

         Print_Token (T_Right_Parenthesis);
      end if;
   end Print_In_Modes;

   ----------------
   -- Print_Mode --
   ----------------

   procedure Print_Mode (Node : Node_Id) is
      use Ocarina.BE_AADL.Properties;

   begin
      Write_Indentation;
      Print_Item_Refined_To (Node);
      Write_Space;

      if Is_Initial (Node) then
         Print_Token (T_Initial);
         Write_Space;
      end if;

      Print_Token (T_Mode);
      Print_Contained_Property_Associations
        (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));
      Print_Token (T_Semicolon);
      Write_Eol;
   end Print_Mode;

   ---------------------------
   -- Print_Mode_Transition --
   ---------------------------

   procedure Print_Mode_Transition (Node : Node_Id) is
      use Ocarina.BE_AADL.Properties;

      List_Node : Node_Id;

   begin
      Write_Indentation;

      if not Is_Empty (Source_Modes (Node)) then
         List_Node := First_Node (Source_Modes (Node));

         while Present (List_Node) loop
            if List_Node /= First_Node (Source_Modes (Node)) then
               Print_Token (T_Comma);
               Write_Space;
            end if;

            Print_Identifier (List_Node);
            List_Node := Next_Node (List_Node);
         end loop;
      end if;

      Write_Space;
      Print_Token (T_Left_Step_Bracket);
      Write_Space;

      if not Is_Empty (Triggers (Node)) then
         List_Node := First_Node (Triggers (Node));

         while Present (List_Node) loop
            if List_Node /= First_Node (Triggers (Node)) then
               Print_Token (T_Comma);
               Write_Space;
            end if;

193
            Print_Trigger (List_Node);
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

            List_Node := Next_Node (List_Node);
         end loop;
      end if;

      Write_Space;
      Print_Token (T_Right_Step_Bracket);
      Write_Space;

      Print_Identifier (Destination_Mode (Node));
      Print_Contained_Property_Associations
        (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (Node));

      Print_Token (T_Semicolon);
      Write_Eol;
   end Print_Mode_Transition;

end Ocarina.BE_AADL.Components.Modes;