OSDN Git Service

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