ocarina-analyzer-aadl-queries.adb 32.4 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--        O C A R I N A . A N A L Y Z E R . A A D L . Q U E R I E S         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2009-2011, 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
--                                                                          --
-- 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 GNAT.Table;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Entities;
with Ocarina.ME_AADL.AADL_Tree.Entities.Properties;
40
with Locations;
41
42
43
44
45
46
47
48
49
50
51
52
with Ocarina.Annotations;

package body Ocarina.Analyzer.AADL.Queries is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Tree.Nodes;
   use Ocarina.ME_AADL.AADL_Tree.Entities;
   use Ocarina.ME_AADL.AADL_Tree.Entities.Properties;
   use Ocarina.Annotations;

   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;

hugues.jerome's avatar
hugues.jerome committed
53
   function Get_Category_Of_Entity (Entity : Node_Id) return Named_Element;
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

   ----------------------------
   -- Compute_Property_Value --
   ----------------------------

   function Compute_Property_Value (Property_Value : Node_Id) return Node_Id is

      pragma Assert (Kind (Property_Value) = K_Property_Value);

      Property_Expression : Node_Id;
   begin
      if Expanded_Single_Value (Property_Value) /= No_Node then
         Property_Expression := Expanded_Single_Value (Property_Value);
      elsif Expanded_Multi_Value (Property_Value) /= No_List then
         Property_Expression :=
           First_Node (Expanded_Multi_Value (Property_Value));
      elsif Single_Value (Property_Value) /= No_Node then
         Property_Expression := Single_Value (Property_Value);
      elsif Multi_Value (Property_Value) /= No_List then
         Property_Expression := First_Node (Multi_Value (Property_Value));
      else
         Property_Expression := No_Node;
      end if;

      return Property_Expression;
   end Compute_Property_Value;

   ------------------------------
   -- Get_Property_Association --
   ------------------------------

   function Get_Property_Association
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Node_Id
   is
   begin
      return Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
         In_Mode       => In_Mode);
   end Get_Property_Association;

   --------------------------
   -- Get_Boolean_Property --
   --------------------------

   function Get_Boolean_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Boolean
         then
            return Get_Boolean_Of_Property_Value (Property_Value);
         else
            return False;
         end if;
      else
         return False;
      end if;
   end Get_Boolean_Property;

   ----------------------------
   -- Get_Category_Of_Entity --
   ----------------------------

hugues.jerome's avatar
hugues.jerome committed
130
   function Get_Category_Of_Entity (Entity : Node_Id) return Named_Element is
131
      pragma Assert (Present (Entity));
hugues.jerome's avatar
hugues.jerome committed
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
   begin
      case Kind (Entity) is
         when K_Component_Type
           | K_Component_Implementation
           | K_Subcomponent
           | K_Subcomponent_Access =>
            return PO_Component_Category;

         when K_Mode =>
            return PO_Mode;

         when K_Feature_Group_Type =>
            if AADL_Version = AADL_V1 then
               return PO_Port_Group;
            else
               return PO_Feature_Group;
            end if;

         when K_Flow_Spec
           | K_Flow_Implementation
           | K_End_To_End_Flow_Spec
           | K_Flow_Implementation_Refinement
           | K_End_To_End_Flow_Refinement =>
            return PO_Flow;

         when K_Port_Spec =>
            if Is_Event (Entity) and then Is_Data (Entity) then
               return PO_Event_Data_Port;
            elsif Is_Event (Entity) then
               return PO_Event_Port;
            else
               return PO_Data_Port;
            end if;

         when K_Parameter =>
            return PO_Parameter;

         when K_Subprogram_Spec =>
            if Is_Server (Entity) then
               return PO_Server_Subprogram;
            else
               return PO_Component_Category;
            end if;

         when K_Subprogram_Call =>
            return PO_Component_Category;

         when K_Connection =>
            case Get_Category_Of_Connection (Entity) is
               when CT_Error =>
                  raise Program_Error;
               when CT_Port_Connection =>
                  return PO_Data_Port_Connections;
                  --  XXX Incomplete TODO
               when CT_Data
                 | CT_Data_Delayed =>
                  return PO_Data_Port_Connections;
               when CT_Event =>
                  return PO_Event_Port_Connections;
               when CT_Event_Data =>
                  return PO_Event_Data_Port_Connections;
               when CT_Parameter =>
                  return PO_Parameter_Connections;
               when CT_Feature_Group =>
                  case AADL_Version is
                     when AADL_V1 =>
                        return PO_Port_Group_Connections;
                     when AADL_V2 =>
                        return PO_Feature_Group_Connection;
                  end case;
               when CT_Access_Bus
                 | CT_Access_Data
                 | CT_Access_Subprogram
                 | CT_Access_Subprogram_Group
207
208
                 | CT_Access_Virtual_Bus
                 | CT_Access =>
209
210
211
212
                  return PO_Access_Connection;
            end case;

         when others =>
213
214
            raise Program_Error with "Invalid kind " & Kind (Entity)'Img
              & " at " & Locations.Image (Loc (Entity));
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
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
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
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
      end case;
   end Get_Category_Of_Entity;

   ------------------------------
   -- Get_Enumeration_Property --
   ------------------------------

   function Get_Enumeration_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return String
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Enumeration
         then
            return Get_Enumeration_Of_Property_Value (Property_Value);
         else
            return "";
         end if;
      else
         return "";
      end if;
   end Get_Enumeration_Property;

   function Get_Enumeration_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Name_Id
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Enumeration
         then
            return Get_Enumeration_Of_Property_Value (Property_Value);
         else
            return No_Name;
         end if;
      else
         return No_Name;
      end if;
   end Get_Enumeration_Property;

   ------------------------
   -- Get_Float_Property --
   ------------------------

   function Get_Float_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Long_Long_Float
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value (Property_Value, True) = PT_Float
           or else Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Unsigned_Float
         then
            return Get_Float_Of_Property_Value (Property_Value);
         else
            return 0.0;
         end if;
      else
         return 0.0;
      end if;
   end Get_Float_Property;

   --------------------------
   -- Get_Integer_Property --
   --------------------------

   function Get_Integer_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Unsigned_Long_Long
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value (Property_Value, True) = PT_Integer
           or else Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Unsigned_Integer
         then
            return Get_Integer_Of_Property_Value (Property_Value);
         else
            return 0;
         end if;
      else
         return 0;
      end if;
   end Get_Integer_Property;

   ----------------------------
   -- Get_Reference_Property --
   ----------------------------

   function Get_Reference_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Node_Id
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Reference
         then
            return Get_Reference_Of_Property_Value (Property_Value);
         else
            return No_Node;
         end if;
      else
         return No_Node;
      end if;
   end Get_Reference_Property;

   -----------------------------
   -- Get_Classifier_Property --
   -----------------------------

   function Get_Classifier_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Node_Id
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value
           (Property_Value, True) = PT_Classifier
         then
            return Get_Classifier_Of_Property_Value (Property_Value);
         else
            return No_Node;
         end if;
      else
         return No_Node;
      end if;
   end Get_Classifier_Property;

   ------------------------
   -- Get_Range_Property --
   ------------------------

   function Get_Range_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Node_Id
   is
      Property : constant Node_Id := Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
         In_Mode       => In_Mode);
   begin

      if Property = No_Node then
         return No_Node;
      end if;

      if Get_Type_Of_Property (Property) /= PT_Range then
         return No_Node;
      end if;

      return Expanded_Single_Value (Property_Association_Value (Property));
   end Get_Range_Property;

   -----------------------
   -- Get_List_Property --
   -----------------------

   function Get_List_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return List_Id
   is
      Property : constant Node_Id := Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
         In_Mode       => In_Mode);
   begin
hugues.jerome's avatar
hugues.jerome committed
426
427
428
      if No (Property)
        or else not Type_Of_Property_Is_A_List
        (Get_Referenced_Entity (Property_Name (Property)))
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
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
637
638
639
640
641
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
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
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
      then
         return No_List;
      end if;

      return Expanded_Multi_Value (Property_Association_Value (Property));
   end Get_List_Property;

   -------------------------
   -- Get_String_Property --
   -------------------------

   function Get_String_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return String
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value (Property_Value, True) = PT_String then
            return Get_String_Of_Property_Value (Property_Value);
         else
            return "";
         end if;
      else
         return "";
      end if;
   end Get_String_Property;

   -------------------------
   -- Get_String_Property --
   -------------------------

   function Get_String_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Name_Id
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      if Property_Value /= No_Node then
         if Get_Type_Of_Property_Value (Property_Value, True) = PT_String then
            return Get_String_Of_Property_Value (Property_Value);
         else
            return No_Name;
         end if;
      else
         return No_Name;
      end if;
   end Get_String_Property;

   ---------------------------------------
   -- Get_Value_Of_Property_Association --
   ---------------------------------------

   function Get_Value_Of_Property_Association
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Node_Id
   is
      Property : constant Node_Id := Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
         In_Mode       => In_Mode);
   begin
      if Property /= No_Node then
         return Compute_Property_Value
           (Property_Association_Value (Property));
      else
         return No_Node;
      end if;
   end Get_Value_Of_Property_Association;

   ---------------------
   -- Is_An_Extension --
   ---------------------

   function Is_An_Extension
     (Component : Node_Id;
      Ancestor  : Node_Id)
     return Boolean
   is
      pragma Assert (Kind (Component) = K_Component_Implementation
                     or else Kind (Component) = K_Component_Type
                     or else Kind (Component) = K_Feature_Group_Type);

      pragma Assert (No (Ancestor)
                     or else Kind (Ancestor) = K_Component_Implementation
                     or else Kind (Ancestor) = K_Component_Type
                     or else Kind (Ancestor) = K_Feature_Group_Type);

      Temp_Node : Node_Id := Component;
      Type_Node : Node_Id := Component;
   begin
      if Ancestor = No_Node then
         return False;
      end if;

      while Temp_Node /= No_Node loop
         if Temp_Node = Ancestor then
            return True;

         elsif Kind (Component) = K_Component_Implementation then
            Type_Node := Corresponding_Entity
              (Component_Type_Identifier (Temp_Node));

            while Type_Node /= No_Node loop
               if Type_Node = Ancestor then
                  return True;
               end if;

               if Parent (Type_Node) /= No_Node then
                  Type_Node := Get_Referenced_Entity (Parent (Type_Node));
               else
                  Type_Node := No_Node;
               end if;
            end loop;
         end if;

         if Parent (Temp_Node) /= No_Node then
            Temp_Node := Get_Referenced_Entity (Parent (Temp_Node));
         else
            Temp_Node := No_Node;
         end if;
      end loop;

      return False;
   end Is_An_Extension;

   ---------------------------------
   -- Is_Defined_Boolean_Property --
   ---------------------------------

   function Is_Defined_Boolean_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        (Get_Type_Of_Property_Value (Property_Value, True) = PT_Boolean);
   end Is_Defined_Boolean_Property;

   -------------------------------------
   -- Is_Defined_Enumeration_Property --
   -------------------------------------

   function Is_Defined_Enumeration_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        Get_Type_Of_Property_Value (Property_Value, True) = PT_Enumeration;
   end Is_Defined_Enumeration_Property;

   -------------------------------
   -- Is_Defined_Float_Property --
   -------------------------------

   function Is_Defined_Float_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        (Get_Type_Of_Property_Value (Property_Value, True) = PT_Float
         or else Get_Type_Of_Property_Value (Property_Value, True) =
         PT_Unsigned_Float);
   end Is_Defined_Float_Property;

   ---------------------------------
   -- Is_Defined_Integer_Property --
   ---------------------------------

   function Is_Defined_Integer_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        (Get_Type_Of_Property_Value (Property_Value, True) = PT_Integer
         or else  Get_Type_Of_Property_Value (Property_Value, True) =
         PT_Unsigned_Integer);
   end Is_Defined_Integer_Property;

   -------------------------
   -- Is_Defined_Property --
   -------------------------

   function Is_Defined_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
   begin
      --  A property is defined if it exists and has a value

      return
        Get_Value_Of_Property_Association (Entity, Name, In_Mode) /= No_Node;
   end Is_Defined_Property;

   -----------------------------------
   -- Is_Defined_Reference_Property --
   -----------------------------------

   function Is_Defined_Reference_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        Get_Type_Of_Property_Value (Property_Value, True) = PT_Reference;
   end Is_Defined_Reference_Property;

   function Is_Defined_Classifier_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        Get_Type_Of_Property_Value (Property_Value, True) = PT_Classifier;
   end Is_Defined_Classifier_Property;

   -------------------------------
   -- Is_Defined_Range_Property --
   -------------------------------

   function Is_Defined_Range_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property : constant Node_Id := Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
         In_Mode       => In_Mode);
   begin
      return Present (Property) and then
        Get_Type_Of_Property_Value
        (Property_Association_Value (Property), True) = PT_Range;
   end Is_Defined_Range_Property;

   ------------------------------
   -- Is_Defined_List_Property --
   ------------------------------

   function Is_Defined_List_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      Property : constant Node_Id := Find_Property_Association_From_Name
        (Property_List => ATN.Properties (Entity),
         Property_Name => Name,
        In_Mode        => In_Mode);
   begin
      return Present (Property)
        and then Type_Of_Property_Is_A_List
        (Get_Referenced_Entity
         (Property_Name
          (Property)));
   end Is_Defined_List_Property;

   --------------------------------
   -- Is_Defined_String_Property --
   --------------------------------

   function Is_Defined_String_Property
     (Entity  : Node_Id;
      Name    : Name_Id;
      In_Mode : Name_Id := No_Name)
     return Boolean
   is
      pragma Assert (Present (Entity));

      Property_Value : Node_Id;
   begin
      Property_Value := Get_Value_Of_Property_Association
        (Entity, Name, In_Mode);

      return Present (Property_Value) and then
        Get_Type_Of_Property_Value (Property_Value, True) = PT_String;
   end Is_Defined_String_Property;

   ---------------
   -- Needed_By --
   ---------------

   function Needed_By (N : Node_Id; Entity : Node_Id) return Boolean is
      --  During the expansion phase, each component or property
      --  declaration is annotated with the components that need
      --  it. For exemple each AADL component C corresponding to a
      --  subcomponent S of another component D will be annotated with
      --  D. Therefore, D "needs" C.

      --  To see whether N is needed by Entity, we loop through all
      --  the annotations of N and see whether one of them is eqaul to
      --  Entity or if it is (recursively) "needed" by Entity.

      --  To avoid infinite recursion (that may occurs between data
      --  having a subprogram as a feature and a being access-required
      --  by the same subprogram), we build a list of the visited
      --  nodes to guarantee they are checked only once.

      package Checked_Nodes is new GNAT.Table (Node_Id, Nat, 1, 10, 50);
      --  This is the list of the already checked "nodes"

      function Is_Checked (E : Node_Id) return Boolean;
      --  See whether E has already been ckecked or not

      procedure Set_Checked (E : Node_Id);
      --  Append E to the checked node table

      function Need (E : Node_Id) return Boolean;
      --  This is the Actual recursive routine. It returns True when
      --  Entity is an annotation of E or else whether it is "needs"
      --  one of the annotations of E.

      ----------------
      -- Is_Checked --
      ----------------

      function Is_Checked (E : Node_Id) return Boolean is
         use Checked_Nodes;
      begin
         for J in First .. Last loop
            if Table (J) = E then
               return True;
            end if;
         end loop;

         return False;
      end Is_Checked;

      -----------------
      -- Set_Checked --
      -----------------

      procedure Set_Checked (E : Node_Id) is
         use Checked_Nodes;
      begin
         Append (E);
      end Set_Checked;

      ----------
      -- Need --
      ----------

      function Need (E : Node_Id) return Boolean is
         A      : Annotation_Id;
         Result : Boolean;

      begin
         Set_Checked (E);

         A := First_Annotation (E);
         if A = No_Annotation then
            Result := False;

         elsif Annotation_Index (E, Entity) /= 0 then
            Result := True;

         else
            Result := False;
            while A /= No_Annotation loop
               if not Is_Checked (Annotation_Node (A)) then
                  Result := Need (Annotation_Node (A));
                  exit when Result;
               end if;

               A := Next_Annotation (A);
            end loop;
         end if;

         return Result;
      end Need;

      Result : Boolean;
   begin
      --  Always return true when asked for a dependency upon a
      --  property declaration.

      Result := Kind (N) = K_Property_Definition_Declaration or else
        Kind (N) = K_Property_Type_Declaration               or else
        Kind (N) = K_Constant_Property_Declaration           or else
        Need (N);

      --  Deallocate the checked nodes list

      Checked_Nodes.Free;

      return Result;
   end Needed_By;

   ----------------------------------
   -- Property_Can_Apply_To_Entity --
   ----------------------------------

   function Property_Can_Apply_To_Entity
     (Property : Node_Id;
      Entity   : Node_Id)
     return Boolean
   is
      pragma Assert (Kind (Property) = K_Property_Association);
      pragma Assert (Present (Entity));

      Property_Name : constant Node_Id := Get_Referenced_Entity
        (Ocarina.Me_AADL.AADL_Tree.Nodes.Property_Name (Property));

      pragma Assert
        (Is_All (Applies_To (Property_Name))
         or else Owner_Categories (Applies_To (Property_Name)) /= No_List);

      List_Node                  : Node_Id := No_Node;
      Corresponding_Component    : Node_Id := No_Node;
      Category_Of_Property_Owner : Named_Element;
      Category_Of_Component      : Component_Category;
      Success                    : Boolean;
      Can_Apply                  : Boolean;
   begin
      if Is_All (Applies_To (Property_Name)) then
         Success := True;

      else
         Success := False;
         Category_Of_Property_Owner :=
           Get_Category_Of_Entity (Entity);

         --  Get the corresponding component, for some tests

         if Kind (Entity) = K_Subcomponent then
            Corresponding_Component :=
              Get_Corresponding_Component (Entity);

         elsif Kind (Entity) = K_Subprogram_Call then
            Corresponding_Component :=
              Get_Corresponding_Subprogram (Entity);

         else
            Corresponding_Component := Entity;
         end if;

         --  Get the category of the entity

         if Kind (Entity) = K_Component_Type
           or else Kind (Entity) = K_Component_Implementation
         then
            Category_Of_Component :=
              Get_Category_Of_Component (Entity);

         elsif Kind (Entity) = K_Subprogram_Spec
           and then not Is_Server (Entity)
         then
            Category_Of_Component := CC_Subprogram;

         elsif Kind (Entity) = K_Subprogram_Call then
            Category_Of_Component := CC_Subprogram;

         elsif Kind (Entity) = K_Subcomponent then
            Category_Of_Component :=
              Get_Category_Of_Subcomponent (Entity);

         elsif Kind (Entity) = K_Subcomponent_Access then
            Category_Of_Component := Component_Category'Val
              (Subcomponent_Category (Entity));
         end if;

944
945
946
         if AADL_Version = AADL_V1 then
            --  AADLV1 only: access property names can be applied to
            --  subcomponent accesses.
947

948
949
950
951
            if Kind (Entity) = K_Subcomponent_Access
              and then not Is_Access (Property_Name)
            then
               --  No need to go further, it cannot apply
952

953
954
               return False;
            end if;
955
956
957
958
959
960
961
962
963
964
         end if;

         --  Check if the property can be applied to the entity

         List_Node := First_Node
           (Owner_Categories (Applies_To (Property_Name)));

         while List_Node /= No_Node and then not Success loop
            case Category_Of_Property_Owner is
               when PO_Component_Category =>
965
966
967
968
969
                  --  Here, we check that the component (or an access
                  --  to this component matches on of the
                  --  corresponding component types or meta model
                  --  elements in the 'applies to'

970
971
                  Can_Apply :=
                    (Named_Element'Val (Category (List_Node)) =
972
973
974
975
                     PO_Component_Category
                       or else
                     Named_Element'Val (Category (List_Node)) =
                     PO_Component_Access)
976
977
978
979
                    and then
                    (Category_Of_Component =
                     Component_Category'Val (Component_Cat (List_Node)));

980
981
982
                  --  XXX dubious, here we erase the previously
                  --  computed value of Can_Apply, to be investigated.

983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
                  if Present (Classifier_Ref (List_Node)) then
                     if Present (Corresponding_Component) then
                        Can_Apply := Is_An_Extension
                          (Component => Corresponding_Component,
                           Ancestor  => Get_Referenced_Entity
                             (Classifier_Ref (List_Node)));
                     else
                        Can_Apply := False;
                     end if;
                  end if;

               when PO_Event_Data_Port
                 | PO_Event_Port
                 | PO_Data_Port
                 | PO_Port =>
                  Can_Apply := Named_Element'Val
                    (Category (List_Node)) = Category_Of_Property_Owner
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Port;

               when PO_Data_Port_Connections
                 | PO_Event_Port_Connections
                 | PO_Event_Data_Port_Connections =>

                  Can_Apply := Named_Element'Val
                    (Category (List_Node)) = Category_Of_Property_Owner
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Port_Connections
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Connection
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Connections;

               when PO_Parameter_Connections
                 | PO_Feature_Group_Connection
                 | PO_Port_Group_Connections
                 | PO_Access_Connection
                 | PO_Connection
                 | PO_Connections =>
                  Can_Apply := Named_Element'Val
                    (Category (List_Node)) = Category_Of_Property_Owner
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Connection
                    or else Named_Element'Val
                    (Category (List_Node)) = PO_Connections;

               when others =>
                  Can_Apply := Named_Element'Val
                    (Category (List_Node)) = Category_Of_Property_Owner;
            end case;

            Success := Success or else Can_Apply;
            List_Node := Next_Node (List_Node);
         end loop;
      end if;

      return Success;
   end Property_Can_Apply_To_Entity;

end Ocarina.Analyzer.AADL.Queries;