OSDN Git Service

* make.adb (Check_Mains, Switches_Of): Adapt to name changes in
[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-2004 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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This package defines the structure of the Project File tree
28
29 with GNAT.HTable;
30
31 with Prj.Attr; use Prj.Attr;
32 with Table;    use Table;
33 with Types;    use Types;
34
35 package Prj.Tree is
36
37    Project_Nodes_Initial   : constant := 1_000;
38    Project_Nodes_Increment : constant := 100;
39    --  Allocation parameters for initializing and extending number
40    --  of nodes in table Tree_Private_Part.Project_Nodes
41
42    Project_Node_Low_Bound  : constant := 0;
43    Project_Node_High_Bound : constant := 099_999_999;
44    --  Range of values for project node id's (in practice infinite)
45
46    type Project_Node_Id is range
47      Project_Node_Low_Bound .. Project_Node_High_Bound;
48    --  The index of table Tree_Private_Part.Project_Nodes
49
50    Empty_Node : constant Project_Node_Id := Project_Node_Low_Bound;
51    --  Designates no node in table Project_Nodes
52
53    First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound + 1;
54
55    subtype Variable_Node_Id is Project_Node_Id;
56    --  Used to designate a node whose expected kind is one of
57    --  N_Typed_Variable_Declaration, N_Variable_Declaration or
58    --  N_Variable_Reference.
59
60    subtype Package_Declaration_Id is Project_Node_Id;
61    --  Used to designate a node whose expected kind is N_Proect_Declaration
62
63    type Project_Node_Kind is
64      (N_Project,
65       N_With_Clause,
66       N_Project_Declaration,
67       N_Declarative_Item,
68       N_Package_Declaration,
69       N_String_Type_Declaration,
70       N_Literal_String,
71       N_Attribute_Declaration,
72       N_Typed_Variable_Declaration,
73       N_Variable_Declaration,
74       N_Expression,
75       N_Term,
76       N_Literal_String_List,
77       N_Variable_Reference,
78       N_External_Value,
79       N_Attribute_Reference,
80       N_Case_Construction,
81       N_Case_Item,
82       N_Comment_Zones,
83       N_Comment);
84    --  Each node in the tree is of a Project_Node_Kind
85    --  For the signification of the fields in each node of a
86    --  Project_Node_Kind, look at package Tree_Private_Part.
87
88    procedure Initialize;
89    --  Initialize the Project File tree: empty the Project_Nodes table
90    --  and reset the Projects_Htable.
91
92    function Default_Project_Node
93      (Of_Kind       : Project_Node_Kind;
94       And_Expr_Kind : Variable_Kind := Undefined) return Project_Node_Id;
95    --  Returns a Project_Node_Record with the specified Kind and
96    --  Expr_Kind; all the other components have default nil values.
97
98    function Hash (N : Project_Node_Id) return Header_Num;
99    --  Used for hash tables where the key is a Project_Node_Id
100
101    function Imported_Or_Extended_Project_Of
102      (Project   : Project_Node_Id;
103       With_Name : Name_Id) return Project_Node_Id;
104    --  Return the node of a project imported or extended by project Project and
105    --  whose name is With_Name. Return Empty_Node if there is no such project.
106
107    --------------
108    -- Comments --
109    --------------
110
111    type Comment_State is private;
112    --  A type to store the values of several global variables related to
113    --  comments.
114
115    procedure Save (S : out Comment_State);
116    --  Save in variable S the comment state. Called before scanning a new
117    --  project file.
118
119    procedure Restore (S : in Comment_State);
120    --  Restore the comment state to a previously saved value. Called after
121    --  scanning a project file.
122
123    procedure Reset_State;
124    --  Set the comment state to its initial value. Called before scanning a
125    --  new project file.
126
127    function There_Are_Unkept_Comments return Boolean;
128    --  Indicates that some of the comments in a project file could not be
129    --  stored in the parse tree.
130
131    procedure Set_Previous_Line_Node (To : Project_Node_Id);
132    --  Indicate the node on the previous line. If there are comments
133    --  immediately following this line, then they should be associated with
134    --  this node.
135
136    procedure Set_Previous_End_Node (To : Project_Node_Id);
137    --  Indicate that on the previous line the "end" belongs to node To.
138    --  If there are comments immediately following this "end" line, they
139    --  should be associated with this node.
140
141    procedure Set_End_Of_Line (To : Project_Node_Id);
142    --  Indicate the node on the current line. If there is an end of line
143    --  comment, then it should be associated with this node.
144
145    procedure Set_Next_End_Node (To : Project_Node_Id);
146    --  Put node To on the top of the end node stack. When an "end" line
147    --  is found with this node on the top of the end node stack, the comments,
148    --  if any, immediately preceding this "end" line will be associated with
149    --  this node.
150
151    procedure Remove_Next_End_Node;
152    --  Remove the top of the end node stack
153
154    ------------------------
155    -- Comment Processing --
156    ------------------------
157
158    type Comment_Data is record
159       Value                     : Name_Id := No_Name;
160       Follows_Empty_Line        : Boolean := False;
161       Is_Followed_By_Empty_Line : Boolean := False;
162    end record;
163
164    package Comments is new Table.Table
165      (Table_Component_Type => Comment_Data,
166       Table_Index_Type     => Natural,
167       Table_Low_Bound      => 1,
168       Table_Initial        => 10,
169       Table_Increment      => 100,
170       Table_Name           => "Prj.Tree.Comments");
171    --  A table to store the comments that may be stored is the tree
172
173    procedure Scan;
174    --  Scan the tokens and accumulate comments
175
176    type Comment_Location is
177      (Before, After, Before_End, After_End, End_Of_Line);
178
179    procedure Add_Comments (To : Project_Node_Id; Where : Comment_Location);
180    --  Add comments to this node
181
182    ----------------------
183    -- Access Functions --
184    ----------------------
185
186    --  The following query functions are part of the abstract interface
187    --  of the Project File tree
188
189    function Name_Of (Node : Project_Node_Id) return Name_Id;
190    pragma Inline (Name_Of);
191    --  Valid for all non empty nodes. May return No_Name for nodes that have
192    --  no names.
193
194    function Kind_Of (Node : Project_Node_Id) return Project_Node_Kind;
195    pragma Inline (Kind_Of);
196    --  Valid for all non empty nodes
197
198    function Location_Of (Node : Project_Node_Id) return Source_Ptr;
199    pragma Inline (Location_Of);
200    --  Valid for all non empty nodes
201
202    function First_Comment_After
203      (Node : Project_Node_Id) return Project_Node_Id;
204    --  Valid only for N_Comment_Zones nodes
205
206    function First_Comment_After_End
207      (Node : Project_Node_Id) return Project_Node_Id;
208    --  Valid only for N_Comment_Zones nodes
209
210    function First_Comment_Before
211      (Node : Project_Node_Id) return Project_Node_Id;
212    --  Valid only for N_Comment_Zones nodes
213
214    function First_Comment_Before_End
215      (Node : Project_Node_Id) return Project_Node_Id;
216    --  Valid only for N_Comment_Zones nodes
217
218    function Next_Comment (Node : Project_Node_Id) return Project_Node_Id;
219    --  Valid only for N_Comment nodes
220
221    function End_Of_Line_Comment (Node : Project_Node_Id) return Name_Id;
222    --  Valid only for non empty nodes
223
224    function Follows_Empty_Line (Node : Project_Node_Id) return Boolean;
225    --  Valid only for N_Comment nodes
226
227    function Is_Followed_By_Empty_Line (Node : Project_Node_Id) return Boolean;
228    --  Valid only for N_Comment nodes
229
230    function Project_File_Includes_Unkept_Comments
231      (Node : Project_Node_Id)
232       return Boolean;
233    --  Valid only for N_Project nodes
234
235    function Directory_Of (Node : Project_Node_Id) return Name_Id;
236    pragma Inline (Directory_Of);
237    --  Only valid for N_Project nodes
238
239    function Expression_Kind_Of (Node : Project_Node_Id) return Variable_Kind;
240    pragma Inline (Expression_Kind_Of);
241    --  Only valid for N_Literal_String, N_Attribute_Declaration,
242    --  N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
243    --  N_Term, N_Variable_Reference or N_Attribute_Reference nodes.
244
245    function Is_Extending_All (Node  : Project_Node_Id) return Boolean;
246    pragma Inline (Is_Extending_All);
247    --  Only valid for N_Project and N_With_Clause
248
249    function First_Variable_Of
250      (Node : Project_Node_Id) return Variable_Node_Id;
251    pragma Inline (First_Variable_Of);
252    --  Only valid for N_Project or N_Package_Declaration nodes
253
254    function First_Package_Of
255      (Node : Project_Node_Id) return Package_Declaration_Id;
256    pragma Inline (First_Package_Of);
257    --  Only valid for N_Project nodes
258
259    function Package_Id_Of (Node  : Project_Node_Id) return Package_Node_Id;
260    pragma Inline (Package_Id_Of);
261    --  Only valid for N_Package_Declaration nodes
262
263    function Path_Name_Of (Node : Project_Node_Id) return Name_Id;
264    pragma Inline (Path_Name_Of);
265    --  Only valid for N_Project and N_With_Clause nodes
266
267    function String_Value_Of (Node : Project_Node_Id) return Name_Id;
268    pragma Inline (String_Value_Of);
269    --  Only valid for N_With_Clause, N_Literal_String nodes or N_Comment
270
271    function Source_Index_Of (Node : Project_Node_Id) return Int;
272    pragma Inline (Source_Index_Of);
273    --  Only valid for N_Literal_String and N_Attribute_Declaration nodes
274
275    function First_With_Clause_Of
276      (Node : Project_Node_Id) return Project_Node_Id;
277    pragma Inline (First_With_Clause_Of);
278    --  Only valid for N_Project nodes
279
280    function Project_Declaration_Of
281      (Node : Project_Node_Id) return Project_Node_Id;
282    pragma Inline (Project_Declaration_Of);
283    --  Only valid for N_Project nodes
284
285    function Extending_Project_Of
286      (Node : Project_Node_Id) return Project_Node_Id;
287    pragma Inline (Extending_Project_Of);
288    --  Only valid for N_Project_Declaration nodes
289
290    function First_String_Type_Of
291      (Node : Project_Node_Id) return Project_Node_Id;
292    pragma Inline (First_String_Type_Of);
293    --  Only valid for N_Project nodes
294
295    function Extended_Project_Path_Of
296      (Node : Project_Node_Id) return Name_Id;
297    pragma Inline (Extended_Project_Path_Of);
298    --  Only valid for N_With_Clause nodes
299
300    function Project_Node_Of
301      (Node : Project_Node_Id) return Project_Node_Id;
302    pragma Inline (Project_Node_Of);
303    --  Only valid for N_With_Clause, N_Variable_Reference and
304    --  N_Attribute_Reference nodes.
305
306    function Non_Limited_Project_Node_Of
307      (Node : Project_Node_Id) return Project_Node_Id;
308    pragma Inline (Non_Limited_Project_Node_Of);
309    --  Only valid for N_With_Clause nodes. Returns Empty_Node for limited
310    --  imported project files, otherwise returns the same result as
311    --  Project_Node_Of.
312
313    function Next_With_Clause_Of
314      (Node : Project_Node_Id) return Project_Node_Id;
315    pragma Inline (Next_With_Clause_Of);
316    --  Only valid for N_With_Clause nodes
317
318    function First_Declarative_Item_Of
319      (Node : Project_Node_Id) return Project_Node_Id;
320    pragma Inline (First_Declarative_Item_Of);
321    --  Only valid for N_With_Clause nodes
322
323    function Extended_Project_Of
324      (Node : Project_Node_Id) return Project_Node_Id;
325    pragma Inline (Extended_Project_Of);
326    --  Only valid for N_Project_Declaration nodes
327
328    function Current_Item_Node
329      (Node : Project_Node_Id) return Project_Node_Id;
330    pragma Inline (Current_Item_Node);
331    --  Only valid for N_Declarative_Item nodes
332
333    function Next_Declarative_Item
334      (Node : Project_Node_Id) return Project_Node_Id;
335    pragma Inline (Next_Declarative_Item);
336    --  Only valid for N_Declarative_Item node
337
338    function Project_Of_Renamed_Package_Of
339      (Node : Project_Node_Id) return Project_Node_Id;
340    pragma Inline (Project_Of_Renamed_Package_Of);
341    --  Only valid for N_Package_Declaration nodes.
342    --  May return Empty_Node.
343
344    function Next_Package_In_Project
345      (Node : Project_Node_Id) return Project_Node_Id;
346    pragma Inline (Next_Package_In_Project);
347    --  Only valid for N_Package_Declaration nodes
348
349    function First_Literal_String
350      (Node : Project_Node_Id) return Project_Node_Id;
351    pragma Inline (First_Literal_String);
352    --  Only valid for N_String_Type_Declaration nodes
353
354    function Next_String_Type
355      (Node : Project_Node_Id) return Project_Node_Id;
356    pragma Inline (Next_String_Type);
357    --  Only valid for N_String_Type_Declaration nodes
358
359    function Next_Literal_String
360      (Node : Project_Node_Id) return Project_Node_Id;
361    pragma Inline (Next_Literal_String);
362    --  Only valid for N_Literal_String nodes
363
364    function Expression_Of
365      (Node : Project_Node_Id) return Project_Node_Id;
366    pragma Inline (Expression_Of);
367    --  Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
368    --  or N_Variable_Declaration nodes
369
370    function Associative_Project_Of
371      (Node  : Project_Node_Id)
372       return  Project_Node_Id;
373    pragma Inline (Associative_Project_Of);
374    --  Only valid for N_Attribute_Declaration nodes
375
376    function Associative_Package_Of
377      (Node  : Project_Node_Id)
378       return  Project_Node_Id;
379    pragma Inline (Associative_Package_Of);
380    --  Only valid for N_Attribute_Declaration nodes
381
382    function Value_Is_Valid
383      (For_Typed_Variable : Project_Node_Id;
384       Value              : Name_Id) return Boolean;
385    pragma Inline (Value_Is_Valid);
386    --  Only valid for N_Typed_Variable_Declaration. Returns True if Value is
387    --  in the list of allowed strings for For_Typed_Variable. False otherwise.
388
389    function Associative_Array_Index_Of
390      (Node : Project_Node_Id) return Name_Id;
391    pragma Inline (Associative_Array_Index_Of);
392    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference.
393    --  Returns No_String for non associative array attributes.
394
395    function Next_Variable
396      (Node : Project_Node_Id) return Project_Node_Id;
397    pragma Inline (Next_Variable);
398    --  Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
399    --  nodes.
400
401    function First_Term
402      (Node : Project_Node_Id) return Project_Node_Id;
403    pragma Inline (First_Term);
404    --  Only valid for N_Expression nodes
405
406    function Next_Expression_In_List
407      (Node : Project_Node_Id) return Project_Node_Id;
408    pragma Inline (Next_Expression_In_List);
409    --  Only valid for N_Expression nodes
410
411    function Current_Term
412      (Node : Project_Node_Id) return Project_Node_Id;
413    pragma Inline (Current_Term);
414    --  Only valid for N_Term nodes
415
416    function Next_Term
417      (Node : Project_Node_Id) return Project_Node_Id;
418    pragma Inline (Next_Term);
419    --  Only valid for N_Term nodes
420
421    function First_Expression_In_List
422      (Node : Project_Node_Id) return Project_Node_Id;
423    pragma Inline (First_Expression_In_List);
424    --  Only valid for N_Literal_String_List nodes
425
426    function Package_Node_Of
427      (Node : Project_Node_Id) return Project_Node_Id;
428    pragma Inline (Package_Node_Of);
429    --  Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
430    --  May return Empty_Node.
431
432    function String_Type_Of
433      (Node : Project_Node_Id) return Project_Node_Id;
434    pragma Inline (String_Type_Of);
435    --  Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
436    --  nodes.
437
438    function External_Reference_Of
439      (Node : Project_Node_Id) return Project_Node_Id;
440    pragma Inline (External_Reference_Of);
441    --  Only valid for N_External_Value nodes
442
443    function External_Default_Of
444      (Node : Project_Node_Id) return Project_Node_Id;
445    pragma Inline (External_Default_Of);
446    --  Only valid for N_External_Value nodes
447
448    function Case_Variable_Reference_Of
449      (Node : Project_Node_Id) return Project_Node_Id;
450    pragma Inline (Case_Variable_Reference_Of);
451    --  Only valid for N_Case_Construction nodes
452
453    function First_Case_Item_Of
454      (Node : Project_Node_Id) return Project_Node_Id;
455    pragma Inline (First_Case_Item_Of);
456    --  Only valid for N_Case_Construction nodes
457
458    function First_Choice_Of
459      (Node : Project_Node_Id) return Project_Node_Id;
460    pragma Inline (First_Choice_Of);
461    --  Return the first choice in a N_Case_Item, or Empty_Node if
462    --  this is when others.
463
464    function Next_Case_Item
465      (Node : Project_Node_Id) return Project_Node_Id;
466    pragma Inline (Next_Case_Item);
467    --  Only valid for N_Case_Item nodes
468
469    function Case_Insensitive (Node : Project_Node_Id) return Boolean;
470    --  Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
471
472    --------------------
473    -- Set Procedures --
474    --------------------
475
476    --  The following procedures are part of the abstract interface of
477    --  the Project File tree.
478
479    --  Each Set_* procedure is valid only for the same Project_Node_Kind
480    --  nodes as the corresponding query function above.
481
482    procedure Set_Name_Of
483      (Node : Project_Node_Id;
484       To   : Name_Id);
485    pragma Inline (Set_Name_Of);
486
487    procedure Set_Kind_Of
488      (Node : Project_Node_Id;
489       To   : Project_Node_Kind);
490    pragma Inline (Set_Kind_Of);
491
492    procedure Set_Location_Of
493      (Node : Project_Node_Id;
494       To   : Source_Ptr);
495    pragma Inline (Set_Location_Of);
496
497    procedure Set_First_Comment_After
498      (Node : Project_Node_Id;
499       To   : Project_Node_Id);
500    pragma Inline (Set_First_Comment_After);
501
502    procedure Set_First_Comment_After_End
503      (Node : Project_Node_Id;
504       To   : Project_Node_Id);
505    pragma Inline (Set_First_Comment_After_End);
506
507    procedure Set_First_Comment_Before
508      (Node : Project_Node_Id;
509       To   : Project_Node_Id);
510    pragma Inline (Set_First_Comment_Before);
511
512    procedure Set_First_Comment_Before_End
513      (Node : Project_Node_Id;
514       To   : Project_Node_Id);
515    pragma Inline (Set_First_Comment_Before_End);
516
517    procedure Set_Next_Comment
518      (Node : Project_Node_Id;
519       To   : Project_Node_Id);
520    pragma Inline (Set_Next_Comment);
521
522    procedure Set_Project_File_Includes_Unkept_Comments
523      (Node : Project_Node_Id;
524       To   : Boolean);
525
526    procedure Set_Directory_Of
527      (Node : Project_Node_Id;
528       To   : Name_Id);
529    pragma Inline (Set_Directory_Of);
530
531    procedure Set_Expression_Kind_Of
532      (Node : Project_Node_Id;
533       To   : Variable_Kind);
534    pragma Inline (Set_Expression_Kind_Of);
535
536    procedure Set_Is_Extending_All (Node  : Project_Node_Id);
537    pragma Inline (Set_Is_Extending_All);
538
539    procedure Set_First_Variable_Of
540      (Node : Project_Node_Id;
541       To   : Variable_Node_Id);
542    pragma Inline (Set_First_Variable_Of);
543
544    procedure Set_First_Package_Of
545      (Node : Project_Node_Id;
546       To   : Package_Declaration_Id);
547    pragma Inline (Set_First_Package_Of);
548
549    procedure Set_Package_Id_Of
550      (Node : Project_Node_Id;
551       To   : Package_Node_Id);
552    pragma Inline (Set_Package_Id_Of);
553
554    procedure Set_Path_Name_Of
555      (Node : Project_Node_Id;
556       To   : Name_Id);
557    pragma Inline (Set_Path_Name_Of);
558
559    procedure Set_String_Value_Of
560      (Node : Project_Node_Id;
561       To   : Name_Id);
562    pragma Inline (Set_String_Value_Of);
563
564    procedure Set_First_With_Clause_Of
565      (Node : Project_Node_Id;
566       To   : Project_Node_Id);
567    pragma Inline (Set_First_With_Clause_Of);
568
569    procedure Set_Project_Declaration_Of
570      (Node : Project_Node_Id;
571       To   : Project_Node_Id);
572    pragma Inline (Set_Project_Declaration_Of);
573
574    procedure Set_Extending_Project_Of
575      (Node : Project_Node_Id;
576       To   : Project_Node_Id);
577    pragma Inline (Set_Extending_Project_Of);
578
579    procedure Set_First_String_Type_Of
580      (Node : Project_Node_Id;
581       To   : Project_Node_Id);
582    pragma Inline (Set_First_String_Type_Of);
583
584    procedure Set_Extended_Project_Path_Of
585      (Node : Project_Node_Id;
586       To   : Name_Id);
587    pragma Inline (Set_Extended_Project_Path_Of);
588
589    procedure Set_Project_Node_Of
590      (Node         : Project_Node_Id;
591       To           : Project_Node_Id;
592       Limited_With : Boolean := False);
593    pragma Inline (Set_Project_Node_Of);
594
595    procedure Set_Next_With_Clause_Of
596      (Node : Project_Node_Id;
597       To   : Project_Node_Id);
598    pragma Inline (Set_Next_With_Clause_Of);
599
600    procedure Set_First_Declarative_Item_Of
601      (Node : Project_Node_Id;
602       To   : Project_Node_Id);
603    pragma Inline (Set_First_Declarative_Item_Of);
604
605    procedure Set_Extended_Project_Of
606      (Node : Project_Node_Id;
607       To   : Project_Node_Id);
608    pragma Inline (Set_Extended_Project_Of);
609
610    procedure Set_Current_Item_Node
611      (Node : Project_Node_Id;
612       To   : Project_Node_Id);
613    pragma Inline (Set_Current_Item_Node);
614
615    procedure Set_Next_Declarative_Item
616      (Node : Project_Node_Id;
617       To   : Project_Node_Id);
618    pragma Inline (Set_Next_Declarative_Item);
619
620    procedure Set_Project_Of_Renamed_Package_Of
621      (Node : Project_Node_Id;
622       To   : Project_Node_Id);
623    pragma Inline (Set_Project_Of_Renamed_Package_Of);
624
625    procedure Set_Next_Package_In_Project
626      (Node : Project_Node_Id;
627       To   : Project_Node_Id);
628    pragma Inline (Set_Next_Package_In_Project);
629
630    procedure Set_First_Literal_String
631      (Node : Project_Node_Id;
632       To   : Project_Node_Id);
633    pragma Inline (Set_First_Literal_String);
634
635    procedure Set_Next_String_Type
636      (Node : Project_Node_Id;
637       To   : Project_Node_Id);
638    pragma Inline (Set_Next_String_Type);
639
640    procedure Set_Next_Literal_String
641      (Node : Project_Node_Id;
642       To   : Project_Node_Id);
643    pragma Inline (Set_Next_Literal_String);
644
645    procedure Set_Expression_Of
646      (Node : Project_Node_Id;
647       To   : Project_Node_Id);
648    pragma Inline (Set_Expression_Of);
649
650    procedure Set_Associative_Project_Of
651      (Node : Project_Node_Id;
652       To   : Project_Node_Id);
653    pragma Inline (Set_Associative_Project_Of);
654
655    procedure Set_Associative_Package_Of
656      (Node : Project_Node_Id;
657       To   : Project_Node_Id);
658    pragma Inline (Set_Associative_Package_Of);
659
660    procedure Set_Associative_Array_Index_Of
661      (Node : Project_Node_Id;
662       To   : Name_Id);
663    pragma Inline (Set_Associative_Array_Index_Of);
664
665    procedure Set_Next_Variable
666      (Node : Project_Node_Id;
667       To   : Project_Node_Id);
668    pragma Inline (Set_Next_Variable);
669
670    procedure Set_First_Term
671      (Node : Project_Node_Id;
672       To   : Project_Node_Id);
673    pragma Inline (Set_First_Term);
674
675    procedure Set_Next_Expression_In_List
676      (Node : Project_Node_Id;
677       To   : Project_Node_Id);
678    pragma Inline (Set_Next_Expression_In_List);
679
680    procedure Set_Current_Term
681      (Node : Project_Node_Id;
682       To   : Project_Node_Id);
683    pragma Inline (Set_Current_Term);
684
685    procedure Set_Next_Term
686      (Node : Project_Node_Id;
687       To   : Project_Node_Id);
688    pragma Inline (Set_Next_Term);
689
690    procedure Set_First_Expression_In_List
691      (Node : Project_Node_Id;
692       To   : Project_Node_Id);
693    pragma Inline (Set_First_Expression_In_List);
694
695    procedure Set_Package_Node_Of
696      (Node : Project_Node_Id;
697       To   : Project_Node_Id);
698    pragma Inline (Set_Package_Node_Of);
699
700    procedure Set_Source_Index_Of
701      (Node : Project_Node_Id;
702       To   : Int);
703    pragma Inline (Set_Source_Index_Of);
704
705    procedure Set_String_Type_Of
706      (Node : Project_Node_Id;
707       To   : Project_Node_Id);
708    pragma Inline (Set_String_Type_Of);
709
710    procedure Set_External_Reference_Of
711      (Node : Project_Node_Id;
712       To   : Project_Node_Id);
713    pragma Inline (Set_External_Reference_Of);
714
715    procedure Set_External_Default_Of
716      (Node : Project_Node_Id;
717       To   : Project_Node_Id);
718    pragma Inline (Set_External_Default_Of);
719
720    procedure Set_Case_Variable_Reference_Of
721      (Node : Project_Node_Id;
722       To   : Project_Node_Id);
723    pragma Inline (Set_Case_Variable_Reference_Of);
724
725    procedure Set_First_Case_Item_Of
726      (Node : Project_Node_Id;
727       To   : Project_Node_Id);
728    pragma Inline (Set_First_Case_Item_Of);
729
730    procedure Set_First_Choice_Of
731      (Node : Project_Node_Id;
732       To   : Project_Node_Id);
733    pragma Inline (Set_First_Choice_Of);
734
735    procedure Set_Next_Case_Item
736      (Node : Project_Node_Id;
737       To   : Project_Node_Id);
738    pragma Inline (Set_Next_Case_Item);
739
740    procedure Set_Case_Insensitive
741      (Node : Project_Node_Id;
742       To   : Boolean);
743
744    -------------------------------
745    -- Restricted Access Section --
746    -------------------------------
747
748    package Tree_Private_Part is
749
750       --  This is conceptually in the private part.
751       --  However, for efficiency, some packages are accessing it directly.
752
753       type Project_Node_Record is record
754
755          Kind : Project_Node_Kind;
756
757          Location : Source_Ptr := No_Location;
758
759          Directory : Name_Id       := No_Name;
760          --  Only for N_Project
761
762          Expr_Kind : Variable_Kind := Undefined;
763          --  See below for what Project_Node_Kind it is used
764
765          Variables : Variable_Node_Id := Empty_Node;
766          --  First variable in a project or a package
767
768          Packages : Package_Declaration_Id := Empty_Node;
769          --  First package declaration in a project
770
771          Pkg_Id : Package_Node_Id := Empty_Package;
772          --  Only used for N_Package_Declaration
773          --  The component Pkg_Id is an entry into the table Package_Attributes
774          --  (in Prj.Attr). It is used to indicate all the attributes of the
775          --  package with their characteristics.
776          --
777          --  The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes
778          --  are built once and for all through a call (from Prj.Initialize)
779          --  to procedure Prj.Attr.Initialize. It is never modified after that.
780
781          Name : Name_Id := No_Name;
782          --  See below for what Project_Node_Kind it is used
783
784          Src_Index : Int := 0;
785          --  Index of a unit in a multi-unit source.
786          --  Onli for some N_Attribute_Declaration and N_Literal_String.
787
788          Path_Name : Name_Id := No_Name;
789          --  See below for what Project_Node_Kind it is used
790
791          Value : Name_Id := No_Name;
792          --  See below for what Project_Node_Kind it is used
793
794          Field1 : Project_Node_Id := Empty_Node;
795          --  See below the meaning for each Project_Node_Kind
796
797          Field2 : Project_Node_Id := Empty_Node;
798          --  See below the meaning for each Project_Node_Kind
799
800          Field3 : Project_Node_Id := Empty_Node;
801          --  See below the meaning for each Project_Node_Kind
802
803          Flag1 : Boolean := False;
804          --  This flag is significant only for:
805          --    N_Attribute_Declaration and N_Atribute_Reference
806          --      It indicates for an associative array attribute, that the
807          --      index is case insensitive.
808          --    N_Comment - it indicates that the comment is preceded by an
809          --                empty line.
810          --    N_Project - it indicates that there are comments in the project
811          --                source that cannot be kept in the tree.
812          --    N_Project_Declaration
813          --              - it indicates that there are unkept comments in the
814          --                project.
815
816          Flag2 : Boolean := False;
817          --  This flag is significant only for:
818          --    N_Project - it indicates that the project "extends all" another
819          --                project.
820          --    N_Comment - it indicates that the comment is followed by an
821          --                empty line.
822          --    N_With_Clause
823          --              - it indicates that the originally imported project
824          --                is an extending all project.
825
826          Comments : Project_Node_Id := Empty_Node;
827          --  For nodes other that N_Comment_Zones or N_Comment, designates the
828          --  comment zones associated with the node.
829          --  for N_Comment_Zones, designates the comment after the "end" of
830          --  the construct.
831          --  For N_Comment, designates the next comment, if any.
832
833       end record;
834
835       --  type Project_Node_Kind is
836
837       --   (N_Project,
838       --    --  Name:      project name
839       --    --  Path_Name: project path name
840       --    --  Expr_Kind: Undefined
841       --    --  Field1:    first with clause
842       --    --  Field2:    project declaration
843       --    --  Field3:    first string type
844       --    --  Value:     extended project path name (if any)
845
846       --    N_With_Clause,
847       --    --  Name:      imported project name
848       --    --  Path_Name: imported project path name
849       --    --  Expr_Kind: Undefined
850       --    --  Field1:    project node
851       --    --  Field2:    next with clause
852       --    --  Field3:    project node or empty if "limited with"
853       --    --  Value:     literal string withed
854
855       --    N_Project_Declaration,
856       --    --  Name:      not used
857       --    --  Path_Name: not used
858       --    --  Expr_Kind: Undefined
859       --    --  Field1:    first declarative item
860       --    --  Field2:    extended project
861       --    --  Field3:    extending project
862       --    --  Value:     not used
863
864       --    N_Declarative_Item,
865       --    --  Name:      not used
866       --    --  Path_Name: not used
867       --    --  Expr_Kind: Undefined
868       --    --  Field1:    current item node
869       --    --  Field2:    next declarative item
870       --    --  Field3:    not used
871       --    --  Value:     not used
872
873       --    N_Package_Declaration,
874       --    --  Name:      package name
875       --    --  Path_Name: not used
876       --    --  Expr_Kind: Undefined
877       --    --  Field1:    project of renamed package (if any)
878       --    --  Field2:    first declarative item
879       --    --  Field3:    next package in project
880       --    --  Value:     not used
881
882       --    N_String_Type_Declaration,
883       --    --  Name:      type name
884       --    --  Path_Name: not used
885       --    --  Expr_Kind: Undefined
886       --    --  Field1:    first literal string
887       --    --  Field2:    next string type
888       --    --  Field3:    not used
889       --    --  Value:     not used
890
891       --    N_Literal_String,
892       --    --  Name:      not used
893       --    --  Path_Name: not used
894       --    --  Expr_Kind: Single
895       --    --  Field1:    next literal string
896       --    --  Field2:    not used
897       --    --  Field3:    not used
898       --    --  Value:     string value
899
900       --    N_Attribute_Declaration,
901       --    --  Name:      attribute name
902       --    --  Path_Name: not used
903       --    --  Expr_Kind: attribute kind
904       --    --  Field1:    expression
905       --    --  Field2:    project of full associative array
906       --    --  Field3:    package of full associative array
907       --    --  Value:     associative array index
908       --    --             (if an associative array element)
909
910       --    N_Typed_Variable_Declaration,
911       --    --  Name:      variable name
912       --    --  Path_Name: not used
913       --    --  Expr_Kind: Single
914       --    --  Field1:    expression
915       --    --  Field2:    type of variable (N_String_Type_Declaration)
916       --    --  Field3:    next variable
917       --    --  Value:     not used
918
919       --    N_Variable_Declaration,
920       --    --  Name:      variable name
921       --    --  Path_Name: not used
922       --    --  Expr_Kind: variable kind
923       --    --  Field1:    expression
924       --    --  Field2:    not used
925       --    --             Field3 is used for next variable, instead of Field2,
926       --    --             so that it is the same field for
927       --    --             N_Variable_Declaration and
928       --    --             N_Typed_Variable_Declaration
929       --    --  Field3:    next variable
930       --    --  Value:     not used
931
932       --    N_Expression,
933       --    --  Name:      not used
934       --    --  Path_Name: not used
935       --    --  Expr_Kind: expression kind
936       --    --  Field1:    first term
937       --    --  Field2:    next expression in list
938       --    --  Field3:    not used
939       --    --  Value:     not used
940
941       --    N_Term,
942       --    --  Name:      not used
943       --    --  Path_Name: not used
944       --    --  Expr_Kind: term kind
945       --    --  Field1:    current term
946       --    --  Field2:    next term in the expression
947       --    --  Field3:    not used
948       --    --  Value:     not used
949
950       --    N_Literal_String_List,
951       --    --  Designates a list of string expressions between brackets
952       --    --  separated by commas. The string expressions are not necessarily
953       --    --  literal strings.
954       --    --  Name:      not used
955       --    --  Path_Name: not used
956       --    --  Expr_Kind: List
957       --    --  Field1:    first expression
958       --    --  Field2:    not used
959       --    --  Field3:    not used
960       --    --  Value:     not used
961
962       --    N_Variable_Reference,
963       --    --  Name:      variable name
964       --    --  Path_Name: not used
965       --    --  Expr_Kind: variable kind
966       --    --  Field1:    project (if specified)
967       --    --  Field2:    package (if specified)
968       --    --  Field3:    type of variable (N_String_Type_Declaration), if any
969       --    --  Value:     not used
970
971       --    N_External_Value,
972       --    --  Name:      not used
973       --    --  Path_Name: not used
974       --    --  Expr_Kind: Single
975       --    --  Field1:    Name of the external reference (literal string)
976       --    --  Field2:    Default (literal string)
977       --    --  Field3:    not used
978       --    --  Value:     not used
979
980       --    N_Attribute_Reference,
981       --    --  Name:      attribute name
982       --    --  Path_Name: not used
983       --    --  Expr_Kind: attribute kind
984       --    --  Field1:    project
985       --    --  Field2:    package (if attribute of a package)
986       --    --  Field3:    not used
987       --    --  Value:     associative array index
988       --    --             (if an associative array element)
989
990       --    N_Case_Construction,
991       --    --  Name:      not used
992       --    --  Path_Name: not used
993       --    --  Expr_Kind: Undefined
994       --    --  Field1:    case variable reference
995       --    --  Field2:    first case item
996       --    --  Field3:    not used
997       --    --  Value:     not used
998
999       --    N_Case_Item
1000       --    --  Name:      not used
1001       --    --  Path_Name: not used
1002       --    --  Expr_Kind: not used
1003       --    --  Field1:    first choice (literal string), or Empty_Node
1004       --    --             for when others
1005       --    --  Field2:    first declarative item
1006       --    --  Field3:    next case item
1007       --    --  Value:     not used
1008
1009       --    N_Comment_zones
1010       --    --  Name:      not used
1011       --    --  Path_Name: not used
1012       --    --  Expr_Kind: not used
1013       --    --  Field1:    comment before the construct
1014       --    --  Field2:    comment after the construct
1015       --    --  Field3:    comment before the "end" of the construct
1016       --    --  Value:     end of line comment
1017       --    --  Comments:  comment after the "end" of the construct
1018
1019       --    N_Comment
1020       --    --  Name:      not used
1021       --    --  Path_Name: not used
1022       --    --  Expr_Kind: not used
1023       --    --  Field1:    not used
1024       --    --  Field2:    not used
1025       --    --  Field3:    not used
1026       --    --  Value:     comment
1027       --    --  Flag1:     comment is preceded by an empty line
1028       --    --  Flag2:     comment is followed by an empty line
1029       --    --  Comments:  next comment
1030
1031       package Project_Nodes is
1032          new Table.Table (Table_Component_Type => Project_Node_Record,
1033                           Table_Index_Type     => Project_Node_Id,
1034                           Table_Low_Bound      => First_Node_Id,
1035                           Table_Initial        => Project_Nodes_Initial,
1036                           Table_Increment      => Project_Nodes_Increment,
1037                           Table_Name           => "Project_Nodes");
1038       --  This table contains the syntactic tree of project data
1039       --  from project files.
1040
1041       type Project_Name_And_Node is record
1042          Name : Name_Id;
1043          --  Name of the project
1044
1045          Node : Project_Node_Id;
1046          --  Node of the project in table Project_Nodes
1047
1048          Canonical_Path : Name_Id;
1049          --  Resolved and canonical path of the project file
1050
1051          Extended : Boolean;
1052          --  True when the project is being extended by another project
1053       end record;
1054
1055       No_Project_Name_And_Node : constant Project_Name_And_Node :=
1056         (Name           => No_Name,
1057          Node           => Empty_Node,
1058          Canonical_Path => No_Name,
1059          Extended       => True);
1060
1061       package Projects_Htable is new GNAT.HTable.Simple_HTable
1062         (Header_Num => Header_Num,
1063          Element    => Project_Name_And_Node,
1064          No_Element => No_Project_Name_And_Node,
1065          Key        => Name_Id,
1066          Hash       => Hash,
1067          Equal      => "=");
1068       --  This hash table contains a mapping of project names to project nodes.
1069       --  Note that this hash table contains only the nodes whose Kind is
1070       --  N_Project. It is used to find the node of a project from its
1071       --  name, and to verify if a project has already been parsed, knowing
1072       --  its name.
1073
1074    end Tree_Private_Part;
1075
1076 private
1077    type Comment_Array is array (Positive range <>) of Comment_Data;
1078    type Comments_Ptr is access Comment_Array;
1079
1080    type Comment_State is record
1081       End_Of_Line_Node   : Project_Node_Id := Empty_Node;
1082
1083       Previous_Line_Node : Project_Node_Id := Empty_Node;
1084
1085       Previous_End_Node  : Project_Node_Id := Empty_Node;
1086
1087       Unkept_Comments    : Boolean := False;
1088
1089       Comments           : Comments_Ptr := null;
1090    end record;
1091
1092 end Prj.Tree;