OSDN Git Service

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