OSDN Git Service

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