OSDN Git Service

2008-04-08 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-tree.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . T R E E                             --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with Prj.Err;
27
28 package body Prj.Tree is
29
30    Node_With_Comments : constant array (Project_Node_Kind) of Boolean :=
31      (N_Project                    => True,
32       N_With_Clause                => True,
33       N_Project_Declaration        => False,
34       N_Declarative_Item           => False,
35       N_Package_Declaration        => True,
36       N_String_Type_Declaration    => True,
37       N_Literal_String             => False,
38       N_Attribute_Declaration      => True,
39       N_Typed_Variable_Declaration => True,
40       N_Variable_Declaration       => True,
41       N_Expression                 => False,
42       N_Term                       => False,
43       N_Literal_String_List        => False,
44       N_Variable_Reference         => False,
45       N_External_Value             => False,
46       N_Attribute_Reference        => False,
47       N_Case_Construction          => True,
48       N_Case_Item                  => True,
49       N_Comment_Zones              => True,
50       N_Comment                    => True);
51    --  Indicates the kinds of node that may have associated comments
52
53    package Next_End_Nodes is new Table.Table
54      (Table_Component_Type => Project_Node_Id,
55       Table_Index_Type     => Natural,
56       Table_Low_Bound      => 1,
57       Table_Initial        => 10,
58       Table_Increment      => 100,
59       Table_Name           => "Next_End_Nodes");
60    --  A stack of nodes to indicates to what node the next "end" is associated
61
62    use Tree_Private_Part;
63
64    End_Of_Line_Node   : Project_Node_Id := Empty_Node;
65    --  The node an end of line comment may be associated with
66
67    Previous_Line_Node : Project_Node_Id := Empty_Node;
68    --  The node an immediately following comment may be associated with
69
70    Previous_End_Node  : Project_Node_Id := Empty_Node;
71    --  The node comments immediately following an "end" line may be
72    --  associated with.
73
74    Unkept_Comments    : Boolean := False;
75    --  Set to True when some comments may not be associated with any node
76
77    function Comment_Zones_Of
78      (Node    : Project_Node_Id;
79       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
80    --  Returns the ID of the N_Comment_Zones node associated with node Node.
81    --  If there is not already an N_Comment_Zones node, create one and
82    --  associate it with node Node.
83
84    ------------------
85    -- Add_Comments --
86    ------------------
87
88    procedure Add_Comments
89      (To       : Project_Node_Id;
90       In_Tree  : Project_Node_Tree_Ref;
91       Where    : Comment_Location) is
92       Zone     : Project_Node_Id := Empty_Node;
93       Previous : Project_Node_Id := Empty_Node;
94
95    begin
96       pragma Assert
97         (To /= Empty_Node
98           and then
99          In_Tree.Project_Nodes.Table (To).Kind /= N_Comment);
100
101       Zone := In_Tree.Project_Nodes.Table (To).Comments;
102
103       if Zone = Empty_Node then
104
105          --  Create new N_Comment_Zones node
106
107          Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
108          In_Tree.Project_Nodes.Table
109            (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
110            (Kind             => N_Comment_Zones,
111             Qualifier        => Unspecified,
112             Expr_Kind        => Undefined,
113             Location         => No_Location,
114             Directory        => No_Path,
115             Variables        => Empty_Node,
116             Packages         => Empty_Node,
117             Pkg_Id           => Empty_Package,
118             Name             => No_Name,
119             Src_Index        => 0,
120             Path_Name        => No_Path,
121             Value            => No_Name,
122             Field1           => Empty_Node,
123             Field2           => Empty_Node,
124             Field3           => Empty_Node,
125             Flag1            => False,
126             Flag2            => False,
127             Comments         => Empty_Node);
128
129          Zone := Project_Node_Table.Last (In_Tree.Project_Nodes);
130          In_Tree.Project_Nodes.Table (To).Comments := Zone;
131       end if;
132
133       if Where = End_Of_Line then
134          In_Tree.Project_Nodes.Table (Zone).Value := Comments.Table (1).Value;
135
136       else
137          --  Get each comments in the Comments table and link them to node To
138
139          for J in 1 .. Comments.Last loop
140
141             --  Create new N_Comment node
142
143             if (Where = After or else Where = After_End) and then
144               Token /= Tok_EOF and then
145               Comments.Table (J).Follows_Empty_Line
146             then
147                Comments.Table (1 .. Comments.Last - J + 1) :=
148                  Comments.Table (J .. Comments.Last);
149                Comments.Set_Last (Comments.Last - J + 1);
150                return;
151             end if;
152
153             Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
154             In_Tree.Project_Nodes.Table
155               (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
156               (Kind             => N_Comment,
157                Qualifier        => Unspecified,
158                Expr_Kind        => Undefined,
159                Flag1            => Comments.Table (J).Follows_Empty_Line,
160                Flag2            =>
161                  Comments.Table (J).Is_Followed_By_Empty_Line,
162                Location         => No_Location,
163                Directory        => No_Path,
164                Variables        => Empty_Node,
165                Packages         => Empty_Node,
166                Pkg_Id           => Empty_Package,
167                Name             => No_Name,
168                Src_Index        => 0,
169                Path_Name        => No_Path,
170                Value            => Comments.Table (J).Value,
171                Field1           => Empty_Node,
172                Field2           => Empty_Node,
173                Field3           => Empty_Node,
174                Comments         => Empty_Node);
175
176             --  If this is the first comment, put it in the right field of
177             --  the node Zone.
178
179             if Previous = Empty_Node then
180                case Where is
181                   when Before =>
182                      In_Tree.Project_Nodes.Table (Zone).Field1 :=
183                        Project_Node_Table.Last (In_Tree.Project_Nodes);
184
185                   when After =>
186                      In_Tree.Project_Nodes.Table (Zone).Field2 :=
187                        Project_Node_Table.Last (In_Tree.Project_Nodes);
188
189                   when Before_End =>
190                      In_Tree.Project_Nodes.Table (Zone).Field3 :=
191                        Project_Node_Table.Last (In_Tree.Project_Nodes);
192
193                   when After_End =>
194                      In_Tree.Project_Nodes.Table (Zone).Comments :=
195                        Project_Node_Table.Last (In_Tree.Project_Nodes);
196
197                   when End_Of_Line =>
198                      null;
199                end case;
200
201             else
202                --  When it is not the first, link it to the previous one
203
204                In_Tree.Project_Nodes.Table (Previous).Comments :=
205                  Project_Node_Table.Last (In_Tree.Project_Nodes);
206             end if;
207
208             --  This node becomes the previous one for the next comment, if
209             --  there is one.
210
211             Previous := Project_Node_Table.Last (In_Tree.Project_Nodes);
212          end loop;
213       end if;
214
215       --  Empty the Comments table, so that there is no risk to link the same
216       --  comments to another node.
217
218       Comments.Set_Last (0);
219    end Add_Comments;
220
221    --------------------------------
222    -- Associative_Array_Index_Of --
223    --------------------------------
224
225    function Associative_Array_Index_Of
226      (Node    : Project_Node_Id;
227       In_Tree : Project_Node_Tree_Ref) return Name_Id
228    is
229    begin
230       pragma Assert
231         (Node /= Empty_Node
232           and then
233             (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
234                or else
235              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
236       return In_Tree.Project_Nodes.Table (Node).Value;
237    end Associative_Array_Index_Of;
238
239    ----------------------------
240    -- Associative_Package_Of --
241    ----------------------------
242
243    function Associative_Package_Of
244      (Node    : Project_Node_Id;
245       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
246    is
247    begin
248       pragma Assert
249         (Node /= Empty_Node
250           and then
251           (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration));
252       return In_Tree.Project_Nodes.Table (Node).Field3;
253    end Associative_Package_Of;
254
255    ----------------------------
256    -- Associative_Project_Of --
257    ----------------------------
258
259    function Associative_Project_Of
260      (Node    : Project_Node_Id;
261       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
262    is
263    begin
264       pragma Assert
265         (Node /= Empty_Node
266           and then
267           (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration));
268       return In_Tree.Project_Nodes.Table (Node).Field2;
269    end Associative_Project_Of;
270
271    ----------------------
272    -- Case_Insensitive --
273    ----------------------
274
275    function Case_Insensitive
276      (Node    : Project_Node_Id;
277       In_Tree : Project_Node_Tree_Ref) return Boolean is
278    begin
279       pragma Assert
280         (Node /= Empty_Node
281           and then
282             (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
283                or else
284              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
285       return In_Tree.Project_Nodes.Table (Node).Flag1;
286    end Case_Insensitive;
287
288    --------------------------------
289    -- Case_Variable_Reference_Of --
290    --------------------------------
291
292    function Case_Variable_Reference_Of
293      (Node    : Project_Node_Id;
294       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
295    is
296    begin
297       pragma Assert
298         (Node /= Empty_Node
299           and then
300             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Construction);
301       return In_Tree.Project_Nodes.Table (Node).Field1;
302    end Case_Variable_Reference_Of;
303
304    ----------------------
305    -- Comment_Zones_Of --
306    ----------------------
307
308    function Comment_Zones_Of
309      (Node    : Project_Node_Id;
310       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
311    is
312       Zone : Project_Node_Id;
313
314    begin
315       pragma Assert (Node /= Empty_Node);
316       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
317
318       --  If there is not already an N_Comment_Zones associated, create a new
319       --  one and associate it with node Node.
320
321       if Zone = Empty_Node then
322          Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
323          Zone := Project_Node_Table.Last (In_Tree.Project_Nodes);
324          In_Tree.Project_Nodes.Table (Zone) :=
325         (Kind             => N_Comment_Zones,
326          Qualifier        => Unspecified,
327          Location         => No_Location,
328          Directory        => No_Path,
329          Expr_Kind        => Undefined,
330          Variables        => Empty_Node,
331          Packages         => Empty_Node,
332          Pkg_Id           => Empty_Package,
333          Name             => No_Name,
334          Src_Index        => 0,
335          Path_Name        => No_Path,
336          Value            => No_Name,
337          Field1           => Empty_Node,
338          Field2           => Empty_Node,
339          Field3           => Empty_Node,
340          Flag1            => False,
341          Flag2            => False,
342          Comments         => Empty_Node);
343          In_Tree.Project_Nodes.Table (Node).Comments := Zone;
344       end if;
345
346       return Zone;
347    end Comment_Zones_Of;
348
349    -----------------------
350    -- Current_Item_Node --
351    -----------------------
352
353    function Current_Item_Node
354      (Node    : Project_Node_Id;
355       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
356    is
357    begin
358       pragma Assert
359         (Node /= Empty_Node
360           and then
361             In_Tree.Project_Nodes.Table (Node).Kind = N_Declarative_Item);
362       return In_Tree.Project_Nodes.Table (Node).Field1;
363    end Current_Item_Node;
364
365    ------------------
366    -- Current_Term --
367    ------------------
368
369    function Current_Term
370      (Node    : Project_Node_Id;
371       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
372    is
373    begin
374       pragma Assert
375         (Node /= Empty_Node
376           and then
377             In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
378       return In_Tree.Project_Nodes.Table (Node).Field1;
379    end Current_Term;
380
381    --------------------------
382    -- Default_Project_Node --
383    --------------------------
384
385    function Default_Project_Node
386      (In_Tree       : Project_Node_Tree_Ref;
387       Of_Kind       : Project_Node_Kind;
388       And_Expr_Kind : Variable_Kind := Undefined) return Project_Node_Id
389    is
390       Result   : Project_Node_Id;
391       Zone     : Project_Node_Id;
392       Previous : Project_Node_Id;
393
394    begin
395       --  Create new node with specified kind and expression kind
396
397       Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
398       In_Tree.Project_Nodes.Table
399         (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
400         (Kind             => Of_Kind,
401          Qualifier        => Unspecified,
402          Location         => No_Location,
403          Directory        => No_Path,
404          Expr_Kind        => And_Expr_Kind,
405          Variables        => Empty_Node,
406          Packages         => Empty_Node,
407          Pkg_Id           => Empty_Package,
408          Name             => No_Name,
409          Src_Index        => 0,
410          Path_Name        => No_Path,
411          Value            => No_Name,
412          Field1           => Empty_Node,
413          Field2           => Empty_Node,
414          Field3           => Empty_Node,
415          Flag1            => False,
416          Flag2            => False,
417          Comments         => Empty_Node);
418
419       --  Save the new node for the returned value
420
421       Result := Project_Node_Table.Last (In_Tree.Project_Nodes);
422
423       if Comments.Last > 0 then
424
425          --  If this is not a node with comments, then set the flag
426
427          if not Node_With_Comments (Of_Kind) then
428             Unkept_Comments := True;
429
430          elsif Of_Kind /= N_Comment and then Of_Kind /= N_Comment_Zones then
431
432             Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
433             In_Tree.Project_Nodes.Table
434               (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
435               (Kind             => N_Comment_Zones,
436                Qualifier        => Unspecified,
437                Expr_Kind        => Undefined,
438                Location         => No_Location,
439                Directory        => No_Path,
440                Variables        => Empty_Node,
441                Packages         => Empty_Node,
442                Pkg_Id           => Empty_Package,
443                Name             => No_Name,
444                Src_Index        => 0,
445                Path_Name        => No_Path,
446                Value            => No_Name,
447                Field1           => Empty_Node,
448                Field2           => Empty_Node,
449                Field3           => Empty_Node,
450                Flag1            => False,
451                Flag2            => False,
452                Comments         => Empty_Node);
453
454             Zone := Project_Node_Table.Last (In_Tree.Project_Nodes);
455             In_Tree.Project_Nodes.Table (Result).Comments := Zone;
456             Previous := Empty_Node;
457
458             for J in 1 .. Comments.Last loop
459
460                --  Create a new N_Comment node
461
462                Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
463                In_Tree.Project_Nodes.Table
464                  (Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
465                  (Kind             => N_Comment,
466                   Qualifier        => Unspecified,
467                   Expr_Kind        => Undefined,
468                   Flag1            => Comments.Table (J).Follows_Empty_Line,
469                   Flag2            =>
470                     Comments.Table (J).Is_Followed_By_Empty_Line,
471                   Location         => No_Location,
472                   Directory        => No_Path,
473                   Variables        => Empty_Node,
474                   Packages         => Empty_Node,
475                   Pkg_Id           => Empty_Package,
476                   Name             => No_Name,
477                   Src_Index        => 0,
478                   Path_Name        => No_Path,
479                   Value            => Comments.Table (J).Value,
480                   Field1           => Empty_Node,
481                   Field2           => Empty_Node,
482                   Field3           => Empty_Node,
483                   Comments         => Empty_Node);
484
485                --  Link it to the N_Comment_Zones node, if it is the first,
486                --  otherwise to the previous one.
487
488                if Previous = Empty_Node then
489                   In_Tree.Project_Nodes.Table (Zone).Field1 :=
490                     Project_Node_Table.Last (In_Tree.Project_Nodes);
491
492                else
493                   In_Tree.Project_Nodes.Table (Previous).Comments :=
494                     Project_Node_Table.Last (In_Tree.Project_Nodes);
495                end if;
496
497                --  This new node will be the previous one for the next
498                --  N_Comment node, if there is one.
499
500                Previous := Project_Node_Table.Last (In_Tree.Project_Nodes);
501             end loop;
502
503             --  Empty the Comments table after all comments have been processed
504
505             Comments.Set_Last (0);
506          end if;
507       end if;
508
509       return Result;
510    end Default_Project_Node;
511
512    ------------------
513    -- Directory_Of --
514    ------------------
515
516    function Directory_Of
517      (Node    : Project_Node_Id;
518       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type is
519    begin
520       pragma Assert
521         (Node /= Empty_Node
522           and then
523             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
524       return In_Tree.Project_Nodes.Table (Node).Directory;
525    end Directory_Of;
526
527    -------------------------
528    -- End_Of_Line_Comment --
529    -------------------------
530
531    function End_Of_Line_Comment
532      (Node    : Project_Node_Id;
533       In_Tree : Project_Node_Tree_Ref) return Name_Id is
534       Zone : Project_Node_Id := Empty_Node;
535
536    begin
537       pragma Assert (Node /= Empty_Node);
538       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
539
540       if Zone = Empty_Node then
541          return No_Name;
542       else
543          return In_Tree.Project_Nodes.Table (Zone).Value;
544       end if;
545    end End_Of_Line_Comment;
546
547    ------------------------
548    -- Expression_Kind_Of --
549    ------------------------
550
551    function Expression_Kind_Of
552      (Node    : Project_Node_Id;
553       In_Tree : Project_Node_Tree_Ref) return Variable_Kind is
554    begin
555       pragma Assert
556         (Node /= Empty_Node
557            and then
558              (In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String
559                 or else
560               In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
561                 or else
562               In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Declaration
563                 or else
564               In_Tree.Project_Nodes.Table (Node).Kind =
565                        N_Typed_Variable_Declaration
566                 or else
567               In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration
568                 or else
569               In_Tree.Project_Nodes.Table (Node).Kind = N_Expression
570                 or else
571               In_Tree.Project_Nodes.Table (Node).Kind = N_Term
572                 or else
573               In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
574                 or else
575               In_Tree.Project_Nodes.Table (Node).Kind =
576                         N_Attribute_Reference));
577
578       return In_Tree.Project_Nodes.Table (Node).Expr_Kind;
579    end Expression_Kind_Of;
580
581    -------------------
582    -- Expression_Of --
583    -------------------
584
585    function Expression_Of
586      (Node    : Project_Node_Id;
587       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
588    is
589    begin
590       pragma Assert
591         (Node /= Empty_Node
592           and then
593            (In_Tree.Project_Nodes.Table (Node).Kind =
594               N_Attribute_Declaration
595                or else
596             In_Tree.Project_Nodes.Table (Node).Kind =
597               N_Typed_Variable_Declaration
598                or else
599             In_Tree.Project_Nodes.Table (Node).Kind =
600               N_Variable_Declaration));
601
602       return In_Tree.Project_Nodes.Table (Node).Field1;
603    end Expression_Of;
604
605    -------------------------
606    -- Extended_Project_Of --
607    -------------------------
608
609    function Extended_Project_Of
610      (Node    : Project_Node_Id;
611       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
612    is
613    begin
614       pragma Assert
615         (Node /= Empty_Node
616           and then
617             In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration);
618       return In_Tree.Project_Nodes.Table (Node).Field2;
619    end Extended_Project_Of;
620
621    ------------------------------
622    -- Extended_Project_Path_Of --
623    ------------------------------
624
625    function Extended_Project_Path_Of
626      (Node    : Project_Node_Id;
627       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type
628    is
629    begin
630       pragma Assert
631         (Node /= Empty_Node
632           and then
633             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
634       return Path_Name_Type (In_Tree.Project_Nodes.Table (Node).Value);
635    end Extended_Project_Path_Of;
636
637    --------------------------
638    -- Extending_Project_Of --
639    --------------------------
640    function Extending_Project_Of
641      (Node    : Project_Node_Id;
642       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
643    is
644    begin
645       pragma Assert
646         (Node /= Empty_Node
647           and then
648             In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration);
649       return In_Tree.Project_Nodes.Table (Node).Field3;
650    end Extending_Project_Of;
651
652    ---------------------------
653    -- External_Reference_Of --
654    ---------------------------
655
656    function External_Reference_Of
657      (Node    : Project_Node_Id;
658       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
659    is
660    begin
661       pragma Assert
662         (Node /= Empty_Node
663           and then
664             In_Tree.Project_Nodes.Table (Node).Kind = N_External_Value);
665       return In_Tree.Project_Nodes.Table (Node).Field1;
666    end External_Reference_Of;
667
668    -------------------------
669    -- External_Default_Of --
670    -------------------------
671
672    function External_Default_Of
673      (Node    : Project_Node_Id;
674       In_Tree : Project_Node_Tree_Ref)
675       return Project_Node_Id
676    is
677    begin
678       pragma Assert
679         (Node /= Empty_Node
680           and then
681             In_Tree.Project_Nodes.Table (Node).Kind = N_External_Value);
682       return In_Tree.Project_Nodes.Table (Node).Field2;
683    end External_Default_Of;
684
685    ------------------------
686    -- First_Case_Item_Of --
687    ------------------------
688
689    function First_Case_Item_Of
690      (Node    : Project_Node_Id;
691       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
692    is
693    begin
694       pragma Assert
695         (Node /= Empty_Node
696           and then
697             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Construction);
698       return In_Tree.Project_Nodes.Table (Node).Field2;
699    end First_Case_Item_Of;
700
701    ---------------------
702    -- First_Choice_Of --
703    ---------------------
704
705    function First_Choice_Of
706      (Node    : Project_Node_Id;
707       In_Tree : Project_Node_Tree_Ref)
708       return Project_Node_Id
709    is
710    begin
711       pragma Assert
712         (Node /= Empty_Node
713           and then
714             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item);
715       return In_Tree.Project_Nodes.Table (Node).Field1;
716    end First_Choice_Of;
717
718    -------------------------
719    -- First_Comment_After --
720    -------------------------
721
722    function First_Comment_After
723      (Node    : Project_Node_Id;
724       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
725    is
726       Zone : Project_Node_Id := Empty_Node;
727    begin
728       pragma Assert (Node /= Empty_Node);
729       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
730
731       if Zone = Empty_Node then
732          return Empty_Node;
733
734       else
735          return In_Tree.Project_Nodes.Table (Zone).Field2;
736       end if;
737    end First_Comment_After;
738
739    -----------------------------
740    -- First_Comment_After_End --
741    -----------------------------
742
743    function First_Comment_After_End
744      (Node    : Project_Node_Id;
745       In_Tree : Project_Node_Tree_Ref)
746       return Project_Node_Id
747    is
748       Zone : Project_Node_Id := Empty_Node;
749
750    begin
751       pragma Assert (Node /= Empty_Node);
752       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
753
754       if Zone = Empty_Node then
755          return Empty_Node;
756
757       else
758          return In_Tree.Project_Nodes.Table (Zone).Comments;
759       end if;
760    end First_Comment_After_End;
761
762    --------------------------
763    -- First_Comment_Before --
764    --------------------------
765
766    function First_Comment_Before
767      (Node    : Project_Node_Id;
768       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
769    is
770       Zone : Project_Node_Id := Empty_Node;
771
772    begin
773       pragma Assert (Node /= Empty_Node);
774       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
775
776       if Zone = Empty_Node then
777          return Empty_Node;
778
779       else
780          return In_Tree.Project_Nodes.Table (Zone).Field1;
781       end if;
782    end First_Comment_Before;
783
784    ------------------------------
785    -- First_Comment_Before_End --
786    ------------------------------
787
788    function First_Comment_Before_End
789      (Node    : Project_Node_Id;
790       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
791    is
792       Zone : Project_Node_Id := Empty_Node;
793
794    begin
795       pragma Assert (Node /= Empty_Node);
796       Zone := In_Tree.Project_Nodes.Table (Node).Comments;
797
798       if Zone = Empty_Node then
799          return Empty_Node;
800
801       else
802          return In_Tree.Project_Nodes.Table (Zone).Field3;
803       end if;
804    end First_Comment_Before_End;
805
806    -------------------------------
807    -- First_Declarative_Item_Of --
808    -------------------------------
809
810    function First_Declarative_Item_Of
811      (Node    : Project_Node_Id;
812       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
813    is
814    begin
815       pragma Assert
816         (Node /= Empty_Node
817           and then
818             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration
819                or else
820              In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item
821                or else
822              In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration));
823
824       if In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration then
825          return In_Tree.Project_Nodes.Table (Node).Field1;
826       else
827          return In_Tree.Project_Nodes.Table (Node).Field2;
828       end if;
829    end First_Declarative_Item_Of;
830
831    ------------------------------
832    -- First_Expression_In_List --
833    ------------------------------
834
835    function First_Expression_In_List
836      (Node    : Project_Node_Id;
837       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
838    is
839    begin
840       pragma Assert
841         (Node /= Empty_Node
842           and then
843             In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String_List);
844       return In_Tree.Project_Nodes.Table (Node).Field1;
845    end First_Expression_In_List;
846
847    --------------------------
848    -- First_Literal_String --
849    --------------------------
850
851    function First_Literal_String
852      (Node    : Project_Node_Id;
853       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
854    is
855    begin
856       pragma Assert
857         (Node /= Empty_Node
858           and then
859          In_Tree.Project_Nodes.Table (Node).Kind =
860            N_String_Type_Declaration);
861       return In_Tree.Project_Nodes.Table (Node).Field1;
862    end First_Literal_String;
863
864    ----------------------
865    -- First_Package_Of --
866    ----------------------
867
868    function First_Package_Of
869      (Node    : Project_Node_Id;
870       In_Tree : Project_Node_Tree_Ref) return Package_Declaration_Id
871    is
872    begin
873       pragma Assert
874         (Node /= Empty_Node
875           and then
876             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
877       return In_Tree.Project_Nodes.Table (Node).Packages;
878    end First_Package_Of;
879
880    --------------------------
881    -- First_String_Type_Of --
882    --------------------------
883
884    function First_String_Type_Of
885      (Node    : Project_Node_Id;
886       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
887    is
888    begin
889       pragma Assert
890         (Node /= Empty_Node
891           and then
892             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
893       return In_Tree.Project_Nodes.Table (Node).Field3;
894    end First_String_Type_Of;
895
896    ----------------
897    -- First_Term --
898    ----------------
899
900    function First_Term
901      (Node    : Project_Node_Id;
902       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
903    is
904    begin
905       pragma Assert
906         (Node /= Empty_Node
907           and then
908             In_Tree.Project_Nodes.Table (Node).Kind = N_Expression);
909       return In_Tree.Project_Nodes.Table (Node).Field1;
910    end First_Term;
911
912    -----------------------
913    -- First_Variable_Of --
914    -----------------------
915
916    function First_Variable_Of
917      (Node    : Project_Node_Id;
918       In_Tree : Project_Node_Tree_Ref) return Variable_Node_Id
919    is
920    begin
921       pragma Assert
922         (Node /= Empty_Node
923           and then
924             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
925                or else
926              In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration));
927
928       return In_Tree.Project_Nodes.Table (Node).Variables;
929    end First_Variable_Of;
930
931    --------------------------
932    -- First_With_Clause_Of --
933    --------------------------
934
935    function First_With_Clause_Of
936      (Node    : Project_Node_Id;
937       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
938    is
939    begin
940       pragma Assert
941         (Node /= Empty_Node
942           and then
943             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
944       return In_Tree.Project_Nodes.Table (Node).Field1;
945    end First_With_Clause_Of;
946
947    ------------------------
948    -- Follows_Empty_Line --
949    ------------------------
950
951    function Follows_Empty_Line
952      (Node    : Project_Node_Id;
953       In_Tree : Project_Node_Tree_Ref) return Boolean is
954    begin
955       pragma Assert
956         (Node /= Empty_Node
957          and then
958          In_Tree.Project_Nodes.Table (Node).Kind = N_Comment);
959       return In_Tree.Project_Nodes.Table (Node).Flag1;
960    end Follows_Empty_Line;
961
962    ----------
963    -- Hash --
964    ----------
965
966    function Hash (N : Project_Node_Id) return Header_Num is
967    begin
968       return Header_Num (N mod Project_Node_Id (Header_Num'Last));
969    end Hash;
970
971    ----------------
972    -- Initialize --
973    ----------------
974
975    procedure Initialize (Tree : Project_Node_Tree_Ref) is
976    begin
977       Project_Node_Table.Init (Tree.Project_Nodes);
978       Projects_Htable.Reset (Tree.Projects_HT);
979    end Initialize;
980
981    -------------------------------
982    -- Is_Followed_By_Empty_Line --
983    -------------------------------
984
985    function Is_Followed_By_Empty_Line
986      (Node    : Project_Node_Id;
987       In_Tree : Project_Node_Tree_Ref) return Boolean
988    is
989    begin
990       pragma Assert
991         (Node /= Empty_Node
992           and then
993             In_Tree.Project_Nodes.Table (Node).Kind = N_Comment);
994       return In_Tree.Project_Nodes.Table (Node).Flag2;
995    end Is_Followed_By_Empty_Line;
996
997    ----------------------
998    -- Is_Extending_All --
999    ----------------------
1000
1001    function Is_Extending_All
1002      (Node    : Project_Node_Id;
1003       In_Tree : Project_Node_Tree_Ref) return Boolean is
1004    begin
1005       pragma Assert
1006         (Node /= Empty_Node
1007           and then
1008            (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
1009               or else
1010             In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause));
1011       return In_Tree.Project_Nodes.Table (Node).Flag2;
1012    end Is_Extending_All;
1013
1014    -------------------------
1015    -- Is_Not_Last_In_List --
1016    -------------------------
1017
1018    function Is_Not_Last_In_List
1019      (Node    : Project_Node_Id;
1020       In_Tree : Project_Node_Tree_Ref) return Boolean is
1021    begin
1022       pragma Assert
1023         (Node /= Empty_Node
1024           and then
1025             In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause);
1026       return In_Tree.Project_Nodes.Table (Node).Flag1;
1027    end Is_Not_Last_In_List;
1028
1029    -------------------------------------
1030    -- Imported_Or_Extended_Project_Of --
1031    -------------------------------------
1032
1033    function Imported_Or_Extended_Project_Of
1034      (Project   : Project_Node_Id;
1035       In_Tree   : Project_Node_Tree_Ref;
1036       With_Name : Name_Id) return Project_Node_Id
1037    is
1038       With_Clause : Project_Node_Id :=
1039         First_With_Clause_Of (Project, In_Tree);
1040       Result      : Project_Node_Id := Empty_Node;
1041
1042    begin
1043       --  First check all the imported projects
1044
1045       while With_Clause /= Empty_Node loop
1046
1047          --  Only non limited imported project may be used as prefix
1048          --  of variable or attributes.
1049
1050          Result := Non_Limited_Project_Node_Of (With_Clause, In_Tree);
1051          exit when Result /= Empty_Node
1052            and then Name_Of (Result, In_Tree) = With_Name;
1053          With_Clause := Next_With_Clause_Of (With_Clause, In_Tree);
1054       end loop;
1055
1056       --  If it is not an imported project, it might be an extended project
1057
1058       if With_Clause = Empty_Node then
1059          Result := Project;
1060          loop
1061             Result :=
1062               Extended_Project_Of
1063                 (Project_Declaration_Of (Result, In_Tree), In_Tree);
1064
1065             exit when Result = Empty_Node
1066               or else Name_Of (Result, In_Tree) = With_Name;
1067          end loop;
1068       end if;
1069
1070       return Result;
1071    end Imported_Or_Extended_Project_Of;
1072
1073    -------------
1074    -- Kind_Of --
1075    -------------
1076
1077    function Kind_Of
1078      (Node    : Project_Node_Id;
1079       In_Tree : Project_Node_Tree_Ref) return Project_Node_Kind is
1080    begin
1081       pragma Assert (Node /= Empty_Node);
1082       return In_Tree.Project_Nodes.Table (Node).Kind;
1083    end Kind_Of;
1084
1085    -----------------
1086    -- Location_Of --
1087    -----------------
1088
1089    function Location_Of
1090      (Node    : Project_Node_Id;
1091       In_Tree : Project_Node_Tree_Ref) return Source_Ptr is
1092    begin
1093       pragma Assert (Node /= Empty_Node);
1094       return In_Tree.Project_Nodes.Table (Node).Location;
1095    end Location_Of;
1096
1097    -------------
1098    -- Name_Of --
1099    -------------
1100
1101    function Name_Of
1102      (Node    : Project_Node_Id;
1103       In_Tree : Project_Node_Tree_Ref) return Name_Id is
1104    begin
1105       pragma Assert (Node /= Empty_Node);
1106       return In_Tree.Project_Nodes.Table (Node).Name;
1107    end Name_Of;
1108
1109    --------------------
1110    -- Next_Case_Item --
1111    --------------------
1112
1113    function Next_Case_Item
1114      (Node    : Project_Node_Id;
1115       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1116    is
1117    begin
1118       pragma Assert
1119         (Node /= Empty_Node
1120           and then
1121             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item);
1122       return In_Tree.Project_Nodes.Table (Node).Field3;
1123    end Next_Case_Item;
1124
1125    ------------------
1126    -- Next_Comment --
1127    ------------------
1128
1129    function Next_Comment
1130      (Node    : Project_Node_Id;
1131       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id is
1132    begin
1133       pragma Assert
1134         (Node /= Empty_Node
1135           and then
1136             In_Tree.Project_Nodes.Table (Node).Kind = N_Comment);
1137       return In_Tree.Project_Nodes.Table (Node).Comments;
1138    end Next_Comment;
1139
1140    ---------------------------
1141    -- Next_Declarative_Item --
1142    ---------------------------
1143
1144    function Next_Declarative_Item
1145      (Node    : Project_Node_Id;
1146       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1147    is
1148    begin
1149       pragma Assert
1150         (Node /= Empty_Node
1151           and then
1152             In_Tree.Project_Nodes.Table (Node).Kind = N_Declarative_Item);
1153       return In_Tree.Project_Nodes.Table (Node).Field2;
1154    end Next_Declarative_Item;
1155
1156    -----------------------------
1157    -- Next_Expression_In_List --
1158    -----------------------------
1159
1160    function Next_Expression_In_List
1161      (Node    : Project_Node_Id;
1162       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1163    is
1164    begin
1165       pragma Assert
1166         (Node /= Empty_Node
1167           and then
1168             In_Tree.Project_Nodes.Table (Node).Kind = N_Expression);
1169       return In_Tree.Project_Nodes.Table (Node).Field2;
1170    end Next_Expression_In_List;
1171
1172    -------------------------
1173    -- Next_Literal_String --
1174    -------------------------
1175
1176    function Next_Literal_String
1177      (Node    : Project_Node_Id;
1178       In_Tree : Project_Node_Tree_Ref)
1179       return Project_Node_Id
1180    is
1181    begin
1182       pragma Assert
1183         (Node /= Empty_Node
1184           and then
1185             In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String);
1186       return In_Tree.Project_Nodes.Table (Node).Field1;
1187    end Next_Literal_String;
1188
1189    -----------------------------
1190    -- Next_Package_In_Project --
1191    -----------------------------
1192
1193    function Next_Package_In_Project
1194      (Node    : Project_Node_Id;
1195       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1196    is
1197    begin
1198       pragma Assert
1199         (Node /= Empty_Node
1200           and then
1201             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
1202       return In_Tree.Project_Nodes.Table (Node).Field3;
1203    end Next_Package_In_Project;
1204
1205    ----------------------
1206    -- Next_String_Type --
1207    ----------------------
1208
1209    function Next_String_Type
1210      (Node    : Project_Node_Id;
1211       In_Tree : Project_Node_Tree_Ref)
1212       return Project_Node_Id
1213    is
1214    begin
1215       pragma Assert
1216         (Node /= Empty_Node
1217           and then
1218          In_Tree.Project_Nodes.Table (Node).Kind =
1219            N_String_Type_Declaration);
1220       return In_Tree.Project_Nodes.Table (Node).Field2;
1221    end Next_String_Type;
1222
1223    ---------------
1224    -- Next_Term --
1225    ---------------
1226
1227    function Next_Term
1228      (Node    : Project_Node_Id;
1229       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1230    is
1231    begin
1232       pragma Assert
1233         (Node /= Empty_Node
1234           and then
1235             In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
1236       return In_Tree.Project_Nodes.Table (Node).Field2;
1237    end Next_Term;
1238
1239    -------------------
1240    -- Next_Variable --
1241    -------------------
1242
1243    function Next_Variable
1244      (Node    : Project_Node_Id;
1245       In_Tree : Project_Node_Tree_Ref)
1246       return Project_Node_Id
1247    is
1248    begin
1249       pragma Assert
1250         (Node /= Empty_Node
1251           and then
1252            (In_Tree.Project_Nodes.Table (Node).Kind =
1253               N_Typed_Variable_Declaration
1254                or else
1255             In_Tree.Project_Nodes.Table (Node).Kind =
1256               N_Variable_Declaration));
1257
1258       return In_Tree.Project_Nodes.Table (Node).Field3;
1259    end Next_Variable;
1260
1261    -------------------------
1262    -- Next_With_Clause_Of --
1263    -------------------------
1264
1265    function Next_With_Clause_Of
1266      (Node    : Project_Node_Id;
1267       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1268    is
1269    begin
1270       pragma Assert
1271         (Node /= Empty_Node
1272           and then
1273             In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause);
1274       return In_Tree.Project_Nodes.Table (Node).Field2;
1275    end Next_With_Clause_Of;
1276
1277    ---------------------------------
1278    -- Non_Limited_Project_Node_Of --
1279    ---------------------------------
1280
1281    function Non_Limited_Project_Node_Of
1282      (Node    : Project_Node_Id;
1283       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1284    is
1285    begin
1286       pragma Assert
1287         (Node /= Empty_Node
1288           and then
1289            (In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause));
1290       return In_Tree.Project_Nodes.Table (Node).Field3;
1291    end Non_Limited_Project_Node_Of;
1292
1293    -------------------
1294    -- Package_Id_Of --
1295    -------------------
1296
1297    function Package_Id_Of
1298      (Node    : Project_Node_Id;
1299       In_Tree : Project_Node_Tree_Ref) return Package_Node_Id
1300    is
1301    begin
1302       pragma Assert
1303         (Node /= Empty_Node
1304           and then
1305             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
1306       return In_Tree.Project_Nodes.Table (Node).Pkg_Id;
1307    end Package_Id_Of;
1308
1309    ---------------------
1310    -- Package_Node_Of --
1311    ---------------------
1312
1313    function Package_Node_Of
1314      (Node    : Project_Node_Id;
1315       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1316    is
1317    begin
1318       pragma Assert
1319         (Node /= Empty_Node
1320           and then
1321             (In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
1322                or else
1323              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
1324       return In_Tree.Project_Nodes.Table (Node).Field2;
1325    end Package_Node_Of;
1326
1327    ------------------
1328    -- Path_Name_Of --
1329    ------------------
1330
1331    function Path_Name_Of
1332      (Node    : Project_Node_Id;
1333       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type
1334    is
1335    begin
1336       pragma Assert
1337         (Node /= Empty_Node
1338           and then
1339             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
1340                or else
1341              In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause));
1342       return In_Tree.Project_Nodes.Table (Node).Path_Name;
1343    end Path_Name_Of;
1344
1345    ----------------------------
1346    -- Project_Declaration_Of --
1347    ----------------------------
1348
1349    function Project_Declaration_Of
1350      (Node    : Project_Node_Id;
1351       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1352    is
1353    begin
1354       pragma Assert
1355         (Node /= Empty_Node
1356           and then
1357             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
1358       return In_Tree.Project_Nodes.Table (Node).Field2;
1359    end Project_Declaration_Of;
1360
1361    --------------------------
1362    -- Project_Qualifier_Of --
1363    --------------------------
1364
1365    function Project_Qualifier_Of
1366      (Node    : Project_Node_Id;
1367       In_Tree : Project_Node_Tree_Ref) return Project_Qualifier
1368    is
1369    begin
1370       pragma Assert
1371         (Node /= Empty_Node
1372           and then
1373             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
1374       return In_Tree.Project_Nodes.Table (Node).Qualifier;
1375    end Project_Qualifier_Of;
1376
1377    -------------------------------------------
1378    -- Project_File_Includes_Unkept_Comments --
1379    -------------------------------------------
1380
1381    function Project_File_Includes_Unkept_Comments
1382      (Node    : Project_Node_Id;
1383       In_Tree : Project_Node_Tree_Ref) return Boolean
1384    is
1385       Declaration : constant Project_Node_Id :=
1386                       Project_Declaration_Of (Node, In_Tree);
1387    begin
1388       return In_Tree.Project_Nodes.Table (Declaration).Flag1;
1389    end Project_File_Includes_Unkept_Comments;
1390
1391    ---------------------
1392    -- Project_Node_Of --
1393    ---------------------
1394
1395    function Project_Node_Of
1396      (Node    : Project_Node_Id;
1397       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1398    is
1399    begin
1400       pragma Assert
1401         (Node /= Empty_Node
1402           and then
1403            (In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause
1404               or else
1405             In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
1406               or else
1407             In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
1408       return In_Tree.Project_Nodes.Table (Node).Field1;
1409    end Project_Node_Of;
1410
1411    -----------------------------------
1412    -- Project_Of_Renamed_Package_Of --
1413    -----------------------------------
1414
1415    function Project_Of_Renamed_Package_Of
1416      (Node    : Project_Node_Id;
1417       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
1418    is
1419    begin
1420       pragma Assert
1421         (Node /= Empty_Node
1422           and then
1423             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
1424       return In_Tree.Project_Nodes.Table (Node).Field1;
1425    end Project_Of_Renamed_Package_Of;
1426
1427    --------------------------
1428    -- Remove_Next_End_Node --
1429    --------------------------
1430
1431    procedure Remove_Next_End_Node is
1432    begin
1433       Next_End_Nodes.Decrement_Last;
1434    end Remove_Next_End_Node;
1435
1436    -----------------
1437    -- Reset_State --
1438    -----------------
1439
1440    procedure Reset_State is
1441    begin
1442       End_Of_Line_Node   := Empty_Node;
1443       Previous_Line_Node := Empty_Node;
1444       Previous_End_Node  := Empty_Node;
1445       Unkept_Comments    := False;
1446       Comments.Set_Last (0);
1447    end Reset_State;
1448
1449    -------------
1450    -- Restore --
1451    -------------
1452
1453    procedure Restore (S : Comment_State) is
1454    begin
1455       End_Of_Line_Node   := S.End_Of_Line_Node;
1456       Previous_Line_Node := S.Previous_Line_Node;
1457       Previous_End_Node  := S.Previous_End_Node;
1458       Next_End_Nodes.Set_Last (0);
1459       Unkept_Comments    := S.Unkept_Comments;
1460
1461       Comments.Set_Last (0);
1462
1463       for J in S.Comments'Range loop
1464          Comments.Increment_Last;
1465          Comments.Table (Comments.Last) := S.Comments (J);
1466       end loop;
1467    end Restore;
1468
1469    ----------
1470    -- Save --
1471    ----------
1472
1473    procedure Save (S : out Comment_State) is
1474       Cmts : constant Comments_Ptr := new Comment_Array (1 .. Comments.Last);
1475
1476    begin
1477       for J in 1 .. Comments.Last loop
1478          Cmts (J) := Comments.Table (J);
1479       end loop;
1480
1481       S :=
1482         (End_Of_Line_Node   => End_Of_Line_Node,
1483          Previous_Line_Node => Previous_Line_Node,
1484          Previous_End_Node  => Previous_End_Node,
1485          Unkept_Comments    => Unkept_Comments,
1486          Comments           => Cmts);
1487    end Save;
1488
1489    ----------
1490    -- Scan --
1491    ----------
1492
1493    procedure Scan (In_Tree : Project_Node_Tree_Ref) is
1494       Empty_Line : Boolean := False;
1495
1496    begin
1497       --  If there are comments, then they will not be kept. Set the flag and
1498       --  clear the comments.
1499
1500       if Comments.Last > 0 then
1501          Unkept_Comments := True;
1502          Comments.Set_Last (0);
1503       end if;
1504
1505       --  Loop until a token other that End_Of_Line or Comment is found
1506
1507       loop
1508          Prj.Err.Scanner.Scan;
1509
1510          case Token is
1511             when Tok_End_Of_Line =>
1512                if Prev_Token = Tok_End_Of_Line then
1513                   Empty_Line := True;
1514
1515                   if Comments.Last > 0 then
1516                      Comments.Table (Comments.Last).Is_Followed_By_Empty_Line
1517                      := True;
1518                   end if;
1519                end if;
1520
1521             when Tok_Comment =>
1522                --  If this is a line comment, add it to the comment table
1523
1524                if Prev_Token = Tok_End_Of_Line
1525                  or else Prev_Token = No_Token
1526                then
1527                   Comments.Increment_Last;
1528                   Comments.Table (Comments.Last) :=
1529                     (Value                     => Comment_Id,
1530                      Follows_Empty_Line        => Empty_Line,
1531                      Is_Followed_By_Empty_Line => False);
1532
1533                --  Otherwise, it is an end of line comment. If there is
1534                --  an end of line node specified, associate the comment with
1535                --  this node.
1536
1537                elsif End_Of_Line_Node /= Empty_Node then
1538                   declare
1539                      Zones : constant Project_Node_Id :=
1540                                Comment_Zones_Of (End_Of_Line_Node, In_Tree);
1541                   begin
1542                      In_Tree.Project_Nodes.Table (Zones).Value := Comment_Id;
1543                   end;
1544
1545                --  Otherwise, this end of line node cannot be kept
1546
1547                else
1548                   Unkept_Comments := True;
1549                   Comments.Set_Last (0);
1550                end if;
1551
1552                Empty_Line := False;
1553
1554             when others =>
1555                --  If there are comments, where the first comment is not
1556                --  following an empty line, put the initial uninterrupted
1557                --  comment zone with the node of the preceding line (either
1558                --  a Previous_Line or a Previous_End node), if any.
1559
1560                if Comments.Last > 0 and then
1561                  not Comments.Table (1).Follows_Empty_Line then
1562                   if Previous_Line_Node /= Empty_Node then
1563                      Add_Comments
1564                        (To      => Previous_Line_Node,
1565                         Where   => After,
1566                         In_Tree => In_Tree);
1567
1568                   elsif Previous_End_Node /= Empty_Node then
1569                      Add_Comments
1570                        (To      => Previous_End_Node,
1571                         Where   => After_End,
1572                         In_Tree => In_Tree);
1573                   end if;
1574                end if;
1575
1576                --  If there are still comments and the token is "end", then
1577                --  put these comments with the Next_End node, if any;
1578                --  otherwise, these comments cannot be kept. Always clear
1579                --  the comments.
1580
1581                if Comments.Last > 0 and then Token = Tok_End then
1582                   if Next_End_Nodes.Last > 0 then
1583                      Add_Comments
1584                        (To      => Next_End_Nodes.Table (Next_End_Nodes.Last),
1585                         Where   => Before_End,
1586                         In_Tree => In_Tree);
1587
1588                   else
1589                      Unkept_Comments := True;
1590                   end if;
1591
1592                   Comments.Set_Last (0);
1593                end if;
1594
1595                --  Reset the End_Of_Line, Previous_Line and Previous_End nodes
1596                --  so that they are not used again.
1597
1598                End_Of_Line_Node   := Empty_Node;
1599                Previous_Line_Node := Empty_Node;
1600                Previous_End_Node  := Empty_Node;
1601
1602                --  And return
1603
1604                exit;
1605          end case;
1606       end loop;
1607    end Scan;
1608
1609    ------------------------------------
1610    -- Set_Associative_Array_Index_Of --
1611    ------------------------------------
1612
1613    procedure Set_Associative_Array_Index_Of
1614      (Node    : Project_Node_Id;
1615       In_Tree : Project_Node_Tree_Ref;
1616       To      : Name_Id)
1617    is
1618    begin
1619       pragma Assert
1620         (Node /= Empty_Node
1621           and then
1622             (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
1623                or else
1624              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
1625       In_Tree.Project_Nodes.Table (Node).Value := To;
1626    end Set_Associative_Array_Index_Of;
1627
1628    --------------------------------
1629    -- Set_Associative_Package_Of --
1630    --------------------------------
1631
1632    procedure Set_Associative_Package_Of
1633      (Node    : Project_Node_Id;
1634       In_Tree : Project_Node_Tree_Ref;
1635       To      : Project_Node_Id)
1636    is
1637    begin
1638       pragma Assert
1639          (Node /= Empty_Node
1640           and then
1641             In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration);
1642       In_Tree.Project_Nodes.Table (Node).Field3 := To;
1643    end Set_Associative_Package_Of;
1644
1645    --------------------------------
1646    -- Set_Associative_Project_Of --
1647    --------------------------------
1648
1649    procedure Set_Associative_Project_Of
1650      (Node    : Project_Node_Id;
1651       In_Tree : Project_Node_Tree_Ref;
1652       To      : Project_Node_Id)
1653    is
1654    begin
1655       pragma Assert
1656         (Node /= Empty_Node
1657           and then
1658            (In_Tree.Project_Nodes.Table (Node).Kind =
1659               N_Attribute_Declaration));
1660       In_Tree.Project_Nodes.Table (Node).Field2 := To;
1661    end Set_Associative_Project_Of;
1662
1663    --------------------------
1664    -- Set_Case_Insensitive --
1665    --------------------------
1666
1667    procedure Set_Case_Insensitive
1668      (Node    : Project_Node_Id;
1669       In_Tree : Project_Node_Tree_Ref;
1670       To      : Boolean)
1671    is
1672    begin
1673       pragma Assert
1674         (Node /= Empty_Node
1675           and then
1676            (In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
1677                or else
1678             In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
1679       In_Tree.Project_Nodes.Table (Node).Flag1 := To;
1680    end Set_Case_Insensitive;
1681
1682    ------------------------------------
1683    -- Set_Case_Variable_Reference_Of --
1684    ------------------------------------
1685
1686    procedure Set_Case_Variable_Reference_Of
1687      (Node    : Project_Node_Id;
1688       In_Tree : Project_Node_Tree_Ref;
1689       To      : Project_Node_Id)
1690    is
1691    begin
1692       pragma Assert
1693         (Node /= Empty_Node
1694           and then
1695             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Construction);
1696       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1697    end Set_Case_Variable_Reference_Of;
1698
1699    ---------------------------
1700    -- Set_Current_Item_Node --
1701    ---------------------------
1702
1703    procedure Set_Current_Item_Node
1704      (Node    : Project_Node_Id;
1705       In_Tree : Project_Node_Tree_Ref;
1706       To      : Project_Node_Id)
1707    is
1708    begin
1709       pragma Assert
1710         (Node /= Empty_Node
1711           and then
1712             In_Tree.Project_Nodes.Table (Node).Kind = N_Declarative_Item);
1713       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1714    end Set_Current_Item_Node;
1715
1716    ----------------------
1717    -- Set_Current_Term --
1718    ----------------------
1719
1720    procedure Set_Current_Term
1721      (Node    : Project_Node_Id;
1722       In_Tree : Project_Node_Tree_Ref;
1723       To      : Project_Node_Id)
1724    is
1725    begin
1726       pragma Assert
1727         (Node /= Empty_Node
1728           and then
1729             In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
1730       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1731    end Set_Current_Term;
1732
1733    ----------------------
1734    -- Set_Directory_Of --
1735    ----------------------
1736
1737    procedure Set_Directory_Of
1738      (Node    : Project_Node_Id;
1739       In_Tree : Project_Node_Tree_Ref;
1740       To      : Path_Name_Type)
1741    is
1742    begin
1743       pragma Assert
1744         (Node /= Empty_Node
1745           and then
1746             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
1747       In_Tree.Project_Nodes.Table (Node).Directory := To;
1748    end Set_Directory_Of;
1749
1750    ---------------------
1751    -- Set_End_Of_Line --
1752    ---------------------
1753
1754    procedure Set_End_Of_Line (To : Project_Node_Id) is
1755    begin
1756       End_Of_Line_Node := To;
1757    end Set_End_Of_Line;
1758
1759    ----------------------------
1760    -- Set_Expression_Kind_Of --
1761    ----------------------------
1762
1763    procedure Set_Expression_Kind_Of
1764      (Node    : Project_Node_Id;
1765       In_Tree : Project_Node_Tree_Ref;
1766       To      : Variable_Kind)
1767    is
1768    begin
1769       pragma Assert
1770         (Node /= Empty_Node
1771            and then
1772              (In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String
1773                 or else
1774               In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Declaration
1775                 or else
1776               In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Declaration
1777                 or else
1778               In_Tree.Project_Nodes.Table (Node).Kind =
1779                 N_Typed_Variable_Declaration
1780                 or else
1781               In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration
1782                 or else
1783               In_Tree.Project_Nodes.Table (Node).Kind = N_Expression
1784                 or else
1785               In_Tree.Project_Nodes.Table (Node).Kind = N_Term
1786                 or else
1787               In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
1788                 or else
1789               In_Tree.Project_Nodes.Table (Node).Kind =
1790                 N_Attribute_Reference));
1791       In_Tree.Project_Nodes.Table (Node).Expr_Kind := To;
1792    end Set_Expression_Kind_Of;
1793
1794    -----------------------
1795    -- Set_Expression_Of --
1796    -----------------------
1797
1798    procedure Set_Expression_Of
1799      (Node    : Project_Node_Id;
1800       In_Tree : Project_Node_Tree_Ref;
1801       To      : Project_Node_Id)
1802    is
1803    begin
1804       pragma Assert
1805         (Node /= Empty_Node
1806           and then
1807            (In_Tree.Project_Nodes.Table (Node).Kind =
1808               N_Attribute_Declaration
1809                or else
1810             In_Tree.Project_Nodes.Table (Node).Kind =
1811               N_Typed_Variable_Declaration
1812                or else
1813             In_Tree.Project_Nodes.Table (Node).Kind =
1814               N_Variable_Declaration));
1815       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1816    end Set_Expression_Of;
1817
1818    -------------------------------
1819    -- Set_External_Reference_Of --
1820    -------------------------------
1821
1822    procedure Set_External_Reference_Of
1823      (Node    : Project_Node_Id;
1824       In_Tree : Project_Node_Tree_Ref;
1825       To      : Project_Node_Id)
1826    is
1827    begin
1828       pragma Assert
1829         (Node /= Empty_Node
1830           and then
1831             In_Tree.Project_Nodes.Table (Node).Kind = N_External_Value);
1832       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1833    end Set_External_Reference_Of;
1834
1835    -----------------------------
1836    -- Set_External_Default_Of --
1837    -----------------------------
1838
1839    procedure Set_External_Default_Of
1840      (Node    : Project_Node_Id;
1841       In_Tree : Project_Node_Tree_Ref;
1842       To      : Project_Node_Id)
1843    is
1844    begin
1845       pragma Assert
1846         (Node /= Empty_Node
1847           and then
1848             In_Tree.Project_Nodes.Table (Node).Kind = N_External_Value);
1849       In_Tree.Project_Nodes.Table (Node).Field2 := To;
1850    end Set_External_Default_Of;
1851
1852    ----------------------------
1853    -- Set_First_Case_Item_Of --
1854    ----------------------------
1855
1856    procedure Set_First_Case_Item_Of
1857      (Node    : Project_Node_Id;
1858       In_Tree : Project_Node_Tree_Ref;
1859       To      : Project_Node_Id)
1860    is
1861    begin
1862       pragma Assert
1863         (Node /= Empty_Node
1864           and then
1865             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Construction);
1866       In_Tree.Project_Nodes.Table (Node).Field2 := To;
1867    end Set_First_Case_Item_Of;
1868
1869    -------------------------
1870    -- Set_First_Choice_Of --
1871    -------------------------
1872
1873    procedure Set_First_Choice_Of
1874      (Node    : Project_Node_Id;
1875       In_Tree : Project_Node_Tree_Ref;
1876       To      : Project_Node_Id)
1877    is
1878    begin
1879       pragma Assert
1880         (Node /= Empty_Node
1881           and then
1882             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item);
1883       In_Tree.Project_Nodes.Table (Node).Field1 := To;
1884    end Set_First_Choice_Of;
1885
1886    -----------------------------
1887    -- Set_First_Comment_After --
1888    -----------------------------
1889
1890    procedure Set_First_Comment_After
1891      (Node    : Project_Node_Id;
1892       In_Tree : Project_Node_Tree_Ref;
1893       To      : Project_Node_Id)
1894    is
1895       Zone : constant Project_Node_Id := Comment_Zones_Of (Node, In_Tree);
1896    begin
1897       In_Tree.Project_Nodes.Table (Zone).Field2 := To;
1898    end Set_First_Comment_After;
1899
1900    ---------------------------------
1901    -- Set_First_Comment_After_End --
1902    ---------------------------------
1903
1904    procedure Set_First_Comment_After_End
1905      (Node    : Project_Node_Id;
1906       In_Tree : Project_Node_Tree_Ref;
1907       To      : Project_Node_Id)
1908    is
1909       Zone : constant Project_Node_Id := Comment_Zones_Of (Node, In_Tree);
1910    begin
1911       In_Tree.Project_Nodes.Table (Zone).Comments := To;
1912    end Set_First_Comment_After_End;
1913
1914    ------------------------------
1915    -- Set_First_Comment_Before --
1916    ------------------------------
1917
1918    procedure Set_First_Comment_Before
1919      (Node    : Project_Node_Id;
1920       In_Tree : Project_Node_Tree_Ref;
1921       To      : Project_Node_Id)
1922
1923    is
1924       Zone : constant Project_Node_Id := Comment_Zones_Of (Node, In_Tree);
1925    begin
1926       In_Tree.Project_Nodes.Table (Zone).Field1 := To;
1927    end Set_First_Comment_Before;
1928
1929    ----------------------------------
1930    -- Set_First_Comment_Before_End --
1931    ----------------------------------
1932
1933    procedure Set_First_Comment_Before_End
1934      (Node    : Project_Node_Id;
1935       In_Tree : Project_Node_Tree_Ref;
1936       To      : Project_Node_Id)
1937    is
1938       Zone : constant Project_Node_Id := Comment_Zones_Of (Node, In_Tree);
1939    begin
1940       In_Tree.Project_Nodes.Table (Zone).Field2 := To;
1941    end Set_First_Comment_Before_End;
1942
1943    ------------------------
1944    -- Set_Next_Case_Item --
1945    ------------------------
1946
1947    procedure Set_Next_Case_Item
1948      (Node    : Project_Node_Id;
1949       In_Tree : Project_Node_Tree_Ref;
1950       To      : Project_Node_Id)
1951    is
1952    begin
1953       pragma Assert
1954         (Node /= Empty_Node
1955           and then
1956             In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item);
1957       In_Tree.Project_Nodes.Table (Node).Field3 := To;
1958    end Set_Next_Case_Item;
1959
1960    ----------------------
1961    -- Set_Next_Comment --
1962    ----------------------
1963
1964    procedure Set_Next_Comment
1965      (Node    : Project_Node_Id;
1966       In_Tree : Project_Node_Tree_Ref;
1967       To      : Project_Node_Id)
1968    is
1969    begin
1970       pragma Assert
1971         (Node /= Empty_Node
1972           and then
1973             In_Tree.Project_Nodes.Table (Node).Kind = N_Comment);
1974       In_Tree.Project_Nodes.Table (Node).Comments := To;
1975    end Set_Next_Comment;
1976
1977    -----------------------------------
1978    -- Set_First_Declarative_Item_Of --
1979    -----------------------------------
1980
1981    procedure Set_First_Declarative_Item_Of
1982      (Node    : Project_Node_Id;
1983       In_Tree : Project_Node_Tree_Ref;
1984       To      : Project_Node_Id)
1985    is
1986    begin
1987       pragma Assert
1988         (Node /= Empty_Node
1989           and then
1990             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration
1991                or else
1992              In_Tree.Project_Nodes.Table (Node).Kind = N_Case_Item
1993                or else
1994              In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration));
1995
1996       if In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration then
1997          In_Tree.Project_Nodes.Table (Node).Field1 := To;
1998       else
1999          In_Tree.Project_Nodes.Table (Node).Field2 := To;
2000       end if;
2001    end Set_First_Declarative_Item_Of;
2002
2003    ----------------------------------
2004    -- Set_First_Expression_In_List --
2005    ----------------------------------
2006
2007    procedure Set_First_Expression_In_List
2008      (Node    : Project_Node_Id;
2009       In_Tree : Project_Node_Tree_Ref;
2010       To      : Project_Node_Id)
2011    is
2012    begin
2013       pragma Assert
2014         (Node /= Empty_Node
2015           and then
2016             In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String_List);
2017       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2018    end Set_First_Expression_In_List;
2019
2020    ------------------------------
2021    -- Set_First_Literal_String --
2022    ------------------------------
2023
2024    procedure Set_First_Literal_String
2025      (Node    : Project_Node_Id;
2026       In_Tree : Project_Node_Tree_Ref;
2027       To      : Project_Node_Id)
2028    is
2029    begin
2030       pragma Assert
2031         (Node /= Empty_Node
2032           and then
2033          In_Tree.Project_Nodes.Table (Node).Kind =
2034            N_String_Type_Declaration);
2035       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2036    end Set_First_Literal_String;
2037
2038    --------------------------
2039    -- Set_First_Package_Of --
2040    --------------------------
2041
2042    procedure Set_First_Package_Of
2043      (Node    : Project_Node_Id;
2044       In_Tree : Project_Node_Tree_Ref;
2045       To      : Package_Declaration_Id)
2046    is
2047    begin
2048       pragma Assert
2049         (Node /= Empty_Node
2050           and then
2051             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2052       In_Tree.Project_Nodes.Table (Node).Packages := To;
2053    end Set_First_Package_Of;
2054
2055    ------------------------------
2056    -- Set_First_String_Type_Of --
2057    ------------------------------
2058
2059    procedure Set_First_String_Type_Of
2060      (Node    : Project_Node_Id;
2061       In_Tree : Project_Node_Tree_Ref;
2062       To      : Project_Node_Id)
2063    is
2064    begin
2065       pragma Assert
2066         (Node /= Empty_Node
2067           and then
2068             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2069       In_Tree.Project_Nodes.Table (Node).Field3 := To;
2070    end Set_First_String_Type_Of;
2071
2072    --------------------
2073    -- Set_First_Term --
2074    --------------------
2075
2076    procedure Set_First_Term
2077      (Node    : Project_Node_Id;
2078       In_Tree : Project_Node_Tree_Ref;
2079       To      : Project_Node_Id)
2080    is
2081    begin
2082       pragma Assert
2083         (Node /= Empty_Node
2084           and then
2085             In_Tree.Project_Nodes.Table (Node).Kind = N_Expression);
2086       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2087    end Set_First_Term;
2088
2089    ---------------------------
2090    -- Set_First_Variable_Of --
2091    ---------------------------
2092
2093    procedure Set_First_Variable_Of
2094      (Node    : Project_Node_Id;
2095       In_Tree : Project_Node_Tree_Ref;
2096       To      : Variable_Node_Id)
2097    is
2098    begin
2099       pragma Assert
2100         (Node /= Empty_Node
2101           and then
2102             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
2103                or else
2104              In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration));
2105       In_Tree.Project_Nodes.Table (Node).Variables := To;
2106    end Set_First_Variable_Of;
2107
2108    ------------------------------
2109    -- Set_First_With_Clause_Of --
2110    ------------------------------
2111
2112    procedure Set_First_With_Clause_Of
2113      (Node    : Project_Node_Id;
2114       In_Tree : Project_Node_Tree_Ref;
2115       To      : Project_Node_Id)
2116    is
2117    begin
2118       pragma Assert
2119         (Node /= Empty_Node
2120           and then
2121             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2122       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2123    end Set_First_With_Clause_Of;
2124
2125    --------------------------
2126    -- Set_Is_Extending_All --
2127    --------------------------
2128
2129    procedure Set_Is_Extending_All
2130      (Node    : Project_Node_Id;
2131       In_Tree : Project_Node_Tree_Ref)
2132    is
2133    begin
2134       pragma Assert
2135         (Node /= Empty_Node
2136           and then
2137             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
2138                or else
2139              In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause));
2140       In_Tree.Project_Nodes.Table (Node).Flag2 := True;
2141    end Set_Is_Extending_All;
2142
2143    -----------------------------
2144    -- Set_Is_Not_Last_In_List --
2145    -----------------------------
2146
2147    procedure Set_Is_Not_Last_In_List
2148      (Node    : Project_Node_Id;
2149       In_Tree : Project_Node_Tree_Ref)
2150    is
2151    begin
2152       pragma Assert
2153         (Node /= Empty_Node
2154           and then
2155              In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause);
2156       In_Tree.Project_Nodes.Table (Node).Flag1 := True;
2157    end Set_Is_Not_Last_In_List;
2158
2159    -----------------
2160    -- Set_Kind_Of --
2161    -----------------
2162
2163    procedure Set_Kind_Of
2164      (Node    : Project_Node_Id;
2165       In_Tree : Project_Node_Tree_Ref;
2166       To      : Project_Node_Kind)
2167    is
2168    begin
2169       pragma Assert (Node /= Empty_Node);
2170       In_Tree.Project_Nodes.Table (Node).Kind := To;
2171    end Set_Kind_Of;
2172
2173    ---------------------
2174    -- Set_Location_Of --
2175    ---------------------
2176
2177    procedure Set_Location_Of
2178      (Node    : Project_Node_Id;
2179       In_Tree : Project_Node_Tree_Ref;
2180       To      : Source_Ptr)
2181    is
2182    begin
2183       pragma Assert (Node /= Empty_Node);
2184       In_Tree.Project_Nodes.Table (Node).Location := To;
2185    end Set_Location_Of;
2186
2187    -----------------------------
2188    -- Set_Extended_Project_Of --
2189    -----------------------------
2190
2191    procedure Set_Extended_Project_Of
2192      (Node    : Project_Node_Id;
2193       In_Tree : Project_Node_Tree_Ref;
2194       To      : Project_Node_Id)
2195    is
2196    begin
2197       pragma Assert
2198         (Node /= Empty_Node
2199           and then
2200             In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration);
2201       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2202    end Set_Extended_Project_Of;
2203
2204    ----------------------------------
2205    -- Set_Extended_Project_Path_Of --
2206    ----------------------------------
2207
2208    procedure Set_Extended_Project_Path_Of
2209      (Node    : Project_Node_Id;
2210       In_Tree : Project_Node_Tree_Ref;
2211       To      : Path_Name_Type)
2212    is
2213    begin
2214       pragma Assert
2215         (Node /= Empty_Node
2216           and then
2217             In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2218       In_Tree.Project_Nodes.Table (Node).Value := Name_Id (To);
2219    end Set_Extended_Project_Path_Of;
2220
2221    ------------------------------
2222    -- Set_Extending_Project_Of --
2223    ------------------------------
2224
2225    procedure Set_Extending_Project_Of
2226      (Node    : Project_Node_Id;
2227       In_Tree : Project_Node_Tree_Ref;
2228       To      : Project_Node_Id)
2229    is
2230    begin
2231       pragma Assert
2232         (Node /= Empty_Node
2233           and then
2234             In_Tree.Project_Nodes.Table (Node).Kind = N_Project_Declaration);
2235       In_Tree.Project_Nodes.Table (Node).Field3 := To;
2236    end Set_Extending_Project_Of;
2237
2238    -----------------
2239    -- Set_Name_Of --
2240    -----------------
2241
2242    procedure Set_Name_Of
2243      (Node    : Project_Node_Id;
2244       In_Tree : Project_Node_Tree_Ref;
2245       To      : Name_Id)
2246    is
2247    begin
2248       pragma Assert (Node /= Empty_Node);
2249       In_Tree.Project_Nodes.Table (Node).Name := To;
2250    end Set_Name_Of;
2251
2252    -------------------------------
2253    -- Set_Next_Declarative_Item --
2254    -------------------------------
2255
2256    procedure Set_Next_Declarative_Item
2257      (Node    : Project_Node_Id;
2258       In_Tree : Project_Node_Tree_Ref;
2259       To      : Project_Node_Id)
2260    is
2261    begin
2262       pragma Assert
2263         (Node /= Empty_Node
2264           and then
2265             In_Tree.Project_Nodes.Table (Node).Kind = N_Declarative_Item);
2266       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2267    end Set_Next_Declarative_Item;
2268
2269    -----------------------
2270    -- Set_Next_End_Node --
2271    -----------------------
2272
2273    procedure Set_Next_End_Node (To : Project_Node_Id) is
2274    begin
2275       Next_End_Nodes.Increment_Last;
2276       Next_End_Nodes.Table (Next_End_Nodes.Last) := To;
2277    end Set_Next_End_Node;
2278
2279    ---------------------------------
2280    -- Set_Next_Expression_In_List --
2281    ---------------------------------
2282
2283    procedure Set_Next_Expression_In_List
2284      (Node    : Project_Node_Id;
2285       In_Tree : Project_Node_Tree_Ref;
2286       To      : Project_Node_Id)
2287    is
2288    begin
2289       pragma Assert
2290         (Node /= Empty_Node
2291           and then
2292             In_Tree.Project_Nodes.Table (Node).Kind = N_Expression);
2293       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2294    end Set_Next_Expression_In_List;
2295
2296    -----------------------------
2297    -- Set_Next_Literal_String --
2298    -----------------------------
2299
2300    procedure Set_Next_Literal_String
2301      (Node    : Project_Node_Id;
2302       In_Tree : Project_Node_Tree_Ref;
2303       To      : Project_Node_Id)
2304    is
2305    begin
2306       pragma Assert
2307         (Node /= Empty_Node
2308           and then
2309             In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String);
2310       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2311    end Set_Next_Literal_String;
2312
2313    ---------------------------------
2314    -- Set_Next_Package_In_Project --
2315    ---------------------------------
2316
2317    procedure Set_Next_Package_In_Project
2318      (Node    : Project_Node_Id;
2319       In_Tree : Project_Node_Tree_Ref;
2320       To      : Project_Node_Id)
2321    is
2322    begin
2323       pragma Assert
2324         (Node /= Empty_Node
2325           and then
2326             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
2327       In_Tree.Project_Nodes.Table (Node).Field3 := To;
2328    end Set_Next_Package_In_Project;
2329
2330    --------------------------
2331    -- Set_Next_String_Type --
2332    --------------------------
2333
2334    procedure Set_Next_String_Type
2335      (Node    : Project_Node_Id;
2336       In_Tree : Project_Node_Tree_Ref;
2337       To      : Project_Node_Id)
2338    is
2339    begin
2340       pragma Assert
2341         (Node /= Empty_Node
2342           and then
2343          In_Tree.Project_Nodes.Table (Node).Kind =
2344            N_String_Type_Declaration);
2345       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2346    end Set_Next_String_Type;
2347
2348    -------------------
2349    -- Set_Next_Term --
2350    -------------------
2351
2352    procedure Set_Next_Term
2353      (Node    : Project_Node_Id;
2354       In_Tree : Project_Node_Tree_Ref;
2355       To      : Project_Node_Id)
2356    is
2357    begin
2358       pragma Assert
2359         (Node /= Empty_Node
2360           and then
2361             In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
2362       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2363    end Set_Next_Term;
2364
2365    -----------------------
2366    -- Set_Next_Variable --
2367    -----------------------
2368
2369    procedure Set_Next_Variable
2370      (Node    : Project_Node_Id;
2371       In_Tree : Project_Node_Tree_Ref;
2372       To      : Project_Node_Id)
2373    is
2374    begin
2375       pragma Assert
2376         (Node /= Empty_Node
2377           and then
2378            (In_Tree.Project_Nodes.Table (Node).Kind =
2379               N_Typed_Variable_Declaration
2380                or else
2381             In_Tree.Project_Nodes.Table (Node).Kind =
2382               N_Variable_Declaration));
2383       In_Tree.Project_Nodes.Table (Node).Field3 := To;
2384    end Set_Next_Variable;
2385
2386    -----------------------------
2387    -- Set_Next_With_Clause_Of --
2388    -----------------------------
2389
2390    procedure Set_Next_With_Clause_Of
2391      (Node    : Project_Node_Id;
2392       In_Tree : Project_Node_Tree_Ref;
2393       To      : Project_Node_Id)
2394    is
2395    begin
2396       pragma Assert
2397         (Node /= Empty_Node
2398           and then
2399             In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause);
2400       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2401    end Set_Next_With_Clause_Of;
2402
2403    -----------------------
2404    -- Set_Package_Id_Of --
2405    -----------------------
2406
2407    procedure Set_Package_Id_Of
2408      (Node    : Project_Node_Id;
2409       In_Tree : Project_Node_Tree_Ref;
2410       To      : Package_Node_Id)
2411    is
2412    begin
2413       pragma Assert
2414         (Node /= Empty_Node
2415           and then
2416             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
2417       In_Tree.Project_Nodes.Table (Node).Pkg_Id := To;
2418    end Set_Package_Id_Of;
2419
2420    -------------------------
2421    -- Set_Package_Node_Of --
2422    -------------------------
2423
2424    procedure Set_Package_Node_Of
2425      (Node    : Project_Node_Id;
2426       In_Tree : Project_Node_Tree_Ref;
2427       To      : Project_Node_Id)
2428    is
2429    begin
2430       pragma Assert
2431         (Node /= Empty_Node
2432           and then
2433             (In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
2434                or else
2435              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
2436       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2437    end Set_Package_Node_Of;
2438
2439    ----------------------
2440    -- Set_Path_Name_Of --
2441    ----------------------
2442
2443    procedure Set_Path_Name_Of
2444      (Node    : Project_Node_Id;
2445       In_Tree : Project_Node_Tree_Ref;
2446       To      : Path_Name_Type)
2447    is
2448    begin
2449       pragma Assert
2450         (Node /= Empty_Node
2451           and then
2452             (In_Tree.Project_Nodes.Table (Node).Kind = N_Project
2453                or else
2454              In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause));
2455       In_Tree.Project_Nodes.Table (Node).Path_Name := To;
2456    end Set_Path_Name_Of;
2457
2458    ---------------------------
2459    -- Set_Previous_End_Node --
2460    ---------------------------
2461    procedure Set_Previous_End_Node (To : Project_Node_Id) is
2462    begin
2463       Previous_End_Node := To;
2464    end Set_Previous_End_Node;
2465
2466    ----------------------------
2467    -- Set_Previous_Line_Node --
2468    ----------------------------
2469
2470    procedure Set_Previous_Line_Node (To : Project_Node_Id) is
2471    begin
2472       Previous_Line_Node := To;
2473    end Set_Previous_Line_Node;
2474
2475    --------------------------------
2476    -- Set_Project_Declaration_Of --
2477    --------------------------------
2478
2479    procedure Set_Project_Declaration_Of
2480      (Node    : Project_Node_Id;
2481       In_Tree : Project_Node_Tree_Ref;
2482       To      : Project_Node_Id)
2483    is
2484    begin
2485       pragma Assert
2486         (Node /= Empty_Node
2487          and then
2488            In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2489       In_Tree.Project_Nodes.Table (Node).Field2 := To;
2490    end Set_Project_Declaration_Of;
2491
2492    ------------------------------
2493    -- Set_Project_Qualifier_Of --
2494    ------------------------------
2495
2496    procedure Set_Project_Qualifier_Of
2497      (Node    : Project_Node_Id;
2498       In_Tree : Project_Node_Tree_Ref;
2499       To      : Project_Qualifier)
2500    is
2501    begin
2502       pragma Assert
2503         (Node /= Empty_Node
2504           and then In_Tree.Project_Nodes.Table (Node).Kind = N_Project);
2505       In_Tree.Project_Nodes.Table (Node).Qualifier := To;
2506    end Set_Project_Qualifier_Of;
2507
2508    -----------------------------------------------
2509    -- Set_Project_File_Includes_Unkept_Comments --
2510    -----------------------------------------------
2511
2512    procedure Set_Project_File_Includes_Unkept_Comments
2513      (Node    : Project_Node_Id;
2514       In_Tree : Project_Node_Tree_Ref;
2515       To      : Boolean)
2516    is
2517       Declaration : constant Project_Node_Id :=
2518                       Project_Declaration_Of (Node, In_Tree);
2519    begin
2520       In_Tree.Project_Nodes.Table (Declaration).Flag1 := To;
2521    end Set_Project_File_Includes_Unkept_Comments;
2522
2523    -------------------------
2524    -- Set_Project_Node_Of --
2525    -------------------------
2526
2527    procedure Set_Project_Node_Of
2528      (Node         : Project_Node_Id;
2529       In_Tree      : Project_Node_Tree_Ref;
2530       To           : Project_Node_Id;
2531       Limited_With : Boolean := False)
2532    is
2533    begin
2534       pragma Assert
2535         (Node /= Empty_Node
2536           and then
2537             (In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause
2538                or else
2539              In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference
2540                or else
2541              In_Tree.Project_Nodes.Table (Node).Kind = N_Attribute_Reference));
2542       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2543
2544       if In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause
2545         and then not Limited_With
2546       then
2547          In_Tree.Project_Nodes.Table (Node).Field3 := To;
2548       end if;
2549    end Set_Project_Node_Of;
2550
2551    ---------------------------------------
2552    -- Set_Project_Of_Renamed_Package_Of --
2553    ---------------------------------------
2554
2555    procedure Set_Project_Of_Renamed_Package_Of
2556      (Node    : Project_Node_Id;
2557       In_Tree : Project_Node_Tree_Ref;
2558       To      : Project_Node_Id)
2559    is
2560    begin
2561       pragma Assert
2562         (Node /= Empty_Node
2563           and then
2564             In_Tree.Project_Nodes.Table (Node).Kind = N_Package_Declaration);
2565       In_Tree.Project_Nodes.Table (Node).Field1 := To;
2566    end Set_Project_Of_Renamed_Package_Of;
2567
2568    -------------------------
2569    -- Set_Source_Index_Of --
2570    -------------------------
2571
2572    procedure Set_Source_Index_Of
2573      (Node    : Project_Node_Id;
2574       In_Tree : Project_Node_Tree_Ref;
2575       To      : Int)
2576    is
2577    begin
2578       pragma Assert
2579         (Node /= Empty_Node
2580           and then
2581            (In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String
2582             or else
2583             In_Tree.Project_Nodes.Table (Node).Kind =
2584               N_Attribute_Declaration));
2585       In_Tree.Project_Nodes.Table (Node).Src_Index := To;
2586    end Set_Source_Index_Of;
2587
2588    ------------------------
2589    -- Set_String_Type_Of --
2590    ------------------------
2591
2592    procedure Set_String_Type_Of
2593      (Node    : Project_Node_Id;
2594       In_Tree : Project_Node_Tree_Ref;
2595       To      : Project_Node_Id)
2596    is
2597    begin
2598       pragma Assert
2599         (Node /= Empty_Node
2600           and then
2601            (In_Tree.Project_Nodes.Table (Node).Kind =
2602               N_Variable_Reference
2603                or else
2604             In_Tree.Project_Nodes.Table (Node).Kind =
2605               N_Typed_Variable_Declaration)
2606           and then
2607             In_Tree.Project_Nodes.Table (To).Kind = N_String_Type_Declaration);
2608
2609       if In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference then
2610          In_Tree.Project_Nodes.Table (Node).Field3 := To;
2611       else
2612          In_Tree.Project_Nodes.Table (Node).Field2 := To;
2613       end if;
2614    end Set_String_Type_Of;
2615
2616    -------------------------
2617    -- Set_String_Value_Of --
2618    -------------------------
2619
2620    procedure Set_String_Value_Of
2621      (Node    : Project_Node_Id;
2622       In_Tree : Project_Node_Tree_Ref;
2623       To      : Name_Id)
2624    is
2625    begin
2626       pragma Assert
2627         (Node /= Empty_Node
2628           and then
2629             (In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause
2630                or else
2631              In_Tree.Project_Nodes.Table (Node).Kind = N_Comment
2632                or else
2633              In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String));
2634       In_Tree.Project_Nodes.Table (Node).Value := To;
2635    end Set_String_Value_Of;
2636
2637    ---------------------
2638    -- Source_Index_Of --
2639    ---------------------
2640
2641    function Source_Index_Of
2642      (Node    : Project_Node_Id;
2643       In_Tree : Project_Node_Tree_Ref) return Int
2644    is
2645    begin
2646       pragma Assert
2647         (Node /= Empty_Node
2648           and then
2649             (In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String
2650               or else
2651              In_Tree.Project_Nodes.Table (Node).Kind =
2652                N_Attribute_Declaration));
2653       return In_Tree.Project_Nodes.Table (Node).Src_Index;
2654    end Source_Index_Of;
2655
2656    --------------------
2657    -- String_Type_Of --
2658    --------------------
2659
2660    function String_Type_Of
2661      (Node    : Project_Node_Id;
2662       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
2663    is
2664    begin
2665       pragma Assert
2666         (Node /= Empty_Node
2667           and then
2668            (In_Tree.Project_Nodes.Table (Node).Kind =
2669               N_Variable_Reference
2670                or else
2671             In_Tree.Project_Nodes.Table (Node).Kind =
2672               N_Typed_Variable_Declaration));
2673
2674       if In_Tree.Project_Nodes.Table (Node).Kind = N_Variable_Reference then
2675          return In_Tree.Project_Nodes.Table (Node).Field3;
2676       else
2677          return In_Tree.Project_Nodes.Table (Node).Field2;
2678       end if;
2679    end String_Type_Of;
2680
2681    ---------------------
2682    -- String_Value_Of --
2683    ---------------------
2684
2685    function String_Value_Of
2686      (Node    : Project_Node_Id;
2687       In_Tree : Project_Node_Tree_Ref) return Name_Id
2688    is
2689    begin
2690       pragma Assert
2691         (Node /= Empty_Node
2692           and then
2693            (In_Tree.Project_Nodes.Table (Node).Kind = N_With_Clause
2694               or else
2695             In_Tree.Project_Nodes.Table (Node).Kind = N_Comment
2696                or else
2697             In_Tree.Project_Nodes.Table (Node).Kind = N_Literal_String));
2698       return In_Tree.Project_Nodes.Table (Node).Value;
2699    end String_Value_Of;
2700
2701    --------------------
2702    -- Value_Is_Valid --
2703    --------------------
2704
2705    function Value_Is_Valid
2706      (For_Typed_Variable : Project_Node_Id;
2707       In_Tree            : Project_Node_Tree_Ref;
2708       Value              : Name_Id) return Boolean
2709    is
2710    begin
2711       pragma Assert
2712         (For_Typed_Variable /= Empty_Node
2713           and then
2714            (In_Tree.Project_Nodes.Table (For_Typed_Variable).Kind =
2715                                      N_Typed_Variable_Declaration));
2716
2717       declare
2718          Current_String : Project_Node_Id :=
2719                             First_Literal_String
2720                               (String_Type_Of (For_Typed_Variable, In_Tree),
2721                                In_Tree);
2722
2723       begin
2724          while Current_String /= Empty_Node
2725            and then
2726              String_Value_Of (Current_String, In_Tree) /= Value
2727          loop
2728             Current_String :=
2729               Next_Literal_String (Current_String, In_Tree);
2730          end loop;
2731
2732          return Current_String /= Empty_Node;
2733       end;
2734
2735    end Value_Is_Valid;
2736
2737    -------------------------------
2738    -- There_Are_Unkept_Comments --
2739    -------------------------------
2740
2741    function There_Are_Unkept_Comments return Boolean is
2742    begin
2743       return Unkept_Comments;
2744    end There_Are_Unkept_Comments;
2745
2746 end Prj.Tree;