ocarina-backends-pn-format-cami.adb 23.4 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 . P N . F O R M A T . C A M I       --
--                                                                          --
--                                 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
with Ocarina.Output;
33 34 35 36
with Ocarina.Backends.PN.Debug;

with Ocarina.Backends.PN.Nodes;
with Ocarina.Backends.PN.Nutils;
37
with Ocarina.Namet;
38 39 40 41 42 43 44 45 46 47 48 49 50
with Ocarina.AADL_Values;
with Ocarina.Backends.Utils;

package body Ocarina.Backends.PN.Format.Cami is

   package OPN renames Ocarina.Backends.PN.Nodes;
   package OPU renames Ocarina.Backends.PN.Nutils;
   package OAV renames Ocarina.AADL_Values;

   -------------------
   --  Print_Place  --
   -------------------

51
   procedure Print_Place (Pn_Generated : Node_Id; Pn_P : Node_Id) is
52
      use Ocarina.Output;
53 54
      use Ocarina.Backends.PN.Debug;
      use OPN;
55
      use Ocarina.Namet;
56 57 58 59 60 61 62 63 64 65 66
      use OAV;

   begin

      if Pn_Generated /= No_Node and then Pn_P /= No_Node then
         --  print node
         Write_Line ("CN(5:place," & Image (Pn_P) & ")");
         --  print name
         declare
            S : constant String := Get_Name_String (Name (Identifier (Pn_P)));
         begin
67 68 69 70 71 72 73 74
            Write_Line
              ("CT(4:name," &
               Image (Pn_P) &
               "," &
               OAV.Image (New_Integer_Value (S'Length), False) &
               ":" &
               S &
               ")");
75 76 77 78 79
         end;
         --  print domain
         if Domain (Pn_P) /= No_Node then
            --  colored
            declare
80 81
               S : constant String :=
                 Get_Name_String (Name (Identifier (Domain (Pn_P))));
82
            begin
83 84 85 86 87 88 89 90
               Write_Line
                 ("CT(6:domain," &
                  Image (Pn_P) &
                  "," &
                  OAV.Image (New_Integer_Value (S'Length), False) &
                  ":" &
                  S &
                  ")");
91 92 93 94 95 96 97 98 99 100 101
            end;
         end if;
         --  print marking
         if Domain (Pn_P) /= No_Node then
            --  build complete string in order to compute length
            --  potentially colored place
            declare
               Node_Iter : Node_Id;
            begin
               Node_Iter := OPN.First_Node (Tokens (Marking (Pn_P)));
               if Node_Iter /= No_Node then
102
                  Write_Str ("CT(7:marking," & Image (Pn_P) & ",");
103 104
                  Set_Str_To_Name_Buffer ("<");
                  while Present (Node_Iter) loop
105 106
                     Add_Str_To_Name_Buffer
                       (Get_Name_String (Name (Identifier (Node_Iter))));
107 108 109 110 111 112 113 114 115 116 117
                     if OPN.Next_Node (Node_Iter) = No_Node then
                        Add_Str_To_Name_Buffer (">");
                     else
                        Add_Str_To_Name_Buffer (",");
                     end if;
                     --  next
                     Node_Iter := OPN.Next_Node (Node_Iter);
                  end loop;

                  --  here, marking is accessible through name_find
                  declare
118
                     S : constant String := Get_Name_String (Name_Find);
119
                  begin
120 121 122 123
                     Write_Str
                       (OAV.Image (New_Integer_Value (S'Length), False) &
                        ":" &
                        S);
124 125 126 127 128 129 130 131 132
                  end;

                  Write_Line (")");
               end if;
            end;

         else
            --  uncolored
            declare
133 134
               Tokens_Count : constant Value_Type :=
                 Get_Value_Type (Nb_T (Pn_P));
135
            begin
136
               if Tokens_Count.IVal /= 0 then
137
                  --  uncolored place
138
                  Write_Str ("CT(7:marking," & Image (Pn_P) & ",");
139 140
                  Set_Str_To_Name_Buffer (OAV.Image (Tokens_Count));
                  declare
141
                     S : constant String := Get_Name_String (Name_Find);
142
                  begin
143 144 145 146
                     Write_Str
                       (OAV.Image (New_Integer_Value (S'Length), False) &
                        ":" &
                        S);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
                  end;

                  Write_Line (")");

               end if;
            end;
         end if;                        --  color on not

      end if;
   end Print_Place;

   -------------------
   --  Print_Trans  --
   -------------------

162
   procedure Print_Trans (Pn_Generated : Node_Id; Pn_T : Node_Id) is
163
      use Ocarina.Output;
164 165
      use Ocarina.Backends.PN.Debug;
      use OPN;
166
      use Ocarina.Namet;
167 168 169 170 171
      use OAV;
      use OPU;
      use Ocarina.Backends.Utils;

   begin
172 173 174 175
      if Pn_Generated /= No_Node
        and then Pn_T /= No_Node
        and then Get_Handling (Pn_T, By_Node, H_PN_To_Delete) = No_Node
      then
176 177 178 179 180 181 182
         --  print node
         Write_Line ("CN(10:transition," & Image (Pn_T) & ")");

         --  print name
         declare
            S : constant String := Get_Name_String (Name (Identifier (Pn_T)));
         begin
183 184 185 186 187 188 189 190
            Write_Line
              ("CT(4:name," &
               Image (Pn_T) &
               "," &
               OAV.Image (New_Integer_Value (S'Length), False) &
               ":" &
               S &
               ")");
191 192 193 194 195 196 197 198 199 200 201 202 203 204
         end;

         --  print guard
         --  XXX

         --  print arcs

         declare
            Iter : Node_Id;
         begin
            --  in
            if not Is_Empty (Pn_Arcs_In (Pn_T)) then
               Iter := OPN.First_Node (Pn_Arcs_In (Pn_T));
               while Present (Iter) loop
205 206 207 208 209 210 211 212
                  Write_Line
                    ("CA(3:arc," &
                     Image (Iter) &
                     "," &
                     Image (Pn_From (Iter)) &
                     "," &
                     Image (Pn_To (Iter)) &
                     ")");
213 214
                  --  valuation
                  if not Is_Empty (Valuations (Iter)) then
215
                     Write_Str ("CT(9:valuation," & Image (Iter) & ",");
216 217
                     --  build string to compute length
                     declare
218 219
                        Val_Iter : Node_Id :=
                          OPN.First_Node (Valuations (Iter));
220 221 222 223 224 225
                     begin
                        if Is_Colored (Val_Iter) then
                           Set_Str_To_Name_Buffer ("<");
                           while Present (Val_Iter) loop
                              Add_Str_To_Name_Buffer
                                (Get_Name_String
226
                                   (Name (Identifier (Val_Iter))));
227 228 229 230 231 232 233 234 235
                              if OPN.Next_Node (Val_Iter) /= No_Node then
                                 Add_Str_To_Name_Buffer (",");
                              end if;
                              --  next
                              Val_Iter := OPN.Next_Node (Val_Iter);
                           end loop;
                           Add_Str_To_Name_Buffer (">");
                        else
                           Set_Str_To_Name_Buffer
236
                             (Get_Name_String (Name (Identifier (Val_Iter))));
237 238 239 240
                        end if;
                     end;
                     --  here, marking is accessible through name_find
                     declare
241
                        S : constant String := Get_Name_String (Name_Find);
242
                     begin
243 244 245 246
                        Write_Str
                          (OAV.Image (New_Integer_Value (S'Length), False) &
                           ":" &
                           S);
247 248 249 250 251 252 253 254 255 256 257 258 259
                     end;

                     Write_Line (")");

                  end if;
                  --  next
                  Iter := OPN.Next_Node (Iter);
               end loop;
            end if;
            --  out
            if not Is_Empty (Pn_Arcs_Out (Pn_T)) then
               Iter := OPN.First_Node (Pn_Arcs_Out (Pn_T));
               while Present (Iter) loop
260 261 262 263 264 265 266 267
                  Write_Line
                    ("CA(3:arc," &
                     Image (Iter) &
                     "," &
                     Image (Pn_From (Iter)) &
                     "," &
                     Image (Pn_To (Iter)) &
                     ")");
268 269
                  --  valuation
                  if not Is_Empty (Valuations (Iter)) then
270
                     Write_Str ("CT(9:valuation," & Image (Iter) & ",");
271 272
                     --  build string to compute length
                     declare
273 274
                        Val_Iter : Node_Id :=
                          OPN.First_Node (Valuations (Iter));
275 276 277 278 279 280
                     begin
                        if Is_Colored (Val_Iter) then

                           Set_Str_To_Name_Buffer ("<");
                           while Present (Val_Iter) loop
                              Add_Str_To_Name_Buffer
281 282
                                (Get_Name_String
                                   (Name (Identifier (Val_Iter))));
283 284 285 286 287 288 289 290 291
                              if OPN.Next_Node (Val_Iter) /= No_Node then
                                 Add_Str_To_Name_Buffer (",");
                              end if;
                              --  next
                              Val_Iter := OPN.Next_Node (Val_Iter);
                           end loop;
                           Add_Str_To_Name_Buffer (">");
                        else
                           Set_Str_To_Name_Buffer
292
                             (Get_Name_String (Name (Identifier (Val_Iter))));
293 294 295 296
                        end if;
                     end;
                     --  here, marking is accessible through name_find
                     declare
297
                        S : constant String := Get_Name_String (Name_Find);
298
                     begin
299 300 301 302
                        Write_Str
                          (OAV.Image (New_Integer_Value (S'Length), False) &
                           ":" &
                           S);
303 304 305 306 307 308 309 310 311 312 313 314
                     end;

                     Write_Line (")");

                  end if;
                  --  next
                  Iter := OPN.Next_Node (Iter);
               end loop;
            end if;
         end;
      end if;

315
      --  arcs in
316

317
      --  arcs out
318

319
      --    print arcs valuations
320 321 322 323 324 325 326

   end Print_Trans;

   -----------------------------------
   --  Print_Formalism_Information  --
   -----------------------------------

327
   procedure Print_Formalism_Information (Pn_Generated : Node_Id) is
328
      use Ocarina.Output;
329
      use OPN;
330
      use Ocarina.Namet;
331 332 333 334 335 336 337 338 339 340
      use OAV;
      use OPU;

      Line_Count : Unsigned_Long_Long := 1;
   begin
      if Pn_Generated /= No_Node then
         --  print net node
         Write_Line ("CN(3:net,1)");

         --      print classes
341 342 343 344 345 346 347
         if Classes (Pn_Formalism_Specific_Informations (Pn_Generated)) /=
           No_Node
         then
            Write_Line
              ("CM(11:declaration,1," &
               OAV.Image (New_Integer_Value (Line_Count), False) &
               ",1,5:Class)");
348 349 350 351 352
            Line_Count := Line_Count + 1;

            --  first is th_ids
            declare
               --  hack since OAV.Image blast name_buffer....
353 354 355 356 357 358 359 360 361 362 363 364 365 366
               Begin_Range : constant String :=
                 Get_Name_String
                   (Name
                      (Identifier
                         (OPN.First_Node
                            (Class_List
                               (Classes
                                  (Pn_Formalism_Specific_Informations
                                     (Pn_Generated)))))));
               Max_Range : constant String :=
                 OAV.Image
                   (Get_Value_Type
                      (Threads_Count
                         (Pn_Formalism_Specific_Informations (Pn_Generated))));
367
            begin
368 369
               Set_Str_To_Name_Buffer
                 (Begin_Range & " is 0.." & Max_Range & ";");
370 371 372 373
               declare
                  S : constant String := Get_Name_String (Name_Find);
               begin

374 375 376 377 378 379 380 381
                  Write_Line
                    ("CM(11:declaration,1," &
                     OAV.Image (New_Integer_Value (Line_Count), False) &
                     ",1," &
                     OAV.Image (New_Integer_Value (S'Length), False) &
                     ":" &
                     S &
                     ")");
382 383 384 385 386 387
                  Line_Count := Line_Count + 1;
               end;
            end;

            --  print others according to IDL
            declare
388 389 390 391 392 393 394
               Class_Iter : Node_Id :=
                 OPN.Next_Node
                   (OPN.First_Node
                      (Class_List
                         (Classes
                            (Pn_Formalism_Specific_Informations
                               (Pn_Generated)))));
395 396 397 398 399
            begin
               while Present (Class_Iter) loop
                  case OPN.Kind (Class_Iter) is
                     when K_CPN_Formalism_Class_Item_Enum =>
                        if not Is_Empty (Enum (Class_Iter)) then
400 401 402 403 404 405 406 407 408 409
                           Write_Str
                             ("CM(11:declaration,1," &
                              OAV.Image
                                (New_Integer_Value (Line_Count),
                                 False) &
                              ",1,");
                           Set_Str_To_Name_Buffer
                             (Get_Name_String
                                (Name (Identifier (Class_Iter))) &
                              " is [");
410
                           declare
411 412
                              Enum_Iter : Node_Id :=
                                OPN.First_Node (Enum (Class_Iter));
413 414 415
                           begin
                              while Present (Enum_Iter) loop
                                 Add_Str_To_Name_Buffer
416 417
                                   (Get_Name_String
                                      (Name (Identifier (Enum_Iter))));
418 419 420 421 422 423 424 425
                                 if OPN.Next_Node (Enum_Iter) /= No_Node then
                                    Add_Str_To_Name_Buffer ("|");
                                 end if;
                                 --  next
                                 Enum_Iter := OPN.Next_Node (Enum_Iter);
                              end loop;
                              Add_Str_To_Name_Buffer ("];");
                              declare
426 427
                                 S : constant String :=
                                   Get_Name_String (Name_Find);
428 429
                              begin

430 431 432 433 434 435 436
                                 Write_Line
                                   (OAV.Image
                                      (New_Integer_Value (S'Length),
                                       False) &
                                    ":" &
                                    S &
                                    ")");
437 438 439 440 441 442 443
                                 Line_Count := Line_Count + 1;
                              end;
                           end;
                        end if;
                     when K_CPN_Formalism_Class_Item_Range =>
                        declare
                           --  hack since OAV.Image blast name_buffer....
444 445 446 447 448 449
                           Begin_Range : constant String :=
                             Get_Name_String (Name (Identifier (Class_Iter)));
                           Max_Range : constant String :=
                             OAV.Image (Get_Value_Type (High (Class_Iter)));
                           Min_Range : constant String :=
                             OAV.Image (Get_Value_Type (Low (Class_Iter)));
450
                        begin
451 452 453 454 455 456 457
                           Set_Str_To_Name_Buffer
                             (Begin_Range &
                              " is " &
                              Min_Range &
                              ".." &
                              Max_Range &
                              ";");
458
                           declare
459 460
                              S : constant String :=
                                Get_Name_String (Name_Find);
461 462
                           begin

463 464 465 466 467 468 469 470 471 472 473 474
                              Write_Line
                                ("CM(11:declaration, 1," &
                                 OAV.Image
                                   (New_Integer_Value (Line_Count),
                                    False) &
                                 ",1," &
                                 OAV.Image
                                   (New_Integer_Value (S'Length),
                                    False) &
                                 ":" &
                                 S &
                                 ")");
475 476 477 478 479 480 481 482 483 484 485 486 487
                              Line_Count := Line_Count + 1;
                           end;
                        end;

                     when others =>
                        null;
                  end case;
                  --  next
                  Class_Iter := OPN.Next_Node (Class_Iter);
               end loop;
            end;
         end if;
         --      print domains
488 489 490 491 492 493 494
         if not Is_Empty
             (Domains (Pn_Formalism_Specific_Informations (Pn_Generated)))
         then
            Write_Line
              ("CM(11:declaration,1," &
               OAV.Image (New_Integer_Value (Line_Count), False) &
               ",1,6:Domain)");
495 496 497
            Line_Count := Line_Count + 1;

            declare
498 499 500 501
               Domain_Iter : Node_Id :=
                 OPN.First_Node
                   (Domains
                      (Pn_Formalism_Specific_Informations (Pn_Generated)));
502 503
            begin
               while Present (Domain_Iter) loop
504 505 506 507 508 509 510 511
                  Write_Str
                    ("CM(11:declaration,1," &
                     OAV.Image (New_Integer_Value (Line_Count), False) &
                     ",1,");

                  Set_Str_To_Name_Buffer
                    (Get_Name_String (Name (Identifier (Domain_Iter))) &
                     " is <");
512 513
                  if not Is_Empty (Domain_List (Domain_Iter)) then
                     declare
514 515
                        Domain_Item : Node_Id :=
                          OPN.First_Node (Domain_List (Domain_Iter));
516 517
                     begin
                        while Present (Domain_Item) loop
518 519 520
                           Add_Str_To_Name_Buffer
                             (Get_Name_String
                                (Name (Identifier (Domain_Item))));
521 522 523 524 525 526 527 528 529 530
                           if OPN.Next_Node (Domain_Item) /= No_Node then
                              Add_Str_To_Name_Buffer (",");
                           end if;
                           --  next
                           Domain_Item := OPN.Next_Node (Domain_Item);
                        end loop;
                     end;
                  end if;
                  Add_Str_To_Name_Buffer (">;");
                  declare
531
                     S : constant String := Get_Name_String (Name_Find);
532 533
                  begin

534 535 536 537 538
                     Write_Line
                       (OAV.Image (New_Integer_Value (S'Length), False) &
                        ":" &
                        S &
                        ")");
539 540 541 542 543 544 545 546 547
                     Line_Count := Line_Count + 1;
                  end;

                  --  next
                  Domain_Iter := OPN.Next_Node (Domain_Iter);
               end loop;
            end;
         end if;
         --      print variables
548 549 550 551 552 553 554
         if not Is_Empty
             (Variables (Pn_Formalism_Specific_Informations (Pn_Generated)))
         then
            Write_Line
              ("CM(11:declaration,1," &
               OAV.Image (New_Integer_Value (Line_Count), False) &
               ",1,3:Var)");
555 556 557
            Line_Count := Line_Count + 1;

            declare
558 559 560 561
               Var_Iter : Node_Id :=
                 OPN.First_Node
                   (Variables
                      (Pn_Formalism_Specific_Informations (Pn_Generated)));
562 563 564
            begin
               while Present (Var_Iter) loop
                  if not Is_Empty (Variable_List (Var_Iter)) then
565 566 567 568
                     Write_Str
                       ("CM(11:declaration,1," &
                        OAV.Image (New_Integer_Value (Line_Count), False) &
                        ",1,");
569 570
                     Set_Str_To_Name_Buffer (" "); --  to clear name_buffer
                     declare
571 572
                        Var_Item : Node_Id :=
                          OPN.First_Node (Variable_List (Var_Iter));
573 574
                     begin
                        while Present (Var_Item) loop
575 576
                           Add_Str_To_Name_Buffer
                             (Get_Name_String (Name (Identifier (Var_Item))));
577 578 579 580 581 582
                           if OPN.Next_Node (Var_Item) /= No_Node then
                              Add_Str_To_Name_Buffer (", ");
                           end if;
                           --  next
                           Var_Item := OPN.Next_Node (Var_Item);
                        end loop;
583 584 585 586 587
                        Add_Str_To_Name_Buffer
                          (" in " &
                           Get_Name_String
                             (Name (Identifier (Class_Type (Var_Iter)))) &
                           ";");
588
                        declare
589
                           S : constant String := Get_Name_String (Name_Find);
590 591
                        begin

592 593 594 595 596
                           Write_Line
                             (OAV.Image (New_Integer_Value (S'Length), False) &
                              ":" &
                              S &
                              ")");
597 598 599 600 601 602 603 604 605 606 607 608 609
                           Line_Count := Line_Count + 1;
                        end;
                     end;
                  end if;
                  --  next
                  Var_Iter := OPN.Next_Node (Var_Iter);
               end loop;
            end;
         end if;
      end if;
   end Print_Formalism_Information;

end Ocarina.Backends.PN.Format.Cami;