ocarina-backends-real.adb 106 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                O C A R I N A . B A C K E N D S . R E A L                 --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--               Copyright (C) 2009-2011, GET-Telecom Paris.                --
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
--                                                                          --
-- 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 Namet;
with Output;
36
with Locations; use Locations;
37
38
39
40
41
42
43

with Ocarina.ME_REAL.REAL_Tree.Nodes;
with Ocarina.ME_REAL.REAL_Tree.Nutils;
with Ocarina.ME_REAL.REAL_Tree.Utils;
with Ocarina.REAL_Values;
with Ocarina.Backends.Messages;

44
with Ocarina.ME_AADL.AADL_Tree.Nodes;
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
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;

with Ocarina.Instances.REAL_Finder;
with Ocarina.Instances.REAL_Checker.Queries.Subcomponent_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Bound_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Connected_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Call_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Access_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Passing_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Predecessor_Predicates;
with Ocarina.Instances.REAL_Checker.Queries.Provided_Class_Predicates;

with Unchecked_Deallocation;

package body Ocarina.Backends.REAL is

   use Ocarina.ME_REAL.REAL_Tree.Nodes;
   use Ocarina.ME_REAL.REAL_Tree.Nutils;
   use Ocarina.ME_REAL.REAL_Tree.Utils;
   use Ocarina.REAL_Values;
   use Ocarina.Instances.REAL_Finder;
   use Ocarina.Backends.Messages;
   use Namet;
   use Output;

   package RN renames Ocarina.ME_REAL.REAL_Tree.Nodes;
   package RNU renames Ocarina.ME_REAL.REAL_Tree.Nutils;
   --  package AIEP renames Ocarina.ME_AADL.AADL_Instances.Entities.Properties;
74
75
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
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
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
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

   --  This variable refers to the current element of the range set

   Current_Range_Variable : Node_Id;

   --  Buffer for runtime instance

   type Runtime_Instance is record
      Set_Array : Set_Table_Access;
      Current_Range_Variable : Node_Id;
      REAL_Root_Node : Node_Id;
   end record;
   type Runtime_Instance_Access is access Runtime_Instance;

   procedure Initialize_Sets_Table (R : Node_Id);
   --  Initialization procedure

   procedure Build_All_Objects (R : Node_Id; Success : in out Boolean);
   --  Builds all sets (independants or not) and variables

   procedure Apply_To_All_Elements (R : Node_Id);
   --  For each element of the range set :
   --  1/ build all dependant sets
   --  2/ evaluate the check expression

   procedure Compute_Value
     (R : Node_Id; Success : out Boolean; Res : out Float);
   --  We returns the value computed for the range set if
   --  it contains only one element, otherwise we compute the
   --  expected range function value.
   --  If there is a function value called on a single element,
   --  it is ignored.
   --  If they are multiples elements without a range fucntion call,
   --  we return an error value

   function Check_Requirements (R : Node_Id) return Boolean;
   --  Execute all requirements that are in "requires" field
   --  importing current environment (ie. Owner_Node variable)

   procedure Clean_Runtime;
   --  Clean array table

   function Save_Instance return Runtime_Instance_Access;
   --  Save the current runtime instance

   procedure Load_Instance (Instance : Runtime_Instance_Access);
   --  Load a previously-saved runtime instance

   --  Internal functions

   function Compute_Set_Expression (E : Node_Id) return Result_Set;

   procedure Compute_Check_Expression
     (E : Node_Id; Ret : out Return_Type; Result : out Value_id);

   procedure Compute_Check_Subprogram_Call
     (E : Node_Id; T : out Return_Type; Result : out Value_Id);

   function Apply_To_All_Elements (R : Node_Id) return Boolean;
   --  Test the theorem on all elements of the range set;
   --  return false if at least one of them fail

   procedure Manage_Set_Declaration (E : Node_Id);
   --  Compute the value (ie elements) of a set

   procedure Manage_Variable_Declaration
     (E : Node_Id; Success : in out Boolean);
   --  Compute the value of a variable with an expression

   procedure Manage_Variable_Theorem_Call
     (E : Node_Id; Success : in out Boolean);
   --  Compute the value of a variable with an extern theorem call

   function Build_Predefined_Set (T : Value_Id) return Result_Set;
   --  Build a predefined set according to the value given as parameter

   function Manage_Check_Expression (E : Node_Id) return Boolean;
   --  Evaluate the check expression for the current value of
   --  the range variable element

   function Manage_Return_Expression (E : Node_Id) return Float;
   --  Evaluate the return expression for the current value of
   --  the range variable element

   procedure Compute_Range_Function_Value
     (R : Node_Id; Success : out Boolean; Res : out Float);
   --  Compute the value of a range (i.e. multi-element based) function;
   --  return an error if there is no element.

   procedure Load_Environment;
   --  Load the parameter-passed variables

   procedure Load_Environment is
      N, P : Node_Id;
      Cpt  : Natural := 0;
      M    : Name_Id;
      V    : Value_Id;
      RT   : Return_Type;

   begin
      if Environment /= No_List then
         N := First_Node (Environment);
         while Present (N) loop
            Set_Str_To_Name_Buffer ("argv_" & Image (Cpt));
            M := Name_Find;
            P := Find_Node_By_Name (M, Used_Var (RNU.REAL_Root));
            case Kind (N) is

               when K_Literal =>
                  V :=  Value (N);
                  RT := Returned_Type (N);

               when K_Var_Reference =>
                  V := Var_Value (Referenced_Var (N));
                  RT := Var_Type (Referenced_Var (N));

               when others =>
                  Display_Located_Error
                    (Loc (N), "Could not analyze parameter " &
                     Get_Name_String (M), Fatal => True);
            end case;
            Set_Var_Type (P, RT);
            Set_Var_Value (P, V);
            Cpt := Cpt + 1;
            N := Next_Node (N);
         end loop;
      end if;
   end Load_Environment;

   ---------------------------
   -- Initialize_Sets_Table --
   ---------------------------

   procedure Initialize_Sets_Table (R : Node_Id) is
      pragma Assert (Kind (R) = K_Theorem);

      Cpt : Natural := 0;
      N   : Node_Id := First_Node (Used_Set (R));
      A   : Node_Id;

   begin
      --  We compute the actual number of used sets, both implicit or
      --  explicit (complex set expressions)

      while Present (N) loop
         Cpt := Cpt + 1;

         --  Put annotations to find back the corresponding index in
         --  set table from the tree

         A := New_Node (K_Annotation, Loc (N));
         Set_Index (A, Value_Id (Cpt));
         Set_Annotation (N, A);

         N := Next_Node (N);
      end loop;

      --  We allocate the set table
      Set_Array := new Set_Table (1 .. Cpt);

      --  Build used predefined sets

      declare
         Res : Result_Set;
      begin

         N := First_Node (Used_Set (R));
         while Present (N) loop
            --  No expression can refer to non-previously declared
            --  sets, so there is no order issue

            if Predefined_Type (N) /= SV_No_Type then
               Res := Build_Predefined_Set (Predefined_Type (N));
               Set_Array (Integer (Index (Annotation (N)))) := Res;
            end if;

            N := Next_Node (N);
         end loop;
      end;

      if RNU.Environment /= No_List then
         Load_Environment;
      end if;
   end Initialize_Sets_Table;

   -------------------
   -- Clean_Runtime --
   -------------------

   procedure Clean_Runtime is
      procedure Free is
         new Unchecked_Deallocation (Set_Table, Set_Table_Access);
   begin
      Free (Set_Array);
   end Clean_Runtime;

   ---------------------------
   -- Apply_To_All_Elements --
   ---------------------------

   procedure Apply_To_All_Elements (R : Node_Id) is

      --  Actually, Dummy can be false since in some cases we want to
      --  handle an erroneous theorem more precisely than leaving an
      --  exception.
      Dummy : Boolean;
      pragma Unreferenced (Dummy);

   begin
      Dummy := Apply_To_All_Elements (R);
   end Apply_To_All_Elements;

   ---------------------------
   -- Apply_To_All_Elements --
   ---------------------------

   function Apply_To_All_Elements (R : Node_Id) return Boolean is
      pragma Assert (Kind (R) = K_Theorem);

      Range_Set : constant Result_Set := Set_Array
        (Integer
297
298
299
300
301
302
           (Index
              (Annotation
                 (Referenced_Set
                    (Set_Reference
                       (Range_Variable
                          (Range_Declaration (R))))))));
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
      Success   : Boolean := True;
   begin
      --  For each element of the global ("range") set,
      --  we build the dependant sets and then
      --  we check the verification expression

      for J in 1 .. Cardinal (Range_Set) loop
         Current_Range_Variable := Get (Range_Set, J);
         Set_Var_Value
           (Referenced_Var (Variable_Ref (Range_Declaration (R))),
            New_Elem_Value (Current_Range_Variable));
         Build_All_Objects (R, Success);
         if Success then
            Success := Manage_Check_Expression (R);
         end if;
         exit when not Success;
      end loop;

      Write_Line ("theorem " & Get_Name_String (Name (Identifier (R)))
                    & " is: "& Boolean'Image (Success));

      return Success;
   end Apply_To_All_Elements;

   -------------------
   -- Compute_Value --
   -------------------

   procedure Compute_Value
     (R : Node_Id; Success : out Boolean; Res : out Float)
   is
      pragma Assert (Kind (R) = K_Theorem);

      Range_Set : constant Result_Set := Set_Array
        (Integer
         (Index
          (Annotation
           (Referenced_Set
            (Set_Reference
             (Range_Variable
              (Range_Declaration (R))))))));
   begin
      Success := True;

347
348
349
      --  We returns the value computed for the range set if it
      --  contains only one element, otherwise we compute the expected
      --  range function value.
350
351
352
353
354
355
356
357
358
359
360
361
362
      --  If there is a function value called on a single element,
      --  it is ignored.
      --  If there are multiples elements without a range function call,
      --  we return an error value

      if Cardinal (Range_Set) = 0 then
         Display_Located_Error
           (Loc (R),
            "Empty range set, returned value is 0.0",
            Fatal => False,
            Warning => True);
         Res := 0.0;

363
364
365
      elsif Return_Expression (R) /= No_Node
        and then Range_Function (Return_Expression (R)) /= No_Value
      then
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
         Compute_Range_Function_Value (R, Success, Res);

      elsif Cardinal (Range_Set) = 1 then
         Current_Range_Variable := Get (Range_Set, 1);
         Set_Var_Value
           (Referenced_Var (Variable_Ref (Range_Declaration (R))),
            New_Elem_Value (Current_Range_Variable));
         Build_All_Objects (R, Success);

         if Success then
            Res := Manage_Return_Expression (R);
         end if;

      else
         Display_Located_Error
           (Loc (R), "returns value cannot be valuated "
            & "for multi-element range sets",
            Fatal => True);
      end if;
   end Compute_Value;

   ----------------------------------
   -- Compute_Range_Function_Value --
   ----------------------------------

   procedure Compute_Range_Function_Value
     (R : Node_Id; Success : out Boolean; Res : out Float)
   is
      pragma Assert (Kind (R) = K_Theorem);

      Range_Set : constant Result_Set := Set_Array
        (Integer
         (Index
          (Annotation
           (Referenced_Set
            (Set_Reference
             (Range_Variable
              (Range_Declaration (R))))))));
      Tmp    : Float;
      Buf    : Float;
      Found  : Boolean := False;
   begin
      Success := True;

      case Range_Function (Return_Expression (R)) is
         when FC_MMax =>
            Buf := 0.0;

         when FC_MProduct =>
            Buf := 1.0;

         when FC_MSum =>
            Buf := 0.0;

         when FC_MMin =>
            Buf := 0.0;

         when FC_MAll_Equals =>
            null;

         when others =>
            Display_Located_Error
              (Loc (R), "expected range-level function", Fatal => True);
      end case;

      for I in 1 .. Cardinal (Range_Set) loop
         Current_Range_Variable := Get (Range_Set, I);

         Set_Var_Value
           (Referenced_Var (Variable_Ref (Range_Declaration (R))),
            New_Elem_Value (Current_Range_Variable));

         Build_All_Objects (R, Success);
         if not Success then
            return;
         end if;
         Tmp := Manage_Return_Expression (R);

         case Range_Function (Return_Expression (R)) is

            when FC_MMax =>
               if not Found then
                  Buf := Tmp;
               elsif Tmp > Buf then
                  Buf := Tmp;
               end if;

            when FC_MMin =>
               if not Found then
                  Buf := Tmp;
               elsif Tmp < Buf then
                  Buf := Tmp;
               end if;

            when FC_MAll_Equals =>
               if not Found then
                  Buf := Tmp;
                  Res := 1.0;
               elsif Tmp /= Buf then
                  Res := 0.0;
                  exit;
               end if;

            when FC_MProduct =>
               Buf := Buf * Tmp;

            when FC_MSum =>
               Buf := Buf + Tmp;

            when others =>
               Display_Located_Error
                 (Loc (R), "expected range-level function", Fatal => True);
         end case;

         Found := True;
      end loop;

      if Range_Function (Return_Expression (R)) /= FC_MAll_Equals then
         Success := Found;
         Res := Buf;
      end if;
   end Compute_Range_Function_Value;

   ------------------------
   -- Check_Requirements --
   ------------------------

   function Check_Requirements (R : Node_Id) return Boolean is
      pragma Assert (Kind (R) = K_Theorem);

      Stored_Root : constant Node_Id := R;
      N           : Node_Id;
      Success     : Boolean := True;
   begin
      N := First_Node (Required_Theorems (R));
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
      while Present (N) loop
         RNU.REAL_Root := Related_Theorem (N);

         Write_Line ("requirement : " &
                     Get_Name_String (Name (Identifier (RNU.REAL_Root))));

         --  Requirements can also have requirements

         if not Check_Requirements (RNU.REAL_Root) then
            Display_Located_Error
              (Loc (RNU.REAL_Root), "requirements are not fulfilled",
               Fatal => True);
         end if;

         --  Library theorems are already analyzed, so we proceed
         --  directly to execution

         Initialize_Sets_Table (RNU.REAL_Root);
         Success := Apply_To_All_Elements (RNU.REAL_Root);

         Clean_Runtime;
         exit when not Success;

         N := Next_Node (N);
      end loop;

      RNU.REAL_Root := Stored_Root;

      return Success;
   end Check_Requirements;

   -----------------------
   -- Build_All_Objects --
   -----------------------

   procedure Build_All_Objects (R : Node_Id; Success : in out Boolean) is
      pragma Assert (Kind (R) = K_Theorem);

      N : Node_Id := First_Node (Used_Set (R));
      Res : Result_Set;

   begin
      Success := True;

      --  Build used predefined sets

      while Present (N) loop
         --  No expression can refer to non-previously declared sets,
         --  so there is no order issue

         if Predefined_Type (N) /= SV_No_Type then
            Res := Build_Predefined_Set (Predefined_Type (N));
            Set_Array (Integer (Index (Annotation (N)))) := Res;
         end if;

         N := Next_Node (N);
      end loop;

      --  Independant set declarations

      N := First_Node (Declarations (R));

      while Present (N) and then Success loop
         case Kind (N) is
            when K_Set_Declaration =>  --  Build a set
               Manage_Set_Declaration (N);
               if Returned_Type (Selection_Expression (N)) = RT_Error then
                  Success := False;
               end if;

            when K_Variable_Decl_Expression =>  --  Build a variable
               Manage_Variable_Declaration (N, Success);

            when K_Variable_Decl_Compute =>  --  Build a variable
               Manage_Variable_Theorem_Call (N, Success);

            when others =>
               --  Parsing error undetected !
               Display_Located_Error
                 (Loc (N),
                  "expected set or variable declaration",
                  Fatal => True);
         end case;

         N := Next_Node (N);
      end loop;
   end Build_All_Objects;

   ----------------------------------
   -- Manage_Variable_Theorem_Call --
   ----------------------------------

   procedure Manage_Variable_Theorem_Call
     (E : Node_Id; Success : in out Boolean)
   is
      pragma Assert (Kind (E) = K_Variable_Decl_Compute);

      procedure Export_Domain (E : Node_Id; Success : in out Boolean);

      -------------------
      -- Export_Domain --
      -------------------

      procedure Export_Domain (E : Node_Id; Success : in out Boolean) is
      begin
         --  1/ extract the domain

         case Kind (E) is

            when K_Set_Reference =>
               RNU.Domain := Set_Array (Integer
                                        (Index
                                         (Annotation
                                          (Referenced_Set (E)))));

            when K_Var_Reference =>
               declare
                  VT : constant Value_Type :=
                    Get_Value_Type (Var_Value (Referenced_Var (E)));
               begin
                  RNU.Domain := Empty_Set;
                  Add (RNU.Domain, VT.ELVal);
               end;

            when others =>
               Success := False;
         end case;
      end Export_Domain;

      Result       : Value_Id;
      R            : Float;
      S            : Runtime_Instance_Access;
      Ref          : constant Node_Id := Referenced_Var (Var_Ref (E));
      Local_Domain : constant Boolean := RNU.Is_Domain;
      Local_Domain_value : constant Result_Set := RNU.Domain;
   begin
638
639
640
641
      Write_Line ("   Evaluating "
                    & Get_Name_String
                    (Name (Identifier (Referenced_Var (Var_Ref (E))))));

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
      --  1/ Save the current runtime state

      S := Save_Instance;

      --  2/ Export the user-specified parameters to the environment

      if RN.Domain (E) /= No_Node then
         RNU.Is_Domain := True;
         Export_Domain (RN.Domain (E), Success);
         RNU.Environment := True_Params (E);
         if not Success then
            Display_Located_Error
              (Loc (RNU.REAL_Root), "could not find " &
               Get_Name_String (Theorem_Name (E)) & " domain ",
               Fatal => True);
         end if;
      else
         RNU.Is_Domain := Local_Domain;
         RNU.Domain := Local_Domain_Value;
      end if;

      --  3/ Initialize the runtime space with new values
      --  Library theorems are already analyzed
      --  so we proceed directly to execution
      Clean_Runtime;
      REAL_Root := Related_Theorem (E);

      if not Check_Requirements (RNU.REAL_Root) then
         Display_Located_Error
           (Loc (RNU.REAL_Root), "requirements are not fulfilled",
            Fatal => True);
      end if;

      Initialize_Sets_Table (RNU.REAL_Root);

      --  4/ Launch the extern theorem

      Compute_Value (RNU.REAL_Root, Success, R);
      if not Success then
         Display_Located_Error
           (Loc (RNU.REAL_Root), "Could not compute " &
            Get_Name_String (Theorem_Name (E))
            & " value", Fatal => True);
      end if;

687
688
689
690
691
692
      Write_Line ("   value for "
                    & Get_Name_String
                    (Name (Identifier (Referenced_Var (Var_Ref (E)))))
                    & " after evaluating " & Get_Name_String (Theorem_Name (E))
                    & " is" & Float'Image (R));

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
      --  5/ Restore current runtime state

      Clean_Runtime;
      Load_Instance (S);
      RNU.Environment := No_List;
      RNU.Is_Domain := Local_Domain;
      RNU.Domain := Local_Domain_Value;
      Result := New_Real_Value (Long_Long_Float (R));
      Set_Var_Type (Ref, RT_Float);
      Set_Var_Value (Ref, Result);
   end Manage_Variable_Theorem_Call;

   ---------------------------------
   -- Manage_Variable_Declaration --
   ---------------------------------

   procedure Manage_Variable_Declaration
     (E : Node_Id; Success : in out Boolean)
   is
      pragma Assert (Kind (E) = K_Variable_Decl_Expression);

      Result : Value_Id := No_Value;
      Ret    : Return_Type := RT_Unknown;
      D      : constant Node_Id := Check_Expression (Return_Expr (E));
   begin
      Compute_Check_Expression (D, Ret, Result);
719

720
721
722
723
724
725
      if Ret = RT_Error then
         Display_Located_Error
           (Loc (D), "Could not resolve expression value", Fatal => True);
         Success := False;
         return;
      end if;
726
727
728
729
730
731
732

      Write_Line
        ("     -> value for "
           & Get_Name_String
           (Name (Identifier (Referenced_Var (Var_Ref (E)))))
           & " is " & Image (Result));

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
      Set_Var_Value (Referenced_Var (Var_Ref (E)), Result);
   end Manage_Variable_Declaration;

   ----------------------------
   -- Manage_Set_Declaration --
   ----------------------------

   procedure Manage_Set_Declaration (E : Node_Id) is
      pragma Assert (Kind (E) = K_Set_Declaration);

      R  : Result_Set;
      R2 : Result_Set := Empty_Set;
      S  : Node_Id;
      G  : Node_Id;
   begin
      --  First we compute effective "local" (anonymous) set

      S := Referenced_Set (Local_Set (E));

      --  Compute expression actual value

      R := Compute_Set_Expression (Local_Set_Expression (E));

      --  Bind it in the set table

      Set_Array (Integer (Index (Annotation (S)))) := R;

      --  Find back global set declaration

      G := Referenced_Set (E);

      --  Append the local variable into the local stack

      RNU.Append_Node_To_List (Referenced_Var (Local_Variable (E)),
                               Local_Var (RNU.REAL_Root));

      --  Iterate on the local set

      for I in 1 .. Cardinal (R) loop
         declare
            V        : constant Value_Id := New_Elem_Value (Get (R, I));
            Ret      : Return_Type := RT_Error;
            Result   : Value_Id := No_Value;
         begin
            --  Set the local variable value to the current element of
            --  the local set

            Set_Var_Value (Referenced_Var (Local_Variable (E)), V);

            --  Compute selection expression result
            Compute_Check_Expression (Selection_Expression (E), Ret, Result);
            if Ret /= RT_Boolean then
               Display_Located_Error
                 (Loc (E), "selection expression must return a boolean",
                  Fatal => True);
               Set_Returned_Type (Selection_Expression (E), Ret);
               return;
            end if;

            if Get_Value_Type (Result).BVal then
               Add (R2, Get (R, I));
            end if;
         end;
      end loop;

      --  Append the local variable into the local stack

      RNU.Remove_Node_From_List (Referenced_Var (Local_Variable (E)),
                                 Local_Var (RNU.REAL_Root));

      --  Bind it in the set table,

      Set_Array (Integer (Index (Annotation (G)))) := R2;
   end Manage_Set_Declaration;

   -----------------------------
   -- Manage_Check_Expression --
   -----------------------------

   function Manage_Check_Expression (E : Node_Id) return Boolean is
      pragma Assert (Kind (E) = K_Theorem);

815
816
      use Ocarina.ME_AADL.AADL_Instances.Nutils;

817
818
819
820
      D      : constant Node_Id := Check_Expression (E);
      Result : Value_Id := No_Value;
      Ret    : Return_Type := RT_Unknown;
   begin
821
822
823
824
      if No (D) then
         return True;
      end if;

825
      Compute_Check_Expression (D, Ret, Result);
826

827
      if Ret = RT_Error then
828
         Display_Located_Error (Loc (D), "o<", Fatal => False);
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
         return False;

      elsif Ret = RT_Boolean then
         if Get_Value_Type (Result).BVal = False then
            Display_Located_Error
              (Loc (D), "Property is false for instance " &
               Image (Current_Range_Variable) & " (" &
               Get_Name_String (Compute_Full_Name_Of_Instance
                                (Current_Range_Variable)) & ")",
               Fatal => False);
            return False;
         end if;
         return True;

      else
         Display_Located_Error
           (Loc (D), "Check expression must return a boolean", Fatal => True);
         return False;
      end if;
   end Manage_Check_Expression;

   ------------------------------
   -- Manage_Return_Expression --
   ------------------------------

   function Manage_Return_Expression (E : Node_Id) return Float is
      pragma Assert (Kind (E) = K_Theorem);

857
      D  : constant Node_Id := Check_Expression (Return_Expression (E));
858
859
860
861
862
      Result : Value_Id := No_Value;
      Ret    : Return_Type := RT_Unknown;
   begin
      Compute_Check_Expression (D, Ret, Result);

863
864
865
      case Ret is
         when RT_Float
           | RT_Integer =>
866
867
868
869
870
871
            if Get_Value_Type (Result).T = LT_Integer then
               if Get_Value_Type (Result).ISign then
                  return -(Float (Get_Value_Type (Result).IVal));
               else
                  return Float (Get_Value_Type (Result).IVal);
               end if;
872
            else
873
874
875
876
877
               if Get_Value_Type (Result).RSign then
                  return -(Float (Get_Value_Type (Result).RVal));
               else
                  return Float (Get_Value_Type (Result).RVal);
               end if;
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
            end if;

         when RT_Error =>
            Display_Located_Error
              (Loc (D), "theorem invalid", Fatal => True);
            return 0.0;

         when others =>
            Display_Located_Error
              (Loc (D), "return expression must return a numeric value",
               Fatal => True);
            return 0.0;
      end case;
   end Manage_Return_Expression;

   ------------------------------
   -- Compute_Check_Expression --
   ------------------------------

   procedure Compute_Check_Expression
     (E : Node_Id; Ret : out Return_Type; Result : out Value_Id)
   is
      pragma Assert (Kind (E) = K_Check_Expression or else
                     Kind (E) = K_Ternary_Expression or else
                     Kind (E) = K_Literal or else
                     Kind (E) = K_Var_Reference or else
                     Kind (E) = K_Check_Subprogram_Call);

      T1, T2 : Return_Type := RT_Unknown;
      R1, R2 : Value_Id := No_Value;
      V, V2  : Value_Type;
   begin
      case Kind (E) is
         when K_Var_Reference =>
            Ret := Var_Type (Referenced_Var (E));
            Result := Var_Value (Referenced_Var (E));

         when K_Check_Subprogram_Call =>
            Compute_Check_Subprogram_Call (E, Ret, Result);
            if Ret = RT_Error then
               return;
            end if;

         when K_Literal =>
            V := Get_Value_Type (Value (E));
            case V.T is
               when LT_Integer =>
                  Ret := RT_Integer;
                  Result := New_Integer_Value (V.IVal);

               when LT_Real =>
                  Ret := RT_Float;
                  Result := New_Real_Value (V.RVal);

               when LT_String =>
                  Ret := RT_String;
                  Result := New_String_Value (V.SVal);

               when  LT_Boolean =>
                  Ret := RT_Boolean;
                  Result := New_Boolean_Value (V.BVal);

               when LT_Enumeration =>
                  Display_Located_Error
                    (Loc (E), "could not compute expression value",
                     Fatal => True);

               when others =>
                  Display_Located_Error
                    (Loc (E), "could not compute expression value",
                     Fatal => True);
            end case;

         when K_Ternary_Expression =>
            declare
               Cond  : constant Node_Id := Left_Expr (E);
               Expr1 : constant Node_Id := Right_Expr (E);
               Expr2 : constant Node_Id := Third_Expr (E);
            begin
               case Operator (E) is
                  when OV_If_Then_Else =>
                     --  Choose between expressions evaluation according
                     --  to the condition evaluation result
                     declare
                        R     : Value_Id;
                        T2    : Return_Type;

                     begin
                        Compute_Check_Expression (Cond, T2, R);
                        if T2 /= RT_Boolean then
                           Ret := RT_Error;
                           return;
                        end if;

                        if Get_Value_Type (R).BVal then
                           Compute_Check_Expression (Expr1, Ret, Result);
                        else
                           Compute_Check_Expression (Expr2, Ret, Result);
                        end if;
                     end;

                  when others =>
                     Display_Located_Error
                       (Loc (E), "unknown operator found",
                        Fatal => True);
               end case;
            end;

         when K_Check_Expression =>
            if Present (Left_Expr (E)) and then Present (Right_Expr (E)) then
               Compute_Check_Expression (Left_Expr (E), T1, R1);
989
990
991
992
993
               if T1 = RT_Unknown then
                  Ret := RT_Boolean;
                  Result := New_Boolean_Value (False);
                  return;
               elsif T1 = RT_Error then
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
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
                  Ret := RT_Error;
                  return;
               end if;

               case Operator (E) is
                  when OV_And =>
                     --  Cautious : Lazy evaluation !

                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     if V.BVal then
                        Compute_Check_Expression (Right_Expr (E), T2, R2);
                        if T2 = RT_Error then
                           Ret := RT_Error;
                           return;
                        end if;

                        V2 := Get_Value_Type (R2);
                        Result := New_Boolean_Value (V.BVal and then V2.BVal);
                     else
                        Result := New_Boolean_Value (V.BVal);
                     end if;

                  when OV_Or =>
                     --  Cautious : Lazy evaluation !
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     if V.BVal = False then
                        Compute_Check_Expression (Right_Expr (E), T2, R2);
                        if T2 = RT_Error then
                           Ret := RT_Error;
                           return;
                        end if;

                        V2 := Get_Value_Type (R2);
                        Result := New_Boolean_Value (V.BVal or else V2.BVal);
                     else
                        Result := New_Boolean_Value (V.BVal);
                     end if;

                  when OV_Equal =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value (V = V2);

                  when OV_Different =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value (V /= V2);

                  when OV_Greater =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value ((not (V < V2))
                                                  and then not (V = V2));

                  when OV_Less =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value (V < V2);

                  when OV_Less_Equal =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value (V < V2 or else V = V2);

                  when OV_Greater_Equal =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
1092
1093
1094
1095
1096
                     if T2 = RT_Unknown then
                        Ret := RT_Boolean;
                        Result := New_Boolean_Value (True);
                        return;
                     elsif T2 = RT_Error then
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
                        Ret := RT_Error;
                        return;
                     end if;
                     Ret := RT_Boolean;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     Result := New_Boolean_Value (not (V < V2));

                  when OV_Plus =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     V := V + V2;
                     Result := New_Value (V);
                     case V.T is
                        when LT_Integer =>
                           Ret := RT_Integer;

                        when LT_Real =>
                           Ret := RT_Float;

                        when LT_List =>
                           Ret := Returned_Type (E);

                        when others =>
                           Display_Located_Error
                             (Loc (E), "expected numeric value",
                              Fatal => True);
                     end case;

                  when OV_Minus =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     V := V - V2;
                     Result := New_Value (V);
                     case V.T is
                        when LT_Integer =>
                           Ret := RT_Integer;

                        when LT_Real =>
                           Ret := RT_Float;

                        when others =>
                           Display_Located_Error
                             (Loc (E), "expected numeric value",
                              Fatal => True);
                     end case;

                  when OV_Star =>
                     declare
                        V3 : Value_Type;
                     begin
                        Compute_Check_Expression (Right_Expr (E), T2, R2);
                        if T2 = RT_Error then
                           Ret := RT_Error;
                           return;
                        end if;
                        V := Get_Value_Type (R1);
                        V2 := Get_Value_Type (R2);
                        V3 := V * V2;
                        Result := New_Value (V3);
                        case V3.T is
                           when LT_Integer =>
                              Ret := RT_Integer;

                           when LT_Real =>
                              Ret := RT_Float;

                           when others =>
                              Display_Located_Error
                                (Loc (E), "expected numeric value",
                                 Fatal => True);
                        end case;
                     end;

                  when OV_Modulo =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     V := V mod V2;
                     Result := New_Value (V);
                     if V.T = LT_Integer then
                        Ret := RT_Integer;
                     else
                        Display_Located_Error
                          (Loc (E), "expected integer value",
                           Fatal => True);
                     end if;

                  when OV_Slash =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     V := V / V2;
                     Result := New_Value (V);
                     case V.T is
                        when LT_Integer =>
                           Ret := RT_Integer;

                        when LT_Real =>
                           Ret := RT_Float;

                        when others =>
                           Display_Located_Error
                             (Loc (E), "expected numeric value",
                              Fatal => True);
                     end case;

                  when OV_Power =>
                     Compute_Check_Expression (Right_Expr (E), T2, R2);
                     if T2 = RT_Error then
                        Ret := RT_Error;
                        return;
                     end if;
                     V := Get_Value_Type (R1);
                     V2 := Get_Value_Type (R2);
                     V := Power (V, V2);
                     Result := New_Value (V);

                     case V.T is
                        when LT_Integer =>
                           Ret := RT_Integer;

                        when LT_Real =>
                           Ret := RT_Float;

                        when others =>
                           Display_Located_Error
                             (Loc (E), "expected numeric value",
                              Fatal => True);
                     end case;

                  when others =>
                     Display_Located_Error
                       (Loc (E), "unknown operator found",
                        Fatal => True);
               end case;

            elsif Present (Right_Expr (E)) then
               Compute_Check_Expression (Right_Expr (E), T1, R1);
               if T1 = RT_Error then
                  Ret := RT_Error;
                  return;
               end if;

               case Operator (E) is
                  when OV_Not =>
                     Ret := RT_Boolean;
                     Result := New_Boolean_Value
                       (not Get_Value_Type (R1).BVal);

                  when OV_Minus =>
                     V := Get_Value_Type (R1);
                     case V.T is
                        when LT_Integer =>
                           V.ISign := not V.ISign;
                           Result := New_Value (V);
                           Ret := RT_Integer;

                        when LT_Real =>
                           V.RSign := not V.RSign;
                           Result := New_Value (V);
                           Ret := RT_Float;

                        when others =>
                           Display_Located_Error
                             (Loc (E), "expected numeric value",
                              Fatal => True);
                     end case;

                  when others =>
                     Display_Located_Error
                       (Loc (E), "unknown operator found", Fatal => True);
               end case;
            end if;

         when others =>
            Display_Located_Error
              (Loc (E), "unexpected node kind", Fatal => True);
      end case;
   end Compute_Check_Expression;

   ----------------------------
   -- Compute_Set_Expression --
   ----------------------------

   function Compute_Set_Expression (E : Node_Id) return Result_Set is
      pragma Assert (Kind (E) = K_Set_Expression
                       or else Kind (E) = K_Set_Reference);

      R1 : Result_Set;
      R2 : Result_Set;
   begin
      if Kind (E) = K_Set_Reference then
         return Set_Array (Integer
                           (Index
                            (Annotation
                             (Referenced_Set
                              (E)))));

      else
         if Present (Left_Expr (E))
           and then Present (Right_Expr (E)) then
            R1 := Compute_Set_Expression (Left_Expr (E));
            R2 := Compute_Set_Expression (Right_Expr (E));

            case Operator (E) is
               when OV_Plus =>
                  return Union (R1, R2, Distinct => True);

               when OV_Star =>
                  return Intersection (R1, R2);

               when OV_Minus =>
                  return Exclusion (R1, R2);

               when others =>
                  Display_Located_Error
                    (Loc (E), "not a set operator", Fatal => True);
                  return R1;
            end case;
         else
            Display_Located_Error
              (Loc (E), "missing an operand", Fatal => True);
            return R1;
         end if;
      end if;
   end Compute_Set_Expression;

   -----------------------------------
   -- Compute_Check_Subprogram_Call --
   -----------------------------------

   procedure Compute_Check_Subprogram_Call
     (E : Node_Id; T : out Return_Type; Result : out Value_Id)
   is
      pragma Assert (Kind (E) = K_Check_Subprogram_Call);

      procedure Extract_Parameters_Sets
        (E : Node_Id; R1, R2 : out Result_Set; Success : out Boolean);

      -----------------------------
      -- Extract_Parameters_Sets --
      -----------------------------

      procedure Extract_Parameters_Sets
        (E : Node_Id; R1, R2 : out Result_Set; Success : out Boolean)
      is
         N         : Node_Id;
         Range_Set : constant Node_Id := Referenced_Set
           (Set_Reference
            (Range_Variable
             (Range_Declaration (RNU.REAL_Root))));
         T1, T2    : Result_Set;
      begin
         Success := True;
         T1 := Empty_Set;
         T2 := Empty_Set;

         if not Is_Empty (True_Parameters (E)) then
            N := First_Node (True_Parameters (E));
         else
            Success := False;
            return;
         end if;

         if Kind (N) = K_Var_Reference then
            declare
               N2 : constant Node_Id :=
                 First_Node (Referenced_Sets (E));
               VT : constant Value_Type :=
                 Get_Value_Type (Var_Value (Referenced_Var (N)));
            begin
               Add (T1, VT.ELVal);
               if Referenced_Set (N2) = Range_Set then
                  Add (T2, Current_Range_Variable);
               else
                  T2 := Set_Array (Integer
                                   (Index
                                    (Annotation
                                     (Referenced_Set (N2)))));
               end if;
            end;
         else
            Display_Located_Error
              (Loc (E), "Expected a variable reference as first parameter",
               Fatal => True);
         end if;

         if Variable_Position (E) = Value_Id (1) then
            R1 := T1;
            R2 := T2;
         else
            R1 := T2;
            R2 := T1;
         end if;
      end Extract_Parameters_Sets;

      package OBCQ renames Ocarina.Instances.REAL_Checker.Queries;

      package Is_Bound renames
        OBCQ.Bound_Predicates.Bound_Query;
      package Is_Subcomponent renames
        OBCQ.Subcomponent_Predicates.Subcomponent_Query;
      package Is_Connected renames
        OBCQ.Connected_Predicates.Connected_Query;
      package Is_Called renames
        OBCQ.Call_Predicates.Call_Query;
      package Is_Accessed renames
        OBCQ.Access_Predicates.Access_Query;
      package Is_Passing renames
        OBCQ.Passing_Predicates.Passing_Query;
      package Is_Provided_Class renames
        OBCQ.Provided_Class_Predicates.Provided_Class_Query;
      package Is_Predecessor renames
        OBCQ.Predecessor_Predicates.Predecessor_Query;

      N         : Node_Id;
      R1, R2    : Result_Set;
      RS        : Result_Set;
      Success   : Boolean;

   begin
      case (Code (E)) is
         when FC_Is_Called_By =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               Result := New_Boolean_Value (False);
               return;
            end if;
            RS := Is_Called.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Calling =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Called.Apply (R1, R2, Reversed => True);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Predecessor_Of =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Predecessor.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Passing_Through =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Passing.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Accessed_By =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Accessed.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Accessing_To =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            Rs := Is_Accessed.Apply (R1, R2, Reversed => True);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Connected_To =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Connected.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Connecting_To =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Connected.Apply (R1, R2, Reversed => True);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Bound_To =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Bound.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Subcomponent_Of =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Subcomponent.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Is_Provided_Class =>
            Extract_Parameters_Sets (E, R1, R2, Success);
            if not Success then
               T := RT_Error;
               return;
            end if;
            RS := Is_Provided_Class.Apply (R1, R2);
            T := RT_Boolean;
            if Cardinal (RS) = 0 then
               Result := New_Boolean_Value (False);
            else
               Result := New_Boolean_Value (True);
            end if;

         when FC_Expr =>
            declare
               Var : constant Node_Id := First_Node (True_Parameters (E));
               Set : constant Result_Set :=
                 Set_Array (Integer
                            (Index
                             (Annotation
                              (Referenced_Set
                               (First_Node
                                (Referenced_Sets (E)))))));
               L  : constant List_Id := New_List (K_List_Id, Loc (E));
               F  : Node_Id;
               T1 : Return_Type := RT_Unknown;
               R  : Value_Id := No_Value;
            begin
               for I in 1 .. Cardinal (Set) loop

1610
                  --  Set the current value of the variable to the
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
                  --  value of the element

                  Set_Var_Value (Referenced_Var (Var),
                                 New_Elem_Value (Get (Set, I)));

                  --  Compute the iterative expression value for
                  --  the current variable value

                  Compute_Check_Expression (Next_Node (Var), T1, R);

                  if T1 = RT_Error then
                     Display_Located_Error
                       (Loc (Next_Node (Var)),
                        "could not compute expression value",
                        Fatal => True);
                  else
                     --  Add the computed value to the list of results

                     F := New_Node (K_Value_Node, Loc (E));
                     Set_Item_Val (F, R);
                     RNU.Append_Node_To_List (F, L);
                  end if;
               end loop;

               --  Since we leave the variable's scope,
               --  we delete it.

               RNU.Remove_Node_From_List
                 (Referenced_Var (Var), Used_Var (RNU.REAL_Root));

               Result := New_List_Value (L);
               T := Returned_Type (E);
            end;

         when FC_Get_System_Property_Value =>
            --  Takes 1 parameter :
            --  * a string literal (with property name)

            declare
               RS          : constant Result_Set :=
                 Get_Instances_Of_Component_Type (C_System);
               Root_System : Node_Id;
            begin
               --  1/ Find the root system

               Root_System := Get (RS, 1);
               if Cardinal (RS) > 1 then
                  while AIN.Parent_Subcomponent (Root_System) /= No_Node loop
                     Root_System := AIN.Parent_Component
                       (AIN.Parent_Subcomponent (Root_System));
                  end loop;
               end if;

               --  2/ Search the property

               Result := Get_Property_Value_Function
                 (Value (First_Node (True_Parameters (E))),
                  Returned_Type (E),
                  Root_System);
               if Result = No_Value then
                  T := RT_Error;
                  Display_Located_Error
                    (Loc (First_Node (True_Parameters (E))),
                     "property " & Image
                     (Value (First_Node (True_Parameters (E))))
                     & " is not defined on the root system.",
                     Fatal => True);
               else
                  T := Returned_Type (E);
               end if;
            end;

         when FC_Get_Property_Value =>
            --  Takes 2 parameters :
            --  * an element, a variable reference or a set name
            --  * a string literal (with property name)

            --  If the related set is the range set, then it
            --  actually refers to the range variable.

            --  If the first parameter is an element, then
            --  the property *must* be defined on it.

            N := First_Node (Referenced_Sets (E));
            if Present (N) then
               N := Referenced_Set (N);
            end if;

            if N = Referenced_Set (Set_Reference
                                   (Range_Variable
                                    (Range_Declaration (RNU.REAL_Root))))
            then
               Result := Get_Property_Value_Function
                    (Value (First_Node (True_Parameters (E))),
                     Returned_Type (E),
                     Current_Range_Variable);
1707

1708
1709
1710
1711
1712
1713
               if Result = No_Value then
                  T := RT_Error;
                  Display_Located_Error
                    (Loc (First_Node (True_Parameters (E))),
                     "property " & Image
                     (Value (First_Node (True_Parameters (E))))
1714
                       & " is not defined on element "
1715
1716
1717
1718
1719
1720
                       & Image (Current_Range_Variable) & " (" &
                       Get_Name_String
                       (Ocarina.ME_AADL.AADL_Instances.Nutils.
                          Compute_Full_Name_Of_Instance
                                          (Current_Range_Variable)) & ") "
                       & Image (AIN.Loc (Current_Range_Variable))
1721
                       & Get_Name_String (Name (Identifier (N))),
1722
1723
1724
1725
1726
                     Fatal => False,
                     Warning => True);

                  Result := No_Value;
                  T := RT_Unknown;
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
               else
                  T := Returned_Type (E);
               end if;
            else
               if Present (First_Node (Referenced_Sets (E))) then
                  --  The first parameter is a set
                  declare
                     L  : constant List_Id := New_List (K_List_Id, Loc (E));
                     F  : Node_Id;
                     V  : Value_Id;
                     VT : Value_Type;
                     R1 : constant Result_Set :=
                       Set_Array (Integer
                                  (Index
                                   (Annotation
                                    (Referenced_Set
                                     (First_Node
                                      (Referenced_Sets (E)))))));
                  begin
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
                     if Cardinal (R1) > 0 then
                        for I in 1 .. Cardinal (R1) loop
                           V := Get_Property_Value_Function
                             (Value (First_Node (True_Parameters (E))),
                              Returned_Type (E), Get (R1, I));
                           if V /= No_Value then
                              VT := Get_Value_Type (V);
                              if VT.T /= LT_List then
                                 F := New_Node (K_Value_Node, Loc (E));
                                 Set_Item_Val (F, V);
                                 RNU.Append_Node_To_List (F, L);
                              else
                                 --  If the result is a list, we flatten
                                 --  the list of lists into a single list
                                 declare
                                    P : Node_Id := First_Node (VT.LVal);
                                 begin
                                    while Present (P) loop
                                       F := New_Node (K_Value_Node, Loc (E));
                                       Set_Item_Val (F, Item_Val (P));
                                       RNU.Append_Node_To_List (F, L);
                                       P := Next_Node (P);
                                    end loop;
                                 end;
                              end if;
1771
                           end if;
1772
1773
1774
1775
1776
1777
                        end loop;
                        Result := New_List_Value (L);
                        T := Returned_Type (E);
                     else
                        Display_Located_Error
                          (Loc (E),
1778
1779
1780
1781
1782
1783
1784
1785
                           "cardinal of set "
                             & Get_Name_String
                             (Name
                                (Identifier
                                   (Referenced_Set
                                      (First_Node
                                         (Referenced_Sets (E))))))
                             & " is null",
1786
1787
1788
1789
1790
                           Fatal => False,
                           Warning => True);
                        Result := No_Value;
                        T := RT_Unknown;
                     end if;
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
                  end;
               else
                  --  The first parameter is a variable
                  --  (hence it refers to an element)

                  declare
                     P  : constant Node_Id :=
                       First_Node (True_Parameters (E));
                     VT : constant Value_Type := Get_Value_Type
                       (Var_Value (Referenced_Var (P)));
                  begin
                     Result := Get_Property_Value_Function
                       (Value (Next_Node (P)), Returned_Type (E), VT.ELVal);
                     if Result = No_Value then
                        T := RT_Error;
                        Display_Located_Error
                          (Loc (Next_Node (P)), "property "
                           & Image (Value (Next_Node (P)))
                           & " is not defined on this single element. "
                           & "Try using 'Property_Exists' before.",
                           Fatal => True);
                     else
                        T := Returned_Type (E);
                     end if;
                  end;
               end if;
            end if;

         when FC_Property_Exists =>
            T := Returned_Type (E);
            N := First_Node (Referenced_Sets (E));
            if Present (N) then
               N := Referenced_Set (N);
            end if;
            if N = Referenced_Set (Set_Reference
                                   (Range_Variable
                                    (Range_Declaration (RNU.REAL_Root))))
            then
               Result := Get_Property_Value_Function
                    (Value (First_Node (True_Parameters (E))),
                     Returned_Type (E),
                     Current_Range_Variable);
               if Result /= No_Value then
                  Result := New_Boolean_Value (True);
               else
                  Result := New_Boolean_Value (False);
               end if;
            else
               if Present (First_Node (Referenced_Sets (E))) then

                  --  The first parameter is a set

                  declare
                     Found : Boolean := False;
                     V     : Value_Id;
                     R1    : constant Result_Set := Set_Array
                       (Integer
                        (Index
                         (Annotation
                          (Referenced_Set
                           (First_Node
                            (Referenced_Sets (E)))))));
                  begin
                     for I in 1 .. Cardinal (R1) loop
                        V := Get_Property_Value_Function
                          (Value (First_Node (True_Parameters (E))),
                           Returned_Type (E), Get (R1, I));
                        if V = No_Value then
                           Found := False;
                           exit;
                        else
                           Found := True;
                        end if;
                     end loop;

                     Result := New_Boolean_Value (Found);
                     T := RT_Boolean;
                  end;
               else
                  --  The first parameter is a variable
                  --  (hence it refers to an element)

                  declare
                     P  : constant Node_Id :=
                       First_Node (True_Parameters (E));
                     VT : constant Value_Type := Get_Value_Type
                       (Var_Value (Referenced_Var (P)));
                  begin
                     Result := Get_Property_Value_Function
                       (Value (Next_Node (P)),
                        Returned_Type (E),
                        VT.ELVal);
                     if Result = No_Value then
                        Result := New_Boolean_Value (False);
                     else
                        Result := New_Boolean_Value (True);
                     end if;
                  end;
               end if;
            end if;

         when FC_Cardinal =>
            --  Takes a set as parameter

            declare
               R : constant Result_Set :=
                 Set_Array (Integer
                            (Index
                             (Annotation
                              (Referenced_Set
                               (First_Node
                                (Referenced_Sets (E)))))));
            begin
               Result := New_Integer_Value
                 (Unsigned_Long_Long (Cardinal (R)));
               T := RT_Integer;
            end;

         when FC_First =>
            declare
               VT        : Value_Type;
               N         : Node_Id;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 /= RT_Error then
                  VT := Get_Value_Type (R);
               else
                  T := RT_Error;
                  return;
               end if;

               if T2 = RT_Range_List then
                  declare
                     L : constant List_Id := New_List
                       (K_List_Id, Loc (E));
                     F : Node_Id;
                     VT2 : Value_Type;
                     V : Value_Id;
                  begin
                     T := RT_Float_List;
                     N := First_Node (VT.LVal);
                     while Present (N) loop
                        F := New_Node (K_Value_Node, Loc (E));
                        VT2 := Get_Value_Type (Item_Val (N));
                        V := New_Real_Value
                          (VT2.RVal_Left,
                           VT2.RSign_Left,
                           VT2.RVBase,
                           VT2.RVExp);
                        Set_Item_Val (F, V);
                        RNU.Append_Node_To_List (F, L);
                        N := Next_Node (N);
                     end loop;
                     Result := New_List_Value (L);
                  end;
               else
                  T := RT_Float;
                  Result := New_Real_Value
                    (VT.RVal_Left, VT.RSign_Left, VT.RVBase, VT.RVExp);
               end if;
            end;

         when FC_Last =>
            declare
               VT        : Value_Type;
               N         : Node_Id;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
1965
1966
               if T2 = RT_Unknown then
                  Display_Located_Error
1967
1968
                    (Loc (E), "use default float value of 0.0 for "
                       & "operator Last",
1969
1970
1971
1972
1973
1974
                     Fatal => False, Warning => True);
                  T := RT_Float;
                  Result := New_Real_Value (0.0);
                  return;

               elsif T2 /= RT_Error then
1975
                  VT := Get_Value_Type (R);
1976

1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
               else
                  T := RT_Error;
                  return;
               end if;

               if T2 = RT_Range_List then
                  declare
                     L : constant List_Id := New_List
                       (K_List_Id, Loc (E));
                     F : Node_Id;
                     VT2 : Value_Type;
                     V : Value_Id;
                  begin
                     T := RT_Float_List;
                     N := First_Node (VT.LVal);
                     while Present (N) loop
                        F := New_Node (K_Value_Node, Loc (E));
                        VT2 := Get_Value_Type (Item_Val (N));
                        V := New_Real_Value
                          (VT2.RVal_Right,
                           VT2.RSign_Right,
                           VT2.RVBase,
                           VT2.RVExp);
                        Set_Item_Val (F, V);
                        RNU.Append_Node_To_List (F, L);
                        N := Next_Node (N);
                     end loop;
                     Result := New_List_Value (L);
                  end;
               else
                  T := RT_Float;
                  Result := New_Real_Value
                    (VT.RVal_Right, VT.RSign_Right, VT.RVBase, VT.RVExp);
               end if;
            end;

         when FC_Max =>  --  takes a list as parameter
            declare
               V           : Value_TYpe;
               VT          : Value_Type;
               N           : Node_Id;
               R           : Value_Id;
               T2          : Return_Type;
               Current_Max : Value_Type;
               Min_Value   : constant Value_Id  := New_Real_Value
                 (Long_Long_Float'Last, True);
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
2026
2027
2028

               if T2 = RT_Unknown then
                  Display_Located_Error
2029
2030
                    (Loc (E), "use default float value of 0.0 for operator"
                       & " Max",
2031
2032
2033
2034
2035
2036
                     Fatal => False, Warning => True);
                  T := RT_Float;
                  Result := New_Real_Value (0.0);
                  return;

               elsif T2 = RT_Error then
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is
                  when RT_Float_List =>
                     T := RT_Float;
                  when RT_Int_List =>
                     T := RT_Integer;
                  when others =>
                     Display_Located_Error
                       (Loc (E),
                        "'Max' subprogram cannot be "
                        & "run on non-numeric properties",
                        Fatal => True);
               end case;

               Current_Max := Get_Value_Type (Min_Value);
               while Present (N) loop
                  V := Get_Value_Type (Item_Val (N));

                  if not (V < Current_Max) and then
                    not (V = Current_Max) then
                     Current_Max := V;
                  end if;

                  N := Next_Node (N);
               end loop;

               result := New_Value (Current_Max);
            end;

         when FC_All_Equals =>  --  takes a list as parameter
            declare
               V         : Value_Id;
               VT        : Value_Type;
               Cpt       : Integer := 0;
               Real_Cpt  : Float := 0.0;
               Found     : Boolean := False;
               Equals    : Boolean := True;
               N         : Node_Id;
               Is_Int    : Boolean;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
2087
2088
               if T2 = RT_Unknown then
                  Display_Located_Error
2089
2090
                    (Loc (E), "use default boolean value of true for "
                       & "operator '='",
2091
2092
2093
2094
2095
2096
                     Fatal => False, Warning => True);
                  result := New_Boolean_Value (True);
                  T := RT_Boolean;
                  return;

               elsif T2 = RT_Error then
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
                  T := RT_Error;
                  return;
               end if;

               Result := New_Real_Value (0.0);
               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is
                  when RT_Float_List =>
                     Is_Int := False;

                  when RT_Int_List =>
                     Is_Int := True;

                  when others =>
                     Display_Located_Error
                       (Loc (First_Node (Parameters (E))),
                        "'Max' subprogram cannot be "
                        & "run on non-numeric properties",
                        Fatal => True);
               end case;

               while Equals and then Present (N) loop
                  V := Item_Val (N);
                  if Is_Int then
                     if not Found then
                        Cpt := Integer (Get_Value_Type (V).IVal);
                        Found := True;
                     else
                        if Integer (Get_Value_Type (V).IVal) /= Cpt then
                           Equals := False;
                        end if;
                     end if;
                  else
                     if not Found then
                        Real_Cpt := Float (Get_Value_Type (V).RVal);
                        Found := True;
                     else
                        if Float (Get_Value_Type (V).RVal) /= Real_Cpt then
                           Equals := False;
                        end if;
                     end if;
                  end if;
                  N := Next_Node (N);
               end loop;

               result := New_Boolean_Value (Equals);
               T := RT_Boolean;
            end;

         when FC_Size =>  --  takes a list as parameter
            declare
               VT        : Value_Type;
               Cpt       : Unsigned_Long_Long := 0;
               N         : Node_Id;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is
                  when RT_Int_List
                    | RT_Float_List
                    | RT_String_List
                    | RT_Bool_List
                    | RT_Range_List
                    | RT_Element_List =>
                     T := RT_Integer;

                  when others =>
                     Display_Located_Error
                       (Loc (First_Node (Parameters (E))),
                        "'Size' subprogram cannot be "
                        & "run on non-list values",
                        Fatal => True);
               end case;

               while Present (N) loop
                  Cpt := Cpt + 1;
                  N := Next_Node (N);
               end loop;

               result := New_Integer_Value (Cpt);
            end;

         when FC_Min =>  --  takes a list as parameter
            declare
               V           : Value_Type;
               VT          : Value_Type;
               N           : Node_Id;
               R           : Value_Id;
               T2          : Return_Type;
               Current_Min : Value_Type;
               Max_Value   : constant Value_Id  := New_Real_Value
                 (Long_Long_Float'Last, False);
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

2209
2210
2211
               if T2 = RT_Unknown then
                  Display_Located_Error
                    (Loc (E),
2212
2213
                     "unknown value, use default value of 0.0 for operator"
                       & " Min",
2214
2215
                     Fatal => False,
                     Warning => True);
2216

2217
                  Result := New_Real_Value (0.0, False);
2218

2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
               else
                  VT := Get_Value_Type (R);
                  N := First_Node (VT.LVal);

                  case T2 is
                     when RT_Float_List =>
                        T := RT_Float;
                     when RT_Int_List =>
                        T := RT_Integer;
                     when others =>
                        Display_Located_Error
                          (Loc (E),
                           "'Min' subprogram cannot be "
                             & "run on non-numeric properties",
                           Fatal => True);
                  end case;
2235

2236
2237
2238
                  Current_Min := Get_Value_Type (Max_Value);
                  while Present (N) loop
                     V := Get_Value_Type (Item_Val (N));
2239

2240
2241
2242
                     if V < Current_Min then
                        Current_Min := V;
                     end if;
2243

2244
2245
2246
2247
2248
                     N := Next_Node (N);
                  end loop;

                  result := New_Value (Current_Min);
               end if;
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
            end;

         when FC_Head =>  --  takes a list as parameter
            declare
               VT          : Value_Type;
               N           : Node_Id;
               R           : Value_Id;
               T2          : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is
                  when RT_Int_List =>
                     T := RT_Integer;
                  when RT_Float_List =>
                     T := RT_Float;
                  when RT_String_List =>
                     T := RT_String;
                  when RT_Bool_List =>
                     T := RT_Boolean;
                  when RT_Range_List =>
                     T := RT_Range;
                  when RT_Element_List =>
                     T := RT_Element;
                  when others =>
                     Display_Located_Error
                       (Loc (E),
                        "'head' subprogram cannot be "
                        & "run on a non-list parameter",
                        Fatal => True);
               end case;

               result := New_Value (Get_Value_Type (Item_Val (N)));
            end;

         when FC_Queue =>  --  takes a list as parameter
            declare
               V           : Value_Id;
               VT          : Value_Type;
               N           : Node_Id;
               L           : constant List_Id := New_List
                 (K_List_Id, Loc (E));
               F           : Node_Id;
               R           : Value_Id;
               T2          : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is
                  when RT_Int_List
                    | RT_Float_List
                    | RT_String_List
                    | RT_Bool_List
                    | RT_Range_List
                    | RT_Element_List =>
                     T := T2;

                  when others =>
                     Display_Located_Error
                       (Loc (E),
                        "'queue' subprogram cannot be "
                        & "run on a non-list parameter",
                        Fatal => True);
               end case;

               if Present (N) then
                  N := Next_Node (N);
               end if;

               while Present (N) loop
                  V := Item_Val (N);
                  F := New_Node (K_Value_Node, Loc (E));
                  Set_Item_Val (F, V);
                  RNU.Append_Node_To_List (F, L);
                  N := Next_Node (N);
               end loop;

               Result := New_List_Value (L);
            end;

         when FC_Int =>  --  takes a float or an integer as parameter
            declare
               VT        : Value_Type;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               if VT.T = LT_Real then
                  Result := New_Integer_Value (Unsigned_Long_Long (VT.RVal));
               else
2362
                  Result := New_Integer_Value (VT.IVal);
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
               end if;
               T := RT_Integer;
            end;

         when FC_List =>
            --  takes a set or a list of literal as parameters
            declare
               R           : Result_Set;
               Result_List : constant List_Id := New_List (K_List_Id, Loc (E));
               V           : Value_Id;
               F, P        : Node_Id;
            begin
               if not Is_Empty (Referenced_Sets (E)) then
                  R := Set_Array
                    (Integer
                     (Index
                      (Annotation
                       (Referenced_Set
                        (First_Node
                         (Referenced_Sets (E)))))));
                  for I in 1 .. Cardinal (R) loop
                     V := New_Elem_Value (Get (R, I));
                     F := New_Node (K_Value_Node, Loc (E));
                     Set_Item_Val (F, V);
                     RNU.Append_Node_To_List (F, Result_List);
                  end loop;
                  Result := New_List_Value (Result_List);
                  T := RT_Element_List;
               elsif not Is_Empty (Parameters (E)) then
                  P := First_Node (Parameters (E));
                  while Present (P) loop
                     Compute_Check_Expression (P, T, Result);
                     F := New_Node (K_Value_Node, Loc (E));
                     Set_Item_Val (F, Result);
                     RNU.Append_Node_To_List (F, Result_List);
                     P := Next_Node (P);
                  end loop;
                  Result := New_List_Value (Result_List);
                  T := Returned_Type (E);
               end if;
            end;

         when FC_Float =>  --  takes a float or an integer as parameter
            declare
               VT        : Value_Type;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               VT := Get_Value_Type (R);
               if VT.T = LT_Integer then
                  Result := New_Real_Value (Long_Long_Float (VT.IVal));
               else
2422
                  Result := New_Real_Value (VT.RVal);
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
               end if;
               T := RT_Float;
            end;

         when FC_Product =>  --  takes a list as parameter
            declare
               V         : Value_Id;
               VT        : Value_Type;
               Cpt       : Integer := 1;
               Real_Cpt  : Float := 1.0;
               N         : Node_Id;
               Is_Int    : Boolean;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Subprogram_Call
                 (First_Node (Parameters (E)), T2, R);
               if T2 = RT_Error then
                  T := RT_Error;
                  return;
               end if;

               Result := New_Real_Value (0.0);
               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);

               case T2 is

                  when RT_Float_List =>
                     Is_Int := False;

                  when RT_Int_List =>
                     Is_Int := True;

                  when others =>
                     Display_Located_Error
                       (Loc (First_Node (Parameters (E))),
                        "'Product' subprogram cannot be "
                        & "run on non-numeric properties",
                        Fatal => True);
               end case;

               while Present (N) loop
                  V := Item_Val (N);
                  if Is_Int then
                     Cpt := Cpt * Integer (Get_Value_Type (V).IVal);
                  else
                     Real_Cpt := Real_Cpt * Float (Get_Value_Type (V).RVal);
                  end if;
                  N := Next_Node (N);
               end loop;

               if Is_Int then
                  result := New_Integer_Value
                    (Unsigned_Long_Long (Cpt));
                  T := RT_Integer;
               else
                  result := New_Real_Value
                    (Long_Long_Float (Real_Cpt));
                  T := RT_Float;
               end if;
            end;

         when FC_Sum =>  --  takes a list as parameter
            declare
               V         : Value_Id;
               VT        : Value_Type;
               Cpt       : Integer := 0;
               Real_Cpt  : Float := 0.0;
               N         : Node_Id;
               Is_Int    : Boolean;
               R         : Value_Id;
               T2        : Return_Type;
            begin
               Compute_Check_Expression
                 (First_Node (Parameters (E)), T2, R);
2499
2500
2501

               if T2 = RT_Unknown then
                  Display_Located_Error
2502
2503
                    (Loc (E), "use default float value of 0.0 for operator"
                       & " Sum",
2504
2505
2506
2507
2508
2509
                     Fatal => False, Warning => True);
                  T := RT_Float;
                  Result := New_Real_Value (0.0);
                  return;

               elsif T2 = RT_Error then
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
                  T := RT_Error;
                  return;
               end if;

               Result := New_Real_Value (0.0);
               VT := Get_Value_Type (R);
               N := First_Node (VT.LVal);
               case T2 is
                  when RT_Float_List =>
                     Is_Int := False;

                  when RT_Int_List =>
                     Is_Int := True;

                  when others =>
                     Display_Located_Error
                       (Loc (First_Node (Parameters (E))),
                        "'Sum' subprogram cannot be "
                        & "run on non-numeric properties",
                        Fatal => True);
               end case;

               while Present (N) loop
                  V := Item_Val (N);
                  if Is_Int then
                     Cpt := Cpt + Integer (Get_Value_Type (V).IVal);
                  else
2537