ocarina-be_aadl_ba-specifications.adb 14.6 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 _ B A . S P E C I F I C A T I O N S     --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--       Copyright (C) 2009 Telecom ParisTech, 2010-2016 ESA & ISAE.        --
10
--                                                                          --
11 12 13 14 15 16
-- 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.                     --
17
--                                                                          --
18 19 20 21 22 23 24 25
-- 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 42 43 44

with Ocarina.ME_AADL_BA;
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;

with Ocarina.BE_AADL_BA.Identifiers;
with Ocarina.BE_AADL_BA.Thread_Dispatch;
with Ocarina.BE_AADL_BA.Actions;
with Ocarina.BE_AADL_BA.Expressions;

package body Ocarina.BE_AADL_BA.Specifications is

45
   use Ocarina.Output;
46 47 48 49 50 51 52 53 54 55
   use Ocarina.ME_AADL_BA;
   use Ocarina.ME_AADL_BA.BA_Tree.Nutils;
   use Ocarina.ME_AADL_BA.BA_Tree.Nodes;
   use Ocarina.BE_AADL_BA.Identifiers;
   use Ocarina.BE_AADL_BA.Thread_Dispatch;
   use Ocarina.BE_AADL_BA.Actions;
   use Ocarina.BE_AADL_BA.Expressions;

   package BAN renames Ocarina.ME_AADL_BA.BA_Tree.Nodes;

56 57 58 59
   procedure Print_Behavior_Variable             (Node : Node_Id);
   procedure Print_Behavior_State                (Node : Node_Id);
   procedure Print_Behavior_State_Kind           (State_Kind : Byte);
   procedure Print_Behavior_Transition           (Node : Node_Id);
60
   procedure Print_Execution_Behavior_Transition (Node : Node_Id);
61 62 63 64 65 66 67
   procedure Print_Mode_Transition               (Node : Node_Id);
   procedure Print_Behavior_Condition            (Node : Node_Id);
   procedure Print_Execute_Condition             (Node : Node_Id);
   procedure Print_Mode_Condition                (Node : Node_Id);
   procedure Print_Trigger_Logical_Expression    (Node : Node_Id);
   procedure Print_Event_Trigger                 (Node : Node_Id);
   procedure Print_Port_Component_Ref            (Node : Node_Id);
68 69 70 71 72 73 74 75 76 77 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

   --------------------------
   -- Print_Behavior_Annex --
   --------------------------

   procedure Print_Behavior_Annex (Node : Node_Id) is

      List_Node : Node_Id;
   begin
      Write_Eol;

      if not Is_Empty (Variables (Node)) then
         Write_Indentation;
         Print_Token (T_Variables);
         Write_Eol;

         List_Node := First_Node (Variables (Node));

         while Present (List_Node) loop
            Write_Indentation (+2);
            Print_Behavior_Variable (List_Node);

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

      Write_Indentation;
      if not Is_Empty (States (Node)) then
         Print_Token (T_States);
         Write_Eol;

         List_Node := First_Node (States (Node));

         while Present (List_Node) loop
            Write_Indentation (+2);
            Print_Behavior_State (List_Node);

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

      Write_Indentation;
      if not Is_Empty (Transitions (Node)) then
         Print_Token (T_Transitions);

         List_Node := First_Node (Transitions (Node));

         while Present (List_Node) loop
            Write_Indentation (+2);
            Print_Behavior_Transition (List_Node);

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

      Write_Eol;
   end Print_Behavior_Annex;

   -----------------------------
   -- Print_Behavior_Variable --
   -----------------------------

   procedure Print_Behavior_Variable (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Behavior_Variable);

      List_Node : Node_Id;
   begin
      if not Is_Empty (BAN.Identifiers (Node)) then
         List_Node := First_Node (BAN.Identifiers (Node));

         while Present (List_Node) loop
            Print_Identifier (List_Node);

            if Present (Next_Node (List_Node)) then
               Print_Token (T_Comma);
               Write_Space;
            end if;

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

      if Present (Classifier_Ref (Node)) then
         Write_Space;
         Print_Token (T_Colon);
         Write_Space;
         Print_Component_Classifier_Ref (Classifier_Ref (Node));
      end if;

      Print_Token (T_Semicolon);

      Write_Eol;
   end Print_Behavior_Variable;

   --------------------------
   -- Print_Behavior_State --
   --------------------------

   procedure Print_Behavior_State (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Behavior_State);

      List_Node : Node_Id;
   begin
      if not Is_Empty (BAN.Identifiers (Node)) then
         List_Node := First_Node (BAN.Identifiers (Node));

         while Present (List_Node) loop
            Print_Identifier (List_Node);

            if Present (Next_Node (List_Node)) then
               Print_Token (T_Comma);
               Write_Space;
            end if;

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

      Write_Space;
      Print_Token (T_Colon);

      if Behavior_State_Kind'Val (State_Kind (Node)) /= BSK_No_Kind then
         Write_Space;
         Print_Behavior_State_Kind (State_Kind (Node));
      end if;

      Write_Space;
      Print_Token (T_State);
      Print_Token (T_Semicolon);

      Write_Eol;
   end Print_Behavior_State;

   -------------------------------
   -- Print_Behavior_State_Kind --
   -------------------------------

   procedure Print_Behavior_State_Kind (State_Kind : Byte) is
   begin
      case Behavior_State_Kind'Val (State_Kind) is
208 209 210 211 212 213 214 215 216 217 218 219 220 221
         when BSK_Initial                => Print_Token  (T_Initial);
         when BSK_Initial_Complete       => Print_Tokens ((T_Initial,
                                                           T_Complete));
         when BSK_Initial_Complete_Final => Print_Tokens ((T_Initial,
                                                           T_Complete,
                                                           T_Final));
         when BSK_Initial_Final          => Print_Tokens ((T_Initial,
                                                           T_Final));
         when BSK_Complete               => Print_Token  (T_Complete);
         when BSK_Complete_Final         => Print_Tokens ((T_Complete,
                                                           T_Final));
         when BSK_Final                  => Print_Token  (T_Final);

         when others                     => Write_Line   (Bug_Str);
222 223 224 225 226 227 228 229 230 231 232 233 234 235
      end case;
   end Print_Behavior_State_Kind;

   -------------------------------
   -- Print_Behavior_Transition --
   -------------------------------

   procedure Print_Behavior_Transition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Behavior_Transition);

      Transition_Node : constant Node_Id := Transition (Node);
   begin
      if Kind (Transition_Node) = K_Execution_Behavior_Transition then
         Print_Execution_Behavior_Transition (Transition_Node);
236
      elsif Kind (Transition_Node) = K_Mode_Transition then
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
         Print_Mode_Transition (Transition_Node);
      end if;
   end Print_Behavior_Transition;

   -----------------------------------------
   -- Print_Execution_Behavior_Transition --
   -----------------------------------------

   procedure Print_Execution_Behavior_Transition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Execution_Behavior_Transition);

      List_Node : Node_Id;
   begin
      Write_Eol;
      Write_Indentation (+2);

      if Present (Behavior_Transition_Idt (Node)) then
         Print_Identifier (Behavior_Transition_Idt (Node));
         Write_Space;

         if Present (Behavior_Transition_Priority (Node)) then
            Print_Token (T_Left_Square_Bracket);
            Print_Literal (Behavior_Transition_Priority (Node));
            Print_Token (T_Right_Square_Bracket);
            Write_Space;
         end if;

         Print_Token (T_Colon);
         Write_Space;
      end if;

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

         while Present (List_Node) loop
            Print_Identifier (List_Node);

            if Present (Next_Node (List_Node)) then
               Print_Token (T_Comma);
               Write_Space;
            end if;

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

      Write_Space;
      Print_Token (T_Left_Step_Bracket);

      if Present (Behavior_Condition (Node)) then
         Print_Behavior_Condition (Behavior_Condition (Node));
      end if;

      Print_Token (T_Right_Step_Bracket);
      Write_Space;
      Print_Identifier (Destination (Node));

294 295 296 297 298 299 300 301 302 303 304
      --  if not Is_Empty (Behavior_Actions (Node)) then
      --   Write_Space;
      --   Print_Token (T_Left_Curly_Bracket);
      --   Print_Behavior_Actions (Behavior_Actions (Node));
      --   Write_Eol;
      --   Write_Indentation (+4);
      --   Print_Token (T_Right_Curly_Bracket);
      --  end if;

      if Present (Behavior_Action_Block (Node)) then
         Print_Behavior_Action_Block (Behavior_Action_Block (Node));
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
      end if;

      Print_Token (T_Semicolon);
   end Print_Execution_Behavior_Transition;

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

   procedure Print_Mode_Transition (Node : Node_Id) is
      pragma Unreferenced (Node);

   begin
      Write_Eol;
      Print_Token (T_None);
      Write_Eol;
   end Print_Mode_Transition;

   ------------------------------
   -- Print_Behavior_Condition --
   ------------------------------

   procedure Print_Behavior_Condition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Behavior_Condition);

      Cond_Node : constant Node_Id := Condition (Node);
   begin
      case Kind (Cond_Node) is

334 335 336 337 338 339
         when K_Dispatch_Condition_Thread =>
                                    Print_Dispatch_Condition (Cond_Node);

         when K_Execute_Condition => Print_Execute_Condition (Cond_Node);

         when K_Mode_Condition => Print_Mode_Condition (Cond_Node);
340

341
         when others               => Write_Line               (Bug_Str);
342 343 344
      end case;
   end Print_Behavior_Condition;

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
   ------------------------------
   -- Print_Execute_Condition --
   ------------------------------

   procedure Print_Execute_Condition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Execute_Condition);

      --  Cond_Node : constant Node_Id := Condition (Node);
   begin
      if Present (Value_Expression (Node)) then
         Print_Value_Expression (Value_Expression (Node));
      end if;

      if Is_Otherwise (Node) then
         Print_Token (T_Otherwise);
      end if;
   end Print_Execute_Condition;

   ------------------------------
   -- Print_Mode_Condition --
   ------------------------------

   procedure Print_Mode_Condition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Mode_Condition);

   begin
      Print_Token (T_On);
      Write_Space;

      Print_Trigger_Logical_Expression (Trigger_Logical_Expr (Node));

   end Print_Mode_Condition;

   --------------------------------------
   -- Print_Trigger_Logical_Expression --
   --------------------------------------

   procedure Print_Trigger_Logical_Expression (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Trigger_Logical_Expression);
      pragma Assert (not Is_Empty (Event_Triggers (Node)));

      List_Node : Node_Id;
   begin
      List_Node := First_Node (Event_Triggers (Node));
      Print_Event_Trigger (List_Node);

      List_Node := Next_Node (List_Node);
      while Present (List_Node) loop
         Write_Space;

         case Kind (List_Node) is
            when K_Event_Trigger => Print_Event_Trigger (List_Node);
            when K_Operator => Print_Operator (List_Node);
            when others     => Write_Line     (Bug_Str);
         end case;

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

   -------------------------
   -- Print_Event_Trigger --
   -------------------------

   procedure Print_Event_Trigger (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Event_Trigger);

   begin
      if Present (Trigger_Log_Expr (Node)) then
         Write_Space;
         Print_Token (T_Left_Parenthesis);
         Print_Trigger_Logical_Expression (Trigger_Log_Expr (Node));
         Print_Token (T_Right_Parenthesis);
      end if;
      if Present (Port_Component_Ref (Node)) then
         Write_Space;
         Print_Port_Component_Ref (Port_Component_Ref (Node));
      end if;
   end Print_Event_Trigger;

   ------------------------------
   -- Print_Port_Component_Ref --
   ------------------------------

   procedure Print_Port_Component_Ref (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Port_Component_Reference);

   begin
      if Present (Subcomponent_Name (Node)) then
         Print_Identifier (Subcomponent_Name (Node));
      end if;

      if Present (Port_Idt (Node)) then
         Print_Token (T_Dot);
         Print_Identifier (Port_Idt (Node));
      end if;

   end Print_Port_Component_Ref;

444
end Ocarina.BE_AADL_BA.Specifications;