OSDN Git Service

2011-08-03 Emmanuel Briot <briot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-tree.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . T R E E                             --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2011, 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 --  This package defines the structure of the Project File tree
27
28 with GNAT.Dynamic_HTables;
29 with GNAT.Dynamic_Tables;
30
31 with Table;
32
33 with Prj.Attr; use Prj.Attr;
34 with Prj.Env;
35 with Prj.Ext;
36
37 package Prj.Tree is
38
39    -----------------
40    -- Environment --
41    -----------------
42
43    type Environment is record
44       External : Prj.Ext.External_References;
45       --  External references are stored in this hash table (and manipulated
46       --  through subprograms in prj-ext.ads). External references are
47       --  project-tree specific so that one can load the same tree twice but
48       --  have two views of it, for instance.
49
50       Project_Path : aliased Prj.Env.Project_Search_Path;
51       --  The project path is tree specific, since we might want to load
52       --  simultaneously multiple projects, each with its own search path, in
53       --  particular when using different compilers with different default
54       --  search directories.
55    end record;
56    --  This record contains the context in which projects are parsed and
57    --  processed (finding importing project, resolving external values,...)
58
59    procedure Initialize (Self : in out Environment);
60    --  Initialize a new environment
61
62    procedure Free (Self : in out Environment);
63    --  Free the memory used by Self
64
65    -------------------
66    -- Project nodes --
67    -------------------
68
69    type Project_Node_Tree_Data;
70    type Project_Node_Tree_Ref is access all Project_Node_Tree_Data;
71    --  Type to designate a project node tree, so that several project node
72    --  trees can coexist in memory.
73
74    Project_Nodes_Initial   : constant := 1_000;
75    Project_Nodes_Increment : constant := 100;
76    --  Allocation parameters for initializing and extending number
77    --  of nodes in table Tree_Private_Part.Project_Nodes
78
79    Project_Node_Low_Bound  : constant := 0;
80    Project_Node_High_Bound : constant := 099_999_999;
81    --  Range of values for project node id's (in practice infinite)
82
83    type Project_Node_Id is range
84      Project_Node_Low_Bound .. Project_Node_High_Bound;
85    --  The index of table Tree_Private_Part.Project_Nodes
86
87    Empty_Node : constant Project_Node_Id := Project_Node_Low_Bound;
88    --  Designates no node in table Project_Nodes
89
90    First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound + 1;
91
92    subtype Variable_Node_Id is Project_Node_Id;
93    --  Used to designate a node whose expected kind is one of
94    --  N_Typed_Variable_Declaration, N_Variable_Declaration or
95    --  N_Variable_Reference.
96
97    subtype Package_Declaration_Id is Project_Node_Id;
98    --  Used to designate a node whose expected kind is N_Project_Declaration
99
100    type Project_Node_Kind is
101      (N_Project,
102       N_With_Clause,
103       N_Project_Declaration,
104       N_Declarative_Item,
105       N_Package_Declaration,
106       N_String_Type_Declaration,
107       N_Literal_String,
108       N_Attribute_Declaration,
109       N_Typed_Variable_Declaration,
110       N_Variable_Declaration,
111       N_Expression,
112       N_Term,
113       N_Literal_String_List,
114       N_Variable_Reference,
115       N_External_Value,
116       N_Attribute_Reference,
117       N_Case_Construction,
118       N_Case_Item,
119       N_Comment_Zones,
120       N_Comment);
121    --  Each node in the tree is of a Project_Node_Kind. For the signification
122    --  of the fields in each node of Project_Node_Kind, look at package
123    --  Tree_Private_Part.
124
125    function Present (Node : Project_Node_Id) return Boolean;
126    pragma Inline (Present);
127    --  Return True if Node /= Empty_Node
128
129    function No (Node : Project_Node_Id) return Boolean;
130    pragma Inline (No);
131    --  Return True if Node = Empty_Node
132
133    procedure Initialize (Tree : Project_Node_Tree_Ref;
134                          Env : in out Environment);
135    --  Initialize the Project File tree: empty the Project_Nodes table
136    --  and reset the Projects_Htable.
137
138    function Default_Project_Node
139      (In_Tree       : Project_Node_Tree_Ref;
140       Of_Kind       : Project_Node_Kind;
141       And_Expr_Kind : Variable_Kind := Undefined) return Project_Node_Id;
142    --  Returns a Project_Node_Record with the specified Kind and Expr_Kind. All
143    --  the other components have default nil values.
144    --  To create a node for a project itself, see Create_Project below instead
145
146    function Hash (N : Project_Node_Id) return Header_Num;
147    --  Used for hash tables where the key is a Project_Node_Id
148
149    function Imported_Or_Extended_Project_Of
150      (Project   : Project_Node_Id;
151       In_Tree   : Project_Node_Tree_Ref;
152       With_Name : Name_Id) return Project_Node_Id;
153    --  Return the node of a project imported or extended by project Project and
154    --  whose name is With_Name. Return Empty_Node if there is no such project.
155
156    --------------
157    -- Comments --
158    --------------
159
160    type Comment_State is private;
161    --  A type to store the values of several global variables related to
162    --  comments.
163
164    procedure Save (S : out Comment_State);
165    --  Save in variable S the comment state. Called before scanning a new
166    --  project file.
167
168    procedure Restore_And_Free (S : in out Comment_State);
169    --  Restore the comment state to a previously saved value. Called after
170    --  scanning a project file. Frees the memory occupied by S
171
172    procedure Reset_State;
173    --  Set the comment state to its initial value. Called before scanning a
174    --  new project file.
175
176    function There_Are_Unkept_Comments return Boolean;
177    --  Indicates that some of the comments in a project file could not be
178    --  stored in the parse tree.
179
180    procedure Set_Previous_Line_Node (To : Project_Node_Id);
181    --  Indicate the node on the previous line. If there are comments
182    --  immediately following this line, then they should be associated with
183    --  this node.
184
185    procedure Set_Previous_End_Node (To : Project_Node_Id);
186    --  Indicate that on the previous line the "end" belongs to node To.
187    --  If there are comments immediately following this "end" line, they
188    --  should be associated with this node.
189
190    procedure Set_End_Of_Line (To : Project_Node_Id);
191    --  Indicate the node on the current line. If there is an end of line
192    --  comment, then it should be associated with this node.
193
194    procedure Set_Next_End_Node (To : Project_Node_Id);
195    --  Put node To on the top of the end node stack. When an END line is found
196    --  with this node on the top of the end node stack, the comments, if any,
197    --  immediately preceding this "end" line will be associated with this node.
198
199    procedure Remove_Next_End_Node;
200    --  Remove the top of the end node stack
201
202    ------------------------
203    -- Comment Processing --
204    ------------------------
205
206    type Comment_Data is record
207       Value                     : Name_Id := No_Name;
208       Follows_Empty_Line        : Boolean := False;
209       Is_Followed_By_Empty_Line : Boolean := False;
210    end record;
211    --  Component type for Comments Table below
212
213    package Comments is new Table.Table
214      (Table_Component_Type => Comment_Data,
215       Table_Index_Type     => Natural,
216       Table_Low_Bound      => 1,
217       Table_Initial        => 10,
218       Table_Increment      => 100,
219       Table_Name           => "Prj.Tree.Comments");
220    --  A table to store the comments that may be stored is the tree
221
222    procedure Scan (In_Tree : Project_Node_Tree_Ref);
223    --  Scan the tokens and accumulate comments
224
225    type Comment_Location is
226      (Before, After, Before_End, After_End, End_Of_Line);
227    --  Used in call to Add_Comments below
228
229    procedure Add_Comments
230      (To      : Project_Node_Id;
231       In_Tree : Project_Node_Tree_Ref;
232       Where   : Comment_Location);
233    --  Add comments to this node
234
235    ----------------------
236    -- Access Functions --
237    ----------------------
238
239    --  The following query functions are part of the abstract interface
240    --  of the Project File tree. They provide access to fields of a project.
241
242    --  The access functions should be called only with valid arguments.
243    --  For each function the condition of validity is specified. If an access
244    --  function is called with invalid arguments, then exception
245    --  Assertion_Error is raised if assertions are enabled, otherwise the
246    --  behaviour is not defined and may result in a crash.
247
248    function Name_Of
249      (Node    : Project_Node_Id;
250       In_Tree : Project_Node_Tree_Ref) return Name_Id;
251    pragma Inline (Name_Of);
252    --  Valid for all non empty nodes. May return No_Name for nodes that have
253    --  no names.
254
255    function Kind_Of
256      (Node    : Project_Node_Id;
257       In_Tree : Project_Node_Tree_Ref) return Project_Node_Kind;
258    pragma Inline (Kind_Of);
259    --  Valid for all non empty nodes
260
261    function Location_Of
262      (Node    : Project_Node_Id;
263       In_Tree : Project_Node_Tree_Ref) return Source_Ptr;
264    pragma Inline (Location_Of);
265    --  Valid for all non empty nodes
266
267    function First_Comment_After
268      (Node    : Project_Node_Id;
269       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
270    --  Valid only for N_Comment_Zones nodes
271
272    function First_Comment_After_End
273      (Node    : Project_Node_Id;
274       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
275    --  Valid only for N_Comment_Zones nodes
276
277    function First_Comment_Before
278      (Node    : Project_Node_Id;
279       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
280    --  Valid only for N_Comment_Zones nodes
281
282    function First_Comment_Before_End
283      (Node    : Project_Node_Id;
284       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
285    --  Valid only for N_Comment_Zones nodes
286
287    function Next_Comment
288      (Node    : Project_Node_Id;
289       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
290    --  Valid only for N_Comment nodes
291
292    function End_Of_Line_Comment
293      (Node    : Project_Node_Id;
294       In_Tree : Project_Node_Tree_Ref) return Name_Id;
295    --  Valid only for non empty nodes
296
297    function Follows_Empty_Line
298      (Node    : Project_Node_Id;
299       In_Tree : Project_Node_Tree_Ref) return Boolean;
300    --  Valid only for N_Comment nodes
301
302    function Is_Followed_By_Empty_Line
303      (Node    : Project_Node_Id;
304       In_Tree : Project_Node_Tree_Ref) return Boolean;
305    --  Valid only for N_Comment nodes
306
307    function Parent_Project_Of
308      (Node    : Project_Node_Id;
309       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
310    pragma Inline (Parent_Project_Of);
311    --  Valid only for N_Project nodes
312
313    function Project_File_Includes_Unkept_Comments
314      (Node    : Project_Node_Id;
315       In_Tree : Project_Node_Tree_Ref) return Boolean;
316    --  Valid only for N_Project nodes
317
318    function Directory_Of
319      (Node    : Project_Node_Id;
320       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
321    pragma Inline (Directory_Of);
322    --  Returns the directory that contains the project file. This always ends
323    --  with a directory separator. Only valid for N_Project nodes.
324
325    function Expression_Kind_Of
326      (Node    : Project_Node_Id;
327       In_Tree : Project_Node_Tree_Ref) return Variable_Kind;
328    pragma Inline (Expression_Kind_Of);
329    --  Only valid for N_Literal_String, N_Attribute_Declaration,
330    --  N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
331    --  N_Term, N_Variable_Reference, N_Attribute_Reference nodes or
332    --  N_External_Value.
333
334    function Is_Extending_All
335      (Node    : Project_Node_Id;
336       In_Tree : Project_Node_Tree_Ref) return Boolean;
337    pragma Inline (Is_Extending_All);
338    --  Only valid for N_Project and N_With_Clause
339
340    function Is_Not_Last_In_List
341      (Node    : Project_Node_Id;
342       In_Tree : Project_Node_Tree_Ref) return Boolean;
343    pragma Inline (Is_Not_Last_In_List);
344    --  Only valid for N_With_Clause
345
346    function First_Variable_Of
347      (Node    : Project_Node_Id;
348       In_Tree : Project_Node_Tree_Ref) return Variable_Node_Id;
349    pragma Inline (First_Variable_Of);
350    --  Only valid for N_Project or N_Package_Declaration nodes
351
352    function First_Package_Of
353      (Node    : Project_Node_Id;
354       In_Tree : Project_Node_Tree_Ref) return Package_Declaration_Id;
355    pragma Inline (First_Package_Of);
356    --  Only valid for N_Project nodes
357
358    function Package_Id_Of
359      (Node    : Project_Node_Id;
360       In_Tree : Project_Node_Tree_Ref) return Package_Node_Id;
361    pragma Inline (Package_Id_Of);
362    --  Only valid for N_Package_Declaration nodes
363
364    function Path_Name_Of
365      (Node    : Project_Node_Id;
366       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
367    pragma Inline (Path_Name_Of);
368    --  Only valid for N_Project and N_With_Clause nodes
369
370    function String_Value_Of
371      (Node    : Project_Node_Id;
372       In_Tree : Project_Node_Tree_Ref) return Name_Id;
373    pragma Inline (String_Value_Of);
374    --  Only valid for N_With_Clause, N_Literal_String nodes or N_Comment.
375    --  For a N_With_Clause created automatically for a virtual extending
376    --  project, No_Name is returned.
377
378    function Source_Index_Of
379      (Node    : Project_Node_Id;
380       In_Tree : Project_Node_Tree_Ref) return Int;
381    pragma Inline (Source_Index_Of);
382    --  Only valid for N_Literal_String and N_Attribute_Declaration nodes
383
384    function First_With_Clause_Of
385      (Node    : Project_Node_Id;
386       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
387    pragma Inline (First_With_Clause_Of);
388    --  Only valid for N_Project nodes
389
390    function Project_Declaration_Of
391      (Node    : Project_Node_Id;
392       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
393    pragma Inline (Project_Declaration_Of);
394    --  Only valid for N_Project nodes
395
396    function Project_Qualifier_Of
397      (Node    : Project_Node_Id;
398       In_Tree : Project_Node_Tree_Ref) return Project_Qualifier;
399    pragma Inline (Project_Qualifier_Of);
400    --  Only valid for N_Project nodes
401
402    function Extending_Project_Of
403      (Node    : Project_Node_Id;
404       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
405    pragma Inline (Extending_Project_Of);
406    --  Only valid for N_Project_Declaration nodes
407
408    function First_String_Type_Of
409      (Node    : Project_Node_Id;
410       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
411    pragma Inline (First_String_Type_Of);
412    --  Only valid for N_Project nodes
413
414    function Extended_Project_Path_Of
415      (Node    : Project_Node_Id;
416       In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
417    pragma Inline (Extended_Project_Path_Of);
418    --  Only valid for N_With_Clause nodes
419
420    function Project_Node_Of
421      (Node    : Project_Node_Id;
422       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
423    pragma Inline (Project_Node_Of);
424    --  Only valid for N_With_Clause, N_Variable_Reference and
425    --  N_Attribute_Reference nodes.
426
427    function Non_Limited_Project_Node_Of
428      (Node    : Project_Node_Id;
429       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
430    pragma Inline (Non_Limited_Project_Node_Of);
431    --  Only valid for N_With_Clause nodes. Returns Empty_Node for limited
432    --  imported project files, otherwise returns the same result as
433    --  Project_Node_Of.
434
435    function Next_With_Clause_Of
436      (Node    : Project_Node_Id;
437       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
438    pragma Inline (Next_With_Clause_Of);
439    --  Only valid for N_With_Clause nodes
440
441    function First_Declarative_Item_Of
442      (Node    : Project_Node_Id;
443       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
444    pragma Inline (First_Declarative_Item_Of);
445    --  Only valid for N_Project_Declaration, N_Case_Item and
446    --  N_Package_Declaration.
447
448    function Extended_Project_Of
449      (Node    : Project_Node_Id;
450       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
451    pragma Inline (Extended_Project_Of);
452    --  Only valid for N_Project_Declaration nodes
453
454    function Current_Item_Node
455      (Node    : Project_Node_Id;
456       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
457    pragma Inline (Current_Item_Node);
458    --  Only valid for N_Declarative_Item nodes
459
460    function Next_Declarative_Item
461      (Node    : Project_Node_Id;
462       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
463    pragma Inline (Next_Declarative_Item);
464    --  Only valid for N_Declarative_Item node
465
466    function Project_Of_Renamed_Package_Of
467      (Node    : Project_Node_Id;
468       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
469    pragma Inline (Project_Of_Renamed_Package_Of);
470    --  Only valid for N_Package_Declaration nodes. May return Empty_Node.
471
472    function Next_Package_In_Project
473      (Node    : Project_Node_Id;
474       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
475    pragma Inline (Next_Package_In_Project);
476    --  Only valid for N_Package_Declaration nodes
477
478    function First_Literal_String
479      (Node    : Project_Node_Id;
480       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
481    pragma Inline (First_Literal_String);
482    --  Only valid for N_String_Type_Declaration nodes
483
484    function Next_String_Type
485      (Node    : Project_Node_Id;
486       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
487    pragma Inline (Next_String_Type);
488    --  Only valid for N_String_Type_Declaration nodes
489
490    function Next_Literal_String
491      (Node    : Project_Node_Id;
492       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
493    pragma Inline (Next_Literal_String);
494    --  Only valid for N_Literal_String nodes
495
496    function Expression_Of
497      (Node    : Project_Node_Id;
498       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
499    pragma Inline (Expression_Of);
500    --  Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
501    --  or N_Variable_Declaration nodes
502
503    function Associative_Project_Of
504      (Node    : Project_Node_Id;
505       In_Tree : Project_Node_Tree_Ref)
506       return  Project_Node_Id;
507    pragma Inline (Associative_Project_Of);
508    --  Only valid for N_Attribute_Declaration nodes
509
510    function Associative_Package_Of
511      (Node    : Project_Node_Id;
512       In_Tree : Project_Node_Tree_Ref)
513       return  Project_Node_Id;
514    pragma Inline (Associative_Package_Of);
515    --  Only valid for N_Attribute_Declaration nodes
516
517    function Value_Is_Valid
518      (For_Typed_Variable : Project_Node_Id;
519       In_Tree            : Project_Node_Tree_Ref;
520       Value              : Name_Id) return Boolean;
521    pragma Inline (Value_Is_Valid);
522    --  Only valid for N_Typed_Variable_Declaration. Returns True if Value is
523    --  in the list of allowed strings for For_Typed_Variable. False otherwise.
524
525    function Associative_Array_Index_Of
526      (Node    : Project_Node_Id;
527       In_Tree : Project_Node_Tree_Ref) return Name_Id;
528    pragma Inline (Associative_Array_Index_Of);
529    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference.
530    --  Returns No_Name for non associative array attributes.
531
532    function Next_Variable
533      (Node    : Project_Node_Id;
534       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
535    pragma Inline (Next_Variable);
536    --  Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
537    --  nodes.
538
539    function First_Term
540      (Node    : Project_Node_Id;
541       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
542    pragma Inline (First_Term);
543    --  Only valid for N_Expression nodes
544
545    function Next_Expression_In_List
546      (Node    : Project_Node_Id;
547       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
548    pragma Inline (Next_Expression_In_List);
549    --  Only valid for N_Expression nodes
550
551    function Current_Term
552      (Node    : Project_Node_Id;
553       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
554    pragma Inline (Current_Term);
555    --  Only valid for N_Term nodes
556
557    function Next_Term
558      (Node    : Project_Node_Id;
559       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
560    pragma Inline (Next_Term);
561    --  Only valid for N_Term nodes
562
563    function First_Expression_In_List
564      (Node    : Project_Node_Id;
565       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
566    pragma Inline (First_Expression_In_List);
567    --  Only valid for N_Literal_String_List nodes
568
569    function Package_Node_Of
570      (Node    : Project_Node_Id;
571       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
572    pragma Inline (Package_Node_Of);
573    --  Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
574    --  May return Empty_Node.
575
576    function String_Type_Of
577      (Node    : Project_Node_Id;
578       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
579    pragma Inline (String_Type_Of);
580    --  Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
581    --  nodes.
582
583    function External_Reference_Of
584      (Node    : Project_Node_Id;
585       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
586    pragma Inline (External_Reference_Of);
587    --  Only valid for N_External_Value nodes
588
589    function External_Default_Of
590      (Node    : Project_Node_Id;
591       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
592    pragma Inline (External_Default_Of);
593    --  Only valid for N_External_Value nodes
594
595    function Case_Variable_Reference_Of
596      (Node    : Project_Node_Id;
597       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
598    pragma Inline (Case_Variable_Reference_Of);
599    --  Only valid for N_Case_Construction nodes
600
601    function First_Case_Item_Of
602      (Node    : Project_Node_Id;
603       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
604    pragma Inline (First_Case_Item_Of);
605    --  Only valid for N_Case_Construction nodes
606
607    function First_Choice_Of
608      (Node    : Project_Node_Id;
609       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
610    pragma Inline (First_Choice_Of);
611    --  Only valid for N_Case_Item nodes. Return the first choice in a
612    --  N_Case_Item, or Empty_Node if this is when others.
613
614    function Next_Case_Item
615      (Node    : Project_Node_Id;
616       In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
617    pragma Inline (Next_Case_Item);
618    --  Only valid for N_Case_Item nodes
619
620    function Case_Insensitive
621      (Node    : Project_Node_Id;
622       In_Tree : Project_Node_Tree_Ref) return Boolean;
623    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
624
625    -----------------------
626    -- Create procedures --
627    -----------------------
628    --  The following procedures are used to edit a project file tree. They are
629    --  slightly higher-level than the Set_* procedures below
630
631    function Create_Project
632      (In_Tree        : Project_Node_Tree_Ref;
633       Name           : Name_Id;
634       Full_Path      : Path_Name_Type;
635       Is_Config_File : Boolean := False) return Project_Node_Id;
636    --  Create a new node for a project and register it in the tree so that it
637    --  can be retrieved later on.
638
639    function Create_Package
640      (Tree    : Project_Node_Tree_Ref;
641       Project : Project_Node_Id;
642       Pkg     : String) return Project_Node_Id;
643    --  Create a new package in Project. If the package already exists, it is
644    --  returned. The name of the package *must* be lower-cases, or none of its
645    --  attributes will be recognized.
646
647    function Create_Attribute
648      (Tree       : Project_Node_Tree_Ref;
649       Prj_Or_Pkg : Project_Node_Id;
650       Name       : Name_Id;
651       Index_Name : Name_Id         := No_Name;
652       Kind       : Variable_Kind   := List;
653       At_Index   : Integer         := 0;
654       Value      : Project_Node_Id := Empty_Node) return Project_Node_Id;
655    --  Create a new attribute. The new declaration is added at the end of the
656    --  declarative item list for Prj_Or_Pkg (a project or a package), but
657    --  before any package declaration). No addition is done if Prj_Or_Pkg is
658    --  Empty_Node. If Index_Name is not "", then if creates an attribute value
659    --  for a specific index. At_Index is used for the " at <idx>" in the naming
660    --  exceptions.
661    --
662    --  To set the value of the attribute, either provide a value for Value, or
663    --  use Set_Expression_Of to set the value of the attribute (in which case
664    --  Enclose_In_Expression might be useful). The former is recommended since
665    --  it will more correctly handle cases where the index needs to be set on
666    --  the expression rather than on the index of the attribute (i.e. 'for
667    --  Specification ("unit") use "file" at 3', versus 'for Executable ("file"
668    --  at 3) use "name"'). Value must be a N_String_Literal if an index will be
669    --  added to it.
670
671    function Create_Literal_String
672      (Str  : Namet.Name_Id;
673       Tree : Project_Node_Tree_Ref) return Project_Node_Id;
674    --  Create a literal string whose value is Str
675
676    procedure Add_At_End
677      (Tree                  : Project_Node_Tree_Ref;
678       Parent                : Project_Node_Id;
679       Expr                  : Project_Node_Id;
680       Add_Before_First_Pkg  : Boolean := False;
681       Add_Before_First_Case : Boolean := False);
682    --  Add a new declarative item in the list in Parent. This new declarative
683    --  item will contain Expr (unless Expr is already a declarative item, in
684    --  which case it is added directly to the list). The new item is inserted
685    --  at the end of the list, unless Add_Before_First_Pkg is True. In the
686    --  latter case, it is added just before the first case construction is
687    --  seen, or before the first package (this assumes that all packages are
688    --  found at the end of the project, which isn't true in the general case
689    --  unless you have normalized the project to match this description).
690
691    function Enclose_In_Expression
692      (Node : Project_Node_Id;
693       Tree : Project_Node_Tree_Ref) return Project_Node_Id;
694    --  Enclose the Node inside a N_Expression node, and return this expression.
695    --  This does nothing if Node is already a N_Expression.
696
697    --------------------
698    -- Set Procedures --
699    --------------------
700
701    --  The following procedures are part of the abstract interface of the
702    --  Project File tree.
703
704    --  Foe each Set_* procedure the condition of validity is specified. If an
705    --  access function is called with invalid arguments, then exception
706    --  Assertion_Error is raised if assertions are enabled, otherwise the
707    --  behaviour is not defined and may result in a crash.
708
709    --  These are very low-level, and manipulate the tree itself directly. You
710    --  should look at the Create_* procedure instead if you want to use higher
711    --  level constructs
712
713    procedure Set_Name_Of
714      (Node    : Project_Node_Id;
715       In_Tree : Project_Node_Tree_Ref;
716       To      : Name_Id);
717    pragma Inline (Set_Name_Of);
718    --  Valid for all non empty nodes.
719
720    procedure Set_Kind_Of
721      (Node    : Project_Node_Id;
722       In_Tree : Project_Node_Tree_Ref;
723       To      : Project_Node_Kind);
724    pragma Inline (Set_Kind_Of);
725    --  Valid for all non empty nodes
726
727    procedure Set_Location_Of
728      (Node    : Project_Node_Id;
729       In_Tree : Project_Node_Tree_Ref;
730       To      : Source_Ptr);
731    pragma Inline (Set_Location_Of);
732    --  Valid for all non empty nodes
733
734    procedure Set_First_Comment_After
735      (Node    : Project_Node_Id;
736       In_Tree : Project_Node_Tree_Ref;
737       To      : Project_Node_Id);
738    pragma Inline (Set_First_Comment_After);
739    --  Valid only for N_Comment_Zones nodes
740
741    procedure Set_First_Comment_After_End
742      (Node    : Project_Node_Id;
743       In_Tree : Project_Node_Tree_Ref;
744       To      : Project_Node_Id);
745    pragma Inline (Set_First_Comment_After_End);
746    --  Valid only for N_Comment_Zones nodes
747
748    procedure Set_First_Comment_Before
749      (Node    : Project_Node_Id;
750       In_Tree : Project_Node_Tree_Ref;
751       To      : Project_Node_Id);
752    pragma Inline (Set_First_Comment_Before);
753    --  Valid only for N_Comment_Zones nodes
754
755    procedure Set_First_Comment_Before_End
756      (Node    : Project_Node_Id;
757       In_Tree : Project_Node_Tree_Ref;
758       To      : Project_Node_Id);
759    pragma Inline (Set_First_Comment_Before_End);
760    --  Valid only for N_Comment_Zones nodes
761
762    procedure Set_Next_Comment
763      (Node    : Project_Node_Id;
764       In_Tree : Project_Node_Tree_Ref;
765       To      : Project_Node_Id);
766    pragma Inline (Set_Next_Comment);
767    --  Valid only for N_Comment nodes
768
769    procedure Set_Parent_Project_Of
770      (Node    : Project_Node_Id;
771       In_Tree : Project_Node_Tree_Ref;
772       To      : Project_Node_Id);
773    --  Valid only for N_Project nodes
774
775    procedure Set_Project_File_Includes_Unkept_Comments
776      (Node    : Project_Node_Id;
777       In_Tree : Project_Node_Tree_Ref;
778       To      : Boolean);
779    --  Valid only for N_Project nodes
780
781    procedure Set_Directory_Of
782      (Node    : Project_Node_Id;
783       In_Tree : Project_Node_Tree_Ref;
784       To      : Path_Name_Type);
785    pragma Inline (Set_Directory_Of);
786    --  Valid only for N_Project nodes
787
788    procedure Set_Expression_Kind_Of
789      (Node    : Project_Node_Id;
790       In_Tree : Project_Node_Tree_Ref;
791       To      : Variable_Kind);
792    pragma Inline (Set_Expression_Kind_Of);
793    --  Only valid for N_Literal_String, N_Attribute_Declaration,
794    --  N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
795    --  N_Term, N_Variable_Reference, N_Attribute_Reference or N_External_Value
796    --  nodes.
797
798    procedure Set_Is_Extending_All
799      (Node    : Project_Node_Id;
800       In_Tree : Project_Node_Tree_Ref);
801    pragma Inline (Set_Is_Extending_All);
802    --  Only valid for N_Project and N_With_Clause
803
804    procedure Set_Is_Not_Last_In_List
805      (Node    : Project_Node_Id;
806       In_Tree : Project_Node_Tree_Ref);
807    pragma Inline (Set_Is_Not_Last_In_List);
808    --  Only valid for N_With_Clause
809
810    procedure Set_First_Variable_Of
811      (Node    : Project_Node_Id;
812       In_Tree : Project_Node_Tree_Ref;
813       To      : Variable_Node_Id);
814    pragma Inline (Set_First_Variable_Of);
815    --  Only valid for N_Project or N_Package_Declaration nodes
816
817    procedure Set_First_Package_Of
818      (Node    : Project_Node_Id;
819       In_Tree : Project_Node_Tree_Ref;
820       To      : Package_Declaration_Id);
821    pragma Inline (Set_First_Package_Of);
822    --  Only valid for N_Project nodes
823
824    procedure Set_Package_Id_Of
825      (Node    : Project_Node_Id;
826       In_Tree : Project_Node_Tree_Ref;
827       To      : Package_Node_Id);
828    pragma Inline (Set_Package_Id_Of);
829    --  Only valid for N_Package_Declaration nodes
830
831    procedure Set_Path_Name_Of
832      (Node    : Project_Node_Id;
833       In_Tree : Project_Node_Tree_Ref;
834       To      : Path_Name_Type);
835    pragma Inline (Set_Path_Name_Of);
836    --  Only valid for N_Project and N_With_Clause nodes
837
838    procedure Set_String_Value_Of
839      (Node    : Project_Node_Id;
840       In_Tree : Project_Node_Tree_Ref;
841       To      : Name_Id);
842    pragma Inline (Set_String_Value_Of);
843    --  Only valid for N_With_Clause, N_Literal_String nodes or N_Comment.
844
845    procedure Set_Source_Index_Of
846      (Node    : Project_Node_Id;
847       In_Tree : Project_Node_Tree_Ref;
848       To      : Int);
849    pragma Inline (Set_Source_Index_Of);
850    --  Only valid for N_Literal_String and N_Attribute_Declaration nodes. For
851    --  N_Literal_String, set the source index of the literal string. For
852    --  N_Attribute_Declaration, set the source index of the index of the
853    --  associative array element.
854
855    procedure Set_First_With_Clause_Of
856      (Node    : Project_Node_Id;
857       In_Tree : Project_Node_Tree_Ref;
858       To      : Project_Node_Id);
859    pragma Inline (Set_First_With_Clause_Of);
860    --  Only valid for N_Project nodes
861
862    procedure Set_Project_Declaration_Of
863      (Node    : Project_Node_Id;
864       In_Tree : Project_Node_Tree_Ref;
865       To      : Project_Node_Id);
866    pragma Inline (Set_Project_Declaration_Of);
867    --  Only valid for N_Project nodes
868
869    procedure Set_Project_Qualifier_Of
870      (Node    : Project_Node_Id;
871       In_Tree : Project_Node_Tree_Ref;
872       To      : Project_Qualifier);
873    pragma Inline (Set_Project_Qualifier_Of);
874    --  Only valid for N_Project nodes
875
876    procedure Set_Extending_Project_Of
877      (Node    : Project_Node_Id;
878       In_Tree : Project_Node_Tree_Ref;
879       To      : Project_Node_Id);
880    pragma Inline (Set_Extending_Project_Of);
881    --  Only valid for N_Project_Declaration nodes
882
883    procedure Set_First_String_Type_Of
884      (Node    : Project_Node_Id;
885       In_Tree : Project_Node_Tree_Ref;
886       To      : Project_Node_Id);
887    pragma Inline (Set_First_String_Type_Of);
888    --  Only valid for N_Project nodes
889
890    procedure Set_Extended_Project_Path_Of
891      (Node    : Project_Node_Id;
892       In_Tree : Project_Node_Tree_Ref;
893       To      : Path_Name_Type);
894    pragma Inline (Set_Extended_Project_Path_Of);
895    --  Only valid for N_With_Clause nodes
896
897    procedure Set_Project_Node_Of
898      (Node         : Project_Node_Id;
899       In_Tree      : Project_Node_Tree_Ref;
900       To           : Project_Node_Id;
901       Limited_With : Boolean := False);
902    pragma Inline (Set_Project_Node_Of);
903    --  Only valid for N_With_Clause, N_Variable_Reference and
904    --  N_Attribute_Reference nodes.
905
906    procedure Set_Next_With_Clause_Of
907      (Node    : Project_Node_Id;
908       In_Tree : Project_Node_Tree_Ref;
909       To      : Project_Node_Id);
910    pragma Inline (Set_Next_With_Clause_Of);
911    --  Only valid for N_With_Clause nodes
912
913    procedure Set_First_Declarative_Item_Of
914      (Node    : Project_Node_Id;
915       In_Tree : Project_Node_Tree_Ref;
916       To      : Project_Node_Id);
917    pragma Inline (Set_First_Declarative_Item_Of);
918    --  Only valid for N_Project_Declaration, N_Case_Item and
919    --  N_Package_Declaration.
920
921    procedure Set_Extended_Project_Of
922      (Node    : Project_Node_Id;
923       In_Tree : Project_Node_Tree_Ref;
924       To      : Project_Node_Id);
925    pragma Inline (Set_Extended_Project_Of);
926    --  Only valid for N_Project_Declaration nodes
927
928    procedure Set_Current_Item_Node
929      (Node    : Project_Node_Id;
930       In_Tree : Project_Node_Tree_Ref;
931       To      : Project_Node_Id);
932    pragma Inline (Set_Current_Item_Node);
933    --  Only valid for N_Declarative_Item nodes
934
935    procedure Set_Next_Declarative_Item
936      (Node    : Project_Node_Id;
937       In_Tree : Project_Node_Tree_Ref;
938       To      : Project_Node_Id);
939    pragma Inline (Set_Next_Declarative_Item);
940    --  Only valid for N_Declarative_Item node
941
942    procedure Set_Project_Of_Renamed_Package_Of
943      (Node    : Project_Node_Id;
944       In_Tree : Project_Node_Tree_Ref;
945       To      : Project_Node_Id);
946    pragma Inline (Set_Project_Of_Renamed_Package_Of);
947    --  Only valid for N_Package_Declaration nodes.
948
949    procedure Set_Next_Package_In_Project
950      (Node    : Project_Node_Id;
951       In_Tree : Project_Node_Tree_Ref;
952       To      : Project_Node_Id);
953    pragma Inline (Set_Next_Package_In_Project);
954    --  Only valid for N_Package_Declaration nodes
955
956    procedure Set_First_Literal_String
957      (Node    : Project_Node_Id;
958       In_Tree : Project_Node_Tree_Ref;
959       To      : Project_Node_Id);
960    pragma Inline (Set_First_Literal_String);
961    --  Only valid for N_String_Type_Declaration nodes
962
963    procedure Set_Next_String_Type
964      (Node    : Project_Node_Id;
965       In_Tree : Project_Node_Tree_Ref;
966       To      : Project_Node_Id);
967    pragma Inline (Set_Next_String_Type);
968    --  Only valid for N_String_Type_Declaration nodes
969
970    procedure Set_Next_Literal_String
971      (Node    : Project_Node_Id;
972       In_Tree : Project_Node_Tree_Ref;
973       To      : Project_Node_Id);
974    pragma Inline (Set_Next_Literal_String);
975    --  Only valid for N_Literal_String nodes
976
977    procedure Set_Expression_Of
978      (Node    : Project_Node_Id;
979       In_Tree : Project_Node_Tree_Ref;
980       To      : Project_Node_Id);
981    pragma Inline (Set_Expression_Of);
982    --  Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
983    --  or N_Variable_Declaration nodes
984
985    procedure Set_Associative_Project_Of
986      (Node    : Project_Node_Id;
987       In_Tree : Project_Node_Tree_Ref;
988       To      : Project_Node_Id);
989    pragma Inline (Set_Associative_Project_Of);
990    --  Only valid for N_Attribute_Declaration nodes
991
992    procedure Set_Associative_Package_Of
993      (Node    : Project_Node_Id;
994       In_Tree : Project_Node_Tree_Ref;
995       To      : Project_Node_Id);
996    pragma Inline (Set_Associative_Package_Of);
997    --  Only valid for N_Attribute_Declaration nodes
998
999    procedure Set_Associative_Array_Index_Of
1000      (Node    : Project_Node_Id;
1001       In_Tree : Project_Node_Tree_Ref;
1002       To      : Name_Id);
1003    pragma Inline (Set_Associative_Array_Index_Of);
1004    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference.
1005
1006    procedure Set_Next_Variable
1007      (Node    : Project_Node_Id;
1008       In_Tree : Project_Node_Tree_Ref;
1009       To      : Project_Node_Id);
1010    pragma Inline (Set_Next_Variable);
1011    --  Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
1012    --  nodes.
1013
1014    procedure Set_First_Term
1015      (Node    : Project_Node_Id;
1016       In_Tree : Project_Node_Tree_Ref;
1017       To      : Project_Node_Id);
1018    pragma Inline (Set_First_Term);
1019    --  Only valid for N_Expression nodes
1020
1021    procedure Set_Next_Expression_In_List
1022      (Node    : Project_Node_Id;
1023       In_Tree : Project_Node_Tree_Ref;
1024       To      : Project_Node_Id);
1025    pragma Inline (Set_Next_Expression_In_List);
1026    --  Only valid for N_Expression nodes
1027
1028    procedure Set_Current_Term
1029      (Node    : Project_Node_Id;
1030       In_Tree : Project_Node_Tree_Ref;
1031       To      : Project_Node_Id);
1032    pragma Inline (Set_Current_Term);
1033    --  Only valid for N_Term nodes
1034
1035    procedure Set_Next_Term
1036      (Node    : Project_Node_Id;
1037       In_Tree : Project_Node_Tree_Ref;
1038       To      : Project_Node_Id);
1039    pragma Inline (Set_Next_Term);
1040    --  Only valid for N_Term nodes
1041
1042    procedure Set_First_Expression_In_List
1043      (Node    : Project_Node_Id;
1044       In_Tree : Project_Node_Tree_Ref;
1045       To      : Project_Node_Id);
1046    pragma Inline (Set_First_Expression_In_List);
1047    --  Only valid for N_Literal_String_List nodes
1048
1049    procedure Set_Package_Node_Of
1050      (Node    : Project_Node_Id;
1051       In_Tree : Project_Node_Tree_Ref;
1052       To      : Project_Node_Id);
1053    pragma Inline (Set_Package_Node_Of);
1054    --  Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
1055
1056    procedure Set_String_Type_Of
1057      (Node    : Project_Node_Id;
1058       In_Tree : Project_Node_Tree_Ref;
1059       To      : Project_Node_Id);
1060    pragma Inline (Set_String_Type_Of);
1061    --  Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
1062    --  nodes.
1063
1064    procedure Set_External_Reference_Of
1065      (Node    : Project_Node_Id;
1066       In_Tree : Project_Node_Tree_Ref;
1067       To      : Project_Node_Id);
1068    pragma Inline (Set_External_Reference_Of);
1069    --  Only valid for N_External_Value nodes
1070
1071    procedure Set_External_Default_Of
1072      (Node    : Project_Node_Id;
1073       In_Tree : Project_Node_Tree_Ref;
1074       To      : Project_Node_Id);
1075    pragma Inline (Set_External_Default_Of);
1076    --  Only valid for N_External_Value nodes
1077
1078    procedure Set_Case_Variable_Reference_Of
1079      (Node    : Project_Node_Id;
1080       In_Tree : Project_Node_Tree_Ref;
1081       To      : Project_Node_Id);
1082    pragma Inline (Set_Case_Variable_Reference_Of);
1083    --  Only valid for N_Case_Construction nodes
1084
1085    procedure Set_First_Case_Item_Of
1086      (Node    : Project_Node_Id;
1087       In_Tree : Project_Node_Tree_Ref;
1088       To      : Project_Node_Id);
1089    pragma Inline (Set_First_Case_Item_Of);
1090    --  Only valid for N_Case_Construction nodes
1091
1092    procedure Set_First_Choice_Of
1093      (Node    : Project_Node_Id;
1094       In_Tree : Project_Node_Tree_Ref;
1095       To      : Project_Node_Id);
1096    pragma Inline (Set_First_Choice_Of);
1097    --  Only valid for N_Case_Item nodes.
1098
1099    procedure Set_Next_Case_Item
1100      (Node    : Project_Node_Id;
1101       In_Tree : Project_Node_Tree_Ref;
1102       To      : Project_Node_Id);
1103    pragma Inline (Set_Next_Case_Item);
1104    --  Only valid for N_Case_Item nodes.
1105
1106    procedure Set_Case_Insensitive
1107      (Node    : Project_Node_Id;
1108       In_Tree : Project_Node_Tree_Ref;
1109       To      : Boolean);
1110    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
1111
1112    -------------------------------
1113    -- Restricted Access Section --
1114    -------------------------------
1115
1116    package Tree_Private_Part is
1117
1118       --  This is conceptually in the private part. However, for efficiency,
1119       --  some packages are accessing it directly.
1120
1121       type Project_Node_Record is record
1122
1123          Kind : Project_Node_Kind;
1124
1125          Qualifier : Project_Qualifier := Unspecified;
1126
1127          Location : Source_Ptr := No_Location;
1128
1129          Directory : Path_Name_Type := No_Path;
1130          --  Only for N_Project
1131
1132          Expr_Kind : Variable_Kind := Undefined;
1133          --  See below for what Project_Node_Kind it is used
1134
1135          Variables : Variable_Node_Id := Empty_Node;
1136          --  First variable in a project or a package
1137
1138          Packages : Package_Declaration_Id := Empty_Node;
1139          --  First package declaration in a project
1140
1141          Pkg_Id : Package_Node_Id := Empty_Package;
1142          --  Only used for N_Package_Declaration
1143          --
1144          --  The component Pkg_Id is an entry into the table Package_Attributes
1145          --  (in Prj.Attr). It is used to indicate all the attributes of the
1146          --  package with their characteristics.
1147          --
1148          --  The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes
1149          --  are built once and for all through a call (from Prj.Initialize)
1150          --  to procedure Prj.Attr.Initialize. It is never modified after that.
1151
1152          Name : Name_Id := No_Name;
1153          --  See below for what Project_Node_Kind it is used
1154
1155          Src_Index : Int := 0;
1156          --  Index of a unit in a multi-unit source.
1157          --  Only for some N_Attribute_Declaration and N_Literal_String.
1158
1159          Path_Name : Path_Name_Type := No_Path;
1160          --  See below for what Project_Node_Kind it is used
1161
1162          Value : Name_Id := No_Name;
1163          --  See below for what Project_Node_Kind it is used
1164
1165          Field1 : Project_Node_Id := Empty_Node;
1166          --  See below the meaning for each Project_Node_Kind
1167
1168          Field2 : Project_Node_Id := Empty_Node;
1169          --  See below the meaning for each Project_Node_Kind
1170
1171          Field3 : Project_Node_Id := Empty_Node;
1172          --  See below the meaning for each Project_Node_Kind
1173
1174          Field4 : Project_Node_Id := Empty_Node;
1175          --  See below the meaning for each Project_Node_Kind
1176
1177          Flag1 : Boolean := False;
1178          --  This flag is significant only for:
1179          --
1180          --    N_Attribute_Declaration and N_Attribute_Reference
1181          --      Indicates for an associative array attribute, that the
1182          --      index is case insensitive.
1183          --
1184          --    N_Comment
1185          --      Indicates that the comment is preceded by an empty line.
1186          --
1187          --    N_Project
1188          --      Indicates that there are comments in the project source that
1189          --      cannot be kept in the tree.
1190          --
1191          --    N_Project_Declaration
1192          --      Indicates that there are unkept comments in the project.
1193          --
1194          --    N_With_Clause
1195          --      Indicates that this is not the last with in a with clause.
1196          --      Set for "A", but not for "B" in with "B"; and with "A", "B";
1197
1198          Flag2 : Boolean := False;
1199          --  This flag is significant only for:
1200          --
1201          --    N_Project
1202          --      Indicates that the project "extends all" another project.
1203          --
1204          --    N_Comment
1205          --      Indicates that the comment is followed by an empty line.
1206          --
1207          --    N_With_Clause
1208          --      Indicates that the originally imported project is an extending
1209          --      all project.
1210
1211          Comments : Project_Node_Id := Empty_Node;
1212          --  For nodes other that N_Comment_Zones or N_Comment, designates the
1213          --  comment zones associated with the node.
1214          --
1215          --  For N_Comment_Zones, designates the comment after the "end" of
1216          --  the construct.
1217          --
1218          --  For N_Comment, designates the next comment, if any.
1219
1220       end record;
1221
1222       --  type Project_Node_Kind is
1223
1224       --   (N_Project,
1225       --    --  Name:      project name
1226       --    --  Path_Name: project path name
1227       --    --  Expr_Kind: Undefined
1228       --    --  Field1:    first with clause
1229       --    --  Field2:    project declaration
1230       --    --  Field3:    first string type
1231       --    --  Field4:    parent project, if any
1232       --    --  Value:     extended project path name (if any)
1233
1234       --    N_With_Clause,
1235       --    --  Name:      imported project name
1236       --    --  Path_Name: imported project path name
1237       --    --  Expr_Kind: Undefined
1238       --    --  Field1:    project node
1239       --    --  Field2:    next with clause
1240       --    --  Field3:    project node or empty if "limited with"
1241       --    --  Field4:    not used
1242       --    --  Value:     literal string withed
1243
1244       --    N_Project_Declaration,
1245       --    --  Name:      not used
1246       --    --  Path_Name: not used
1247       --    --  Expr_Kind: Undefined
1248       --    --  Field1:    first declarative item
1249       --    --  Field2:    extended project
1250       --    --  Field3:    extending project
1251       --    --  Field4:    not used
1252       --    --  Value:     not used
1253
1254       --    N_Declarative_Item,
1255       --    --  Name:      not used
1256       --    --  Path_Name: not used
1257       --    --  Expr_Kind: Undefined
1258       --    --  Field1:    current item node
1259       --    --  Field2:    next declarative item
1260       --    --  Field3:    not used
1261       --    --  Field4:    not used
1262       --    --  Value:     not used
1263
1264       --    N_Package_Declaration,
1265       --    --  Name:      package name
1266       --    --  Path_Name: not used
1267       --    --  Expr_Kind: Undefined
1268       --    --  Field1:    project of renamed package (if any)
1269       --    --  Field2:    first declarative item
1270       --    --  Field3:    next package in project
1271       --    --  Field4:    not used
1272       --    --  Value:     not used
1273
1274       --    N_String_Type_Declaration,
1275       --    --  Name:      type name
1276       --    --  Path_Name: not used
1277       --    --  Expr_Kind: Undefined
1278       --    --  Field1:    first literal string
1279       --    --  Field2:    next string type
1280       --    --  Field3:    not used
1281       --    --  Field4:    not used
1282       --    --  Value:     not used
1283
1284       --    N_Literal_String,
1285       --    --  Name:      not used
1286       --    --  Path_Name: not used
1287       --    --  Expr_Kind: Single
1288       --    --  Field1:    next literal string
1289       --    --  Field2:    not used
1290       --    --  Field3:    not used
1291       --    --  Field4:    not used
1292       --    --  Value:     string value
1293
1294       --    N_Attribute_Declaration,
1295       --    --  Name:      attribute name
1296       --    --  Path_Name: not used
1297       --    --  Expr_Kind: attribute kind
1298       --    --  Field1:    expression
1299       --    --  Field2:    project of full associative array
1300       --    --  Field3:    package of full associative array
1301       --    --  Field4:    not used
1302       --    --  Value:     associative array index
1303       --    --             (if an associative array element)
1304
1305       --    N_Typed_Variable_Declaration,
1306       --    --  Name:      variable name
1307       --    --  Path_Name: not used
1308       --    --  Expr_Kind: Single
1309       --    --  Field1:    expression
1310       --    --  Field2:    type of variable (N_String_Type_Declaration)
1311       --    --  Field3:    next variable
1312       --    --  Field4:    not used
1313       --    --  Value:     not used
1314
1315       --    N_Variable_Declaration,
1316       --    --  Name:      variable name
1317       --    --  Path_Name: not used
1318       --    --  Expr_Kind: variable kind
1319       --    --  Field1:    expression
1320       --    --  Field2:    not used
1321       --    --             Field3 is used for next variable, instead of Field2,
1322       --    --             so that it is the same field for
1323       --    --             N_Variable_Declaration and
1324       --    --             N_Typed_Variable_Declaration
1325       --    --  Field3:    next variable
1326       --    --  Field4:    not used
1327       --    --  Value:     not used
1328
1329       --    N_Expression,
1330       --    --  Name:      not used
1331       --    --  Path_Name: not used
1332       --    --  Expr_Kind: expression kind
1333       --    --  Field1:    first term
1334       --    --  Field2:    next expression in list
1335       --    --  Field3:    not used
1336       --    --  Value:     not used
1337
1338       --    N_Term,
1339       --    --  Name:      not used
1340       --    --  Path_Name: not used
1341       --    --  Expr_Kind: term kind
1342       --    --  Field1:    current term
1343       --    --  Field2:    next term in the expression
1344       --    --  Field3:    not used
1345       --    --  Field4:    not used
1346       --    --  Value:     not used
1347
1348       --    N_Literal_String_List,
1349       --    --  Designates a list of string expressions between brackets
1350       --    --  separated by commas. The string expressions are not necessarily
1351       --    --  literal strings.
1352       --    --  Name:      not used
1353       --    --  Path_Name: not used
1354       --    --  Expr_Kind: List
1355       --    --  Field1:    first expression
1356       --    --  Field2:    not used
1357       --    --  Field3:    not used
1358       --    --  Field4:    not used
1359       --    --  Value:     not used
1360
1361       --    N_Variable_Reference,
1362       --    --  Name:      variable name
1363       --    --  Path_Name: not used
1364       --    --  Expr_Kind: variable kind
1365       --    --  Field1:    project (if specified)
1366       --    --  Field2:    package (if specified)
1367       --    --  Field3:    type of variable (N_String_Type_Declaration), if any
1368       --    --  Field4:    not used
1369       --    --  Value:     not used
1370
1371       --    N_External_Value,
1372       --    --  Name:      not used
1373       --    --  Path_Name: not used
1374       --    --  Expr_Kind: Single
1375       --    --  Field1:    Name of the external reference (literal string)
1376       --    --  Field2:    Default (literal string)
1377       --    --  Field3:    not used
1378       --    --  Value:     not used
1379
1380       --    N_Attribute_Reference,
1381       --    --  Name:      attribute name
1382       --    --  Path_Name: not used
1383       --    --  Expr_Kind: attribute kind
1384       --    --  Field1:    project
1385       --    --  Field2:    package (if attribute of a package)
1386       --    --  Field3:    not used
1387       --    --  Field4:    not used
1388       --    --  Value:     associative array index
1389       --    --             (if an associative array element)
1390
1391       --    N_Case_Construction,
1392       --    --  Name:      not used
1393       --    --  Path_Name: not used
1394       --    --  Expr_Kind: Undefined
1395       --    --  Field1:    case variable reference
1396       --    --  Field2:    first case item
1397       --    --  Field3:    not used
1398       --    --  Field4:    not used
1399       --    --  Value:     not used
1400
1401       --    N_Case_Item
1402       --    --  Name:      not used
1403       --    --  Path_Name: not used
1404       --    --  Expr_Kind: not used
1405       --    --  Field1:    first choice (literal string), or Empty_Node
1406       --    --             for when others
1407       --    --  Field2:    first declarative item
1408       --    --  Field3:    next case item
1409       --    --  Field4:    not used
1410       --    --  Value:     not used
1411
1412       --    N_Comment_zones
1413       --    --  Name:      not used
1414       --    --  Path_Name: not used
1415       --    --  Expr_Kind: not used
1416       --    --  Field1:    comment before the construct
1417       --    --  Field2:    comment after the construct
1418       --    --  Field3:    comment before the "end" of the construct
1419       --    --  Value:     end of line comment
1420       --    --  Field4:    not used
1421       --    --  Comments:  comment after the "end" of the construct
1422
1423       --    N_Comment
1424       --    --  Name:      not used
1425       --    --  Path_Name: not used
1426       --    --  Expr_Kind: not used
1427       --    --  Field1:    not used
1428       --    --  Field2:    not used
1429       --    --  Field3:    not used
1430       --    --  Field4:    not used
1431       --    --  Value:     comment
1432       --    --  Flag1:     comment is preceded by an empty line
1433       --    --  Flag2:     comment is followed by an empty line
1434       --    --  Comments:  next comment
1435
1436       package Project_Node_Table is new
1437         GNAT.Dynamic_Tables
1438           (Table_Component_Type => Project_Node_Record,
1439            Table_Index_Type     => Project_Node_Id,
1440            Table_Low_Bound      => First_Node_Id,
1441            Table_Initial        => Project_Nodes_Initial,
1442            Table_Increment      => Project_Nodes_Increment);
1443       --  Table contains the syntactic tree of project data from project files
1444
1445       type Project_Name_And_Node is record
1446          Name : Name_Id;
1447          --  Name of the project
1448
1449          Display_Name : Name_Id;
1450          --  The name of the project as it appears in the .gpr file
1451
1452          Node : Project_Node_Id;
1453          --  Node of the project in table Project_Nodes
1454
1455          Canonical_Path : Path_Name_Type;
1456          --  Resolved and canonical path of a real project file.
1457          --  No_Name in case of virtual projects.
1458
1459          Extended : Boolean;
1460          --  True when the project is being extended by another project
1461
1462          Proj_Qualifier : Project_Qualifier;
1463          --  The project qualifier of the project, if any
1464       end record;
1465
1466       No_Project_Name_And_Node : constant Project_Name_And_Node :=
1467         (Name           => No_Name,
1468          Display_Name   => No_Name,
1469          Node           => Empty_Node,
1470          Canonical_Path => No_Path,
1471          Extended       => True,
1472          Proj_Qualifier => Unspecified);
1473
1474       package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable
1475         (Header_Num => Header_Num,
1476          Element    => Project_Name_And_Node,
1477          No_Element => No_Project_Name_And_Node,
1478          Key        => Name_Id,
1479          Hash       => Hash,
1480          Equal      => "=");
1481       --  This hash table contains a mapping of project names to project nodes.
1482       --  Note that this hash table contains only the nodes whose Kind is
1483       --  N_Project. It is used to find the node of a project from its name,
1484       --  and to verify if a project has already been parsed, knowing its name.
1485
1486    end Tree_Private_Part;
1487
1488    type Project_Node_Tree_Data is record
1489       Project_Nodes : Tree_Private_Part.Project_Node_Table.Instance;
1490       Projects_HT   : Tree_Private_Part.Projects_Htable.Instance;
1491    end record;
1492
1493    procedure Free (Proj : in out Project_Node_Tree_Ref;
1494                    Env : in out Environment);
1495    --  Free memory used by Prj
1496
1497 private
1498    type Comment_Array is array (Positive range <>) of Comment_Data;
1499    type Comments_Ptr is access Comment_Array;
1500
1501    type Comment_State is record
1502       End_Of_Line_Node   : Project_Node_Id := Empty_Node;
1503       Previous_Line_Node : Project_Node_Id := Empty_Node;
1504       Previous_End_Node  : Project_Node_Id := Empty_Node;
1505       Unkept_Comments    : Boolean := False;
1506       Comments           : Comments_Ptr := null;
1507    end record;
1508
1509 end Prj.Tree;