1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package defines the structure of the Project File tree
28 with GNAT.Dynamic_HTables;
29 with GNAT.Dynamic_Tables;
33 with Prj.Attr; use Prj.Attr;
37 type Project_Node_Tree_Data;
38 type Project_Node_Tree_Ref is access all Project_Node_Tree_Data;
39 -- Type to designate a project node tree, so that several project node
40 -- trees can coexist in memory.
42 Project_Nodes_Initial : constant := 1_000;
43 Project_Nodes_Increment : constant := 100;
44 -- Allocation parameters for initializing and extending number
45 -- of nodes in table Tree_Private_Part.Project_Nodes
47 Project_Node_Low_Bound : constant := 0;
48 Project_Node_High_Bound : constant := 099_999_999;
49 -- Range of values for project node id's (in practice infinite)
51 type Project_Node_Id is range
52 Project_Node_Low_Bound .. Project_Node_High_Bound;
53 -- The index of table Tree_Private_Part.Project_Nodes
55 Empty_Node : constant Project_Node_Id := Project_Node_Low_Bound;
56 -- Designates no node in table Project_Nodes
58 First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound + 1;
60 subtype Variable_Node_Id is Project_Node_Id;
61 -- Used to designate a node whose expected kind is one of
62 -- N_Typed_Variable_Declaration, N_Variable_Declaration or
63 -- N_Variable_Reference.
65 subtype Package_Declaration_Id is Project_Node_Id;
66 -- Used to designate a node whose expected kind is N_Project_Declaration
68 type Project_Node_Kind is
71 N_Project_Declaration,
73 N_Package_Declaration,
74 N_String_Type_Declaration,
76 N_Attribute_Declaration,
77 N_Typed_Variable_Declaration,
78 N_Variable_Declaration,
81 N_Literal_String_List,
84 N_Attribute_Reference,
89 -- Each node in the tree is of a Project_Node_Kind. For the signification
90 -- of the fields in each node of Project_Node_Kind, look at package
93 procedure Initialize (Tree : Project_Node_Tree_Ref);
94 -- Initialize the Project File tree: empty the Project_Nodes table
95 -- and reset the Projects_Htable.
97 function Default_Project_Node
98 (In_Tree : Project_Node_Tree_Ref;
99 Of_Kind : Project_Node_Kind;
100 And_Expr_Kind : Variable_Kind := Undefined) return Project_Node_Id;
101 -- Returns a Project_Node_Record with the specified Kind and Expr_Kind. All
102 -- the other components have default nil values.
104 function Hash (N : Project_Node_Id) return Header_Num;
105 -- Used for hash tables where the key is a Project_Node_Id
107 function Imported_Or_Extended_Project_Of
108 (Project : Project_Node_Id;
109 In_Tree : Project_Node_Tree_Ref;
110 With_Name : Name_Id) return Project_Node_Id;
111 -- Return the node of a project imported or extended by project Project and
112 -- whose name is With_Name. Return Empty_Node if there is no such project.
118 type Comment_State is private;
119 -- A type to store the values of several global variables related to
122 procedure Save (S : out Comment_State);
123 -- Save in variable S the comment state. Called before scanning a new
126 procedure Restore (S : Comment_State);
127 -- Restore the comment state to a previously saved value. Called after
128 -- scanning a project file.
130 procedure Reset_State;
131 -- Set the comment state to its initial value. Called before scanning a
134 function There_Are_Unkept_Comments return Boolean;
135 -- Indicates that some of the comments in a project file could not be
136 -- stored in the parse tree.
138 procedure Set_Previous_Line_Node (To : Project_Node_Id);
139 -- Indicate the node on the previous line. If there are comments
140 -- immediately following this line, then they should be associated with
143 procedure Set_Previous_End_Node (To : Project_Node_Id);
144 -- Indicate that on the previous line the "end" belongs to node To.
145 -- If there are comments immediately following this "end" line, they
146 -- should be associated with this node.
148 procedure Set_End_Of_Line (To : Project_Node_Id);
149 -- Indicate the node on the current line. If there is an end of line
150 -- comment, then it should be associated with this node.
152 procedure Set_Next_End_Node (To : Project_Node_Id);
153 -- Put node To on the top of the end node stack. When an END line is found
154 -- with this node on the top of the end node stack, the comments, if any,
155 -- immediately preceding this "end" line will be associated with this node.
157 procedure Remove_Next_End_Node;
158 -- Remove the top of the end node stack
160 ------------------------
161 -- Comment Processing --
162 ------------------------
164 type Comment_Data is record
165 Value : Name_Id := No_Name;
166 Follows_Empty_Line : Boolean := False;
167 Is_Followed_By_Empty_Line : Boolean := False;
169 -- Component type for Comments Table below
171 package Comments is new Table.Table
172 (Table_Component_Type => Comment_Data,
173 Table_Index_Type => Natural,
174 Table_Low_Bound => 1,
176 Table_Increment => 100,
177 Table_Name => "Prj.Tree.Comments");
178 -- A table to store the comments that may be stored is the tree
180 procedure Scan (In_Tree : Project_Node_Tree_Ref);
181 -- Scan the tokens and accumulate comments
183 type Comment_Location is
184 (Before, After, Before_End, After_End, End_Of_Line);
185 -- Used in call to Add_Comments below
187 procedure Add_Comments
188 (To : Project_Node_Id;
189 In_Tree : Project_Node_Tree_Ref;
190 Where : Comment_Location);
191 -- Add comments to this node
193 ----------------------
194 -- Access Functions --
195 ----------------------
197 -- The following query functions are part of the abstract interface
198 -- of the Project File tree. They provide access to fields of a project.
200 -- The access functions should be called only with valid arguments.
201 -- For each function the condition of validity is specified. If an access
202 -- function is called with invalid arguments, then exception
203 -- Assertion_Error is raised if assertions are enabled, otherwise the
204 -- behaviour is not defined and may result in a crash.
207 (Node : Project_Node_Id;
208 In_Tree : Project_Node_Tree_Ref) return Name_Id;
209 pragma Inline (Name_Of);
210 -- Valid for all non empty nodes. May return No_Name for nodes that have
214 (Node : Project_Node_Id;
215 In_Tree : Project_Node_Tree_Ref) return Project_Node_Kind;
216 pragma Inline (Kind_Of);
217 -- Valid for all non empty nodes
220 (Node : Project_Node_Id;
221 In_Tree : Project_Node_Tree_Ref) return Source_Ptr;
222 pragma Inline (Location_Of);
223 -- Valid for all non empty nodes
225 function First_Comment_After
226 (Node : Project_Node_Id;
227 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
228 -- Valid only for N_Comment_Zones nodes
230 function First_Comment_After_End
231 (Node : Project_Node_Id;
232 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
233 -- Valid only for N_Comment_Zones nodes
235 function First_Comment_Before
236 (Node : Project_Node_Id;
237 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
238 -- Valid only for N_Comment_Zones nodes
240 function First_Comment_Before_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
245 function Next_Comment
246 (Node : Project_Node_Id;
247 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
248 -- Valid only for N_Comment nodes
250 function End_Of_Line_Comment
251 (Node : Project_Node_Id;
252 In_Tree : Project_Node_Tree_Ref) return Name_Id;
253 -- Valid only for non empty nodes
255 function Follows_Empty_Line
256 (Node : Project_Node_Id;
257 In_Tree : Project_Node_Tree_Ref) return Boolean;
258 -- Valid only for N_Comment nodes
260 function Is_Followed_By_Empty_Line
261 (Node : Project_Node_Id;
262 In_Tree : Project_Node_Tree_Ref) return Boolean;
263 -- Valid only for N_Comment nodes
265 function Project_File_Includes_Unkept_Comments
266 (Node : Project_Node_Id;
267 In_Tree : Project_Node_Tree_Ref)
269 -- Valid only for N_Project nodes
271 function Directory_Of
272 (Node : Project_Node_Id;
273 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
274 pragma Inline (Directory_Of);
275 -- Only valid for N_Project nodes
277 function Expression_Kind_Of
278 (Node : Project_Node_Id;
279 In_Tree : Project_Node_Tree_Ref) return Variable_Kind;
280 pragma Inline (Expression_Kind_Of);
281 -- Only valid for N_Literal_String, N_Attribute_Declaration,
282 -- N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
283 -- N_Term, N_Variable_Reference or N_Attribute_Reference nodes.
285 function Is_Extending_All
286 (Node : Project_Node_Id;
287 In_Tree : Project_Node_Tree_Ref) return Boolean;
288 pragma Inline (Is_Extending_All);
289 -- Only valid for N_Project and N_With_Clause
291 function Is_Not_Last_In_List
292 (Node : Project_Node_Id;
293 In_Tree : Project_Node_Tree_Ref) return Boolean;
294 pragma Inline (Is_Not_Last_In_List);
295 -- Only valid for N_With_Clause
297 function First_Variable_Of
298 (Node : Project_Node_Id;
299 In_Tree : Project_Node_Tree_Ref) return Variable_Node_Id;
300 pragma Inline (First_Variable_Of);
301 -- Only valid for N_Project or N_Package_Declaration nodes
303 function First_Package_Of
304 (Node : Project_Node_Id;
305 In_Tree : Project_Node_Tree_Ref) return Package_Declaration_Id;
306 pragma Inline (First_Package_Of);
307 -- Only valid for N_Project nodes
309 function Package_Id_Of
310 (Node : Project_Node_Id;
311 In_Tree : Project_Node_Tree_Ref) return Package_Node_Id;
312 pragma Inline (Package_Id_Of);
313 -- Only valid for N_Package_Declaration nodes
315 function Path_Name_Of
316 (Node : Project_Node_Id;
317 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
318 pragma Inline (Path_Name_Of);
319 -- Only valid for N_Project and N_With_Clause nodes
321 function String_Value_Of
322 (Node : Project_Node_Id;
323 In_Tree : Project_Node_Tree_Ref) return Name_Id;
324 pragma Inline (String_Value_Of);
325 -- Only valid for N_With_Clause, N_Literal_String nodes or N_Comment.
326 -- For a N_With_Clause created automatically for a virtual extending
327 -- project, No_Name is returned.
329 function Source_Index_Of
330 (Node : Project_Node_Id;
331 In_Tree : Project_Node_Tree_Ref) return Int;
332 pragma Inline (Source_Index_Of);
333 -- Only valid for N_Literal_String and N_Attribute_Declaration nodes
335 function First_With_Clause_Of
336 (Node : Project_Node_Id;
337 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
338 pragma Inline (First_With_Clause_Of);
339 -- Only valid for N_Project nodes
341 function Project_Declaration_Of
342 (Node : Project_Node_Id;
343 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
344 pragma Inline (Project_Declaration_Of);
345 -- Only valid for N_Project nodes
347 function Project_Qualifier_Of
348 (Node : Project_Node_Id;
349 In_Tree : Project_Node_Tree_Ref) return Project_Qualifier;
350 pragma Inline (Project_Qualifier_Of);
351 -- Only valid for N_Project nodes
353 function Extending_Project_Of
354 (Node : Project_Node_Id;
355 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
356 pragma Inline (Extending_Project_Of);
357 -- Only valid for N_Project_Declaration nodes
359 function First_String_Type_Of
360 (Node : Project_Node_Id;
361 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
362 pragma Inline (First_String_Type_Of);
363 -- Only valid for N_Project nodes
365 function Extended_Project_Path_Of
366 (Node : Project_Node_Id;
367 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
368 pragma Inline (Extended_Project_Path_Of);
369 -- Only valid for N_With_Clause nodes
371 function Project_Node_Of
372 (Node : Project_Node_Id;
373 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
374 pragma Inline (Project_Node_Of);
375 -- Only valid for N_With_Clause, N_Variable_Reference and
376 -- N_Attribute_Reference nodes.
378 function Non_Limited_Project_Node_Of
379 (Node : Project_Node_Id;
380 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
381 pragma Inline (Non_Limited_Project_Node_Of);
382 -- Only valid for N_With_Clause nodes. Returns Empty_Node for limited
383 -- imported project files, otherwise returns the same result as
386 function Next_With_Clause_Of
387 (Node : Project_Node_Id;
388 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
389 pragma Inline (Next_With_Clause_Of);
390 -- Only valid for N_With_Clause nodes
392 function First_Declarative_Item_Of
393 (Node : Project_Node_Id;
394 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
395 pragma Inline (First_Declarative_Item_Of);
396 -- Only valid for N_With_Clause nodes
398 function Extended_Project_Of
399 (Node : Project_Node_Id;
400 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
401 pragma Inline (Extended_Project_Of);
402 -- Only valid for N_Project_Declaration nodes
404 function Current_Item_Node
405 (Node : Project_Node_Id;
406 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
407 pragma Inline (Current_Item_Node);
408 -- Only valid for N_Declarative_Item nodes
410 function Next_Declarative_Item
411 (Node : Project_Node_Id;
412 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
413 pragma Inline (Next_Declarative_Item);
414 -- Only valid for N_Declarative_Item node
416 function Project_Of_Renamed_Package_Of
417 (Node : Project_Node_Id;
418 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
419 pragma Inline (Project_Of_Renamed_Package_Of);
420 -- Only valid for N_Package_Declaration nodes.
421 -- May return Empty_Node.
423 function Next_Package_In_Project
424 (Node : Project_Node_Id;
425 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
426 pragma Inline (Next_Package_In_Project);
427 -- Only valid for N_Package_Declaration nodes
429 function First_Literal_String
430 (Node : Project_Node_Id;
431 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
432 pragma Inline (First_Literal_String);
433 -- Only valid for N_String_Type_Declaration nodes
435 function Next_String_Type
436 (Node : Project_Node_Id;
437 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
438 pragma Inline (Next_String_Type);
439 -- Only valid for N_String_Type_Declaration nodes
441 function Next_Literal_String
442 (Node : Project_Node_Id;
443 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
444 pragma Inline (Next_Literal_String);
445 -- Only valid for N_Literal_String nodes
447 function Expression_Of
448 (Node : Project_Node_Id;
449 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
450 pragma Inline (Expression_Of);
451 -- Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
452 -- or N_Variable_Declaration nodes
454 function Associative_Project_Of
455 (Node : Project_Node_Id;
456 In_Tree : Project_Node_Tree_Ref)
457 return Project_Node_Id;
458 pragma Inline (Associative_Project_Of);
459 -- Only valid for N_Attribute_Declaration nodes
461 function Associative_Package_Of
462 (Node : Project_Node_Id;
463 In_Tree : Project_Node_Tree_Ref)
464 return Project_Node_Id;
465 pragma Inline (Associative_Package_Of);
466 -- Only valid for N_Attribute_Declaration nodes
468 function Value_Is_Valid
469 (For_Typed_Variable : Project_Node_Id;
470 In_Tree : Project_Node_Tree_Ref;
471 Value : Name_Id) return Boolean;
472 pragma Inline (Value_Is_Valid);
473 -- Only valid for N_Typed_Variable_Declaration. Returns True if Value is
474 -- in the list of allowed strings for For_Typed_Variable. False otherwise.
476 function Associative_Array_Index_Of
477 (Node : Project_Node_Id;
478 In_Tree : Project_Node_Tree_Ref) return Name_Id;
479 pragma Inline (Associative_Array_Index_Of);
480 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference.
481 -- Returns No_String for non associative array attributes.
483 function Next_Variable
484 (Node : Project_Node_Id;
485 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
486 pragma Inline (Next_Variable);
487 -- Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
491 (Node : Project_Node_Id;
492 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
493 pragma Inline (First_Term);
494 -- Only valid for N_Expression nodes
496 function Next_Expression_In_List
497 (Node : Project_Node_Id;
498 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
499 pragma Inline (Next_Expression_In_List);
500 -- Only valid for N_Expression nodes
502 function Current_Term
503 (Node : Project_Node_Id;
504 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
505 pragma Inline (Current_Term);
506 -- Only valid for N_Term nodes
509 (Node : Project_Node_Id;
510 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
511 pragma Inline (Next_Term);
512 -- Only valid for N_Term nodes
514 function First_Expression_In_List
515 (Node : Project_Node_Id;
516 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
517 pragma Inline (First_Expression_In_List);
518 -- Only valid for N_Literal_String_List nodes
520 function Package_Node_Of
521 (Node : Project_Node_Id;
522 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
523 pragma Inline (Package_Node_Of);
524 -- Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
525 -- May return Empty_Node.
527 function String_Type_Of
528 (Node : Project_Node_Id;
529 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
530 pragma Inline (String_Type_Of);
531 -- Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
534 function External_Reference_Of
535 (Node : Project_Node_Id;
536 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
537 pragma Inline (External_Reference_Of);
538 -- Only valid for N_External_Value nodes
540 function External_Default_Of
541 (Node : Project_Node_Id;
542 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
543 pragma Inline (External_Default_Of);
544 -- Only valid for N_External_Value nodes
546 function Case_Variable_Reference_Of
547 (Node : Project_Node_Id;
548 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
549 pragma Inline (Case_Variable_Reference_Of);
550 -- Only valid for N_Case_Construction nodes
552 function First_Case_Item_Of
553 (Node : Project_Node_Id;
554 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
555 pragma Inline (First_Case_Item_Of);
556 -- Only valid for N_Case_Construction nodes
558 function First_Choice_Of
559 (Node : Project_Node_Id;
560 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
561 pragma Inline (First_Choice_Of);
562 -- Return the first choice in a N_Case_Item, or Empty_Node if
563 -- this is when others.
565 function Next_Case_Item
566 (Node : Project_Node_Id;
567 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
568 pragma Inline (Next_Case_Item);
569 -- Only valid for N_Case_Item nodes
571 function Case_Insensitive
572 (Node : Project_Node_Id;
573 In_Tree : Project_Node_Tree_Ref) return Boolean;
574 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
580 -- The following procedures are part of the abstract interface of
581 -- the Project File tree.
583 -- Each Set_* procedure is valid only for the same Project_Node_Kind
584 -- nodes as the corresponding query function above.
586 procedure Set_Name_Of
587 (Node : Project_Node_Id;
588 In_Tree : Project_Node_Tree_Ref;
590 pragma Inline (Set_Name_Of);
592 procedure Set_Kind_Of
593 (Node : Project_Node_Id;
594 In_Tree : Project_Node_Tree_Ref;
595 To : Project_Node_Kind);
596 pragma Inline (Set_Kind_Of);
598 procedure Set_Location_Of
599 (Node : Project_Node_Id;
600 In_Tree : Project_Node_Tree_Ref;
602 pragma Inline (Set_Location_Of);
604 procedure Set_First_Comment_After
605 (Node : Project_Node_Id;
606 In_Tree : Project_Node_Tree_Ref;
607 To : Project_Node_Id);
608 pragma Inline (Set_First_Comment_After);
610 procedure Set_First_Comment_After_End
611 (Node : Project_Node_Id;
612 In_Tree : Project_Node_Tree_Ref;
613 To : Project_Node_Id);
614 pragma Inline (Set_First_Comment_After_End);
616 procedure Set_First_Comment_Before
617 (Node : Project_Node_Id;
618 In_Tree : Project_Node_Tree_Ref;
619 To : Project_Node_Id);
620 pragma Inline (Set_First_Comment_Before);
622 procedure Set_First_Comment_Before_End
623 (Node : Project_Node_Id;
624 In_Tree : Project_Node_Tree_Ref;
625 To : Project_Node_Id);
626 pragma Inline (Set_First_Comment_Before_End);
628 procedure Set_Next_Comment
629 (Node : Project_Node_Id;
630 In_Tree : Project_Node_Tree_Ref;
631 To : Project_Node_Id);
632 pragma Inline (Set_Next_Comment);
634 procedure Set_Project_File_Includes_Unkept_Comments
635 (Node : Project_Node_Id;
636 In_Tree : Project_Node_Tree_Ref;
639 procedure Set_Directory_Of
640 (Node : Project_Node_Id;
641 In_Tree : Project_Node_Tree_Ref;
642 To : Path_Name_Type);
643 pragma Inline (Set_Directory_Of);
645 procedure Set_Expression_Kind_Of
646 (Node : Project_Node_Id;
647 In_Tree : Project_Node_Tree_Ref;
649 pragma Inline (Set_Expression_Kind_Of);
651 procedure Set_Is_Extending_All
652 (Node : Project_Node_Id;
653 In_Tree : Project_Node_Tree_Ref);
654 pragma Inline (Set_Is_Extending_All);
656 procedure Set_Is_Not_Last_In_List
657 (Node : Project_Node_Id;
658 In_Tree : Project_Node_Tree_Ref);
659 pragma Inline (Set_Is_Not_Last_In_List);
661 procedure Set_First_Variable_Of
662 (Node : Project_Node_Id;
663 In_Tree : Project_Node_Tree_Ref;
664 To : Variable_Node_Id);
665 pragma Inline (Set_First_Variable_Of);
667 procedure Set_First_Package_Of
668 (Node : Project_Node_Id;
669 In_Tree : Project_Node_Tree_Ref;
670 To : Package_Declaration_Id);
671 pragma Inline (Set_First_Package_Of);
673 procedure Set_Package_Id_Of
674 (Node : Project_Node_Id;
675 In_Tree : Project_Node_Tree_Ref;
676 To : Package_Node_Id);
677 pragma Inline (Set_Package_Id_Of);
679 procedure Set_Path_Name_Of
680 (Node : Project_Node_Id;
681 In_Tree : Project_Node_Tree_Ref;
682 To : Path_Name_Type);
683 pragma Inline (Set_Path_Name_Of);
685 procedure Set_String_Value_Of
686 (Node : Project_Node_Id;
687 In_Tree : Project_Node_Tree_Ref;
689 pragma Inline (Set_String_Value_Of);
691 procedure Set_First_With_Clause_Of
692 (Node : Project_Node_Id;
693 In_Tree : Project_Node_Tree_Ref;
694 To : Project_Node_Id);
695 pragma Inline (Set_First_With_Clause_Of);
697 procedure Set_Project_Declaration_Of
698 (Node : Project_Node_Id;
699 In_Tree : Project_Node_Tree_Ref;
700 To : Project_Node_Id);
701 pragma Inline (Set_Project_Declaration_Of);
703 procedure Set_Project_Qualifier_Of
704 (Node : Project_Node_Id;
705 In_Tree : Project_Node_Tree_Ref;
706 To : Project_Qualifier);
707 pragma Inline (Set_Project_Qualifier_Of);
709 procedure Set_Extending_Project_Of
710 (Node : Project_Node_Id;
711 In_Tree : Project_Node_Tree_Ref;
712 To : Project_Node_Id);
713 pragma Inline (Set_Extending_Project_Of);
715 procedure Set_First_String_Type_Of
716 (Node : Project_Node_Id;
717 In_Tree : Project_Node_Tree_Ref;
718 To : Project_Node_Id);
719 pragma Inline (Set_First_String_Type_Of);
721 procedure Set_Extended_Project_Path_Of
722 (Node : Project_Node_Id;
723 In_Tree : Project_Node_Tree_Ref;
724 To : Path_Name_Type);
725 pragma Inline (Set_Extended_Project_Path_Of);
727 procedure Set_Project_Node_Of
728 (Node : Project_Node_Id;
729 In_Tree : Project_Node_Tree_Ref;
730 To : Project_Node_Id;
731 Limited_With : Boolean := False);
732 pragma Inline (Set_Project_Node_Of);
734 procedure Set_Next_With_Clause_Of
735 (Node : Project_Node_Id;
736 In_Tree : Project_Node_Tree_Ref;
737 To : Project_Node_Id);
738 pragma Inline (Set_Next_With_Clause_Of);
740 procedure Set_First_Declarative_Item_Of
741 (Node : Project_Node_Id;
742 In_Tree : Project_Node_Tree_Ref;
743 To : Project_Node_Id);
744 pragma Inline (Set_First_Declarative_Item_Of);
746 procedure Set_Extended_Project_Of
747 (Node : Project_Node_Id;
748 In_Tree : Project_Node_Tree_Ref;
749 To : Project_Node_Id);
750 pragma Inline (Set_Extended_Project_Of);
752 procedure Set_Current_Item_Node
753 (Node : Project_Node_Id;
754 In_Tree : Project_Node_Tree_Ref;
755 To : Project_Node_Id);
756 pragma Inline (Set_Current_Item_Node);
758 procedure Set_Next_Declarative_Item
759 (Node : Project_Node_Id;
760 In_Tree : Project_Node_Tree_Ref;
761 To : Project_Node_Id);
762 pragma Inline (Set_Next_Declarative_Item);
764 procedure Set_Project_Of_Renamed_Package_Of
765 (Node : Project_Node_Id;
766 In_Tree : Project_Node_Tree_Ref;
767 To : Project_Node_Id);
768 pragma Inline (Set_Project_Of_Renamed_Package_Of);
770 procedure Set_Next_Package_In_Project
771 (Node : Project_Node_Id;
772 In_Tree : Project_Node_Tree_Ref;
773 To : Project_Node_Id);
774 pragma Inline (Set_Next_Package_In_Project);
776 procedure Set_First_Literal_String
777 (Node : Project_Node_Id;
778 In_Tree : Project_Node_Tree_Ref;
779 To : Project_Node_Id);
780 pragma Inline (Set_First_Literal_String);
782 procedure Set_Next_String_Type
783 (Node : Project_Node_Id;
784 In_Tree : Project_Node_Tree_Ref;
785 To : Project_Node_Id);
786 pragma Inline (Set_Next_String_Type);
788 procedure Set_Next_Literal_String
789 (Node : Project_Node_Id;
790 In_Tree : Project_Node_Tree_Ref;
791 To : Project_Node_Id);
792 pragma Inline (Set_Next_Literal_String);
794 procedure Set_Expression_Of
795 (Node : Project_Node_Id;
796 In_Tree : Project_Node_Tree_Ref;
797 To : Project_Node_Id);
798 pragma Inline (Set_Expression_Of);
800 procedure Set_Associative_Project_Of
801 (Node : Project_Node_Id;
802 In_Tree : Project_Node_Tree_Ref;
803 To : Project_Node_Id);
804 pragma Inline (Set_Associative_Project_Of);
806 procedure Set_Associative_Package_Of
807 (Node : Project_Node_Id;
808 In_Tree : Project_Node_Tree_Ref;
809 To : Project_Node_Id);
810 pragma Inline (Set_Associative_Package_Of);
812 procedure Set_Associative_Array_Index_Of
813 (Node : Project_Node_Id;
814 In_Tree : Project_Node_Tree_Ref;
816 pragma Inline (Set_Associative_Array_Index_Of);
818 procedure Set_Next_Variable
819 (Node : Project_Node_Id;
820 In_Tree : Project_Node_Tree_Ref;
821 To : Project_Node_Id);
822 pragma Inline (Set_Next_Variable);
824 procedure Set_First_Term
825 (Node : Project_Node_Id;
826 In_Tree : Project_Node_Tree_Ref;
827 To : Project_Node_Id);
828 pragma Inline (Set_First_Term);
830 procedure Set_Next_Expression_In_List
831 (Node : Project_Node_Id;
832 In_Tree : Project_Node_Tree_Ref;
833 To : Project_Node_Id);
834 pragma Inline (Set_Next_Expression_In_List);
836 procedure Set_Current_Term
837 (Node : Project_Node_Id;
838 In_Tree : Project_Node_Tree_Ref;
839 To : Project_Node_Id);
840 pragma Inline (Set_Current_Term);
842 procedure Set_Next_Term
843 (Node : Project_Node_Id;
844 In_Tree : Project_Node_Tree_Ref;
845 To : Project_Node_Id);
846 pragma Inline (Set_Next_Term);
848 procedure Set_First_Expression_In_List
849 (Node : Project_Node_Id;
850 In_Tree : Project_Node_Tree_Ref;
851 To : Project_Node_Id);
852 pragma Inline (Set_First_Expression_In_List);
854 procedure Set_Package_Node_Of
855 (Node : Project_Node_Id;
856 In_Tree : Project_Node_Tree_Ref;
857 To : Project_Node_Id);
858 pragma Inline (Set_Package_Node_Of);
860 procedure Set_Source_Index_Of
861 (Node : Project_Node_Id;
862 In_Tree : Project_Node_Tree_Ref;
864 pragma Inline (Set_Source_Index_Of);
866 procedure Set_String_Type_Of
867 (Node : Project_Node_Id;
868 In_Tree : Project_Node_Tree_Ref;
869 To : Project_Node_Id);
870 pragma Inline (Set_String_Type_Of);
872 procedure Set_External_Reference_Of
873 (Node : Project_Node_Id;
874 In_Tree : Project_Node_Tree_Ref;
875 To : Project_Node_Id);
876 pragma Inline (Set_External_Reference_Of);
878 procedure Set_External_Default_Of
879 (Node : Project_Node_Id;
880 In_Tree : Project_Node_Tree_Ref;
881 To : Project_Node_Id);
882 pragma Inline (Set_External_Default_Of);
884 procedure Set_Case_Variable_Reference_Of
885 (Node : Project_Node_Id;
886 In_Tree : Project_Node_Tree_Ref;
887 To : Project_Node_Id);
888 pragma Inline (Set_Case_Variable_Reference_Of);
890 procedure Set_First_Case_Item_Of
891 (Node : Project_Node_Id;
892 In_Tree : Project_Node_Tree_Ref;
893 To : Project_Node_Id);
894 pragma Inline (Set_First_Case_Item_Of);
896 procedure Set_First_Choice_Of
897 (Node : Project_Node_Id;
898 In_Tree : Project_Node_Tree_Ref;
899 To : Project_Node_Id);
900 pragma Inline (Set_First_Choice_Of);
902 procedure Set_Next_Case_Item
903 (Node : Project_Node_Id;
904 In_Tree : Project_Node_Tree_Ref;
905 To : Project_Node_Id);
906 pragma Inline (Set_Next_Case_Item);
908 procedure Set_Case_Insensitive
909 (Node : Project_Node_Id;
910 In_Tree : Project_Node_Tree_Ref;
913 -------------------------------
914 -- Restricted Access Section --
915 -------------------------------
917 package Tree_Private_Part is
919 -- This is conceptually in the private part
921 -- However, for efficiency, some packages are accessing it directly
923 type Project_Node_Record is record
925 Kind : Project_Node_Kind;
927 Qualifier : Project_Qualifier := Unspecified;
929 Location : Source_Ptr := No_Location;
931 Directory : Path_Name_Type := No_Path;
932 -- Only for N_Project
934 Expr_Kind : Variable_Kind := Undefined;
935 -- See below for what Project_Node_Kind it is used
937 Variables : Variable_Node_Id := Empty_Node;
938 -- First variable in a project or a package
940 Packages : Package_Declaration_Id := Empty_Node;
941 -- First package declaration in a project
943 Pkg_Id : Package_Node_Id := Empty_Package;
944 -- Only used for N_Package_Declaration
945 -- The component Pkg_Id is an entry into the table Package_Attributes
946 -- (in Prj.Attr). It is used to indicate all the attributes of the
947 -- package with their characteristics.
949 -- The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes
950 -- are built once and for all through a call (from Prj.Initialize)
951 -- to procedure Prj.Attr.Initialize. It is never modified after that.
953 Name : Name_Id := No_Name;
954 -- See below for what Project_Node_Kind it is used
956 Src_Index : Int := 0;
957 -- Index of a unit in a multi-unit source.
958 -- Only for some N_Attribute_Declaration and N_Literal_String.
960 Path_Name : Path_Name_Type := No_Path;
961 -- See below for what Project_Node_Kind it is used
963 Value : Name_Id := No_Name;
964 -- See below for what Project_Node_Kind it is used
966 Field1 : Project_Node_Id := Empty_Node;
967 -- See below the meaning for each Project_Node_Kind
969 Field2 : Project_Node_Id := Empty_Node;
970 -- See below the meaning for each Project_Node_Kind
972 Field3 : Project_Node_Id := Empty_Node;
973 -- See below the meaning for each Project_Node_Kind
975 Flag1 : Boolean := False;
976 -- This flag is significant only for:
977 -- N_Attribute_Declaration and N_Attribute_Reference
978 -- It indicates for an associative array attribute, that the
979 -- index is case insensitive.
980 -- N_Comment - it indicates that the comment is preceded by an
982 -- N_Project - it indicates that there are comments in the project
983 -- source that cannot be kept in the tree.
984 -- N_Project_Declaration
985 -- - it indicates that there are unkept comments in the
988 -- - it indicates that this is not the last with in a
989 -- with clause. It is set for "A", but not for "B" in
994 Flag2 : Boolean := False;
995 -- This flag is significant only for:
996 -- N_Project - it indicates that the project "extends all" another
998 -- N_Comment - it indicates that the comment is followed by an
1001 -- - it indicates that the originally imported project
1002 -- is an extending all project.
1004 Comments : Project_Node_Id := Empty_Node;
1005 -- For nodes other that N_Comment_Zones or N_Comment, designates the
1006 -- comment zones associated with the node.
1007 -- for N_Comment_Zones, designates the comment after the "end" of
1009 -- For N_Comment, designates the next comment, if any.
1013 -- type Project_Node_Kind is
1016 -- -- Name: project name
1017 -- -- Path_Name: project path name
1018 -- -- Expr_Kind: Undefined
1019 -- -- Field1: first with clause
1020 -- -- Field2: project declaration
1021 -- -- Field3: first string type
1022 -- -- Value: extended project path name (if any)
1025 -- -- Name: imported project name
1026 -- -- Path_Name: imported project path name
1027 -- -- Expr_Kind: Undefined
1028 -- -- Field1: project node
1029 -- -- Field2: next with clause
1030 -- -- Field3: project node or empty if "limited with"
1031 -- -- Value: literal string withed
1033 -- N_Project_Declaration,
1034 -- -- Name: not used
1035 -- -- Path_Name: not used
1036 -- -- Expr_Kind: Undefined
1037 -- -- Field1: first declarative item
1038 -- -- Field2: extended project
1039 -- -- Field3: extending project
1040 -- -- Value: not used
1042 -- N_Declarative_Item,
1043 -- -- Name: not used
1044 -- -- Path_Name: not used
1045 -- -- Expr_Kind: Undefined
1046 -- -- Field1: current item node
1047 -- -- Field2: next declarative item
1048 -- -- Field3: not used
1049 -- -- Value: not used
1051 -- N_Package_Declaration,
1052 -- -- Name: package name
1053 -- -- Path_Name: not used
1054 -- -- Expr_Kind: Undefined
1055 -- -- Field1: project of renamed package (if any)
1056 -- -- Field2: first declarative item
1057 -- -- Field3: next package in project
1058 -- -- Value: not used
1060 -- N_String_Type_Declaration,
1061 -- -- Name: type name
1062 -- -- Path_Name: not used
1063 -- -- Expr_Kind: Undefined
1064 -- -- Field1: first literal string
1065 -- -- Field2: next string type
1066 -- -- Field3: not used
1067 -- -- Value: not used
1069 -- N_Literal_String,
1070 -- -- Name: not used
1071 -- -- Path_Name: not used
1072 -- -- Expr_Kind: Single
1073 -- -- Field1: next literal string
1074 -- -- Field2: not used
1075 -- -- Field3: not used
1076 -- -- Value: string value
1078 -- N_Attribute_Declaration,
1079 -- -- Name: attribute name
1080 -- -- Path_Name: not used
1081 -- -- Expr_Kind: attribute kind
1082 -- -- Field1: expression
1083 -- -- Field2: project of full associative array
1084 -- -- Field3: package of full associative array
1085 -- -- Value: associative array index
1086 -- -- (if an associative array element)
1088 -- N_Typed_Variable_Declaration,
1089 -- -- Name: variable name
1090 -- -- Path_Name: not used
1091 -- -- Expr_Kind: Single
1092 -- -- Field1: expression
1093 -- -- Field2: type of variable (N_String_Type_Declaration)
1094 -- -- Field3: next variable
1095 -- -- Value: not used
1097 -- N_Variable_Declaration,
1098 -- -- Name: variable name
1099 -- -- Path_Name: not used
1100 -- -- Expr_Kind: variable kind
1101 -- -- Field1: expression
1102 -- -- Field2: not used
1103 -- -- Field3 is used for next variable, instead of Field2,
1104 -- -- so that it is the same field for
1105 -- -- N_Variable_Declaration and
1106 -- -- N_Typed_Variable_Declaration
1107 -- -- Field3: next variable
1108 -- -- Value: not used
1111 -- -- Name: not used
1112 -- -- Path_Name: not used
1113 -- -- Expr_Kind: expression kind
1114 -- -- Field1: first term
1115 -- -- Field2: next expression in list
1116 -- -- Field3: not used
1117 -- -- Value: not used
1120 -- -- Name: not used
1121 -- -- Path_Name: not used
1122 -- -- Expr_Kind: term kind
1123 -- -- Field1: current term
1124 -- -- Field2: next term in the expression
1125 -- -- Field3: not used
1126 -- -- Value: not used
1128 -- N_Literal_String_List,
1129 -- -- Designates a list of string expressions between brackets
1130 -- -- separated by commas. The string expressions are not necessarily
1131 -- -- literal strings.
1132 -- -- Name: not used
1133 -- -- Path_Name: not used
1134 -- -- Expr_Kind: List
1135 -- -- Field1: first expression
1136 -- -- Field2: not used
1137 -- -- Field3: not used
1138 -- -- Value: not used
1140 -- N_Variable_Reference,
1141 -- -- Name: variable name
1142 -- -- Path_Name: not used
1143 -- -- Expr_Kind: variable kind
1144 -- -- Field1: project (if specified)
1145 -- -- Field2: package (if specified)
1146 -- -- Field3: type of variable (N_String_Type_Declaration), if any
1147 -- -- Value: not used
1149 -- N_External_Value,
1150 -- -- Name: not used
1151 -- -- Path_Name: not used
1152 -- -- Expr_Kind: Single
1153 -- -- Field1: Name of the external reference (literal string)
1154 -- -- Field2: Default (literal string)
1155 -- -- Field3: not used
1156 -- -- Value: not used
1158 -- N_Attribute_Reference,
1159 -- -- Name: attribute name
1160 -- -- Path_Name: not used
1161 -- -- Expr_Kind: attribute kind
1162 -- -- Field1: project
1163 -- -- Field2: package (if attribute of a package)
1164 -- -- Field3: not used
1165 -- -- Value: associative array index
1166 -- -- (if an associative array element)
1168 -- N_Case_Construction,
1169 -- -- Name: not used
1170 -- -- Path_Name: not used
1171 -- -- Expr_Kind: Undefined
1172 -- -- Field1: case variable reference
1173 -- -- Field2: first case item
1174 -- -- Field3: not used
1175 -- -- Value: not used
1178 -- -- Name: not used
1179 -- -- Path_Name: not used
1180 -- -- Expr_Kind: not used
1181 -- -- Field1: first choice (literal string), or Empty_Node
1182 -- -- for when others
1183 -- -- Field2: first declarative item
1184 -- -- Field3: next case item
1185 -- -- Value: not used
1188 -- -- Name: not used
1189 -- -- Path_Name: not used
1190 -- -- Expr_Kind: not used
1191 -- -- Field1: comment before the construct
1192 -- -- Field2: comment after the construct
1193 -- -- Field3: comment before the "end" of the construct
1194 -- -- Value: end of line comment
1195 -- -- Comments: comment after the "end" of the construct
1198 -- -- Name: not used
1199 -- -- Path_Name: not used
1200 -- -- Expr_Kind: not used
1201 -- -- Field1: not used
1202 -- -- Field2: not used
1203 -- -- Field3: not used
1204 -- -- Value: comment
1205 -- -- Flag1: comment is preceded by an empty line
1206 -- -- Flag2: comment is followed by an empty line
1207 -- -- Comments: next comment
1209 package Project_Node_Table is
1210 new GNAT.Dynamic_Tables
1211 (Table_Component_Type => Project_Node_Record,
1212 Table_Index_Type => Project_Node_Id,
1213 Table_Low_Bound => First_Node_Id,
1214 Table_Initial => Project_Nodes_Initial,
1215 Table_Increment => Project_Nodes_Increment);
1216 -- This table contains the syntactic tree of project data
1217 -- from project files.
1219 type Project_Name_And_Node is record
1221 -- Name of the project
1223 Node : Project_Node_Id;
1224 -- Node of the project in table Project_Nodes
1226 Canonical_Path : Path_Name_Type;
1227 -- Resolved and canonical path of a real project file.
1228 -- No_Name in case of virtual projects.
1231 -- True when the project is being extended by another project
1234 No_Project_Name_And_Node : constant Project_Name_And_Node :=
1237 Canonical_Path => No_Path,
1240 package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable
1241 (Header_Num => Header_Num,
1242 Element => Project_Name_And_Node,
1243 No_Element => No_Project_Name_And_Node,
1247 -- This hash table contains a mapping of project names to project nodes.
1248 -- Note that this hash table contains only the nodes whose Kind is
1249 -- N_Project. It is used to find the node of a project from its name,
1250 -- and to verify if a project has already been parsed, knowing its name.
1252 end Tree_Private_Part;
1254 type Project_Node_Tree_Data is record
1255 Project_Nodes : Tree_Private_Part.Project_Node_Table.Instance;
1256 Projects_HT : Tree_Private_Part.Projects_Htable.Instance;
1258 -- The data for a project node tree
1261 type Comment_Array is array (Positive range <>) of Comment_Data;
1262 type Comments_Ptr is access Comment_Array;
1264 type Comment_State is record
1265 End_Of_Line_Node : Project_Node_Id := Empty_Node;
1267 Previous_Line_Node : Project_Node_Id := Empty_Node;
1269 Previous_End_Node : Project_Node_Id := Empty_Node;
1271 Unkept_Comments : Boolean := False;
1273 Comments : Comments_Ptr := null;