ocarina-backends-aadl_xml-main.adb 21.9 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 . A A D L _ X M L . M A I N        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--                   Copyright (C) 2011-2014 ESA & ISAE.                    --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- 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.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
--                                                                          --
------------------------------------------------------------------------------

yoogx's avatar
yoogx committed
34
with Ocarina.Namet;                     use Ocarina.Namet;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
with Ocarina.Instances.Queries; use Ocarina.Instances.Queries;
with Ocarina.AADL_Values;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Ocarina.Backends.AADL_XML.Mapping;

package body Ocarina.Backends.AADL_XML.Main is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.XML_Tree.Nutils;
   use Ocarina.Backends.AADL_XML.Mapping;

55
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package XTN renames Ocarina.Backends.XML_Tree.Nodes;
   use type ATN.Node_Kind;

   procedure Visit_Component (E : Node_Id);
   procedure Visit_Subcomponents_Of (E : Node_Id);

   function Map_Component (E : Node_Id) return Node_Id;

   -------------------
   -- Map_Component --
   -------------------

   function Map_Component (E : Node_Id) return Node_Id is
70
71
      Category_Name_String : constant array
      (Component_Category'Range) of Name_Id :=
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
        (CC_Abstract          => Get_String_Name ("abstract"),
         CC_Bus               => Get_String_Name ("bus"),
         CC_Data              => Get_String_Name ("data"),
         CC_Device            => Get_String_Name ("device"),
         CC_Memory            => Get_String_Name ("memory"),
         CC_Process           => Get_String_Name ("process"),
         CC_Processor         => Get_String_Name ("processor"),
         CC_Subprogram        => Get_String_Name ("subprogram"),
         CC_Subprogram_Group  => Get_String_Name ("subprogram group"),
         CC_System            => Get_String_Name ("system"),
         CC_Thread            => Get_String_Name ("thread"),
         CC_Thread_Group      => Get_String_Name ("thread group"),
         CC_Unknown           => No_Name,
         CC_Virtual_Bus       => Get_String_Name ("virtual bus"),
         CC_Virtual_Processor => Get_String_Name ("virtual processor"));

88
89
      N               : Node_Id;
      Classifier_Node : Node_Id;
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

   begin
      N := Make_XML_Node ("component");

      --  Category

      Append_Node_To_List
        (Make_Assignement
           (Make_Defining_Identifier (Get_String_Name ("category")),
            Make_Defining_Identifier
              (Category_Name_String (Get_Category_Of_Component (E)))),
         XTN.Items (N));

      --  Identifier

      if Present (Parent_Subcomponent (E)) then
         Append_Node_To_List
           (Make_Assignement
              (Make_Defining_Identifier (Get_String_Name ("identifier")),
               Make_Defining_Identifier
                 (Display_Name (Identifier (Parent_Subcomponent (E))))),
            XTN.Items (N));
      else
         Append_Node_To_List
           (Make_Assignement
              (Make_Defining_Identifier (Get_String_Name ("identifier")),
116
               Make_Defining_Identifier (Display_Name (Identifier (E)))),
117
118
119
120
121
122
123
            XTN.Items (N));
      end if;

      --  Classifier

      Classifier_Node := Make_XML_Node ("classifier");
      Append_Node_To_List
124
        (Make_Defining_Identifier (Display_Name (Identifier (E))),
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
         XTN.Subitems (Classifier_Node));
      Append_Node_To_List (Classifier_Node, XTN.Subitems (N));

      return N;
   end Map_Component;

   ----------------------------
   -- Visit_Subcomponents_Of --
   ----------------------------

   procedure Visit_Subcomponents_Of (E : Node_Id) is
      S : Node_Id;
   begin
      if not AINU.Is_Empty (Subcomponents (E)) then
         S := First_Node (Subcomponents (E));
         while Present (S) loop
            --  Visit the component instance corresponding to the
            --  subcomponent S.
            Visit (Corresponding_Instance (S));
            S := Next_Node (S);
         end loop;
      end if;
   end Visit_Subcomponents_Of;

149
150
151
   Root_System_Node : Node_Id := No_Node;
   AADL_XML_Node    : Node_Id := No_Node;
   Current_XML_Node : Node_Id := No_Node;
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

   -----------
   -- Visit --
   -----------

   procedure Visit (E : Node_Id) is
   begin
      case Kind (E) is
         when K_Architecture_Instance =>
            Root_System_Node := Root_System (E);
            Visit (Root_System_Node);

         when K_Component_Instance =>
            Visit_Component (E);

         when others =>
            null;
      end case;
   end Visit;

   ---------------------
   -- Visit_Component --
   ---------------------

   procedure Visit_Component (E : Node_Id) is
177
178
179
180
181
182
183
184
185
186
187
188
189
      Category : constant Component_Category := Get_Category_Of_Component (E);
      N        : Node_Id;

      Old_XML_Node        : Node_Id;
      Subcomponents_Node  : Node_Id;
      Features_Node       : Node_Id;
      Properties_Node     : Node_Id;
      Feature_Node        : Node_Id;
      F                   : Node_Id;
      P                   : Node_Id;
      U                   : Node_Id;
      Property_Node       : Node_Id;
      Components_Node     : Node_Id;
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
      Property_Value_Node : Node_Id;
      AADL_Property_Value : Node_Id;

   begin
      if Category = CC_System then
         P := Map_HI_Node (E);
         Push_Entity (P);

         U := Map_HI_Unit (E);
         Push_Entity (U);

         if AADL_XML_Node = No_Node then
            AADL_XML_Node := Make_XML_Node ("aadl_xml");

            Append_Node_To_List
              (Make_Assignement
                 (Make_Defining_Identifier (Get_String_Name ("root_system")),
                  Make_Defining_Identifier
                    (Display_Name (Identifier (Root_System_Node)))),
               XTN.Items (AADL_XML_Node));

            Append_Node_To_List
212
213
              (AADL_XML_Node,
               XTN.Subitems (XTN.Root_Node (XTN.XML_File (U))));
214
215
            Components_Node := Make_XML_Node ("components");
            Append_Node_To_List
216
217
              (Components_Node,
               XTN.Subitems (AADL_XML_Node));
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
         end if;
         Current_XML_Node := Components_Node;
      end if;

      --  First bits of the component node

      N := Map_Component (E);
      Append_Node_To_List (N, XTN.Subitems (Current_XML_Node));

      --  Features

      Features_Node := Make_XML_Node ("features");
      Append_Node_To_List (Features_Node, XTN.Subitems (N));

      if Present (Features (E)) then
         F := First_Node (Features (E));
         while Present (F) loop
            Feature_Node := Make_XML_Node ("feature");

            --  Identifier

            Append_Node_To_List
              (Make_Assignement
                 (Make_Defining_Identifier (Get_String_Name ("identifier")),
242
                  Make_Defining_Identifier (Display_Name (Identifier (F)))),
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
               XTN.Items (Feature_Node));

            --  Direction: in/out/inout

            declare
               Direction_Node : Node_Id;
               Direction_Kind : Name_Id;
            begin
               Direction_Node := Make_XML_Node ("direction");
               if Kind (F) = K_Port_Spec_Instance then
                  if Is_In (F) and then not Is_Out (F) then
                     Direction_Kind := Get_String_Name ("in");
                  elsif (not Is_In (F)) and then Is_Out (F) then
                     Direction_Kind := Get_String_Name ("out");
                  elsif Is_In (F) and then Is_Out (F) then
                     Direction_Kind := Get_String_Name ("inout");
                  end if;
               else
                  Direction_Kind := Get_String_Name ("none");
               end if;

               Append_Node_To_List
                 (Make_Assignement
                    (Make_Defining_Identifier (Get_String_Name ("kind")),
                     Make_Defining_Identifier (Direction_Kind)),
                  XTN.Items (Direction_Node));

               Append_Node_To_List
271
272
                 (Direction_Node,
                  XTN.Subitems (Feature_Node));
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
            end;

            --  Type: event/data/event data

            declare
               Type_Node : Node_Id;
               Type_Kind : Name_Id;
            begin
               Type_Node := Make_XML_Node ("type");
               if Kind (F) = K_Port_Spec_Instance then
                  if Is_Event (F) and then not Is_Data (F) then
                     Type_Kind := Get_String_Name ("event");
                  elsif not (Is_Event (F)) and then Is_Data (F) then
                     Type_Kind := Get_String_Name ("data");
                  elsif Is_Event (F) and then Is_Data (F) then
                     Type_Kind := Get_String_Name ("event_data");
                  end if;
               elsif Kind (F) = K_Subcomponent_Access_Instance then
                  Type_Kind := Get_String_Name ("access");
               else
                  Type_Kind := Get_String_Name ("feature");
               end if;

               Append_Node_To_List
                 (Make_Assignement
                    (Make_Defining_Identifier (Get_String_Name ("kind")),
                     Make_Defining_Identifier (Type_Kind)),
                  XTN.Items (Type_Node));

302
               Append_Node_To_List (Type_Node, XTN.Subitems (Feature_Node));
303
304
305
306
307
308
309
310
311
312
313
314
315
            end;

            --  Classifier

            declare
               Classifier_Node : Node_Id;
            begin
               Classifier_Node := Make_XML_Node ("classifier");
               Append_Node_To_List
                 (Make_Defining_Identifier
                    (Display_Name (Identifier (Corresponding_Instance (F)))),
                  XTN.Subitems (Classifier_Node));
               Append_Node_To_List
316
317
                 (Classifier_Node,
                  XTN.Subitems (Feature_Node));
318
319
320
321
322
323
324
325
326
327
328
329
            end;

            Append_Node_To_List (Feature_Node, XTN.Subitems (Features_Node));
            F := Next_Node (F);
         end loop;
      end if;

      --  Subcomponents

      Subcomponents_Node := Make_XML_Node ("subcomponents");
      Append_Node_To_List (Subcomponents_Node, XTN.Subitems (N));

330
      Old_XML_Node     := Current_XML_Node;
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
      Current_XML_Node := Subcomponents_Node;
      Visit_Subcomponents_Of (E);
      Current_XML_Node := Old_XML_Node;

      --  Properties

      Properties_Node := Make_XML_Node ("properties");
      Append_Node_To_List (Properties_Node, XTN.Subitems (N));

      if Present (Properties (E)) then
         F := First_Node (Properties (E));
         while Present (F) loop
            --  XXX Warning, if there are multiple values for a
            --  property (e.g. because of inheritance), then all
            --  values are dumped.

            Property_Node := Make_XML_Node ("property");

            Append_Node_To_List
              (Make_Assignement
                 (Make_Defining_Identifier (Get_String_Name ("name")),
352
                  Make_Defining_Identifier (Display_Name (Identifier (F)))),
353
354
355
356
               XTN.Items (Property_Node));

            Property_Value_Node := Make_XML_Node ("property_value");
            Append_Node_To_List
357
358
              (Property_Value_Node,
               XTN.Subitems (Property_Node));
359

360
361
            AADL_Property_Value :=
              Get_Value_Of_Property_Association (E, Name (Identifier (F)));
362
363

            if Present (AADL_Property_Value)
364
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Signed_AADLNumber
365
366
367
368
369
370
371
372
373
374
              and then Present (ATN.Unit_Identifier (AADL_Property_Value))
            then
               --  This property value denotes a property with a unit
               --  identifier.

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("unit");
                  Append_Node_To_List
375
376
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("value")),
                        Make_Defining_Identifier
                          (Get_String_Name
                             (Ocarina.AADL_Values.Image
                                (ATN.Value
                                   (ATN.Number_Value
                                      (AADL_Property_Value)))))),
                     XTN.Items (Unit_Node));

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("unit")),
                        Make_Defining_Identifier
                          (ATN.Display_Name
394
                             (ATN.Unit_Identifier (AADL_Property_Value)))),
395
396
397
398
                     XTN.Items (Unit_Node));
               end;

            elsif Present (AADL_Property_Value)
399
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Signed_AADLNumber
400
401
402
403
404
405
406
407
408
409
              and then
              (not Present (ATN.Unit_Identifier (AADL_Property_Value)))
            then
               --  This property value denotes a property without unit

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("value");
                  Append_Node_To_List
410
411
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
412
413
414
415
416
417
418
419
420
421
422
423
424
425

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("value")),
                        Make_Defining_Identifier
                          (Get_String_Name
                             (Ocarina.AADL_Values.Image
                                (ATN.Value
                                   (ATN.Number_Value
                                      (AADL_Property_Value)))))),
                     XTN.Items (Unit_Node));
               end;

            elsif Present (AADL_Property_Value)
426
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Literal
427
428
429
430
431
432
433
434
            then
               --  This property value denotes a literal

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("value");
                  Append_Node_To_List
435
436
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
437
438
439
440
441
442
443
444
445
446
447
448
449

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("value")),
                        Make_Defining_Identifier
                          (Get_String_Name
                             (Ocarina.AADL_Values.Image
                                (ATN.Value (AADL_Property_Value),
                                 Quoted => False)))),
                     XTN.Items (Unit_Node));
               end;

            elsif Present (AADL_Property_Value)
450
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Reference_Term
451
452
453
454
455
456
457
458
            then
               --  This property value denotes a reference term

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("reference");
                  Append_Node_To_List
459
460
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
461
462
463
464
465
466
467
468
469
470
471
472
473
474

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("value")),
                        Make_Defining_Identifier
                          (ATN.Display_Name
                             (ATN.First_Node --  XXX must iterate
                                (ATN.List_Items
                                   (ATN.Reference_Term
                                      (AADL_Property_Value)))))),
                     XTN.Items (Unit_Node));
               end;

            elsif Present (AADL_Property_Value)
475
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Enumeration_Term
476
            then
477
               --  This property value denotes an enumeration term
478
479
480
481
482
483

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("value");
                  Append_Node_To_List
484
485
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
486
487
488
489
490

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier (Get_String_Name ("value")),
                        Make_Defining_Identifier
491
492
                          (ATN.Display_Name
                             (ATN.Identifier (AADL_Property_Value)))),
493
494
495
496
                     XTN.Items (Unit_Node));
               end;

            elsif Present (AADL_Property_Value)
497
              and then ATN.Kind (AADL_Property_Value) = ATN.K_Number_Range_Term
498
            then
499
               --  This property value denotes a number range term
500
501
502
503
504
505

               declare
                  Unit_Node : Node_Id;
               begin
                  Unit_Node := Make_XML_Node ("range");
                  Append_Node_To_List
506
507
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier
                          (Get_String_Name ("value_low")),
                        Make_Defining_Identifier
                          (Get_String_Name
                             (Ocarina.AADL_Values.Image
                                (ATN.Value
                                   (ATN.Number_Value
                                      (ATN.Lower_Bound
                                         (AADL_Property_Value))))))),
                     XTN.Items (Unit_Node));

                  Append_Node_To_List
                    (Make_Assignement
                       (Make_Defining_Identifier
                          (Get_String_Name ("value_high")),
                        Make_Defining_Identifier
                          (Get_String_Name
                             (Ocarina.AADL_Values.Image
                                (ATN.Value
                                   (ATN.Number_Value
531
                                      (ATN.Upper_Bound
532
533
534
                                         (AADL_Property_Value))))))),
                     XTN.Items (Unit_Node));

535
536
537
                  if Present
                      (ATN.Unit_Identifier
                         (ATN.Lower_Bound (AADL_Property_Value)))
538
539
540
541
542
543
544
                  then
                     Append_Node_To_List
                       (Make_Assignement
                          (Make_Defining_Identifier (Get_String_Name ("unit")),
                           Make_Defining_Identifier
                             (ATN.Display_Name
                                (ATN.Unit_Identifier
545
                                   (ATN.Lower_Bound (AADL_Property_Value))))),
546
547
548
549
550
551
552
553
554
555
                        XTN.Items (Unit_Node));
                  end if;
               end;

            elsif Present (AADL_Property_Value) then
               --  XXX ICE

               declare
                  Unit_Node : Node_Id;
               begin
556
557
                  Unit_Node :=
                    Make_XML_Node (ATN.Kind (AADL_Property_Value)'Img);
558
                  Append_Node_To_List
559
560
                    (Unit_Node,
                     XTN.Subitems (Property_Value_Node));
561
562
563
564
               end;
            end if;

            Append_Node_To_List
565
566
              (Property_Node,
               XTN.Subitems (Properties_Node));
567
568
569
570
571
572
573
574
575
576
577
            F := Next_Node (F);
         end loop;
      end if;

      if Category = CC_System then
         Pop_Entity;
         Pop_Entity; --  A
      end if;
   end Visit_Component;

end Ocarina.Backends.AADL_XML.Main;