ocarina-backends-ada_tree-nutils.adb 93.4 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--     O C A R I N A . B A C K E N D S . A D A _ T R E E . N U T I L S      --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2016 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
32
33
34
35
36
--                                                                          --
------------------------------------------------------------------------------

with GNAT.Table;
with GNAT.Case_Util;

with Charset;   use Charset;
with Locations; use Locations;
37
38
with Ocarina.Namet;     use Ocarina.Namet;
with Ocarina.Output;    use Ocarina.Output;
39
with Ocarina.Types;     use Ocarina.Types;
40
41
42
43
44
45
46
47
48
49
50
51
52
with Utils;     use Utils;

with Ocarina.Backends.Ada_Values; use Ocarina.Backends.Ada_Values;
with Ocarina.Backends.Utils;      use Ocarina.Backends.Utils;
with Ocarina.Backends.Messages;   use Ocarina.Backends.Messages;

with Ocarina.ME_AADL.AADL_Tree.Nodes;

package body Ocarina.Backends.Ada_Tree.Nutils is

   package ADN renames Ocarina.Backends.Ada_Tree.Nodes;
   package AAN renames Ocarina.ME_AADL.AADL_Tree.Nodes;

53
54
   Var_Suffix  : constant String := "_Ü";
   Initialized : Boolean         := False;
55
56
57
58
59
60
61
62
63
64
65

   Keyword_Suffix : constant String := "%Ada";
   --  Used to mark Ada keywords and avoid collision with other
   --  languages

   type Entity_Stack_Entry is record
      Current_Package : Node_Id;
      Current_Entity  : Node_Id;
   end record;

   No_Depth : constant Int := -1;
66
67
68
69
70
71
   package Entity_Stack is new GNAT.Table
     (Entity_Stack_Entry,
      Int,
      No_Depth + 1,
      10,
      10);
72
73
74
75

   use Entity_Stack;

   function Create_Unique_Identifier
76
77
     (Name   : Name_Id;
      Suffix : String := "") return Name_Id;
78
79
80
81
82
83
84
85
86
   --  This function returns a unique identifier for Name with a UT_ prefix,
   --  followed by the name of the node, name of the package, Name
   --  and Suffix if exists.

   function Get_Style_State return Value_Id;
   --  This function returns a string literal which is the value given
   --  to the pragma style_checks. The 'Off' value is does not ignore
   --  line length.

87
   procedure New_Operator (O : Operator_Type; I : String := "");
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

   ----------------------
   -- Add_With_Package --
   ----------------------

   procedure Add_With_Package
     (E            : Node_Id;
      Used         : Boolean := False;
      Warnings_Off : Boolean := False;
      Elaborated   : Boolean := False)
   is

      function To_Library_Unit (E : Node_Id) return Node_Id;
      --  Return the library unit which E belongs to in order to with
      --  it. As a special rule, package Standard returns No_Node.

      ---------------------
      -- To_Library_Unit --
      ---------------------

      function To_Library_Unit (E : Node_Id) return Node_Id is
         U : Node_Id;

      begin
         pragma Assert (Kind (E) = K_Designator);
         U := Corresponding_Node (Defining_Identifier (E));

         --  This node is not properly built as the corresponding node
         --  is not set.

         if No (U) then
            if Output_Tree_Warnings then
120
               Write_Str ("WARNING: node ");
121
122
123
124
125
126
127
128
129
130
               Write_Name (Name (Defining_Identifier (E)));
               Write_Line (" has a null corresponding node");
            end if;
            return E;
         end if;

         if ADN.Kind (U) = K_Package_Declaration then
            U := Package_Specification (U);
         end if;

131
132
133
         pragma Assert
           (Kind (U) = K_Package_Specification
            or else Kind (U) = K_Package_Instantiation);
134
135
136
137
138
139
140

         --  This is a subunit and we do not need to add a with for
         --  this unit but for one of its parents.  If the kind of the
         --  parent unit name is a K_Package_Instantiation, we
         --  consider it as a subunit.

         if Kind (U) = K_Package_Instantiation
141
142
           or else Is_Subunit_Package (U)
         then
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
            U := Parent_Unit_Name (E);

            --  This is a special case to handle package Standard

            if No (U) then
               return No_Node;
            end if;

            return To_Library_Unit (U);
         end if;

         return E;
      end To_Library_Unit;

      P             : constant Node_Id := To_Library_Unit (E);
      W             : Node_Id;
      N             : Name_Id;
      I             : Node_Id;
      Existing_With : Node_Id;

   begin
      if No (P) then
         return;
      end if;

      --  Build a string "<current_entity>%[s,b] <withed_entity>" that
      --  is the current entity name, a character 's' (resp 'b') to
      --  indicate whether we consider the spec (resp. body) of the
      --  current entity and the withed entity name.

      --  To avoid that a package "with"es itself

      if Kind (Current_Package) /= K_Subprogram_Implementation
        and then Kind (Current_Package) /= K_Subprogram_Specification
      then
         --  and then Corresponding_Node (Defining_Identifier (P))
         --  = Package_Declaration (Current_Package)

         if To_Lower (Fully_Qualified_Name (P)) =
           To_Lower
183
184
             (Fully_Qualified_Name
                (Defining_Identifier (Package_Declaration (Current_Package))))
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
         then
            return;
         end if;
      end if;

      --  Routine that check wether the package P has already been
      --  added to the withed packages of the current package. When we
      --  add a 'with' clause to a package specification, we check
      --  only if this clause has been added to the current
      --  spec. However, when we add a 'with' clause to a package
      --  body, we check that the clause has been added in both the
      --  spec and the body.

      --  IMPORTANT: Provided that all specs are generated before all
      --  bodies, this behaviour is automatically applied. We just
      --  need to encode the package name *without* precising whether
      --  it is a spec or a body

      --  Encoding the withed package and the current entity

      N := Fully_Qualified_Name (P);

      if Kind (Current_Package) /= K_Subprogram_Implementation
        and then Kind (Current_Package) /= K_Subprogram_Specification
      then
         I := Defining_Identifier (Package_Declaration (Current_Package));

         Get_Name_String (Fully_Qualified_Name (I));

         --  In both the PolyORB-HI and PolyORB-QoS generators some
         --  packages that are generated for different nodes have
         --  exactly the same name. We must encode the node name to
         --  differenciate them. This happens only when we deal with a
         --  package generated for a root node

         if Present
221
222
223
             (Main_Subprogram
                (Distributed_Application_Unit
                   (Package_Declaration (Current_Package))))
224
225
226
227
228
229
230
         then
            Add_Char_To_Name_Buffer (' ');
            Get_Name_String_And_Append
              (ADN.Name
                 (Defining_Identifier
                    (Main_Subprogram
                       (Distributed_Application_Unit
231
                          (Package_Declaration (Current_Package))))));
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
         end if;

      elsif Kind (Current_Package) /= K_Subprogram_Specification then
         I := Defining_Identifier (Specification (Current_Package));
         Get_Name_String (Fully_Qualified_Name (I));
      else
         I := Defining_Identifier (Current_Package);
         Get_Name_String (Fully_Qualified_Name (I));
      end if;

      Add_Char_To_Name_Buffer (' ');
      Get_Name_String_And_Append (N);
      N := To_Lower (Name_Find);

      --  Get the info associated to the obtained name in the hash
      --  table and check whether it is already set to a value
      --  different from 0 (No_Node) which means that the withed
      --  entity is already in the withed package list. In this case
      --  try to enrich the exisiting with clause with eventual 'use',
      --  'elaborate' or warning disabling clauses.

      Existing_With := Node_Id (Get_Name_Table_Info (N));

      if Present (Existing_With) then
         Set_Used (Existing_With, ADN.Used (Existing_With) or else Used);
         Set_Warnings_Off
           (Existing_With,
            ADN.Warnings_Off (Existing_With) or else Warnings_Off);
         Set_Elaborated
261
262
           (Existing_With,
            ADN.Elaborated (Existing_With) or else Elaborated);
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
         return;
      end if;

      --  Debug message (if wanted by the user)

      if Output_Unit_Withing then
         Write_Name (N);
         Write_Eol;
      end if;

      --  Add entity to the withed packages list of the current
      --  package

      W := Make_Withed_Package (P, Used, Warnings_Off, Elaborated);

      --  Mark the 'with' clause as being added to the current package

      Set_Name_Table_Info (N, Int (W));

      Append_Node_To_List (W, Withed_Packages (Current_Package));
   end Add_With_Package;

   ------------------------------------
   -- Append_Node_To_Current_Package --
   ------------------------------------

289
   procedure Append_Node_To_Current_Package (N : Node_Id) is
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
   begin
      case Kind (Current_Package) is
         when K_Package_Specification =>
            Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
         when K_Package_Implementation =>
            Append_Node_To_List (N, ADN.Statements (Current_Package));
         when others =>
            raise Program_Error;
      end case;
   end Append_Node_To_Current_Package;

   -------------------------
   -- Append_Node_To_List --
   -------------------------

   procedure Append_Node_To_List (E : Node_Id; L : List_Id) is
      Last : Node_Id;

   begin
      Last := Last_Node (L);
      if No (Last) then
         Set_First_Node (L, E);
      else
         Set_Next_Node (Last, E);
      end if;
      Last := E;
      while Present (Last) loop
         Set_Last_Node (L, Last);
         Last := Next_Node (Last);
      end loop;
   end Append_Node_To_List;

   -----------------------
   -- Insert_After_Node --
   -----------------------

   procedure Insert_After_Node (E : Node_Id; N : Node_Id) is
      Next : constant Node_Id := Next_Node (N);
   begin
      Set_Next_Node (N, E);
      Set_Next_Node (E, Next);
   end Insert_After_Node;

   ------------------------
   -- Insert_Before_Node --
   ------------------------

   procedure Insert_Before_Node (E : Node_Id; N : Node_Id; L : List_Id) is
      Entity : Node_Id;
   begin
      Entity := First_Node (L);
      if Entity = N then
         Set_Next_Node (E, Entity);
         Set_First_Node (L, E);
      else
         while Present (Entity) loop
            exit when Next_Node (Entity) = N;
            Entity := Next_Node (Entity);
         end loop;

         Insert_After_Node (E, Entity);
      end if;
   end Insert_Before_Node;

   ---------------------
   -- Copy_Designator --
   ---------------------

   function Copy_Designator
     (Designator : Node_Id;
360
      Withed     : Boolean := True) return Node_Id
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
   is
      D : Node_Id;
      P : Node_Id := Parent_Unit_Name (Designator);

   begin
      D := Copy_Node (Designator);
      if Kind (Designator) = K_Designator
        or else Kind (Designator) = K_Defining_Identifier
      then
         P := Parent_Unit_Name (Designator);
      elsif Kind (Designator) = K_Attribute_Designator then
         P := Parent_Unit_Name (Prefix (Designator));
      end if;

      if Present (P) then
         P := Copy_Designator (P, False);
         if Withed then
            Add_With_Package (P);
         end if;
      end if;
      return D;
   end Copy_Designator;

   ---------------
   -- Copy_Node --
   ---------------

   function Copy_Node (N : Node_Id) return Node_Id is
      C : Node_Id;

   begin
      case Kind (N) is
         when K_Designator =>
            C := New_Node (K_Designator);
            Set_Defining_Identifier (C, Defining_Identifier (N));
            Set_Frontend_Node (C, Frontend_Node (N));
            Set_Homogeneous_Parent_Unit_Name (C, Parent_Unit_Name (N));

         when K_Defining_Identifier =>
            C := New_Node (K_Defining_Identifier);
            Set_Name (C, Name (N));
            Set_Homogeneous_Parent_Unit_Name (C, Parent_Unit_Name (N));
            Set_Corresponding_Node (C, Corresponding_Node (N));

         when K_Attribute_Designator =>
            C := New_Node (K_Attribute_Designator);
            Set_Name (C, Name (N));
            Set_Prefix (C, Copy_Node (Prefix (N)));

         when others =>
            raise Program_Error;
      end case;
      return C;
   end Copy_Node;

   ------------------------------------------
   -- Create_Subtype_From_Range_Constraint --
   ------------------------------------------

420
421
   function Create_Subtype_From_Range_Constraint
     (R : Node_Id) return Node_Id
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
   is
      N         : Node_Id := No_Node;
      C_First   : Node_Id := No_Node;
      C_Last    : Node_Id := No_Node;
      C_Index   : Node_Id := No_Node;
      Ident     : Node_Id := No_Node;
      Sub_Ident : Node_Id := No_Node;
   begin
      pragma Assert (Kind (R) = K_Range_Constraint);

      --  Stock identifier of the node in the variable Ident.
      --  If the node is not a literal, only its identifier is necessary.
      --  Variables C_first, C_Last and C_Index keep informations to
      --  construct the type replacing the range constraint.
      --  C_First and C_Last stock identifier of the node except for
      --  a literal node.

      if Present (Nodes.First (R)) then
         case Kind (Nodes.First (R)) is
            when K_Attribute_Designator =>
               C_First := Defining_Identifier (Nodes.Prefix (Nodes.First (R)));
443
               Ident   := C_First;
444
445
446

            when K_Designator =>
               C_First := Defining_Identifier (Nodes.First (R));
447
               Ident   := C_First;
448
449
450

            when K_Literal =>
               C_First := Nodes.First (R);
451
452
453
454
               Ident   :=
                 Make_Defining_Identifier
                   (Get_String_Name
                      (Ada_Values.Image (Nodes.Value (C_First))));
455
456
457

            when K_Defining_Identifier =>
               C_First := Nodes.First (R);
458
               Ident   := C_First;
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
            when others =>
               null;
         end case;
      end if;

      if Present (Nodes.Last (R)) then
         case Kind (Nodes.Last (R)) is
            when K_Attribute_Designator =>
               C_Last := Defining_Identifier (Nodes.Prefix (Nodes.Last (R)));

            when K_Designator =>
               C_Last := Defining_Identifier (Nodes.Last (R));

            when K_Literal =>
               C_Last :=
                 Make_Defining_Identifier
475
476
                   (Get_String_Name
                      (Ada_Values.Image (Nodes.Value (Nodes.Last (R)))));
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496

            when K_Defining_Identifier =>
               C_Last := Nodes.Last (R);

            when others =>
               null;
         end case;

         --  Construct identifier of the type : First_range_Last_Range
         Get_Name_String (Name (Ident));
         Add_Char_To_Name_Buffer ('_');
         Get_Name_String_And_Append (Name (C_Last));
         Sub_Ident := Make_Defining_Identifier (Name_Find);
      end if;

      if Present (Index_Type (R)) then
         case Kind (Index_Type (R)) is
            when K_Attribute_Designator =>
               Ident := Defining_Identifier (Nodes.Prefix (Index_Type (R)));

497
               if C_First = No_Node and then C_Last = No_Node then
498
499
500

                  --  Consider only Range attribute. Can be problematic
                  --  with a size attribute for instance.
501
502
503
504
505
506
507
508
                  C_Index :=
                    Make_Range_Constraint
                      (Make_Attribute_Designator (Ident, A_First),
                       Make_Attribute_Designator (Ident, A_Last),
                       Ident);

                  Sub_Ident :=
                    Make_Defining_Identifier (Name (Index_Type (R)));
509
510
               end if;
            when K_Designator =>
511
               Ident   := Defining_Identifier (Index_Type (R));
512
513
514
515
516
517
518
519
520
               C_Index := Index_Type (R);

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

      --  Case of unconstraint array (range <>)
      --  or a range attribute (Index'Range).
521
522
      if (C_First = No_Node)
        and then (C_Last = No_Node)
523
        and then (C_Index /= No_Node)
524
525
        and then Ident /= No_Node
      then
526
527
528
529
530
531

         --  if C_Index is an unconstraint array (range <>)
         --  return a range constraint, else return created type.
         if Kind (C_Index) = K_Designator then
            N := Make_Range_Constraint (No_Node, No_Node, Ident);
         else
532
533
534
535
536
            Sub_Ident :=
              Make_Defining_Identifier
                (Create_Unique_Identifier
                   (Name (Ident),
                    Get_Name_String (Name (Sub_Ident))));
537
            if Get_Name_Table_Info (Name (Sub_Ident)) = Int (No_Node) then
538
539
540
541
542
               N :=
                 Make_Full_Type_Declaration
                   (Defining_Identifier => Sub_Ident,
                    Type_Definition     => C_Index,
                    Is_Subtype          => True);
543
544
545
               Set_Name_Table_Info (Name (Sub_Ident), Int (Sub_Ident));
               Append_Node_To_Current_Package (N);
            else
546
547
548
               N :=
                 Corresponding_Node
                   (Node_Id (Get_Name_Table_Info (Name (Sub_Ident))));
549
550
551
552
553
554
            end if;
         end if;

      --  Case range constraint is of the form :
      --  My_Type range Range_First .. Range_Last
      --  create a type : subtype UT_Type is My_Type Range_First ..Range_Last
555
556
557
558
      elsif (C_First /= No_Node)
        and then (C_Last /= No_Node)
        and then (C_Index /= No_Node)
      then
559

560
561
562
         Sub_Ident :=
           Make_Defining_Identifier
             (Create_Unique_Identifier (Name (Sub_Ident)));
563

564
565
566
567
568
569
         N :=
           Make_Full_Type_Declaration
             (Defining_Identifier => Sub_Ident,
              Type_Definition     =>
                Make_Range_Constraint (C_First, C_Last, Ident),
              Is_Subtype => True);
570
571
572
573
574

         if Get_Name_Table_Info (Name (Sub_Ident)) = Int (No_Node) then
            Set_Name_Table_Info (Name (Sub_Ident), Int (Sub_Ident));
            Append_Node_To_Current_Package (N);
         else
575
576
577
            N :=
              Corresponding_Node
                (Node_Id (Get_Name_Table_Info (Name (Sub_Ident))));
578
579
580
581
         end if;

      --  Case range constraint is of the form : 1 .. Max_Size,
      --  create a type : type UT_Type is Integer range 1 .. Max_Size
582
583
584
585
      elsif (C_First /= No_Node)
        and then (C_Last /= No_Node)
        and then (C_Index = No_Node)
      then
586

587
588
589
         Sub_Ident :=
           Make_Defining_Identifier
             (Create_Unique_Identifier (Name (Sub_Ident)));
590

591
592
593
594
595
596
597
598
599
         N :=
           Make_Full_Type_Declaration
             (Defining_Identifier => Sub_Ident,
              Type_Definition     =>
                Make_Range_Constraint
                  (C_First,
                   C_Last,
                   Make_Defining_Identifier (TN (T_Integer))),
              Is_Subtype => True);
600
601
602
603
604

         if Get_Name_Table_Info (Name (Sub_Ident)) = Int (No_Node) then
            Set_Name_Table_Info (Name (Sub_Ident), Int (Sub_Ident));
            Append_Node_To_Current_Package (N);
         else
605
606
607
            N :=
              Corresponding_Node
                (Node_Id (Get_Name_Table_Info (Name (Sub_Ident))));
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
         end if;
      end if;

      return N;
   end Create_Subtype_From_Range_Constraint;

   --------------------
   -- Current_Entity --
   --------------------

   function Current_Entity return Node_Id is
   begin
      if Last = No_Depth then
         return No_Node;
      else
         return Table (Last).Current_Entity;
      end if;
   end Current_Entity;

   ---------------------
   -- Current_Package --
   ---------------------

   function Current_Package return Node_Id is
   begin
      if Last = No_Depth then
         return No_Node;
      else
         return Table (Last).Current_Package;
      end if;
   end Current_Package;

   ---------------------------------------
   -- Defining_Identifier_To_Designator --
   ---------------------------------------

   function Defining_Identifier_To_Designator
     (N                       : Node_Id;
      Copy                    : Boolean := False;
      Keep_Parent             : Boolean := True;
648
      Keep_Corresponding_Node : Boolean := True) return Node_Id
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
   is
      P      : Node_Id;
      Def_Id : Node_Id := N;
   begin
      pragma Assert (ADN.Kind (N) = K_Defining_Identifier);

      if Copy then
         Def_Id := Copy_Node (N);
      end if;

      if not Keep_Parent then
         Def_Id := Make_Defining_Identifier (ADN.Name (N));
      end if;

      if Keep_Corresponding_Node then
664
         Set_Corresponding_Node (Def_Id, Corresponding_Node (N));
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
      end if;

      P := New_Node (K_Designator);
      Set_Defining_Identifier (P, Def_Id);

      if Keep_Parent then
         Set_Homogeneous_Parent_Unit_Name (P, Parent_Unit_Name (N));
      end if;

      return P;
   end Defining_Identifier_To_Designator;

   ---------------------
   -- Message_Comment --
   ---------------------

   function Message_Comment (M : Name_Id) return Node_Id is
      C : Node_Id;
   begin
      C := Make_Ada_Comment (M);
      return C;
   end Message_Comment;

   ---------------------
   -- Message_Comment --
   ---------------------

   function Message_Comment (M : String) return Node_Id is
      C : Node_Id;
   begin
      Set_Str_To_Name_Buffer (M);
      C := Make_Ada_Comment (Name_Find);
      return C;
   end Message_Comment;

   --------------------------
   -- Fully_Qualified_Name --
   --------------------------

   function Fully_Qualified_Name (N : Node_Id) return Name_Id is
      Parent_Node : Node_Id := No_Node;
      Parent_Name : Name_Id := No_Name;

   begin
      case Kind (N) is
         when K_Designator =>
            Parent_Node := Parent_Unit_Name (N);

            if not Present (Parent_Node) then
               Parent_Node := Parent_Unit_Name (Defining_Identifier (N));
            end if;

            if Present (Parent_Node) then
               Parent_Name := Fully_Qualified_Name (Parent_Node);
            end if;

            Name_Len := 0;
            if Present (Parent_Node) then
               Get_Name_String (Parent_Name);
               Add_Char_To_Name_Buffer ('.');
            end if;
            Get_Name_String_And_Append (Name (Defining_Identifier (N)));
            return Name_Find;

         when K_Defining_Identifier =>
            Parent_Node := Parent_Unit_Name (N);
            if Present (Parent_Node) then
               Parent_Name := Fully_Qualified_Name (Parent_Node);
            end if;

            Name_Len := 0;
            if Present (Parent_Node) then
               Get_Name_String (Parent_Name);
               Add_Char_To_Name_Buffer ('.');
            end if;
            Get_Name_String_And_Append (Name (N));
            return Name_Find;

         when K_Attribute_Designator =>
            Get_Name_String (Fully_Qualified_Name (Prefix (N)));
            Add_Char_To_Name_Buffer (''');
            Get_Name_String_And_Append (Name (N));
            return Name_Find;

         when others =>
            raise Program_Error;
      end case;
   end Fully_Qualified_Name;

   ---------------------
   -- Get_Style_State --
   ---------------------

   function Get_Style_State return Value_Id is

      --  The maximum line length allowed by GNAT is 32766

      Max_Line_Length : constant Int := 32766;
      Result          : Value_Id;
   begin
      Set_Str_To_Name_Buffer ("NM");
      Add_Nat_To_Name_Buffer (Max_Line_Length);
      Result := New_String_Value (Name_Find);
      return Result;
   end Get_Style_State;

   -----------
   -- Image --
   -----------

   function Image (T : Token_Type) return String is
      S : String := Token_Type'Image (T);
   begin
      To_Lower (S);
      return S (5 .. S'Last);
   end Image;

   -----------
   -- Image --
   -----------

   function Image (O : Operator_Type) return String is
      S : String := Operator_Type'Image (O);
   begin
      To_Lower (S);
      for I in S'First .. S'Last loop
         if S (I) = '_' then
            S (I) := ' ';
         end if;
      end loop;
      return S (4 .. S'Last);
   end Image;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize is
   begin
      --  Initialize Nutils only once

      if Initialized then
         return;
      end if;

      Initialized := True;

      --  Keywords.
      for I in Keyword_Type loop
         New_Token (I);
      end loop;

      --  Graphic Characters
      New_Token (Tok_Double_Asterisk, "**");
      New_Token (Tok_Ampersand, "&");
      New_Token (Tok_Minus, "-");
      New_Token (Tok_Plus, "+");
      New_Token (Tok_Asterisk, "*");
      New_Token (Tok_Slash, "/");
      New_Token (Tok_Dot, ".");
      New_Token (Tok_Apostrophe, "'");
      New_Token (Tok_Left_Paren, "(");
      New_Token (Tok_Right_Paren, ")");
      New_Token (Tok_Comma, ",");
      New_Token (Tok_Less, "<");
      New_Token (Tok_Equal, "=");
      New_Token (Tok_Greater, ">");
      New_Token (Tok_Not_Equal, "/=");
      New_Token (Tok_Greater_Equal, ">=");
      New_Token (Tok_Less_Equal, "<=");
      New_Token (Tok_Box, "<>");
      New_Token (Tok_Colon_Equal, ":=");
      New_Token (Tok_Colon, ":");
      New_Token (Tok_Greater_Greater, ">>");
      New_Token (Tok_Less_Less, "<<");
      New_Token (Tok_Semicolon, ";");
      New_Token (Tok_Arrow, "=>");
      New_Token (Tok_Vertical_Bar, "|");
      New_Token (Tok_Dot_Dot, "..");
      New_Token (Tok_Minus_Minus, "--");

      for O in Op_And .. Op_Or_Else loop
         New_Operator (O);
      end loop;
      New_Operator (Op_And_Symbol, "&");
      New_Operator (Op_Double_Asterisk, "**");
      New_Operator (Op_Minus, "-");
      New_Operator (Op_Plus, "+");
      New_Operator (Op_Asterisk, "*");
      New_Operator (Op_Slash, "/");
      New_Operator (Op_Less, "<");
      New_Operator (Op_Equal, "=");
      New_Operator (Op_Greater, ">");
      New_Operator (Op_Not_Equal, "/=");
      New_Operator (Op_Greater_Equal, ">=");
      New_Operator (Op_Less_Equal, "<=");
      New_Operator (Op_Box, "<>");
      New_Operator (Op_Colon_Equal, ":=");
      New_Operator (Op_Colon, "--");
      New_Operator (Op_Greater_Greater, ">>");
      New_Operator (Op_Less_Less, "<<");
      New_Operator (Op_Semicolon, ";");
      New_Operator (Op_Arrow, "=>");
      New_Operator (Op_Vertical_Bar, "|");

      for A in Attribute_Id loop
         Set_Str_To_Name_Buffer (Attribute_Id'Image (A));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         AN (A) := Name_Find;
      end loop;

      for C in Component_Id loop
         Set_Str_To_Name_Buffer (Component_Id'Image (C));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         CN (C) := Name_Find;
      end loop;

      for P in Parameter_Id loop
         Set_Str_To_Name_Buffer (Parameter_Id'Image (P));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         PN (P) := Name_Find;
      end loop;

      for S in Subprogram_Id loop
         Set_Str_To_Name_Buffer (Subprogram_Id'Image (S));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         SN (S) := Name_Find;
      end loop;

      for T in Type_Id loop
         Set_Str_To_Name_Buffer (Type_Id'Image (T));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         TN (T) := Name_Find;
      end loop;

      for V in Variable_Id loop
         Set_Str_To_Name_Buffer (Variable_Id'Image (V));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         Add_Str_To_Name_Buffer (Var_Suffix);
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         VN (V) := Name_Find;
      end loop;

      for G in Pragma_Id loop
         Set_Str_To_Name_Buffer (Pragma_Id'Image (G));
         Set_Str_To_Name_Buffer (Name_Buffer (8 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         GN (G) := Name_Find;
      end loop;

      for E in Error_Id loop
         Set_Str_To_Name_Buffer (Error_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (3 .. Name_Len));
         GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
         EN (E) := Name_Find;
      end loop;
   end Initialize;

   -----------
   -- Reset --
   -----------

   procedure Reset is
   begin
      Entity_Stack.Init;

      Initialized := False;
   end Reset;

   --------------
   -- Is_Empty --
   --------------

   function Is_Empty (L : List_Id) return Boolean is
   begin
      return L = No_List or else No (First_Node (L));
   end Is_Empty;

   ------------
   -- Length --
   ------------

   function Length (L : List_Id) return Natural is
      N : Node_Id;
      C : Natural := 0;
   begin
      if not Is_Empty (L) then
         N := First_Node (L);

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

      return C;
   end Length;

   ---------------------------------
   -- Make_Access_Type_Definition --
   ---------------------------------

   function Make_Access_Type_Definition
     (Subtype_Indication : Node_Id;
      Is_All             : Boolean := False;
      Is_Constant        : Boolean := False;
976
      Is_Not_Null        : Boolean := False) return Node_Id
977
978
979
980
981
982
   is
      N : Node_Id;
   begin
      N := New_Node (K_Access_Type_Definition);
      Set_Subtype_Indication (N, Subtype_Indication);

983
      Set_Is_All (N, Is_All);
984
985
986
987
988
989
990
991
992
993
994
      Set_Is_Constant (N, Is_Constant);
      Set_Is_Not_Null (N, Is_Not_Null);
      return N;
   end Make_Access_Type_Definition;

   ----------------------
   -- Make_Ada_Comment --
   ----------------------

   function Make_Ada_Comment
     (N                 : Name_Id;
995
      Has_Header_Spaces : Boolean := True) return Node_Id
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
   is
      C : Node_Id;
   begin
      C := New_Node (K_Ada_Comment);
      Set_Defining_Identifier (C, New_Node (K_Defining_Identifier));
      Set_Name (Defining_Identifier (C), N);
      Set_Has_Header_Spaces (C, Has_Header_Spaces);
      return C;
   end Make_Ada_Comment;

   --------------------------
   -- Make_Array_Aggregate --
   --------------------------

   function Make_Array_Aggregate (Elements : List_Id) return Node_Id is
      pragma Assert (not Is_Empty (Elements));
      N : Node_Id;
   begin
      N := New_Node (K_Array_Aggregate);
      Set_Elements (N, Elements);
      return N;
   end Make_Array_Aggregate;

   ------------------------------
   -- Create_Unique_Identifier --
   ------------------------------

   function Create_Unique_Identifier
1024
1025
     (Name   : Name_Id;
      Suffix : String := "") return Name_Id
1026
1027
   is
      Name_Returned : Name_Id;
1028
1029
1030
      Pack          : constant Name_Id :=
        Nodes.Name
          (Defining_Identifier (Package_Declaration (Current_Package)));
1031
1032
1033
1034
1035
1036
1037
1038
1039
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Pack);
      Add_Char_To_Name_Buffer ('_');
      Get_Name_String_And_Append
        (ADN.Name
           (Defining_Identifier
              (Main_Subprogram
                 (Distributed_Application_Unit
1040
1041
                    (Package_Declaration (Current_Package))))));
      GNAT.Case_Util.To_Mixed (Name_Buffer (1 .. Name_Len));
1042
1043
1044
      Add_Char_To_Name_Buffer ('_');
      Get_Name_String_And_Append (Name);
      if Suffix /= "" then
1045
1046
1047
1048
         Name_Returned :=
           Add_Prefix_To_Name
             ("UT_",
              Add_Suffix_To_Name ("_" & Suffix, Name_Find));
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
      else
         Name_Returned := Add_Prefix_To_Name ("UT_", Name_Find);
      end if;
      return Name_Returned;
   end Create_Unique_Identifier;

   --------------------------------
   -- Make_Array_Type_Definition --
   --------------------------------

   function Make_Array_Type_Definition
     (Range_Constraints    : List_Id;
      Component_Definition : Node_Id;
1062
      Aliased_Present      : Boolean := False) return Node_Id
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
   is
      N : Node_Id;

   begin
      N := New_Node (ADN.K_Array_Type_Definition);
      Set_Range_Constraints (N, Range_Constraints);
      Set_Component_Definition (N, Component_Definition);
      Set_Aliased_Present (N, Aliased_Present);
      return N;
   end Make_Array_Type_Definition;

   -------------------------------
   -- Make_Assignment_Statement --
   -------------------------------

   function Make_Assignment_Statement
     (Variable_Identifier : Node_Id;
1080
      Expression          : Node_Id) return Node_Id
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
   is
      N : Node_Id;
   begin
      N := New_Node (K_Assignment_Statement);
      Set_Defining_Identifier (N, Variable_Identifier);
      Set_Expression (N, Expression);
      return N;
   end Make_Assignment_Statement;

   --------------------------------------
   -- Make_Attribute_Definition_Clause --
   --------------------------------------

   function Make_Attribute_Definition_Clause
     (Defining_Identifier  : Node_Id;
      Attribute_Designator : Attribute_Id;
1097
      Expression           : Node_Id) return Node_Id
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
   is
      N : Node_Id;
   begin
      N := New_Node (K_Attribute_Definition_Clause);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Attribute_Designator (N, AN (Attribute_Designator));
      Set_Expression (N, Expression);

      return N;
   end Make_Attribute_Definition_Clause;

   -------------------------------
   -- Make_Attribute_Designator --
   -------------------------------

   function Make_Attribute_Designator
     (Prefix    : Node_Id;
1115
      Attribute : Attribute_Id) return Node_Id
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
   is
      N : Node_Id;
   begin
      N := New_Node (K_Attribute_Designator);
      Set_Prefix (N, Prefix);
      Set_Name (N, AN (Attribute));
      return N;
   end Make_Attribute_Designator;

   --------------------------
   -- Make_Block_Statement --
   --------------------------

   function Make_Block_Statement
     (Statement_Identifier : Node_Id := No_Node;
      Declarative_Part     : List_Id;
      Statements           : List_Id;
1133
      Exception_Handler    : List_Id := No_List) return Node_Id
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
   is
      N : Node_Id;
   begin
      N := New_Node (K_Block_Statement);
      Set_Defining_Identifier (N, Statement_Identifier);
      if Present (Statement_Identifier) then
         Set_Corresponding_Node (Statement_Identifier, N);
      end if;
      Set_Declarative_Part (N, Declarative_Part);
      Set_Statements (N, Statements);
      if not Is_Empty (Exception_Handler) then
         Set_Exception_Handler (N, Exception_Handler);
      end if;
      return N;
   end Make_Block_Statement;

   ---------------------
   -- Make_Case_Label --
   ---------------------

   function Make_Case_Label (Value : Value_Id) return Node_Id is
      N : Node_Id;
   begin
      N := New_Node (K_Case_Label);
      Set_Value (N, Value);
      return N;
   end Make_Case_Label;

   -------------------------
   -- Make_Case_Statement --
   -------------------------

   function Make_Case_Statement
     (Expression                  : Node_Id;
1168
      Case_Statement_Alternatives : List_Id) return Node_Id
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
   is
      N : Node_Id;
   begin
      N := New_Node (K_Case_Statement);
      Set_Expression (N, Expression);
      Set_Case_Statement_Alternatives (N, Case_Statement_Alternatives);
      return N;
   end Make_Case_Statement;

   -------------------------------------
   -- Make_Case_Statement_Alternative --
   -------------------------------------

   function Make_Case_Statement_Alternative
     (Discret_Choice_List : List_Id;
1184
      Statements          : List_Id) return Node_Id
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
   is
      N : Node_Id;
   begin
      N := New_Node (K_Case_Statement_Alternative);
      Set_Discret_Choice_List (N, Discret_Choice_List);
      Set_Statements (N, Statements);
      return N;
   end Make_Case_Statement_Alternative;

   --------------------------------
   -- Make_Component_Association --
   --------------------------------

   function Make_Component_Association
     (Selector_Name : Node_Id;
1200
      Expression    : Node_Id) return Node_Id
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
   is
      N : Node_Id;
   begin
      N := New_Node (K_Component_Association);
      Set_Defining_Identifier (N, Selector_Name);
      Set_Expression (N, Expression);
      return N;
   end Make_Component_Association;

   --------------------------------
   -- Make_Component_Declaration --
   --------------------------------

   function Make_Component_Declaration
     (Defining_Identifier : Node_Id;
      Subtype_Indication  : Node_Id;
      Expression          : Node_Id := No_Node;
1218
1219
      Aliased_Present     : Boolean := False) return Node_Id
   is
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
      N : Node_Id;

   begin
      N := New_Node (K_Component_Declaration);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Subtype_Indication (N, Subtype_Indication);
      Set_Expression (N, Expression);
      Set_Aliased_Present (N, Aliased_Present);
      return N;
   end Make_Component_Declaration;

   ----------------------------------
   -- Make_Decimal_Type_Definition --
   ----------------------------------

   function Make_Decimal_Type_Definition
     (D_Digits : Unsigned_Long_Long;
1237
      D_Scale  : Unsigned_Long_Long) return Node_Id
1238
1239
1240
1241
1242
1243
   is
      N : Node_Id;
      V : Value_Id;
   begin
      N := New_Node (K_Decimal_Type_Definition);

1244
1245
1246
      V :=
        New_Floating_Point_Value
          (Long_Double (1.0 / (10**(Integer (D_Scale)))));
1247
1248
1249

      Set_Scale (N, Make_Literal (V));

1250
      V := New_Integer_Value (D_Digits, 1, 10);
1251
1252
1253
1254
1255
1256
1257
1258
1259
      Set_Total (N, V);

      return N;
   end Make_Decimal_Type_Definition;

   ------------------------------
   -- Make_Defining_Identifier --
   ------------------------------

1260
   function Make_Defining_Identifier (Name : Name_Id) return Node_Id is
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
      N : Node_Id;

   begin
      N := New_Node (K_Defining_Identifier);
      Set_Name (N, To_Ada_Name (Name));
      return N;
   end Make_Defining_Identifier;

   --------------------------
   -- Make_Delay_Statement --
   --------------------------

   function Make_Delay_Statement
     (Expression : Node_Id;
1275
      Is_Until   : Boolean := False) return Node_Id
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
   is
      N : Node_Id;
   begin
      N := New_Node (K_Delay_Statement);
      Set_Expression (N, Expression);
      Set_Is_Until (N, Is_Until);
      return N;
   end Make_Delay_Statement;

   ----------------------------------
   -- Make_Derived_Type_Definition --
   ----------------------------------

   function Make_Derived_Type_Definition
     (Subtype_Indication    : Node_Id;
      Record_Extension_Part : Node_Id := No_Node;
      Is_Abstract_Type      : Boolean := False;
      Is_Private_Extention  : Boolean := False;
1294
      Is_Subtype            : Boolean := False) return Node_Id
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
   is
      N : Node_Id;

   begin
      N := New_Node (K_Derived_Type_Definition);
      Set_Is_Abstract_Type (N, Is_Abstract_Type);
      Set_Is_Private_Extention (N, Is_Private_Extention);
      Set_Subtype_Indication (N, Subtype_Indication);
      Set_Record_Extension_Part (N, Record_Extension_Part);
      Set_Is_Subtype (N, Is_Subtype);
      return N;
   end Make_Derived_Type_Definition;

   ---------------------
   -- Make_Designator --
   ---------------------

   function Make_Designator
     (Designator : Name_Id;
      Parent     : Name_Id := No_Name;
1315
      Is_All     : Boolean := False) return Node_Id
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
   is
      N : Node_Id;
      P : Node_Id;
   begin
      N := New_Node (K_Designator);
      Set_Defining_Identifier (N, Make_Defining_Identifier (Designator));
      Set_Is_All (N, Is_All);

      if Parent /= No_Name then
         P := New_Node (K_Designator);
         Set_Defining_Identifier (P, Make_Defining_Identifier (Parent));
         Set_Homogeneous_Parent_Unit_Name (N, P);
      end if;

      return N;
   end Make_Designator;

   ------------------------------
   -- Make_Element_Association --
   ------------------------------

   function Make_Element_Association
     (Index      : Node_Id;
1339
      Expression : Node_Id) return Node_Id
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
   is
      N : Node_Id;
   begin
      N := New_Node (K_Element_Association);
      Set_Index (N, Index);
      Set_Expression (N, Expression);
      return N;
   end Make_Element_Association;

   --------------------------
   -- Make_Elsif_Statement --
   --------------------------

   function Make_Elsif_Statement
     (Condition       : Node_Id;
1355
      Then_Statements : List_Id) return Node_Id
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
   is
      N : Node_Id;
   begin
      N := New_Node (K_Elsif_Statement);
      Set_Condition (N, Condition);
      Set_Then_Statements (N, Then_Statements);
      return N;
   end Make_Elsif_Statement;

   --------------------------------------
   -- Make_Enumeration_Type_Definition --
   --------------------------------------

   function Make_Enumeration_Type_Definition
1370
     (Enumeration_Literals : List_Id) return Node_Id
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
   is
      N : Node_Id;

   begin
      N := New_Node (K_Enumeration_Type_Definition);
      Set_Enumeration_Literals (N, Enumeration_Literals);
      return N;
   end Make_Enumeration_Type_Definition;

   --------------------------------------------
   -- Make_Enumeration_Representation_Clause --
   --------------------------------------------

   function Make_Enumeration_Representation_Clause
     (Defining_Identifier : Node_Id;
1386
      Array_Aggregate     : Node_Id) return Node_Id
1387
1388
1389
   is
      N : Node_Id;
   begin
1390
      N := New_Node (K_Enumeration_Representation_Clause);
1391
      Set_Defining_Identifier (N, Defining_Identifier);
1392
      Set_Array_Aggregate (N, Array_Aggregate);
1393
1394
1395
1396
1397
1398
1399
      return N;
   end Make_Enumeration_Representation_Clause;

   -------------------------------
   -- Make_Explicit_Dereference --
   -------------------------------

1400
   function Make_Explicit_Dereference (Prefix : Node_Id) return Node_Id is
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
      N : Node_Id;
   begin
      N := New_Node (K_Explicit_Dereference);
      Set_Prefix (N, Prefix);
      return N;
   end Make_Explicit_Dereference;

   --------------------------------
   -- Make_Exception_Declaration --
   --------------------------------

   function Make_Exception_Declaration
     (Defining_Identifier : Node_Id;
1414
      Renamed_Exception   : Node_Id := No_Node) return Node_Id
1415
1416
1417
1418
   is
      N : Node_Id;

   begin
1419
      N := New_Node (K_Exception_Declaration);
1420
      Set_Defining_Identifier (N, Defining_Identifier);
1421
1422
1423
      Set_Renamed_Entity (N, Renamed_Exception);
      Set_Corresponding_Node (Defining_Identifier, N);
      Set_Parent (N, Current_Package);
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
      return N;
   end Make_Exception_Declaration;

   ---------------------
   -- Make_Expression --
   ---------------------

   function Make_Expression
     (Left_Expr  : Node_Id;
      Operator   : Operator_Type := Op_None;
1434
      Right_Expr : Node_Id       := No_Node) return Node_Id
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
   is
      N : Node_Id;
   begin
      N := New_Node (K_Expression);
      Set_Left_Expr (N, Left_Expr);
      Set_Operator (N, Operator_Type'Pos (Operator));
      Set_Right_Expr (N, Right_Expr);
      return N;
   end Make_Expression;

   ------------------------
   -- Make_For_Statement --
   ------------------------

   function Make_For_Statement
     (Defining_Identifier : Node_Id;
      Range_Constraint    : Node_Id;
1452
      Statements          : List_Id) return Node_Id
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
   is
      N : Node_Id;
   begin
      N := New_Node (K_For_Statement);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Range_Constraint (N, Range_Constraint);
      Set_Statements (N, Statements);
      return N;
   end Make_For_Statement;

   -------------------------
   -- Make_Loop_Statement --
   -------------------------

1467
   function Make_Loop_Statement (Statements : List_Id) return Node_Id is
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
      N : Node_Id;
   begin
      N := New_Node (K_Loop_Statement);
      Set_Statements (N, Statements);
      return N;
   end Make_Loop_Statement;

   --------------------------------
   -- Make_Full_Type_Declaration --
   --------------------------------

   function Make_Full_Type_Declaration
     (Defining_Identifier : Node_Id;
      Type_Definition     : Node_Id;
      Discriminant_Spec   : Node_Id := No_Node;
      Parent              : Node_Id := No_Node;
1484
      Is_Subtype          : Boolean := False) return Node_Id
1485
   is
1486
      N            : Node_Id;
1487
1488
1489
1490
      T_Definition : Node_Id := Type_Definition;
   begin
      --  Remove anonymous type if necessary.
      if Kind (Type_Definition) = K_Array_Type_Definition then
1491
1492
1493
1494
1495
1496
1497
         T_Definition :=
           Remove_Anonymous_Array_Type_Definition
             (Range_Constraints (Type_Definition),
              Component_Definition (Type_Definition),
              Nodes.Aliased_Present (Type_Definition),
              Defining_Identifier,
              True);
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
      end if;

      N := New_Node (K_Full_Type_Declaration);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Corresponding_Node (Defining_Identifier, N);
      Set_Type_Definition (N, T_Definition);
      Set_Discriminant_Spec (N, Discriminant_Spec);
      if Present (Parent) then
         Set_Parent (N, Parent);
      else
         Set_Parent (N, Current_Package);
      end if;
      Set_Is_Subtype (N, Is_Subtype);
      return N;
   end Make_Full_Type_Declaration;

   ------------------------------
   -- Make_Exit_When_Statement --
   ------------------------------

1518
   function Make_Exit_When_Statement (Condition : Node_Id) return Node_Id is
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
      N : Node_Id;
   begin
      N := New_Node (K_Exit_When_Statement);
      Set_Condition (N, Condition);
      return N;
   end Make_Exit_When_Statement;

   -----------------------
   -- Make_If_Statement --
   -----------------------

   function Make_If_Statement
     (Condition        : Node_Id;
      Then_Statements  : List_Id;
      Elsif_Statements : List_Id := No_List;
1534
      Else_Statements  : List_Id := No_List) return Node_Id
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
   is
      N : Node_Id;
   begin
      N := New_Node (K_If_Statement);
      Set_Condition (N, Condition);
      Set_Then_Statements (N, Then_Statements);
      Set_Elsif_Statements (N, Elsif_Statements);
      Set_Else_Statements (N, Else_Statements);
      return N;
   end Make_If_Statement;

   ----------------------------
   -- Make_Indexed_Component --
   ----------------------------

   function Make_Indexed_Component
     (Prefix      : Node_Id;
1552
      Expressions : List_Id) return Node_Id
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
   is
      N : Node_Id;
   begin
      N := New_Node (K_Indexed_Component);
      Set_Prefix (N, Prefix);
      Set_Expressions (N, Expressions);
      return N;
   end Make_Indexed_Component;

   ------------------
   -- Make_List_Id --
   ------------------

   function Make_List_Id
     (N1 : Node_Id;
      N2 : Node_Id := No_Node;
      N3 : Node_Id := No_Node;
1570
      N4 : Node_Id := No_Node) return List_Id
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
   is
      L : List_Id;
   begin
      L := New_List (K_List_Id);
      Append_Node_To_List (N1, L);
      if Present (N2) then
         Append_Node_To_List (N2, L);

         if Present (N3) then
            Append_Node_To_List (N3, L);

            if Present (N4) then
               Append_Node_To_List (N4, L);
            end if;
         end if;
      end if;
      return L;
   end Make_List_Id;

   ------------------
   -- Make_Literal --
   ------------------

   function Make_Literal
     (Value             : Value_Id;
1596
1597
      Parent_Designator : Node_Id := No_Node) return Node_Id
   is
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
      N : Node_Id;

   begin
      N := New_Node (K_Literal);
      Set_Value (N, Value);
      Set_Parent_Designator (N, Parent_Designator);
      return N;
   end Make_Literal;

   -----------------------------------------
   -- Make_Main_Subprogram_Implementation --
   -----------------------------------------

   function Make_Main_Subprogram_Implementation
     (Identifier : Node_Id;
      Build_Spec : Boolean := False;
1614
      Build_Body : Boolean := True) return Node_Id
1615
   is
1616
1617
1618
      Unit        : Node_Id;
      Spg         : Node_Id;
      N           : Node_Id;
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
      Style_State : constant Value_Id := Get_Style_State;
   begin
      Unit := New_Node (K_Main_Subprogram_Implementation);
      Set_Defining_Identifier (Unit, Identifier);
      Set_Corresponding_Node (Identifier, Unit);

      ----------
      -- Spec --
      ----------

1629
1630
1631
1632
1633
1634
1635
      Spg :=
        Make_Subprogram_Specification
          (Defining_Identifier => Copy_Node (Identifier),
           Parameter_Profile   => No_List,
           Return_Type         => No_Node,
           Parent              => No_Node,
           Renamed_Subprogram  => No_Node);
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646

      if Build_Spec then
         Set_Withed_Packages (Spg, New_List (K_Withed_Packages));
         Set_Package_Headers (Spg, New_List (K_Package_Headers));

         --  Adding a comment header

         Make_Comment_Header (Package_Headers (Spg));

         --  Disabling style checks

1647
1648
1649
1650
         N :=
           Make_Pragma_Statement
             (Pragma_Style_Checks,
              Make_List_Id (Make_Literal (Style_State)));
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
         Append_Node_To_List (N, Package_Headers (Spg));

         --  Binding

         Set_Main_Subprogram_Unit (Spg, Unit);
         Set_Subprogram_Specification (Unit, Spg);
      end if;

      if Build_Body then

         ----------
         -- Body --
         ----------

1665
1666
1667
1668
1669
         Spg :=
           Make_Subprogram_Implementation
             (Specification => Spg,
              Declarations  => New_List (K_Declaration_List),
              Statements    => New_List (K_Statement_List));
1670
1671
1672
1673
1674
1675
1676
1677
1678
         Set_Withed_Packages (Spg, New_List (K_Withed_Packages));
         Set_Package_Headers (Spg, New_List (K_Package_Headers));

         --  Adding a comment header

         Make_Comment_Header (Package_Headers (Spg));

         --  Disabling style checks

1679
1680
1681
1682
         N :=
           Make_Pragma_Statement
             (Pragma_Style_Checks,
              Make_List_Id (Make_Literal (Style_State)));
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
         Append_Node_To_List (N, Package_Headers (Spg));

         --  Binding

         Set_Main_Subprogram_Unit (Spg, Unit);
         Set_Subprogram_Implementation (Unit, Spg);
      end if;

      return Unit;
   end Make_Main_Subprogram_Implementation;

   -------------------------
   -- Make_Null_Statement --
   -------------------------

   function Make_Null_Statement return Node_Id is
      N : Node_Id;
   begin
      N := New_Node (K_Null_Statement);
      return N;
   end Make_Null_Statement;

   -----------------------------
   -- Make_Object_Declaration --
   -----------------------------

   function Make_Object_Declaration
     (Defining_Identifier : Node_Id;
      Constant_Present    : Boolean := False;
      Object_Definition   : Node_Id;
      Expression          : Node_Id := No_Node;
      Parent              : Node_Id := No_Node;
      Renamed_Object      : Node_Id := No_Node;
      Aliased_Present     : Boolean := False;
1717
      Discriminant_Spec   : Node_Id := No_Node) return Node_Id
1718
   is
1719
      N              : Node_Id;
1720
1721
1722
1723
1724
      Obj_Definition : Node_Id := Object_Definition;
      Exp            : Node_Id := Expression;
   begin
      --  Remove anonymous type if necessary.
      if Kind (Obj_Definition) = K_Array_Type_Definition then
1725
1726
1727
1728
1729
1730
         Obj_Definition :=
           Remove_Anonymous_Array_Type_Definition
             (Range_Constraints (Object_Definition),
              Component_Definition (Object_Definition),
              Nodes.Aliased_Present (Object_Definition),
              Defining_Identifier);
1731
1732
1733

         --  Fully qualify aggregates
         if Kind (Exp) = K_Array_Aggregate then
1734
            Exp := Make_Qualified_Expression (Obj_Definition, Expression);
1735
1736
         end if;
      end if;
1737
      N := New_Node (K_Object_Declaration);
1738
      Set_Defining_Identifier (N, Defining_Identifier);
1739
1740
1741
1742
1743
1744
1745
      Set_Corresponding_Node (Defining_Identifier, N);
      Set_Constant_Present (N, Constant_Present);
      Set_Aliased_Present (N, Aliased_Present);
      Set_Object_Definition (N, Obj_Definition);
      Set_Expression (N, Exp);
      Set_Renamed_Entity (N, Renamed_Object);
      Set_Discriminant_Spec (N, Discriminant_Spec);
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760

      if No (Parent) then
         Set_Parent (N, Current_Package);
      else
         Set_Parent (N, Parent);
      end if;

      return N;
   end Make_Object_Declaration;

   -------------------------------
   -- Make_Object_Instantiation --
   -------------------------------

   function Make_Object_Instantiation
1761
     (Qualified_Expression : Node_Id) return Node_Id
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
   is
      N : Node_Id;
   begin
      N := New_Node (K_Object_Instantiation);
      Set_Qualified_Expression (N, Qualified_Expression);
      return N;
   end Make_Object_Instantiation;

   ------------------------------
   -- Make_Package_Declaration --
   ------------------------------

   function Make_Package_Declaration (Identifier : Node_Id) return Node_Id is
1775
1776
1777
      Pkg         : Node_Id;
      Unit        : Node_Id;
      N           : Node_Id;
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
      Style_State : constant Value_Id := Get_Style_State;
   begin
      Unit := New_Node (K_Package_Declaration);
      Set_Defining_Identifier (Unit, Identifier);
      Set_Corresponding_Node (Identifier, Unit);

      --  FIXME : Set the correct parent!

      ----------
      -- Spec --
      ----------

      Pkg := New_Node (K_Package_Specification);
      Set_Withed_Packages (Pkg, New_List (K_Withed_Packages));
      Set_Package_Headers (Pkg, New_List (K_Package_Headers));

      --  Adding a comment header

      Make_Comment_Header (Package_Headers (Pkg));

      --  Disabling style checks

1800
1801
1802
1803
      N :=
        Make_Pragma_Statement
          (Pragma_Style_Checks,
           Make_List_Id (Make_Literal (Style_State)));
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
      Append_Node_To_List (N, Package_Headers (Pkg));

      Set_Visible_Part (Pkg, New_List (K_Declaration_List));
      Set_Private_Part (Pkg, New_List (K_Declaration_List));
      Set_Package_Declaration (Pkg, Unit);
      Set_Package_Specification (Unit, Pkg);

      ----------
      -- Body --
      ----------

      Pkg := New_Node (K_Package_Implementation);
      Set_Withed_Packages (Pkg, New_List (K_Withed_Packages));
      Set_Package_Headers (Pkg, New_List (K_Package_Headers));

      --  Adding a comment header

      Make_Comment_Header (Package_Headers (Pkg));

      --  Disabling style checks

1825
1826
1827
1828
      N :=
        Make_Pragma_Statement
          (Pragma_Style_Checks,
           Make_List_Id (Make_Literal (Style_State)));
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
      Append_Node_To_List (N, Package_Headers (Pkg));

      Set_Declarations (Pkg, New_List (K_Declaration_List));
      Set_Statements (Pkg, New_List (K_Statement_List));
      Set_Package_Declaration (Pkg, Unit);
      Set_Package_Implementation (Unit, Pkg);

      return Unit;
   end Make_Package_Declaration;

   --------------------------------
   -- Make_Package_Instantiation --
   --------------------------------

   function Make_Package_Instantiation
     (Defining_Identifier : Node_Id;
      Generic_Package     : Node_Id;
1846
      Parameter_List      : List_Id := No_List) return Node_Id
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
   is
      N : Node_Id;
   begin
      N := New_Node (K_Package_Instantiation);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Corresponding_Node (Defining_Identifier, N);
      Set_Generic_Package (N, Generic_Package);
      Set_Parameter_List (N, Parameter_List);
      return N;
   end Make_Package_Instantiation;

   ----------------------------------
   -- Make_Private_Type_Definition --
   ----------------------------------

   function Make_Private_Type_Definition return Node_Id is
   begin
      return New_Node (K_Private_Type_Definition);
   end Make_Private_Type_Definition;

   --------------------------------
   -- Make_Parameter_Association --
   --------------------------------

   function Make_Parameter_Association
     (Selector_Name    : Node_Id;
1873
      Actual_Parameter : Node_Id) return Node_Id
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
   is
      N : Node_Id;
   begin
      N := New_Node (K_Parameter_Association);
      Set_Selector_Name (N, Selector_Name);
      Set_Actual_Parameter (N, Actual_Parameter);
      return N;
   end Make_Parameter_Association;

   ----------------------------------
   -- Make_Parameter_Specification --
   ----------------------------------

   function Make_Parameter_Specification
     (Defining_Identifier : Node_Id;
      Subtype_Mark        : Node_Id;
      Parameter_Mode      : Mode_Id := Mode_In;
1891
      Expression          : Node_Id := No_Node) return Node_Id
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
   is
      P : Node_Id;

   begin
      P := New_Node (K_Parameter_Specification);
      Set_Defining_Identifier (P, Defining_Identifier);
      Set_Parameter_Type (P, Subtype_Mark);
      Set_Parameter_Mode (P, Parameter_Mode);
      Set_Expression (P, Expression);
      return P;
   end Make_Parameter_Specification;

   ---------------------------
   -- Make_Pragma_Statement --
   ---------------------------

   function Make_Pragma_Statement
     (The_Pragma    : Pragma_Id;
1910
      Argument_List : List_Id := No_List) return Node_Id
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
   is
      N : Node_Id;
   begin
      N := New_Node (K_Pragma_Statement);

      Set_Defining_Identifier (N, Make_Defining_Identifier (GN (The_Pragma)));
      Set_Argument_List (N, Argument_List);
      return N;
   end Make_Pragma_Statement;

   --------------------------------
   -- Make_Protected_Object_Spec --
   --------------------------------

   function Make_Protected_Object_Spec
     (Defining_Identifier : Node_Id;
      Visible_Part        : List_Id;
      Private_Part        : List_Id;
      Parent              : Node_Id := Current_Package;
1930
      Is_Type             : Boolean := False) return Node_Id
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
   is
      N : Node_Id;
   begin
      N := New_Node (K_Protected_Object_Spec);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Visible_Part (N, Visible_Part);
      Set_Private_Part (N, Private_Part);
      Set_Parent (N, Parent);
      Set_Is_Type (N, Is_Type);
      return N;
   end Make_Protected_Object_Spec;

   --------------------------------
   -- Make_Protected_Object_Body --
   --------------------------------

   function Make_Protected_Object_Body
     (Defining_Identifier : Node_Id;
1949
      Statements          : List_Id) return Node_Id
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
   is
      N : Node_Id;
   begin
      N := New_Node (K_Protected_Object_Body);
      Set_Defining_Identifier (N, Defining_Identifier);
      Set_Statements (N, Statements);
      return N;
   end Make_Protected_Object_Body;

   -------------------------------
   -- Make_Qualified_Expression --
   -------------------------------

   function Make_Qualified_Expression
1964
1965
     (Subtype_Mark : Node_Id;
      Aggregate    : Node_Id) return Node_Id
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
   is
      N : Node_Id;
   begin
      N := New_Node (K_Qualified_Expression);
      Set_Subtype_Mark (N, Subtype_Mark);
      Set_Aggregate (N, Aggregate);
      return N;
   end Make_Qualified_Expression;

   --------------------------
   -- Make_Raise_Statement --
   --------------------------

   function Make_Raise_Statement
1980
1981
     (Raised_Error : Node_Id := No_Node) return Node_Id
   is
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
      N : Node_Id;
   begin
      N := New_Node (K_Raise_Statement);
      Set_Raised_Error (N, Raised_Error);
      return N;
   end Make_Raise_Statement;

   ---------------------------
   -- Make_Range_Constraint --
   ---------------------------

   function Make_Range_Constraint
     (First      : Node_Id;
      Last       : Node_Id;
1996
      Index_Type : Node_Id := No_Node) return Node_Id
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
   is
      N : Node_Id;
   begin
      N := New_Node (K_Range_Constraint);
      Set_First (N, First);
      Set_Last (N, Last);
      Set_Index_Type (N, Index_Type);
      return N;
   end Make_Range_Constraint;

   ---------------------------
   -- Make_Record_Aggregate --
   ---------------------------

2011
   function Make_Record_Aggregate (L : List_Id) return Node_Id is
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
      N : Node_Id;
   begin
      N := New_Node (K_Record_Aggregate);
      Set_Component_Association_List (N, L);
      return N;
   end Make_Record_Aggregate;

   ----------------------------
   -- Make_Record_Definition --
   ----------------------------

2023
   function Make_Record_Definition (Component_List : List_Id) return Node_Id is
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
      N : Node_Id;

   begin
      N := New_Node (K_Record_Definition);
      Set_Component_List (N, Component_List);
      return N;
   end Make_Record_Definition;

   ---------------------------------
   -- Make_Record_Type_Definition --
   ---------------------------------

   function Make_Record_Type_Definition
     (Record_Definition : Node_Id;
      Is_Abstract_Type  : Boolean := False;
      Is_Tagged_Type    : Boolean := False;
2040
2041
      Is_Limited_Type   : Boolean := False) return Node_Id
   is
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
      N : Node_Id;

   begin
      N := New_Node (K_Record_Type_Definition);
      Set_Is_Abstract_Type (N, Is_Abstract_Type);
      Set_Is_Tagged_Type (N, Is_Tagged_Type);
      Set_Is_Limited_Type (N, Is_Limited_Type);
      Set_Record_Definition (N, Record_Definition);
      return N;
   end Make_Record_Type_Definition;

   ---------------------------
   -- Make_Return_Statement --
   ---------------------------

2057
   function Make_Return_Statement (Expression : Node_Id) return Node_Id is
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
      N : Node_Id;
   begin
      N := New_Node (K_Return_Statement);
      Set_Expression (N, Ex