ocarina-processor-properties.adb 55.4 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--         O C A R I N A . P R O C E S S O R . 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
140
141
142
143
144
145
146
147
148
149
150
151
--                                                                          --
-- 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 Ocarina.AADL_Values;

with Ocarina.Analyzer.Messages;
with Ocarina.Analyzer.AADL.Queries;

with Ocarina.Builder.AADL.Properties;

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

package body Ocarina.Processor.Properties is

   use Ocarina.ME_AADL.AADL_Tree.Nodes;

   function Evaluate_Property_Value
     (Property_Value, Reference_Property : Node_Id)
     return Node_Id;
   --  Compute the value by fetching the property terms and applying
   --  the operations described in the property value. Return the
   --  first evaluated value (the following ones are chainded using
   --  Next_Node), or No_Node is nothing could be
   --  evaluated. Reference_Property is the property for the value of
   --  which is evaluated; it is used to display errors, in order to
   --  indicate what initiated the problem.

   function Expand_Property_Value
     (Property, Reference_Property : Node_Id)
     return Node_Id;
   --  expand the property terms of the property, and return all the
   --  property values

   function Expand_Property_Type
     (Property_Type : Node_Id)
     return Node_Id;
   --  computes the actual property type, by resolving references

   function Resolve_Type (Root, Property : Node_Id) return Boolean;
   --  Set a direct type (i.e. not a reference to a type declaration)
   --  for the property name declaration

   function Resolve_Value (Root, Property : Node_Id) return Boolean;
   --  Set a direct value (i.e. without value ()) for each value of
   --  the property association.

   function Resolve_Properties
     (Properties : List_Id;
      Root, Container : Node_Id)
     return Boolean;

   function Resolve_Properties_Of_Component_Type
     (Root, Component : Node_Id)
     return Boolean;

   function Resolve_Properties_Of_Component_Implementation
     (Root, Component : Node_Id)
     return Boolean;

   function Resolve_Properties_Of_Port_Group_Type
     (Root, Port_Group : Node_Id)
     return Boolean;

   function Resolve_All_Properties
     (Root : Node_Id)
     return Boolean;

   function Resolve_All_Property_Names
     (Root : Node_Id)
     return Boolean;

   -----------------------------
   -- Compute_Property_Values --
   -----------------------------

   function Compute_Property_Values (Root : Node_Id) return Boolean is
      Success : Boolean;

   begin
      Success := Resolve_All_Properties (Root);
      Success := Resolve_All_Property_Names (Root) and then Success;
      return Success;
   end Compute_Property_Values;

   --------------------------------------------
   -- Diffuse_Package_Properties_To_Entities --
   --------------------------------------------

   procedure Diffuse_Package_Properties_To_Entities (Root : Node_Id) is
      use Ocarina.Analyzer.AADL.Queries;
      use Ocarina.Builder.AADL.Properties;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.ME_AADL.AADL_Tree.Entities;

      pragma Assert (Present (Root));
      pragma Assert (Kind (Root) = K_AADL_Specification);

      List_Node, Property_Node, Declaration_Node : Node_Id;
      Success : Boolean := True;
      Diffused_Property : Node_Id;

   begin
      if Declarations (Root) /= No_List then
         List_Node := First_Node (Declarations (Root));

         while List_Node /= No_Node loop
            if Kind (List_Node) = K_Package_Specification
              and then
              Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (List_Node) /= No_List
              and then Declarations (List_Node) /= No_List
            then
               Property_Node := First_Node
                 (Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (List_Node));

               while Property_Node /= No_Node loop
                  Declaration_Node :=
                    First_Node (Declarations (List_Node));

                  while Declaration_Node /= No_Node loop
152
153
154
                     if Kind (Declaration_Node)
                       /= K_Name_Visibility_declaration
                       and then Is_Private (Property_Node)
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
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
                       = Is_Private (Declaration_Node)
                       and then Property_Can_Apply_To_Entity
                       (Property_Node, Declaration_Node)
                     then
                        Diffused_Property := Add_New_Property_Association
                          (Loc => Loc (Property_Node),
                           Name => Duplicate_Identifier
                             (Identifier (Property_Node)),
                           Property_Name => Property_Name
                             (Property_Node),
                           Container => Declaration_Node,
                           In_Binding => In_Binding (Property_Node),
                           In_Modes => In_Modes (Property_Node),
                           Property_Value =>
                             Property_Association_Value (Property_Node),
                           Is_Constant => Is_Constant
                             (Property_Node),
                           Is_Access => Is_Access (Property_Node),
                           Is_Additive => Is_Additive_Association
                             (Property_Node),
                           Applies_To => Applies_To_Prop
                             (Property_Node),
                           Check_For_Conflicts => True,
                           Override => False);
                        --  We add a new property, by duplicating the
                        --  one of the package

                        Success := Success
                          and then Diffused_Property /= No_Node;
                     end if;

                     Declaration_Node := Next_Node (Declaration_Node);
                  end loop;

                  Remove_Node_From_List
                    (Property_Node,
                     Ocarina.ME_AADL.AADL_Tree.Nodes.Properties (List_Node));
                  --  Simply detach the legacy property from the list. Its
                  --  elements are reused in the new properties

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

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

   ------------------
   -- Resolve_Type --
   ------------------

   function Resolve_Type
     (Root, Property : Node_Id)
     return Boolean
   is
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.ME_AADL.AADL_Tree.Entities;
      use Ocarina.Analyzer.AADL.Queries;

      pragma Assert (Present (Root));
      pragma Assert (Kind (Root) = K_AADL_Specification);
      pragma Assert (Present (Property));
      pragma Assert (Kind (Property) = K_Property_Definition_Declaration);

      Prop_Type : constant Node_Id := Property_Name_Type (Property);
      Expanded_Value, Prop_Value : Node_Id;
      Success : Boolean := True;

   begin
      Set_Expanded_Type_Designator
        (Prop_Type,
         Expand_Property_Type (Property_Type_Designator (Prop_Type)));

      if Expanded_Type_Designator (Prop_Type) /= No_Node
        and then Kind (Expanded_Type_Designator (Prop_Type)) = K_Invalid_Node
      then
         --  FIXME : need for an error message
         Success := False;
      end if;

      if Default_Value (Property) /= No_Node then
         Prop_Value := Default_Value (Property);
         Expanded_Value := Expand_Property_Value (Property, Property);

         if Expanded_Value = No_Node then
            Set_Expanded_Single_Value (Prop_Value, No_Node);
            Set_Expanded_Multi_Value (Prop_Value, No_List);

         elsif Kind (Expanded_Value) = K_Invalid_Node then
            --  FIXME : need for an error message
            Success := False;
            Set_Expanded_Single_Value (Prop_Value, No_Node);
            Set_Expanded_Multi_Value (Prop_Value, No_List);

         elsif Kind (Expanded_Value) = K_List_Id then
            Set_Expanded_Single_Value (Prop_Value, No_Node);
            Set_Expanded_Multi_Value (Prop_Value, List_Id (Expanded_Value));

         elsif Next_Node (Expanded_Value) = No_Node
           and then Single_Value (Prop_Value) /= No_Node
         then
            Set_Expanded_Single_Value (Prop_Value, Expanded_Value);
            Set_Expanded_Multi_Value (Prop_Value, No_List);

         else
            Set_Expanded_Single_Value (Prop_Value, No_Node);
            Set_Expanded_Multi_Value (Prop_Value, New_List
                                      (K_List_Id, Loc (Expanded_Value)));
            Append_Node_To_List (Expanded_Value,
                                 Expanded_Multi_Value (Prop_Value));
         end if;
      end if;

      return Success;
   end Resolve_Type;

   --------------------------
   -- Expand_Property_Type --
   --------------------------

   function Expand_Property_Type
     (Property_Type : Node_Id)
     return Node_Id
   is
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.ME_AADL.AADL_Tree.Entities;

      Expanded_Type : Node_Id;

   begin
      case Kind (Property_Type) is
         when K_Unique_Property_Type_Identifier =>
            Expanded_Type := Get_Referenced_Entity (Property_Type);
            --  We first get the property type of the corresponding
            --  declaration

            Expanded_Type :=
              Expand_Property_Type (Property_Type_Designator (Expanded_Type));
            --  Then we expand it also

         when K_Number_Range =>
            Expanded_Type := New_Node (K_Number_Range, Loc (Property_Type));
            Set_Lower_Bound
              (Expanded_Type,
               Evaluate_Property_Value (Lower_Bound (Property_Type),
                                        Property_Type));
            Set_Upper_Bound
              (Expanded_Type,
               Evaluate_Property_Value (Upper_Bound (Property_Type),
                                        Property_Type));

            if (Upper_Bound (Expanded_Type) /= No_Node
                and then Kind (Upper_Bound (Expanded_Type)) = K_Invalid_Node)
              or else (Lower_Bound (Expanded_Type) /= No_Node
                       and then Kind (Lower_Bound (Expanded_Type)) =
                       K_Invalid_Node)
            then
               Set_Kind (Expanded_Type, K_Invalid_Node);
            end if;

         when K_Real_Type
           | K_Integer_Type =>
            Expanded_Type :=
              New_Node (Kind (Property_Type), Loc (Property_Type));
            Set_Unit_Designator (Expanded_Type,
                                 Unit_Designator (Property_Type));
            if Type_Range (Property_Type) /= No_Node then
               Set_Type_Range (Expanded_Type,
                               New_Node (K_Number_Range,
                                         Loc (Type_Range (Property_Type))));
               Set_Lower_Bound (Type_Range (Expanded_Type),
                                Evaluate_Property_Value
                                (Lower_Bound (Type_Range (Property_Type)),
                                 Property_Type));
               Set_Upper_Bound (Type_Range (Expanded_Type),
                                Evaluate_Property_Value
                                (Upper_Bound (Type_Range (Property_Type)),
                                 Property_Type));

               if (Upper_Bound (Type_Range (Expanded_Type)) /= No_Node
                   and then Kind (Upper_Bound (Type_Range (Expanded_Type))) =
                   K_Invalid_Node)
                 or else (Lower_Bound (Type_Range (Expanded_Type)) /= No_Node
                          and then Kind (Lower_Bound
                                         (Type_Range (Expanded_Type))) =
                          K_Invalid_Node)
               then
                  Set_Kind (Expanded_Type, K_Invalid_Node);
               end if;
            end if;

         when K_Range_Type =>
            Expanded_Type := New_Node (K_Range_Type, Loc (Property_Type));
            Set_Number_Type (Expanded_Type,
                             Expand_Property_Type
                             (Number_Type (Property_Type)));

            if Number_Type (Expanded_Type) /= No_Node
              and then Kind (Number_Type (Expanded_Type)) = K_Invalid_Node
            then
               Set_Kind (Expanded_Type, K_Invalid_Node);
            end if;

         when others =>
            Expanded_Type := Property_Type;
      end case;

      return Expanded_Type;
   end Expand_Property_Type;

   -------------------
   -- Resolve_Value --
   -------------------

hugues.jerome's avatar
hugues.jerome committed
371
   function Resolve_Value (Root, Property : Node_Id) return Boolean is
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
      use Ocarina.ME_AADL.AADL_Tree.Nutils;
      use Ocarina.Analyzer.AADL.Queries;

      pragma Assert (Present (Root));
      pragma Assert (Kind (Root) = K_AADL_Specification);
      pragma Assert (Present (Property));
      pragma Assert (Kind (Property) = K_Property_Association);

      Prop_Value : constant Node_Id := Property_Association_Value (Property);
      Expanded_Value : Node_Id;
      Success : Boolean := True;

   begin
      Expanded_Value := Expand_Property_Value (Property, Property);

      if Expanded_Value = No_Node then
         Set_Expanded_Single_Value (Prop_Value, No_Node);
         Set_Expanded_Multi_Value (Prop_Value, No_List);

      elsif Kind (Expanded_Value) = K_Invalid_Node then
         --  FIXME : need for an error message
         Success := False;
         Set_Expanded_Single_Value (Prop_Value, No_Node);
         Set_Expanded_Multi_Value (Prop_Value, No_List);

      elsif Kind (Expanded_Value) = K_List_Id then
         Set_Expanded_Single_Value (Prop_Value, No_Node);
         Set_Expanded_Multi_Value (Prop_Value, List_Id (Expanded_Value));

      elsif Next_Node (Expanded_Value) = No_Node
        and then Single_Value (Prop_Value) /= No_Node
      then
         Set_Expanded_Single_Value (Prop_Value, Expanded_Value);
         Set_Expanded_Multi_Value (Prop_Value, No_List);

      else
         Set_Expanded_Single_Value (Prop_Value, No_Node);
         Set_Expanded_Multi_Value (Prop_Value, New_List
                                   (K_List_Id, Loc (Expanded_Value)));
         Append_Node_To_List (Expanded_Value,
                              Expanded_Multi_Value (Prop_Value));
      end if;

      return Success;
   end Resolve_Value;

   ---------------------------
   -- Expand_Property_Value --
   ---------------------------

   function Expand_Property_Value
     (Property, Reference_Property : Node_Id)
     return Node_Id
   is
      --  Take a property declaration and return its expanded value

      use Ocarina.Analyzer.Messages;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;

      pragma Assert
        (Property = No_Node
         or else Kind (Property) = K_Property_Association
         or else Kind (Property) = K_Constant_Property_Declaration
         or else Kind (Property) = K_Property_Definition_Declaration
         or else Kind (Property) = K_Property_Type_Declaration
         or else DNKE (Property));

      pragma Assert (Reference_Property /= No_Node);

      Value, List_Node, Expanded_List_Node, Computed_Value : Node_Id;
      Expanded_List : List_Id;
      Undefined_Values : Boolean;
   begin
      if Property = No_Node then
         return No_Node;
      end if;

      --  First get the value of the property
      case Kind (Property) is
         when K_Property_Association =>
            Value := Property_Association_Value (Property);
         when K_Constant_Property_Declaration =>
            Value := Constant_Value (Property);
         when K_Property_Definition_Declaration =>
            Value := Default_Value (Property);
         when K_Property_Type_Declaration =>
            Value := No_Node;

         when others =>
            raise Program_Error;
      end case;

      if Value = No_Node then
         return Value;

      elsif Single_Value (Value) /= No_Node then
         Computed_Value := Evaluate_Property_Value
           (Single_Value (Value), Reference_Property);

         if Computed_Value /= No_Node then
            if Kind (Computed_Value) = K_List_Id then
               Expanded_List_Node := First_Node (List_Id (Computed_Value));
            else
               Expanded_List_Node := Computed_Value;
            end if;

            while Expanded_List_Node /= No_Node loop
               Set_Loc (Expanded_List_Node, Loc (Single_Value (Value)));
               Expanded_List_Node := Next_Node (Expanded_List_Node);
            end loop;
            --  The location of the evaluated values should be the
            --  same as the primitive value
         end if;

         return Computed_Value;
      else
         List_Node := First_Node (Multi_Value (Value));
         Expanded_List := New_List (K_List_Id,
                                    Loc (Node_Id (Multi_Value (Value))));
         Undefined_Values := (List_Node /= No_Node);
         --  If the list is empty, then the value is defined. Else,
         --  the value may be undefined if all the elements of the
         --  list expand to an undefined value (i.e. no node)

         while List_Node /= No_Node loop
            Computed_Value := Evaluate_Property_Value (List_Node, Property);

            if Computed_Value /= No_Node then
               Undefined_Values := False;

               if Kind (Computed_Value) = K_Invalid_Node then
                  return Computed_Value;
               elsif Kind (Computed_Value) = K_List_Id then
                  Expanded_List_Node := First_Node (List_Id (Computed_Value));

                  while Expanded_List_Node /= No_Node loop
                     Set_Loc (Expanded_List_Node, Loc (List_Node));
                     Expanded_List_Node := Next_Node (Expanded_List_Node);
                  end loop;

                  Append_List_To_List
                    (List_Id (Computed_Value), Expanded_List);
               else
                  Expanded_List_Node := Computed_Value;

                  while Expanded_List_Node /= No_Node loop
                     Set_Loc (Expanded_List_Node, Loc (List_Node));
                     Expanded_List_Node := Next_Node (Expanded_List_Node);
                  end loop;

                  Append_Node_To_List (Computed_Value, Expanded_List);
               end if;
            end if;

            List_Node := Next_Node (List_Node);
         end loop;

         if Undefined_Values then
            return No_Node;
         else
            return Node_Id (Expanded_List);
         end if;
      end if;
   end Expand_Property_Value;

   -----------------------------
   -- Evaluate_Property_Value --
   -----------------------------

   function Evaluate_Property_Value
     (Property_Value, Reference_Property : Node_Id)
     return Node_Id
   is
      use Ocarina.ME_AADL.AADL_Tree.Entities;
      use Ocarina.Analyzer.Messages;
      use Ocarina.AADL_Values;
      use Ocarina.ME_AADL.AADL_Tree.Nutils;

      pragma Assert
        (Property_Value = No_Node
         or else Kind (Property_Value) = K_Literal
         or else Kind (Property_Value) = K_Property_Term
         or else Kind (Property_Value) = K_Number_Range_Term
         or else Kind (Property_Value) = K_Reference_Term
         or else Kind (Property_Value) = K_Enumeration_Term
         or else Kind (Property_Value) = K_Property_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
         or else Kind (Property_Value) = K_Unique_Property_Const_Identifier
566
         or else Kind (Property_Value) = K_Record_Term
567
568
569
570
         or else Ocarina.ME_AADL.Aadl_Tree.Entities.DNKE (Property_Value));

      pragma Assert (Reference_Property /= No_Node);

571
572
      Evaluated_Value : Node_Id := No_Node;
      Ref_Term : Node_Id := No_Node;
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
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
   begin
      if Property_Value = No_Node then
         Evaluated_Value := No_Node;
      else
         case Kind (Property_Value) is
            when K_Enumeration_Term =>
               Evaluated_Value := New_Node (Kind (Property_Value),
                                            Loc (Property_Value));
               Set_Identifier (Evaluated_Value, Identifier (Property_Value));

               Set_Property_Set_Identifier (Evaluated_Value,
                                            Property_Set_Identifier
                                              (Property_Value));

               Set_Entity (Evaluated_Value, Entity (Property_Value));

            when K_Unique_Property_Const_Identifier =>
               Evaluated_Value := Expand_Property_Value
                 (Get_Referenced_Entity (Property_Value), Reference_Property);

            when K_Literal =>
               Evaluated_Value := New_Node (Kind (Property_Value),
                                            Loc (Property_Value));
               Set_Value (Evaluated_Value,
                          New_Value (Value (Value (Property_Value))));
               --  We clone the literal value

            when K_Number_Range_Term =>
               declare
                  Evaluated_Lower_Bound,
                  Evaluated_Upper_Bound,
                  Evaluated_Delta_Term : Node_Id;
               begin
                  Evaluated_Value := New_Node (Kind (Property_Value),
                                               Loc (Property_Value));
                  Evaluated_Lower_Bound :=
                    Evaluate_Property_Value
                    (Lower_Bound (Property_Value), Reference_Property);
                  Evaluated_Upper_Bound :=
                    Evaluate_Property_Value
                    (Upper_Bound (Property_Value), Reference_Property);
                  Evaluated_Delta_Term :=
                    Evaluate_Property_Value
                    (Delta_Term (Property_Value), Reference_Property);

                  --  Check the consistency of the evaluated values

                  if Evaluated_Lower_Bound /= No_Node
                    and then ((Kind (Evaluated_Lower_Bound) /= K_Literal
                               and then Kind (Evaluated_Lower_Bound) /=
                               K_Signed_AADLNumber)
                              or else Next_Node (Evaluated_Lower_Bound) /=
                              No_Node)
                  then
                     Display_Inconsistency_In_Property_Values
                       (Property_Value,
                        Evaluated_Lower_Bound,
                        Reference_Property);
                     Set_Kind (Evaluated_Lower_Bound, K_Invalid_Node);
                  end if;

                  if Evaluated_Upper_Bound /= No_Node
                    and then ((Kind (Evaluated_Upper_Bound) /= K_Literal
                               and then Kind (Evaluated_Upper_Bound) /=
                               K_Signed_AADLNumber)
                              or else Next_Node (Evaluated_Upper_Bound) /=
                              No_Node)
                  then
                     Display_Inconsistency_In_Property_Values
                       (Property_Value,
                        Evaluated_Upper_Bound,
                        Reference_Property);
                     Set_Kind (Evaluated_Upper_Bound, K_Invalid_Node);
                  end if;

                  if Evaluated_Delta_Term /= No_Node
                    and then ((Kind (Evaluated_Delta_Term) /= K_Literal
                               and then Kind (Evaluated_Delta_Term) /=
                               K_Signed_AADLNumber)
                              or else Next_Node (Evaluated_Delta_Term) /=
                              No_Node)
                  then
                     Display_Inconsistency_In_Property_Values
                       (Property_Value,
                        Evaluated_Delta_Term,
                        Reference_Property);
                     Set_Kind (Evaluated_Delta_Term, K_Invalid_Node);
                  end if;

                  --  Set the evaluated values

                  if Evaluated_Lower_Bound /= No_Node
                    and then Evaluated_Upper_Bound /= No_Node
                    and then (Evaluated_Delta_Term /= No_Node
                              or else Delta_Term (Property_Value) = No_Node)
                  then
                     if Kind (Evaluated_Lower_Bound) /= K_Invalid_Node
                       and then Kind (Evaluated_Upper_Bound) /= K_Invalid_Node
                       and then (Evaluated_Delta_Term = No_Node
                                 or else Kind (Evaluated_Delta_Term) /=
                                 K_Invalid_Node)
                     then
                        --  If we could evaluate the lower and upper
                        --  bounds, and the delta term (unless there
                        --  was no original value), we store the
                        --  evaluated values

                        Set_Lower_Bound (Evaluated_Value,
                                         Evaluated_Lower_Bound);
                        Set_Upper_Bound (Evaluated_Value,
                                         Evaluated_Upper_Bound);
                        Set_Delta_Term (Evaluated_Value,
                                        Evaluated_Delta_Term);
                     else
                        --  If at least an evaluated value is invalid

                        Set_Kind (Evaluated_Value, K_Invalid_Node);
                     end if;
                  else
                     Evaluated_Value := No_Node;
                  end if;
               end;

            when K_Reference_Term =>
               case Kind (Reference_Term (Property_Value)) is
                  when K_Entity_Reference =>
                     Evaluated_Value := New_Node (Kind (Property_Value),
                                                  Loc (Property_Value));

                     Ref_Term := New_Node (Kind (Reference_Term
                                                   (Property_Value)),
                                           Loc (Reference_Term
                                                  (Property_Value)));
                     Set_Identifier
                       (Ref_Term,
                        Duplicate_Identifier (Identifier
                                                (Reference_Term
                                                   (Property_Value))));
                     Set_Path (Ref_Term,
                               Path (Reference_Term (Property_Value)));
                     Set_Namespace_Path (Ref_Term,
                                         Namespace_Path
                                           (Reference_Term
                                              (Property_Value)));
                     Set_Namespace_Identifier
                       (Ref_Term, Duplicate_Identifier
                          (Namespace_Identifier
                             (Reference_Term (Property_Value))));
                     Set_Referenced_Entity (Ref_Term,
                                            Entity (Reference_Term
                                                      (Property_Value)));

                     Set_Reference_Term (Evaluated_Value, Ref_Term);

                  when K_Contained_Element_Path =>
                     Evaluated_Value := New_Node (Kind (Property_Value),
                                                  Loc (Property_Value));

                     Ref_Term := New_Node (Kind (Reference_Term
                                                   (Property_Value)),
                                           Loc (Reference_Term
                                                  (Property_Value)));
                     Set_List_Items (Ref_Term,
                                     List_Items (Reference_Term
                                                   (Property_Value)));
                     Set_Referenced_Entity (Ref_Term,
                                            Entity
                                              (Reference_Term
                                                 (Property_Value)));

                     Set_Annex_Path (Ref_Term,
                                     Annex_Path (Reference_Term
                                                   (Property_Value)));

                     Set_Reference_Term (Evaluated_Value, Ref_Term);

                  when others =>
                     raise Program_Error;
               end case;

            when K_Property_Term =>
               Evaluated_Value := Expand_Property_Value
                 (Get_Referenced_Entity (Property_Value), Reference_Property);

            when K_Minus_Numeric_Term =>
               declare
                  Val : Value_Type;
                  Literal : Node_Id;
               begin
                  Evaluated_Value := Evaluate_Property_Value
                    (Numeric_Term (Property_Value), Reference_Property);

                  if Evaluated_Value /= No_Node then
                     if Kind (Evaluated_Value) = K_Literal
                       and then Next_Node (Evaluated_Value) = No_Node
                     then
                        Literal := Evaluated_Value;

                     elsif Kind (Evaluated_Value) = K_Signed_AADLNumber
                       and then Next_Node (Evaluated_Value) = No_Node
                     then
                        Literal := Number_Value (Evaluated_Value);
                        --  Since the number has been evaluated, the
                        --  number_value can only be a literal

                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Evaluated_Value,
                           Reference_Property);
                        Literal := No_Node;
                        Evaluated_Value :=
                          New_Node (K_Invalid_Node, Loc (Property_Value));
                     end if;

                     if Literal /= No_Node then
                        if Get_Value_Type (Value (Literal)).T =
                          LT_Integer
                        then
                           Val := Get_Value_Type (Value (Literal));
                           Val.ISign := not Get_Value_Type
                             (Value (Literal)).ISign;
                           Set_Value (Value (Literal), Val);

                        elsif Get_Value_Type (Value (Literal)).T =
                          LT_Real
                        then
                           Val := Get_Value_Type (Value (Literal));
                           Val.RSign := not Val.RSign;
                           Set_Value (Value (Literal), Val);

                        else
                           Display_Inconsistency_In_Property_Values
                             (Property_Value, Literal, Reference_Property);
                           Evaluated_Value :=
                             New_Node (K_Invalid_Node, Loc (Property_Value));
                        end if;

                        if Evaluated_Value /= No_Node then
                           if Kind (Evaluated_Value) = K_Literal then
                              Evaluated_Value := Literal;

                           elsif Kind (Evaluated_Value) =
                             K_Signed_AADLNumber
                           then
                              Set_Number_Value (Evaluated_Value, Literal);
                           end if;
                        end if;

                     else
                        Evaluated_Value := No_Node;
                     end if;
                  end if;
               end;

            when K_Signed_AADLNumber =>
               declare
                  Evaluated_Number_Value : Node_Id;
               begin
                  Evaluated_Value := New_Node (Kind (Property_Value),
                                               Loc (Property_Value));
                  Set_Unit_Identifier (Evaluated_Value,
                                       Unit_Identifier (Property_Value));
                  Evaluated_Number_Value :=
                    Evaluate_Property_Value
                    (Number_Value (Property_Value), Reference_Property);

                  if Evaluated_Number_Value /= No_Node then
                     if Kind (Evaluated_Number_Value) /= K_Literal
                       or else Next_Node (Evaluated_Number_Value) /= No_Node
                     then
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Evaluated_Number_Value,
                           Reference_Property);
                        Set_Kind (Evaluated_Value, K_Invalid_Node);
                     else
                        Set_Number_Value (Evaluated_Value,
                                          Evaluated_Number_Value);
                     end if;
                  else
                     Evaluated_Value := No_Node;
                  end if;
               end;

            when K_Not_Boolean_Term =>
               declare
                  Val : Value_Type;
               begin
                  Evaluated_Value := Evaluate_Property_Value
                    (Boolean_Term (Property_Value), Reference_Property);

                  if Evaluated_Value /= No_Node then
                     if Kind (Evaluated_Value) = K_Literal
                       and then Get_Value_Type (Value (Evaluated_Value)).T =
                       LT_Boolean
                       and then Next_Node (Evaluated_Value) = No_Node
                     then
                        Val := Get_Value_Type (Value (Evaluated_Value));
                        Val.BVal := not Val.BVal;
                        Set_Value (Value (Evaluated_Value), Val);
                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Evaluated_Value,
                           Reference_Property);
                        Set_Kind (Evaluated_Value, K_Invalid_Node);
                     end if;
                  else
                     Evaluated_Value := No_Node;
                  end if;
               end;

            when K_And_Boolean_Term =>
               declare
                  Auxiliary_Value : Node_Id;
                  Val : Value_Type;
                  Val1_OK, Val2_OK : Boolean;
               begin
                  Evaluated_Value := Evaluate_Property_Value
                    (First_Term (Property_Value), Reference_Property);
                  Auxiliary_Value := Evaluate_Property_Value
                    (Second_Term (Property_Value), Reference_Property);

                  if Evaluated_Value /= No_Node then
                     if Kind (Evaluated_Value) = K_Literal
                       and then Get_Value_Type (Value (Evaluated_Value)).T =
                       LT_Boolean
                       and then Next_Node (Evaluated_Value) = No_Node
                     then
                        Val1_OK := True;
                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Evaluated_Value,
                           Reference_Property);
                        Set_Kind (Evaluated_Value, K_Invalid_Node);
                        Val1_OK := False;
                     end if;
                  else
                     Val1_OK := False;
                     Evaluated_Value := No_Node;
                  end if;

                  if Auxiliary_Value /= No_Node then
                     if Kind (Auxiliary_Value) = K_Literal
                       and then Get_Value_Type (Value (Auxiliary_Value)).T =
                       LT_Boolean
                       and then Next_Node (Auxiliary_Value) = No_Node
                     then
                        Val2_OK := True;
                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Auxiliary_Value,
                           Reference_Property);
                        Set_Kind (Auxiliary_Value, K_Invalid_Node);
                        Evaluated_Value := Auxiliary_Value;
                        Val2_OK := False;
                     end if;
                  else
                     Val2_OK := False;
                     Evaluated_Value := No_Node;
                  end if;

                  if Val1_OK and then Val2_OK then
                     Val := Get_Value_Type (Value (Evaluated_Value));
                     Val.BVal := Val.BVal
                       and then Get_Value_Type (Value (Auxiliary_Value)).BVal;
                     Set_Value (Value (Evaluated_Value), Val);
                  end if;
               end;

            when K_Or_Boolean_Term =>
               declare
                  Auxiliary_Value : Node_Id;
                  Val : Value_Type;
                  Val1_OK, Val2_OK : Boolean;
               begin
                  Evaluated_Value := Evaluate_Property_Value
                    (First_Term (Property_Value), Reference_Property);
                  Auxiliary_Value := Evaluate_Property_Value
                    (Second_Term (Property_Value), Reference_Property);

                  if Evaluated_Value /= No_Node then
                     if Kind (Evaluated_Value) = K_Literal
                       and then Get_Value_Type (Value (Evaluated_Value)).T =
                       LT_Boolean
                       and then Next_Node (Evaluated_Value) = No_Node
                     then
                        Val1_OK := True;
                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value,
                           Evaluated_Value,
                           Reference_Property);
                        Set_Kind (Evaluated_Value, K_Invalid_Node);
                        Val1_OK := False;
                     end if;
                  else
                     Val1_OK := False;
                     Evaluated_Value := No_Node;
                  end if;

                  if Auxiliary_Value /= No_Node then
                     if Kind (Auxiliary_Value) = K_Literal
                       and then Get_Value_Type (Value (Auxiliary_Value)).T =
                       LT_Boolean
                       and then Next_Node (Auxiliary_Value) = No_Node
                     then
                        Val2_OK := True;
                     else
                        Display_Inconsistency_In_Property_Values
                          (Property_Value, Auxiliary_Value, Property_Value);
                        Set_Kind (Auxiliary_Value, K_Invalid_Node);
                        Evaluated_Value := Auxiliary_Value;
                        Val2_OK := False;
                     end if;
                  else
                     Val2_OK := False;
                     Evaluated_Value := No_Node;
                  end if;

                  if Val1_OK and then Val2_OK then
                     Val := Get_Value_Type (Value (Evaluated_Value));
                     Val.BVal := Val.BVal
                       or else Get_Value_Type (Value (Auxiliary_Value)).BVal;
                     Set_Value (Value (Evaluated_Value), Val);