ocarina-instances-properties.adb 34 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--         O C A R I N A . I N S T A N C E S . P R O P E R T I E S          --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2005-2010, European Space Agency (ESA).           --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
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
--                                                                          --
-- 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.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with Locations;

with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Entities;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Nutils;

with Ocarina.Instances.Components;
with Ocarina.Instances.Components.Subprogram_Calls;
with Ocarina.Instances.Components.Modes;
with Ocarina.Instances.Messages;
with Ocarina.Instances.Finder;

package body Ocarina.Instances.Properties is

   use Locations;

   use Ocarina.ME_AADL.AADL_Tree.Nodes;
   use Ocarina.ME_AADL.AADL_Tree.Entities;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.ME_AADL.AADL_Tree.Nutils;

   use Ocarina.Instances.Components;
   use Ocarina.Instances.Components.Subprogram_Calls;
   use Ocarina.Instances.Components.Modes;
   use Ocarina.Instances.Messages;
   use Ocarina.Instances.Finder;

   package ATN  renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package AIN  renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package ATE  renames Ocarina.ME_AADL.AADL_Tree.Entities;
   package AIE  renames Ocarina.ME_AADL.AADL_Instances.Entities;

   function Duplicate_Property_Value
     (Instance_Root                  : Node_Id;
      Property_Value                 : Node_Id;
      Instance                       : Node_Id;
      Former_Property_Instance_Value : Node_Id := No_Node)
     return Node_Id;

   function Instantiate_Property_Value
     (Instance_Root  : Node_Id;
      Property_Value : Node_Id;
      Instance       : Node_Id)
     return Node_Id;

   function Instantiate_Reference_Term
     (Instance_Root      : Node_Id;
      Reference_Instance : Node_Id;
      Reference_Term     : Node_Id)
     return Node_Id;
   pragma Unreferenced (Instantiate_Reference_Term);
   --  Return an equivalent of Path, but containing instances instead
   --  of declarations.

   ----------------------
   -- Apply_Properties --
   ----------------------

   function Apply_Properties
     (Instance_Root : Node_Id;
      Instance      : Node_Id;
      Property_List : List_Id;
      Override_Mode : Boolean)
     return Boolean
   is
      pragma Assert (Kind (Instance_Root) = K_Architecture_Instance);
      pragma Assert (Present (Instance));

      Property_List_Node : Node_Id;
      Success            : Boolean := True;
   begin
      --  We then apply the attached properties

      if Property_List /= No_List then
         Property_List_Node := ATN.First_Node (Property_List);

         while Present (Property_List_Node) loop
            Success := Add_Property_Instance
              (Instance_Root, Instance, Property_List_Node, Override_Mode)
              and then Success;

            Property_List_Node := ATN.Next_Node (Property_List_Node);
         end loop;
      end if;

      return Success;
   end Apply_Properties;

   ---------------------------
   -- Add_Property_Instance --
   ---------------------------

   function Add_Property_Instance
     (Instance_Root        : Node_Id;
      Entity_Instance      : Node_Id;
      Property_Association : Node_Id;
      Override_Mode        : Boolean)
     return Boolean
   is
      pragma Assert
        (Kind (Entity_Instance) = K_Component_Instance
140
141
142
143
144
145
146
147
           or else Kind (Entity_Instance) = K_Port_Spec_Instance
           or else Kind (Entity_Instance) = K_Feature_Group_Spec_Instance
           or else Kind (Entity_Instance) = K_Parameter_Instance
           or else Kind (Entity_Instance) = K_Subcomponent_Access_Instance
           or else Kind (Entity_Instance) = K_Subcomponent_Instance
           or else Kind (Entity_Instance) = K_Subprogram_Spec_Instance
           or else Kind (Entity_Instance) = K_Connection_Instance
           or else Kind (Entity_Instance) = K_Mode_Instance);
148
149
150
151

      Property_Instance : Node_Id;
      Pointed_Instance  : Node_Id;
      Success           : Boolean := True;
hugues.jerome's avatar
hugues.jerome committed
152

153
154
155
156
157
158
159
160
161
162
   begin
      --  We first find the instance on which the property applies

      Pointed_Instance := Find_Instance
        (Instance_Root,
         Entity_Instance,
         ATN.Applies_To_Prop (Property_Association));

      if Present (Pointed_Instance) then
         if Ocarina.ME_AADL.AADL_Instances.Nodes.Properties
hugues.jerome's avatar
hugues.jerome committed
163
164
           (Pointed_Instance) = No_List
         then
165
166
167
168
169
170
171
172
173
174
175
            AIN.Set_Properties (Pointed_Instance,
                                AINU.New_List (K_List_Id, No_Location));
         end if;

         --  We then check if the property is already set in the pointed
         --  instance

         Property_Instance := Get_First_Homonym_Instance
           (AIN.Properties (Pointed_Instance),
            Property_Association);

hugues.jerome's avatar
hugues.jerome committed
176
177
         if Present (Property_Instance)
           and then ATN.Is_Additive_Association (Property_Association)
178
179
180
181
182
183
184
185
186
187
         then
            --  Append the current value to the old value list

            AIN.Set_Property_Association_Value
                 (Property_Instance,
                  Duplicate_Property_Value
                  (Instance_Root,
                   ATN.Property_Association_Value (Property_Association),
                   Entity_Instance,
                   ATN.Property_Association_Value (Property_Instance)));
hugues.jerome's avatar
hugues.jerome committed
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
         else
            Property_Instance := AINU.New_Node
              (K_Property_Association_Instance,
               ATN.Loc (Property_Association));
            AIN.Set_Identifier (Property_Instance,
                                AIE.Duplicate_Identifier (ATN.Identifier
                                                      (Property_Association)));
            AIN.Set_Corresponding_Entity (AIN.Identifier (Property_Instance),
                                          Property_Instance);
            AIN.Set_Corresponding_Declaration (Property_Instance,
                                               Property_Association);
            AIN.Set_Property_Name (Property_Instance,
                               ATN.Property_Name (Property_Association));
            AIN.Set_Is_Additive_Association
              (Property_Instance,
               ATN.Is_Additive_Association (Property_Association));
            AIN.Set_Is_Constant (Property_Instance,
                             ATN.Is_Constant (Property_Association));
            AIN.Set_Is_Private (Property_Instance,
                                ATN.Is_Private (Property_Association));
            AIN.Set_Is_Access (Property_Instance,
                           ATN.Is_Access (Property_Association));
            AIN.Set_Applies_To_Prop (Property_Instance, No_List);
            AIN.Set_In_Binding (Property_Instance,
                            ATN.In_Binding (Property_Association));

            --  Instantiate property "in modes". The fact that a property
            --  association of a mode has an "in modes" clause, has
            --  absolutely no sense. It should have been detected as
            --  error during analysis.

            declare
               Container_Component : Node_Id := No_Node;
            begin
               --  The modes belong to the container component
               --  implementation.

               case AIN.Kind (Entity_Instance) is
                  when K_Component_Instance =>
                     Container_Component := Entity_Instance;

                  when K_Port_Spec_Instance |
                    K_Feature_Group_Spec_Instance |
                    K_Parameter_Instance |
                    K_Subcomponent_Access_Instance |
                    K_Subprogram_Spec_Instance |
                    K_Connection_Instance =>
                     Container_Component := Parent_Component (Entity_Instance);

                  when others =>
                     null;
               end case;

               --  Workaround to fetch the in_modes of the original
               --  property association since there is no
               --  property_association_instance node kind.

               AIN.Set_In_Modes (Property_Instance,
                                 ATN.In_Modes (Property_Association));

               if Present (Container_Component) then
                  Instantiate_In_Modes
hugues.jerome's avatar
hugues.jerome committed
251
                    (Container_Component, Property_Instance);
252
253
254
               end if;
            end;

hugues.jerome's avatar
hugues.jerome committed
255
256
            if Present
              (ATN.Property_Association_Value (Property_Association)) then
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
               AIN.Set_Property_Association_Value
                 (Property_Instance,
                  Duplicate_Property_Value
                  (Instance_Root,
                   ATN.Property_Association_Value (Property_Association),
                   Entity_Instance));

               --  IMPORTANT: we use entity instance where the property
               --  has been declared, as the reference node to
               --  duplicate the property, and not pointed_instance,
               --  which is the node on which the property
               --  applies. Indeed, for properties that are
               --  references, the reference path is set from
               --  entity_instance.
            end if;

            if Override_Mode then
               --  Append the node to the BEGINNING of the property list
               --  of the instance so that properties that are declared
               --  for subcomponents override the properties that are
               --  declared for the corresponding components.

hugues.jerome's avatar
hugues.jerome committed
279
280
281
               --  XXX looks strange: why relying on order ? should
               --  _remove_ the property from the list instead

282
283
284
               AINU.Push_Node_To_List
                 (Property_Instance,
                  AIN.Properties (Pointed_Instance));
hugues.jerome's avatar
hugues.jerome committed
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
            else
               AINU.Append_Node_To_List
                (Property_Instance,
                 AIN.Properties (Pointed_Instance));
            end if;
         end if;
      else
         Display_Instantiation_Error (Property_Association);
         Success := False;
      end if;

      return Success;
   end Add_Property_Instance;

   -------------------------------
   -- Replace_Property_Instance --
   -------------------------------

   function Replace_Property_Instance
     (Instance_Root        : Node_Id;
      Entity_Instance      : Node_Id;
      Property_Association : Node_Id;
      Override_Mode        : Boolean)
     return Boolean
   is
      pragma Assert
        (Kind (Entity_Instance) = K_Component_Instance
         or else Kind (Entity_Instance) = K_Port_Spec_Instance
         or else Kind (Entity_Instance) = K_Feature_Group_Spec_Instance
         or else Kind (Entity_Instance) = K_Parameter_Instance
         or else Kind (Entity_Instance) = K_Subcomponent_Access_Instance
         or else Kind (Entity_Instance) = K_Subprogram_Spec_Instance
         or else Kind (Entity_Instance) = K_Connection_Instance
         or else Kind (Entity_Instance) = K_Mode_Instance);

      pragma Assert (AIN.Kind (Property_Association)
                       = K_Property_Association_Instance);

      Property_Instance : Node_Id;
      Pointed_Instance  : Node_Id;
      Success           : Boolean := True;
   begin
      --  We first find the instance on which the property applies

      Pointed_Instance := Find_Instance_In_Instance
        (Instance_Root,
         Entity_Instance,
         AIN.Applies_To_Prop (Property_Association));

      if Present (Pointed_Instance) then
         if Ocarina.ME_AADL.AADL_Instances.Nodes.Properties
           (Pointed_Instance) = No_List then
            AIN.Set_Properties (Pointed_Instance,
                                AINU.New_List (K_List_Id, No_Location));
         end if;

         --  We then check if the property is already set in the pointed
         --  instance

         Property_Instance := Get_First_Homonym_Instance
           (AIN.Properties (Pointed_Instance),
            AIE.Get_Name_Of_Entity (Property_Association, False));

         if Present (Property_Instance) and then
           AIN.Is_Additive_Association (Property_Association)
         then
            --  Append the current value to the old value list

            AIN.Set_Property_Association_Value
                 (Property_Instance,
                  Duplicate_Property_Value
                  (Instance_Root,
                   AIN.Property_Association_Value (Property_Association),
                   Entity_Instance,
                   AIN.Property_Association_Value (Property_Instance)));
hugues.jerome's avatar
hugues.jerome committed
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
         else
            Property_Instance := AINU.New_Node
              (K_Property_Association_Instance,
               ATN.Loc (Property_Association));
            --  XXX TODO CRAP Must Duplicate_Identifier
            AIN.Set_Identifier (Property_Instance,
                                AIN.Identifier (Property_Association));

            AIN.Set_Corresponding_Entity (AIN.Identifier (Property_Instance),
                                          Property_Instance);
            AIN.Set_Corresponding_Declaration (Property_Instance,
                                               Property_Association);
            AIN.Set_Property_Name (Property_Instance,
                               AIN.Property_Name (Property_Association));
            AIN.Set_Is_Additive_Association
              (Property_Instance,
               AIN.Is_Additive_Association (Property_Association));
            AIN.Set_Is_Constant (Property_Instance,
                             AIN.Is_Constant (Property_Association));
            AIN.Set_Is_Private (Property_Instance,
                                AIN.Is_Private (Property_Association));
            AIN.Set_Is_Access (Property_Instance,
                           AIN.Is_Access (Property_Association));
            AIN.Set_Applies_To_Prop (Property_Instance, No_List);
            AIN.Set_In_Binding (Property_Instance,
                            AIN.In_Binding (Property_Association));

            --  Instantiate property "in modes". The fact that a property
            --  association of a mode has an "in modes" clause, has
            --  absolutely no sense. It should have been detected as
            --  error during analysis.

            declare
               Container_Component : Node_Id := No_Node;
            begin
               --  The modes belong to the container component
               --  implementation.

               case AIN.Kind (Entity_Instance) is
                  when K_Component_Instance =>
                     Container_Component := Entity_Instance;

                  when K_Port_Spec_Instance |
                    K_Feature_Group_Spec_Instance |
                    K_Parameter_Instance |
                    K_Subcomponent_Access_Instance |
                    K_Subprogram_Spec_Instance |
                    K_Connection_Instance =>
                     Container_Component := Parent_Component (Entity_Instance);

                  when others =>
                     null;
               end case;

               --  Workaround to fetch the in_modes of the original
               --  property association scince there is no
               --  property_association_instance node kind.

               AIN.Set_In_Modes (Property_Instance,
                                 AIN.In_Modes (Property_Association));

               if Present (Container_Component) then
                  Instantiate_In_Modes
                    (Container_Component,
                     Property_Instance);
               end if;
            end;

            if Present (AIN.Property_Association_Value
                          (Property_Association)) then
               AIN.Set_Property_Association_Value
                 (Property_Instance,
                  Duplicate_Property_Value
                  (Instance_Root,
                   AIN.Property_Association_Value (Property_Association),
                   Entity_Instance));

               --  IMPORTANT: we use entity instance where the property
               --  has been declared, as the reference node to
               --  duplicate the property, and not pointed_instance,
               --  which is the node on which the property
               --  applies. Indeed, for properties that are
               --  references, the reference path is set from
               --  entity_instance.
            end if;

            if Override_Mode then
               --  Append the node to the BEGINNING of the property list
               --  of the instance so that properties that are declared
               --  for subcomponents override the properties that are
               --  declared for the corresponding components.

               AINU.Push_Node_To_List
                 (Property_Instance,
                  AIN.Properties (Pointed_Instance));
            else
               AINU.Append_Node_To_List
                (Property_Instance,
                 AIN.Properties (Pointed_Instance));
            end if;
         end if;
      else
         Display_Instantiation_Error (Property_Association);
         Success := False;
      end if;

      return Success;
   end Replace_Property_Instance;

   ------------------------------
   -- Duplicate_Property_Value --
   ------------------------------

   function Duplicate_Property_Value
     (Instance_Root                  : Node_Id;
      Property_Value                 : Node_Id;
      Instance                       : Node_Id;
      Former_Property_Instance_Value : Node_Id := No_Node)
     return Node_Id
   is
      pragma Assert (No (Property_Value)
                     or else Kind (Property_Value) = K_Property_Value);
      pragma Assert
        (No (Former_Property_Instance_Value)
         or else No (Single_Value (Former_Property_Instance_Value)));
      --  If we are extending a former property value, this one must
      --  be a list.

      Duplicated_Property_Value : Node_Id;
      List_Node                 : Node_Id;
   begin
      if No (Former_Property_Instance_Value) then
         if No (Property_Value) then
            Duplicated_Property_Value := No_Node;

         else
            Duplicated_Property_Value := New_Node
              (K_Property_Value,
               ATN.Loc (Property_Value));

            if Present (Single_Value (Property_Value)) then
               --  We set the value calculated at analysis time

               Set_Single_Value
                 (Duplicated_Property_Value,
                  Instantiate_Property_Value
                  (Instance_Root,
                   Expanded_Single_Value (Property_Value),
                   Instance));
               Set_Expanded_Single_Value
                 (Duplicated_Property_Value,
                  Single_Value (Duplicated_Property_Value));
            end if;

            if Multi_Value (Property_Value) /= No_List then
               --  We set the value calculated at analysis time

               Set_Multi_Value
                 (Duplicated_Property_Value,
                  New_List
                  (K_List_Id,
                   ATN.Loc (Node_Id (Multi_Value (Property_Value)))));
               Set_Expanded_Multi_Value
                 (Duplicated_Property_Value,
                  Multi_Value (Duplicated_Property_Value));

               List_Node := ATN.First_Node (Expanded_Multi_Value
                                              (Property_Value));

               while Present (List_Node) loop
                  Append_Node_To_List (Instantiate_Property_Value
                                       (Instance_Root,
                                        List_Node,
                                        Instance),
                                       Multi_Value
                                       (Duplicated_Property_Value));
                  List_Node := ATN.Next_Node (List_Node);
               end loop;
            end if;
         end if;
hugues.jerome's avatar
hugues.jerome committed
542

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
      else
         --  We first duplicate the values of the former property
         --  association.

         Duplicated_Property_Value := New_Node
           (K_Property_Value,
            ATN.Loc (Property_Value));

         Set_Multi_Value
           (Duplicated_Property_Value,
            New_List
            (K_List_Id,
             ATN.Loc (Node_Id (Multi_Value (Property_Value)))));
         Set_Expanded_Multi_Value
           (Duplicated_Property_Value,
            Multi_Value (Duplicated_Property_Value));

         List_Node := ATN.First_Node
           (Multi_Value (Former_Property_Instance_Value));

         while Present (List_Node) loop
            Append_Node_To_List
              (Instantiate_Property_Value
               (Instance_Root,
                List_Node,
                Instance),
               Multi_Value
               (Duplicated_Property_Value));
            List_Node := ATN.Next_Node (List_Node);
         end loop;

         --  Then, we append the new values

         if Present (Single_Value (Property_Value)) then
            Append_Node_To_List
              (Instantiate_Property_Value
               (Instance_Root,
                Single_Value (Property_Value),
                Instance),
               Multi_Value (Duplicated_Property_Value));

         elsif Multi_Value (Property_Value) /= No_List then
            List_Node := ATN.First_Node (Multi_Value (Property_Value));

            while Present (List_Node) loop
               Append_Node_To_List (Instantiate_Property_Value
                                    (Instance_Root,
                                     List_Node,
                                     Instance),
                                    Multi_Value (Duplicated_Property_Value));
               List_Node := ATN.Next_Node (List_Node);
            end loop;
         end if;
      end if;

      Set_Value_Container (Duplicated_Property_Value, Instance);
      --  The container of the property is the instance in which it is
      --  declared. This way, we know in what context we have to
      --  evaluate its value.

      return Duplicated_Property_Value;
   end Duplicate_Property_Value;

   --------------------------------
   -- Instantiate_Property_Value --
   --------------------------------

   function Instantiate_Property_Value
     (Instance_Root  : Node_Id;
      Property_Value : Node_Id;
      Instance       : Node_Id)
     return Node_Id
   is
      pragma Assert
        (No (Property_Value)
         or else Kind (Property_Value) = K_Literal
         or else Kind (Property_Value) = K_Property_Term
         or else Kind (Property_Value) = K_Enumeration_Term
         or else Kind (Property_Value) = K_Number_Range_Term
         or else Kind (Property_Value) = K_Reference_Term
         or else Kind (Property_Value) = K_Minus_Numeric_Term
         or else Kind (Property_Value) = K_Signed_AADLNumber
         or else Kind (Property_Value) = K_Not_Boolean_Term
         or else Kind (Property_Value) = K_And_Boolean_Term
         or else Kind (Property_Value) = K_Or_Boolean_Term
         or else Kind (Property_Value) = K_Parenthesis_Boolean_Term
         or else Kind (Property_Value) = K_Component_Classifier_Term);
      pragma Assert (Present (Instance));

      Instantiated_Value : Node_Id := No_Node;
      List_Node : Node_Id := No_Node;
      Node : Node_Id;

   begin
637
638
639
640
641
      if No (Property_Value) then
         --  If there is no property value defined, simply return
         return Instantiated_Value;
      end if;

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
      case ATN.Kind (Property_Value) is
         when K_Literal =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Value (Instantiated_Value, Value (Property_Value));

         when K_Property_Term | K_Enumeration_Term =>

            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            ATN.Set_Identifier (Instantiated_Value,
                                ATE.Duplicate_Identifier
                                  (ATN.Identifier (Property_Value)));
            Set_Entity (Instantiated_Value, Entity (Property_Value));
            Set_Property_Set_Identifier (Instantiated_Value,
                                         Property_Set_Identifier
                                           (Property_Value));

         when K_Number_Range_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Lower_Bound (Instantiated_Value, Lower_Bound (Property_Value));
            Set_Upper_Bound (Instantiated_Value, Upper_Bound (Property_Value));
            Set_Delta_Term (Instantiated_Value, Delta_Term (Property_Value));

         when K_Reference_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Node := New_Node (Kind (Reference_Term (Property_Value)),
                              ATN.Loc (Reference_Term (Property_Value)));

            case AADL_Version is
               when AADL_V1 =>
                  --  Node is an Entity_Reference

                  ATN.Set_Path (Node, ATN.Path (Reference_Term
                                                 (Property_Value)));
                  ATN.Set_Identifier (Node,
                                      ATE.Duplicate_Identifier
                                        (ATN.Identifier (Reference_Term
                                                         (Property_Value))));

               when AADL_V2 =>
hugues.jerome's avatar
hugues.jerome committed
685
                  --  Node is a Contained_Element_Path
686
687
688
689
690
691
692

                  Set_List_Items (Node,
                                  New_List (K_List_Id,
                                            ATN.Loc (Node_Id
                                                      (List_Items
                                                        (Reference_Term
                                                         (Property_Value))))));
hugues.jerome's avatar
hugues.jerome committed
693

694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
                  if  List_Items (Reference_Term
                                    (Property_Value)) /= No_List
                  then
                     List_Node := ATN.First_Node (List_Items
                                                   (Reference_Term
                                                     (Property_Value)));

                     while Present (List_Node) loop
                        Append_Node_To_List (ATE.Duplicate_Identifier
                                               (List_Node),
                                             List_Items (Node));
                        List_Node := ATN.Next_Node (List_Node);
                     end loop;
                  end if;

                  --  XXX TODO INSTANCIATE ANNEX_PATH NODE
            end case;
hugues.jerome's avatar
hugues.jerome committed
711

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
            Set_Reference_Term (Instantiated_Value, Node);

         when K_Minus_Numeric_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Numeric_Term (Instantiated_Value,
                              Numeric_Term (Property_Value));

         when K_Signed_AADLNumber =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Number_Value (Instantiated_Value,
                              Number_Value (Property_Value));
            Set_Unit_Identifier (Instantiated_Value,
                                 Unit_Identifier (Property_Value));

         when K_And_Boolean_Term | K_Or_Boolean_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_First_Term (Instantiated_Value,
                            Instantiate_Property_Value
                            (Instance_Root,
                             First_Term (Property_Value),
                             Instance));
            Set_Second_Term (Instantiated_Value,
                             Instantiate_Property_Value
                             (Instance_Root,
                              Second_Term (Property_Value),
                              Instance));

         when K_Not_Boolean_Term | K_Parenthesis_Boolean_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Boolean_Term (Instantiated_Value,
                              Instantiate_Property_Value
                              (Instance_Root,
                               Boolean_Term (Property_Value),
                               Instance));

         when K_Component_Classifier_Term =>
            Instantiated_Value := New_Node (Kind (Property_Value),
                                            ATN.Loc (Property_Value));
            Set_Referenced_Entity
              (Instantiated_Value,
               Instantiate_Component
               (Instance_Root,
                ATE.Get_Referenced_Entity (Property_Value)));
759

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
            Set_Component_Cat (Instantiated_Value,
                               Component_Cat (Property_Value));

         when others =>
            raise Program_Error;
      end case;

      return Instantiated_Value;
   end Instantiate_Property_Value;

   --------------------------------
   -- Instantiate_Reference_Term --
   --------------------------------

   function Instantiate_Reference_Term
     (Instance_Root      : Node_Id;
      Reference_Instance : Node_Id;
      Reference_Term     : Node_Id)
     return Node_Id
   is
      pragma Assert (Kind (Instance_Root) = K_Architecture_Instance);
      pragma Assert (Present (Reference_Instance));
      pragma Assert
        (Kind (Reference_Instance) = K_Component_Instance
         or else Kind (Reference_Instance) = K_Subcomponent_Instance);

      List_Node              : Node_Id;
      Identifier_Of_Instance : Node_Id;
      Pointed_Instance       : Node_Id;
      New_Reference_Term     : constant Node_Id := New_Node
        (K_Reference_Term, ATN.Loc (Reference_Term));
      Initial_Path           : constant List_Id := ATN.Path (Reference_Term);
   begin
      --  The instantiation of a reference path returns a path that leads
      --  to the component instance, while the reference path itself
      --  was likely to point to a subcomponent or a subprogram,
      --  etc. which was associated to a component declaration.

      if Initial_Path = No_List then
         ATN.Set_Path (New_Reference_Term, No_List);
      else
         if Kind (Reference_Instance) = K_Component_Instance then
            Pointed_Instance := Reference_Instance;
         else
            Pointed_Instance := Corresponding_Instance (Reference_Instance);
         end if;

         List_Node := ATN.First_Node (Initial_Path);

         while Present (List_Node) loop
            pragma Assert (ATN.Kind (ATN.Item (List_Node)) = K_Identifier);

            Pointed_Instance := Find_Local_Instance
              (Pointed_Instance, ATN.Item (List_Node));

            if No (Pointed_Instance) then
               ATN.Set_Path (New_Reference_Term, No_List);
               exit;

            elsif Kind (Pointed_Instance) = K_Call_Instance then
               Pointed_Instance := Corresponding_Instance (Pointed_Instance);
               Identifier_Of_Instance :=
                 AIE.Duplicate_Identifier (AIN.Identifier (Pointed_Instance));
               AIE.Add_Path_Element_To_Entity_Reference
                 (New_Reference_Term, Identifier_Of_Instance);
               Pointed_Instance := Duplicate_Subprogram_Call_Instance
                 (Instance_Root, Pointed_Instance);

            elsif Kind (Pointed_Instance) = K_Subcomponent_Instance then
               Pointed_Instance := Corresponding_Instance (Pointed_Instance);
               Identifier_Of_Instance :=
                 AIE.Duplicate_Identifier (AIN.Identifier (Pointed_Instance));
               AIE.Add_Path_Element_To_Entity_Reference
                 (New_Reference_Term, Identifier_Of_Instance);
            end if;

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

      return New_Reference_Term;
   end Instantiate_Reference_Term;

end Ocarina.Instances.Properties;