1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, 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 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package defines the structure of the Project File tree
29 with GNAT.Dynamic_HTables;
30 with GNAT.Dynamic_Tables;
34 with Prj.Attr; use Prj.Attr;
38 type Project_Node_Tree_Data;
39 type Project_Node_Tree_Ref is access all Project_Node_Tree_Data;
40 -- Type to designate a project node tree, so that several project node
41 -- trees can coexist in memory.
43 Project_Nodes_Initial : constant := 1_000;
44 Project_Nodes_Increment : constant := 100;
45 -- Allocation parameters for initializing and extending number
46 -- of nodes in table Tree_Private_Part.Project_Nodes
48 Project_Node_Low_Bound : constant := 0;
49 Project_Node_High_Bound : constant := 099_999_999;
50 -- Range of values for project node id's (in practice infinite)
52 type Project_Node_Id is range
53 Project_Node_Low_Bound .. Project_Node_High_Bound;
54 -- The index of table Tree_Private_Part.Project_Nodes
56 Empty_Node : constant Project_Node_Id := Project_Node_Low_Bound;
57 -- Designates no node in table Project_Nodes
59 First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound + 1;
61 subtype Variable_Node_Id is Project_Node_Id;
62 -- Used to designate a node whose expected kind is one of
63 -- N_Typed_Variable_Declaration, N_Variable_Declaration or
64 -- N_Variable_Reference.
66 subtype Package_Declaration_Id is Project_Node_Id;
67 -- Used to designate a node whose expected kind is N_Proect_Declaration
69 type Project_Node_Kind is
72 N_Project_Declaration,
74 N_Package_Declaration,
75 N_String_Type_Declaration,
77 N_Attribute_Declaration,
78 N_Typed_Variable_Declaration,
79 N_Variable_Declaration,
82 N_Literal_String_List,
85 N_Attribute_Reference,
90 -- Each node in the tree is of a Project_Node_Kind. For the signification
91 -- of the fields in each node of Project_Node_Kind, look at package
94 procedure Initialize (Tree : Project_Node_Tree_Ref);
95 -- Initialize the Project File tree: empty the Project_Nodes table
96 -- and reset the Projects_Htable.
98 function Default_Project_Node
99 (In_Tree : Project_Node_Tree_Ref;
100 Of_Kind : Project_Node_Kind;
101 And_Expr_Kind : Variable_Kind := Undefined) return Project_Node_Id;
102 -- Returns a Project_Node_Record with the specified Kind and Expr_Kind. All
103 -- the other components have default nil values.
105 function Hash (N : Project_Node_Id) return Header_Num;
106 -- Used for hash tables where the key is a Project_Node_Id
108 function Imported_Or_Extended_Project_Of
109 (Project : Project_Node_Id;
110 In_Tree : Project_Node_Tree_Ref;
111 With_Name : Name_Id) return Project_Node_Id;
112 -- Return the node of a project imported or extended by project Project and
113 -- whose name is With_Name. Return Empty_Node if there is no such project.
119 type Comment_State is private;
120 -- A type to store the values of several global variables related to
123 procedure Save (S : out Comment_State);
124 -- Save in variable S the comment state. Called before scanning a new
127 procedure Restore (S : Comment_State);
128 -- Restore the comment state to a previously saved value. Called after
129 -- scanning a project file.
131 procedure Reset_State;
132 -- Set the comment state to its initial value. Called before scanning a
135 function There_Are_Unkept_Comments return Boolean;
136 -- Indicates that some of the comments in a project file could not be
137 -- stored in the parse tree.
139 procedure Set_Previous_Line_Node (To : Project_Node_Id);
140 -- Indicate the node on the previous line. If there are comments
141 -- immediately following this line, then they should be associated with
144 procedure Set_Previous_End_Node (To : Project_Node_Id);
145 -- Indicate that on the previous line the "end" belongs to node To.
146 -- If there are comments immediately following this "end" line, they
147 -- should be associated with this node.
149 procedure Set_End_Of_Line (To : Project_Node_Id);
150 -- Indicate the node on the current line. If there is an end of line
151 -- comment, then it should be associated with this node.
153 procedure Set_Next_End_Node (To : Project_Node_Id);
154 -- Put node To on the top of the end node stack. When an END line is found
155 -- with this node on the top of the end node stack, the comments, if any,
156 -- immediately preceding this "end" line will be associated with this node.
158 procedure Remove_Next_End_Node;
159 -- Remove the top of the end node stack
161 ------------------------
162 -- Comment Processing --
163 ------------------------
165 type Comment_Data is record
166 Value : Name_Id := No_Name;
167 Follows_Empty_Line : Boolean := False;
168 Is_Followed_By_Empty_Line : Boolean := False;
170 -- Component type for Comments Table below
172 package Comments is new Table.Table
173 (Table_Component_Type => Comment_Data,
174 Table_Index_Type => Natural,
175 Table_Low_Bound => 1,
177 Table_Increment => 100,
178 Table_Name => "Prj.Tree.Comments");
179 -- A table to store the comments that may be stored is the tree
181 procedure Scan (In_Tree : Project_Node_Tree_Ref);
182 -- Scan the tokens and accumulate comments
184 type Comment_Location is
185 (Before, After, Before_End, After_End, End_Of_Line);
186 -- Used in call to Add_Comments below
188 procedure Add_Comments
189 (To : Project_Node_Id;
190 In_Tree : Project_Node_Tree_Ref;
191 Where : Comment_Location);
192 -- Add comments to this node
194 ----------------------
195 -- Access Functions --
196 ----------------------
198 -- The following query functions are part of the abstract interface
199 -- of the Project File tree. They provide access to fields of a project.
201 -- The access functions should be called only with valid arguments.
202 -- For each function the condition of validity is specified. If an access
203 -- function is called with invalid arguments, then exception
204 -- Assertion_Error is raised if assertions are enabled, otherwise the
205 -- behaviour is not defined and may result in a crash.
208 (Node : Project_Node_Id;
209 In_Tree : Project_Node_Tree_Ref) return Name_Id;
210 pragma Inline (Name_Of);
211 -- Valid for all non empty nodes. May return No_Name for nodes that have
215 (Node : Project_Node_Id;
216 In_Tree : Project_Node_Tree_Ref) return Project_Node_Kind;
217 pragma Inline (Kind_Of);
218 -- Valid for all non empty nodes
221 (Node : Project_Node_Id;
222 In_Tree : Project_Node_Tree_Ref) return Source_Ptr;
223 pragma Inline (Location_Of);
224 -- Valid for all non empty nodes
226 function First_Comment_After
227 (Node : Project_Node_Id;
228 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
229 -- Valid only for N_Comment_Zones nodes
231 function First_Comment_After_End
232 (Node : Project_Node_Id;
233 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
234 -- Valid only for N_Comment_Zones nodes
236 function First_Comment_Before
237 (Node : Project_Node_Id;
238 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
239 -- Valid only for N_Comment_Zones nodes
241 function First_Comment_Before_End
242 (Node : Project_Node_Id;
243 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
244 -- Valid only for N_Comment_Zones nodes
246 function Next_Comment
247 (Node : Project_Node_Id;
248 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
249 -- Valid only for N_Comment nodes
251 function End_Of_Line_Comment
252 (Node : Project_Node_Id;
253 In_Tree : Project_Node_Tree_Ref) return Name_Id;
254 -- Valid only for non empty nodes
256 function Follows_Empty_Line
257 (Node : Project_Node_Id;
258 In_Tree : Project_Node_Tree_Ref) return Boolean;
259 -- Valid only for N_Comment nodes
261 function Is_Followed_By_Empty_Line
262 (Node : Project_Node_Id;
263 In_Tree : Project_Node_Tree_Ref) return Boolean;
264 -- Valid only for N_Comment nodes
266 function Project_File_Includes_Unkept_Comments
267 (Node : Project_Node_Id;
268 In_Tree : Project_Node_Tree_Ref)
270 -- Valid only for N_Project nodes
272 function Directory_Of
273 (Node : Project_Node_Id;
274 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
275 pragma Inline (Directory_Of);
276 -- Only valid for N_Project nodes
278 function Expression_Kind_Of
279 (Node : Project_Node_Id;
280 In_Tree : Project_Node_Tree_Ref) return Variable_Kind;
281 pragma Inline (Expression_Kind_Of);
282 -- Only valid for N_Literal_String, N_Attribute_Declaration,
283 -- N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
284 -- N_Term, N_Variable_Reference or N_Attribute_Reference nodes.
286 function Is_Extending_All
287 (Node : Project_Node_Id;
288 In_Tree : Project_Node_Tree_Ref) return Boolean;
289 pragma Inline (Is_Extending_All);
290 -- Only valid for N_Project and N_With_Clause
292 function Is_Not_Last_In_List
293 (Node : Project_Node_Id;
294 In_Tree : Project_Node_Tree_Ref) return Boolean;
295 pragma Inline (Is_Not_Last_In_List);
296 -- Only valid for N_With_Clause
298 function First_Variable_Of
299 (Node : Project_Node_Id;
300 In_Tree : Project_Node_Tree_Ref) return Variable_Node_Id;
301 pragma Inline (First_Variable_Of);
302 -- Only valid for N_Project or N_Package_Declaration nodes
304 function First_Package_Of
305 (Node : Project_Node_Id;
306 In_Tree : Project_Node_Tree_Ref) return Package_Declaration_Id;
307 pragma Inline (First_Package_Of);
308 -- Only valid for N_Project nodes
310 function Package_Id_Of
311 (Node : Project_Node_Id;
312 In_Tree : Project_Node_Tree_Ref) return Package_Node_Id;
313 pragma Inline (Package_Id_Of);
314 -- Only valid for N_Package_Declaration nodes
316 function Path_Name_Of
317 (Node : Project_Node_Id;
318 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
319 pragma Inline (Path_Name_Of);
320 -- Only valid for N_Project and N_With_Clause nodes
322 function String_Value_Of
323 (Node : Project_Node_Id;
324 In_Tree : Project_Node_Tree_Ref) return Name_Id;
325 pragma Inline (String_Value_Of);
326 -- Only valid for N_With_Clause, N_Literal_String nodes or N_Comment.
327 -- For a N_With_Clause created automatically for a virtual extending
328 -- project, No_Name is returned.
330 function Source_Index_Of
331 (Node : Project_Node_Id;
332 In_Tree : Project_Node_Tree_Ref) return Int;
333 pragma Inline (Source_Index_Of);
334 -- Only valid for N_Literal_String and N_Attribute_Declaration nodes
336 function First_With_Clause_Of
337 (Node : Project_Node_Id;
338 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
339 pragma Inline (First_With_Clause_Of);
340 -- Only valid for N_Project nodes
342 function Project_Declaration_Of
343 (Node : Project_Node_Id;
344 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
345 pragma Inline (Project_Declaration_Of);
346 -- Only valid for N_Project nodes
348 function Extending_Project_Of
349 (Node : Project_Node_Id;
350 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
351 pragma Inline (Extending_Project_Of);
352 -- Only valid for N_Project_Declaration nodes
354 function First_String_Type_Of
355 (Node : Project_Node_Id;
356 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
357 pragma Inline (First_String_Type_Of);
358 -- Only valid for N_Project nodes
360 function Extended_Project_Path_Of
361 (Node : Project_Node_Id;
362 In_Tree : Project_Node_Tree_Ref) return Path_Name_Type;
363 pragma Inline (Extended_Project_Path_Of);
364 -- Only valid for N_With_Clause nodes
366 function Project_Node_Of
367 (Node : Project_Node_Id;
368 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
369 pragma Inline (Project_Node_Of);
370 -- Only valid for N_With_Clause, N_Variable_Reference and
371 -- N_Attribute_Reference nodes.
373 function Non_Limited_Project_Node_Of
374 (Node : Project_Node_Id;
375 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
376 pragma Inline (Non_Limited_Project_Node_Of);
377 -- Only valid for N_With_Clause nodes. Returns Empty_Node for limited
378 -- imported project files, otherwise returns the same result as
381 function Next_With_Clause_Of
382 (Node : Project_Node_Id;
383 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
384 pragma Inline (Next_With_Clause_Of);
385 -- Only valid for N_With_Clause nodes
387 function First_Declarative_Item_Of
388 (Node : Project_Node_Id;
389 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
390 pragma Inline (First_Declarative_Item_Of);
391 -- Only valid for N_With_Clause nodes
393 function Extended_Project_Of
394 (Node : Project_Node_Id;
395 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
396 pragma Inline (Extended_Project_Of);
397 -- Only valid for N_Project_Declaration nodes
399 function Current_Item_Node
400 (Node : Project_Node_Id;
401 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
402 pragma Inline (Current_Item_Node);
403 -- Only valid for N_Declarative_Item nodes
405 function Next_Declarative_Item
406 (Node : Project_Node_Id;
407 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
408 pragma Inline (Next_Declarative_Item);
409 -- Only valid for N_Declarative_Item node
411 function Project_Of_Renamed_Package_Of
412 (Node : Project_Node_Id;
413 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
414 pragma Inline (Project_Of_Renamed_Package_Of);
415 -- Only valid for N_Package_Declaration nodes.
416 -- May return Empty_Node.
418 function Next_Package_In_Project
419 (Node : Project_Node_Id;
420 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
421 pragma Inline (Next_Package_In_Project);
422 -- Only valid for N_Package_Declaration nodes
424 function First_Literal_String
425 (Node : Project_Node_Id;
426 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
427 pragma Inline (First_Literal_String);
428 -- Only valid for N_String_Type_Declaration nodes
430 function Next_String_Type
431 (Node : Project_Node_Id;
432 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
433 pragma Inline (Next_String_Type);
434 -- Only valid for N_String_Type_Declaration nodes
436 function Next_Literal_String
437 (Node : Project_Node_Id;
438 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
439 pragma Inline (Next_Literal_String);
440 -- Only valid for N_Literal_String nodes
442 function Expression_Of
443 (Node : Project_Node_Id;
444 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
445 pragma Inline (Expression_Of);
446 -- Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
447 -- or N_Variable_Declaration nodes
449 function Associative_Project_Of
450 (Node : Project_Node_Id;
451 In_Tree : Project_Node_Tree_Ref)
452 return Project_Node_Id;
453 pragma Inline (Associative_Project_Of);
454 -- Only valid for N_Attribute_Declaration nodes
456 function Associative_Package_Of
457 (Node : Project_Node_Id;
458 In_Tree : Project_Node_Tree_Ref)
459 return Project_Node_Id;
460 pragma Inline (Associative_Package_Of);
461 -- Only valid for N_Attribute_Declaration nodes
463 function Value_Is_Valid
464 (For_Typed_Variable : Project_Node_Id;
465 In_Tree : Project_Node_Tree_Ref;
466 Value : Name_Id) return Boolean;
467 pragma Inline (Value_Is_Valid);
468 -- Only valid for N_Typed_Variable_Declaration. Returns True if Value is
469 -- in the list of allowed strings for For_Typed_Variable. False otherwise.
471 function Associative_Array_Index_Of
472 (Node : Project_Node_Id;
473 In_Tree : Project_Node_Tree_Ref) return Name_Id;
474 pragma Inline (Associative_Array_Index_Of);
475 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference.
476 -- Returns No_String for non associative array attributes.
478 function Next_Variable
479 (Node : Project_Node_Id;
480 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
481 pragma Inline (Next_Variable);
482 -- Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
486 (Node : Project_Node_Id;
487 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
488 pragma Inline (First_Term);
489 -- Only valid for N_Expression nodes
491 function Next_Expression_In_List
492 (Node : Project_Node_Id;
493 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
494 pragma Inline (Next_Expression_In_List);
495 -- Only valid for N_Expression nodes
497 function Current_Term
498 (Node : Project_Node_Id;
499 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
500 pragma Inline (Current_Term);
501 -- Only valid for N_Term nodes
504 (Node : Project_Node_Id;
505 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
506 pragma Inline (Next_Term);
507 -- Only valid for N_Term nodes
509 function First_Expression_In_List
510 (Node : Project_Node_Id;
511 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
512 pragma Inline (First_Expression_In_List);
513 -- Only valid for N_Literal_String_List nodes
515 function Package_Node_Of
516 (Node : Project_Node_Id;
517 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
518 pragma Inline (Package_Node_Of);
519 -- Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
520 -- May return Empty_Node.
522 function String_Type_Of
523 (Node : Project_Node_Id;
524 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
525 pragma Inline (String_Type_Of);
526 -- Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
529 function External_Reference_Of
530 (Node : Project_Node_Id;
531 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
532 pragma Inline (External_Reference_Of);
533 -- Only valid for N_External_Value nodes
535 function External_Default_Of
536 (Node : Project_Node_Id;
537 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
538 pragma Inline (External_Default_Of);
539 -- Only valid for N_External_Value nodes
541 function Case_Variable_Reference_Of
542 (Node : Project_Node_Id;
543 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
544 pragma Inline (Case_Variable_Reference_Of);
545 -- Only valid for N_Case_Construction nodes
547 function First_Case_Item_Of
548 (Node : Project_Node_Id;
549 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
550 pragma Inline (First_Case_Item_Of);
551 -- Only valid for N_Case_Construction nodes
553 function First_Choice_Of
554 (Node : Project_Node_Id;
555 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
556 pragma Inline (First_Choice_Of);
557 -- Return the first choice in a N_Case_Item, or Empty_Node if
558 -- this is when others.
560 function Next_Case_Item
561 (Node : Project_Node_Id;
562 In_Tree : Project_Node_Tree_Ref) return Project_Node_Id;
563 pragma Inline (Next_Case_Item);
564 -- Only valid for N_Case_Item nodes
566 function Case_Insensitive
567 (Node : Project_Node_Id;
568 In_Tree : Project_Node_Tree_Ref) return Boolean;
569 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
575 -- The following procedures are part of the abstract interface of
576 -- the Project File tree.
578 -- Each Set_* procedure is valid only for the same Project_Node_Kind
579 -- nodes as the corresponding query function above.
581 procedure Set_Name_Of
582 (Node : Project_Node_Id;
583 In_Tree : Project_Node_Tree_Ref;
585 pragma Inline (Set_Name_Of);
587 procedure Set_Kind_Of
588 (Node : Project_Node_Id;
589 In_Tree : Project_Node_Tree_Ref;
590 To : Project_Node_Kind);
591 pragma Inline (Set_Kind_Of);
593 procedure Set_Location_Of
594 (Node : Project_Node_Id;
595 In_Tree : Project_Node_Tree_Ref;
597 pragma Inline (Set_Location_Of);
599 procedure Set_First_Comment_After
600 (Node : Project_Node_Id;
601 In_Tree : Project_Node_Tree_Ref;
602 To : Project_Node_Id);
603 pragma Inline (Set_First_Comment_After);
605 procedure Set_First_Comment_After_End
606 (Node : Project_Node_Id;
607 In_Tree : Project_Node_Tree_Ref;
608 To : Project_Node_Id);
609 pragma Inline (Set_First_Comment_After_End);
611 procedure Set_First_Comment_Before
612 (Node : Project_Node_Id;
613 In_Tree : Project_Node_Tree_Ref;
614 To : Project_Node_Id);
615 pragma Inline (Set_First_Comment_Before);
617 procedure Set_First_Comment_Before_End
618 (Node : Project_Node_Id;
619 In_Tree : Project_Node_Tree_Ref;
620 To : Project_Node_Id);
621 pragma Inline (Set_First_Comment_Before_End);
623 procedure Set_Next_Comment
624 (Node : Project_Node_Id;
625 In_Tree : Project_Node_Tree_Ref;
626 To : Project_Node_Id);
627 pragma Inline (Set_Next_Comment);
629 procedure Set_Project_File_Includes_Unkept_Comments
630 (Node : Project_Node_Id;
631 In_Tree : Project_Node_Tree_Ref;
634 procedure Set_Directory_Of
635 (Node : Project_Node_Id;
636 In_Tree : Project_Node_Tree_Ref;
637 To : Path_Name_Type);
638 pragma Inline (Set_Directory_Of);
640 procedure Set_Expression_Kind_Of
641 (Node : Project_Node_Id;
642 In_Tree : Project_Node_Tree_Ref;
644 pragma Inline (Set_Expression_Kind_Of);
646 procedure Set_Is_Extending_All
647 (Node : Project_Node_Id;
648 In_Tree : Project_Node_Tree_Ref);
649 pragma Inline (Set_Is_Extending_All);
651 procedure Set_Is_Not_Last_In_List
652 (Node : Project_Node_Id;
653 In_Tree : Project_Node_Tree_Ref);
654 pragma Inline (Set_Is_Not_Last_In_List);
656 procedure Set_First_Variable_Of
657 (Node : Project_Node_Id;
658 In_Tree : Project_Node_Tree_Ref;
659 To : Variable_Node_Id);
660 pragma Inline (Set_First_Variable_Of);
662 procedure Set_First_Package_Of
663 (Node : Project_Node_Id;
664 In_Tree : Project_Node_Tree_Ref;
665 To : Package_Declaration_Id);
666 pragma Inline (Set_First_Package_Of);
668 procedure Set_Package_Id_Of
669 (Node : Project_Node_Id;
670 In_Tree : Project_Node_Tree_Ref;
671 To : Package_Node_Id);
672 pragma Inline (Set_Package_Id_Of);
674 procedure Set_Path_Name_Of
675 (Node : Project_Node_Id;
676 In_Tree : Project_Node_Tree_Ref;
677 To : Path_Name_Type);
678 pragma Inline (Set_Path_Name_Of);
680 procedure Set_String_Value_Of
681 (Node : Project_Node_Id;
682 In_Tree : Project_Node_Tree_Ref;
684 pragma Inline (Set_String_Value_Of);
686 procedure Set_First_With_Clause_Of
687 (Node : Project_Node_Id;
688 In_Tree : Project_Node_Tree_Ref;
689 To : Project_Node_Id);
690 pragma Inline (Set_First_With_Clause_Of);
692 procedure Set_Project_Declaration_Of
693 (Node : Project_Node_Id;
694 In_Tree : Project_Node_Tree_Ref;
695 To : Project_Node_Id);
696 pragma Inline (Set_Project_Declaration_Of);
698 procedure Set_Extending_Project_Of
699 (Node : Project_Node_Id;
700 In_Tree : Project_Node_Tree_Ref;
701 To : Project_Node_Id);
702 pragma Inline (Set_Extending_Project_Of);
704 procedure Set_First_String_Type_Of
705 (Node : Project_Node_Id;
706 In_Tree : Project_Node_Tree_Ref;
707 To : Project_Node_Id);
708 pragma Inline (Set_First_String_Type_Of);
710 procedure Set_Extended_Project_Path_Of
711 (Node : Project_Node_Id;
712 In_Tree : Project_Node_Tree_Ref;
713 To : Path_Name_Type);
714 pragma Inline (Set_Extended_Project_Path_Of);
716 procedure Set_Project_Node_Of
717 (Node : Project_Node_Id;
718 In_Tree : Project_Node_Tree_Ref;
719 To : Project_Node_Id;
720 Limited_With : Boolean := False);
721 pragma Inline (Set_Project_Node_Of);
723 procedure Set_Next_With_Clause_Of
724 (Node : Project_Node_Id;
725 In_Tree : Project_Node_Tree_Ref;
726 To : Project_Node_Id);
727 pragma Inline (Set_Next_With_Clause_Of);
729 procedure Set_First_Declarative_Item_Of
730 (Node : Project_Node_Id;
731 In_Tree : Project_Node_Tree_Ref;
732 To : Project_Node_Id);
733 pragma Inline (Set_First_Declarative_Item_Of);
735 procedure Set_Extended_Project_Of
736 (Node : Project_Node_Id;
737 In_Tree : Project_Node_Tree_Ref;
738 To : Project_Node_Id);
739 pragma Inline (Set_Extended_Project_Of);
741 procedure Set_Current_Item_Node
742 (Node : Project_Node_Id;
743 In_Tree : Project_Node_Tree_Ref;
744 To : Project_Node_Id);
745 pragma Inline (Set_Current_Item_Node);
747 procedure Set_Next_Declarative_Item
748 (Node : Project_Node_Id;
749 In_Tree : Project_Node_Tree_Ref;
750 To : Project_Node_Id);
751 pragma Inline (Set_Next_Declarative_Item);
753 procedure Set_Project_Of_Renamed_Package_Of
754 (Node : Project_Node_Id;
755 In_Tree : Project_Node_Tree_Ref;
756 To : Project_Node_Id);
757 pragma Inline (Set_Project_Of_Renamed_Package_Of);
759 procedure Set_Next_Package_In_Project
760 (Node : Project_Node_Id;
761 In_Tree : Project_Node_Tree_Ref;
762 To : Project_Node_Id);
763 pragma Inline (Set_Next_Package_In_Project);
765 procedure Set_First_Literal_String
766 (Node : Project_Node_Id;
767 In_Tree : Project_Node_Tree_Ref;
768 To : Project_Node_Id);
769 pragma Inline (Set_First_Literal_String);
771 procedure Set_Next_String_Type
772 (Node : Project_Node_Id;
773 In_Tree : Project_Node_Tree_Ref;
774 To : Project_Node_Id);
775 pragma Inline (Set_Next_String_Type);
777 procedure Set_Next_Literal_String
778 (Node : Project_Node_Id;
779 In_Tree : Project_Node_Tree_Ref;
780 To : Project_Node_Id);
781 pragma Inline (Set_Next_Literal_String);
783 procedure Set_Expression_Of
784 (Node : Project_Node_Id;
785 In_Tree : Project_Node_Tree_Ref;
786 To : Project_Node_Id);
787 pragma Inline (Set_Expression_Of);
789 procedure Set_Associative_Project_Of
790 (Node : Project_Node_Id;
791 In_Tree : Project_Node_Tree_Ref;
792 To : Project_Node_Id);
793 pragma Inline (Set_Associative_Project_Of);
795 procedure Set_Associative_Package_Of
796 (Node : Project_Node_Id;
797 In_Tree : Project_Node_Tree_Ref;
798 To : Project_Node_Id);
799 pragma Inline (Set_Associative_Package_Of);
801 procedure Set_Associative_Array_Index_Of
802 (Node : Project_Node_Id;
803 In_Tree : Project_Node_Tree_Ref;
805 pragma Inline (Set_Associative_Array_Index_Of);
807 procedure Set_Next_Variable
808 (Node : Project_Node_Id;
809 In_Tree : Project_Node_Tree_Ref;
810 To : Project_Node_Id);
811 pragma Inline (Set_Next_Variable);
813 procedure Set_First_Term
814 (Node : Project_Node_Id;
815 In_Tree : Project_Node_Tree_Ref;
816 To : Project_Node_Id);
817 pragma Inline (Set_First_Term);
819 procedure Set_Next_Expression_In_List
820 (Node : Project_Node_Id;
821 In_Tree : Project_Node_Tree_Ref;
822 To : Project_Node_Id);
823 pragma Inline (Set_Next_Expression_In_List);
825 procedure Set_Current_Term
826 (Node : Project_Node_Id;
827 In_Tree : Project_Node_Tree_Ref;
828 To : Project_Node_Id);
829 pragma Inline (Set_Current_Term);
831 procedure Set_Next_Term
832 (Node : Project_Node_Id;
833 In_Tree : Project_Node_Tree_Ref;
834 To : Project_Node_Id);
835 pragma Inline (Set_Next_Term);
837 procedure Set_First_Expression_In_List
838 (Node : Project_Node_Id;
839 In_Tree : Project_Node_Tree_Ref;
840 To : Project_Node_Id);
841 pragma Inline (Set_First_Expression_In_List);
843 procedure Set_Package_Node_Of
844 (Node : Project_Node_Id;
845 In_Tree : Project_Node_Tree_Ref;
846 To : Project_Node_Id);
847 pragma Inline (Set_Package_Node_Of);
849 procedure Set_Source_Index_Of
850 (Node : Project_Node_Id;
851 In_Tree : Project_Node_Tree_Ref;
853 pragma Inline (Set_Source_Index_Of);
855 procedure Set_String_Type_Of
856 (Node : Project_Node_Id;
857 In_Tree : Project_Node_Tree_Ref;
858 To : Project_Node_Id);
859 pragma Inline (Set_String_Type_Of);
861 procedure Set_External_Reference_Of
862 (Node : Project_Node_Id;
863 In_Tree : Project_Node_Tree_Ref;
864 To : Project_Node_Id);
865 pragma Inline (Set_External_Reference_Of);
867 procedure Set_External_Default_Of
868 (Node : Project_Node_Id;
869 In_Tree : Project_Node_Tree_Ref;
870 To : Project_Node_Id);
871 pragma Inline (Set_External_Default_Of);
873 procedure Set_Case_Variable_Reference_Of
874 (Node : Project_Node_Id;
875 In_Tree : Project_Node_Tree_Ref;
876 To : Project_Node_Id);
877 pragma Inline (Set_Case_Variable_Reference_Of);
879 procedure Set_First_Case_Item_Of
880 (Node : Project_Node_Id;
881 In_Tree : Project_Node_Tree_Ref;
882 To : Project_Node_Id);
883 pragma Inline (Set_First_Case_Item_Of);
885 procedure Set_First_Choice_Of
886 (Node : Project_Node_Id;
887 In_Tree : Project_Node_Tree_Ref;
888 To : Project_Node_Id);
889 pragma Inline (Set_First_Choice_Of);
891 procedure Set_Next_Case_Item
892 (Node : Project_Node_Id;
893 In_Tree : Project_Node_Tree_Ref;
894 To : Project_Node_Id);
895 pragma Inline (Set_Next_Case_Item);
897 procedure Set_Case_Insensitive
898 (Node : Project_Node_Id;
899 In_Tree : Project_Node_Tree_Ref;
902 -------------------------------
903 -- Restricted Access Section --
904 -------------------------------
906 package Tree_Private_Part is
908 -- This is conceptually in the private part
910 -- However, for efficiency, some packages are accessing it directly
912 type Project_Node_Record is record
914 Kind : Project_Node_Kind;
916 Location : Source_Ptr := No_Location;
918 Directory : Path_Name_Type := No_Path;
919 -- Only for N_Project
921 Expr_Kind : Variable_Kind := Undefined;
922 -- See below for what Project_Node_Kind it is used
924 Variables : Variable_Node_Id := Empty_Node;
925 -- First variable in a project or a package
927 Packages : Package_Declaration_Id := Empty_Node;
928 -- First package declaration in a project
930 Pkg_Id : Package_Node_Id := Empty_Package;
931 -- Only used for N_Package_Declaration
932 -- The component Pkg_Id is an entry into the table Package_Attributes
933 -- (in Prj.Attr). It is used to indicate all the attributes of the
934 -- package with their characteristics.
936 -- The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes
937 -- are built once and for all through a call (from Prj.Initialize)
938 -- to procedure Prj.Attr.Initialize. It is never modified after that.
940 Name : Name_Id := No_Name;
941 -- See below for what Project_Node_Kind it is used
943 Src_Index : Int := 0;
944 -- Index of a unit in a multi-unit source.
945 -- Onli for some N_Attribute_Declaration and N_Literal_String.
947 Path_Name : Path_Name_Type := No_Path;
948 -- See below for what Project_Node_Kind it is used
950 Value : Name_Id := No_Name;
951 -- See below for what Project_Node_Kind it is used
953 Field1 : Project_Node_Id := Empty_Node;
954 -- See below the meaning for each Project_Node_Kind
956 Field2 : Project_Node_Id := Empty_Node;
957 -- See below the meaning for each Project_Node_Kind
959 Field3 : Project_Node_Id := Empty_Node;
960 -- See below the meaning for each Project_Node_Kind
962 Flag1 : Boolean := False;
963 -- This flag is significant only for:
964 -- N_Attribute_Declaration and N_Atribute_Reference
965 -- It indicates for an associative array attribute, that the
966 -- index is case insensitive.
967 -- N_Comment - it indicates that the comment is preceded by an
969 -- N_Project - it indicates that there are comments in the project
970 -- source that cannot be kept in the tree.
971 -- N_Project_Declaration
972 -- - it indicates that there are unkept comments in the
975 -- - it indicates that this is not the last with in a
976 -- with clause. It is set for "A", but not for "B" in
981 Flag2 : Boolean := False;
982 -- This flag is significant only for:
983 -- N_Project - it indicates that the project "extends all" another
985 -- N_Comment - it indicates that the comment is followed by an
988 -- - it indicates that the originally imported project
989 -- is an extending all project.
991 Comments : Project_Node_Id := Empty_Node;
992 -- For nodes other that N_Comment_Zones or N_Comment, designates the
993 -- comment zones associated with the node.
994 -- for N_Comment_Zones, designates the comment after the "end" of
996 -- For N_Comment, designates the next comment, if any.
1000 -- type Project_Node_Kind is
1003 -- -- Name: project name
1004 -- -- Path_Name: project path name
1005 -- -- Expr_Kind: Undefined
1006 -- -- Field1: first with clause
1007 -- -- Field2: project declaration
1008 -- -- Field3: first string type
1009 -- -- Value: extended project path name (if any)
1012 -- -- Name: imported project name
1013 -- -- Path_Name: imported project path name
1014 -- -- Expr_Kind: Undefined
1015 -- -- Field1: project node
1016 -- -- Field2: next with clause
1017 -- -- Field3: project node or empty if "limited with"
1018 -- -- Value: literal string withed
1020 -- N_Project_Declaration,
1021 -- -- Name: not used
1022 -- -- Path_Name: not used
1023 -- -- Expr_Kind: Undefined
1024 -- -- Field1: first declarative item
1025 -- -- Field2: extended project
1026 -- -- Field3: extending project
1027 -- -- Value: not used
1029 -- N_Declarative_Item,
1030 -- -- Name: not used
1031 -- -- Path_Name: not used
1032 -- -- Expr_Kind: Undefined
1033 -- -- Field1: current item node
1034 -- -- Field2: next declarative item
1035 -- -- Field3: not used
1036 -- -- Value: not used
1038 -- N_Package_Declaration,
1039 -- -- Name: package name
1040 -- -- Path_Name: not used
1041 -- -- Expr_Kind: Undefined
1042 -- -- Field1: project of renamed package (if any)
1043 -- -- Field2: first declarative item
1044 -- -- Field3: next package in project
1045 -- -- Value: not used
1047 -- N_String_Type_Declaration,
1048 -- -- Name: type name
1049 -- -- Path_Name: not used
1050 -- -- Expr_Kind: Undefined
1051 -- -- Field1: first literal string
1052 -- -- Field2: next string type
1053 -- -- Field3: not used
1054 -- -- Value: not used
1056 -- N_Literal_String,
1057 -- -- Name: not used
1058 -- -- Path_Name: not used
1059 -- -- Expr_Kind: Single
1060 -- -- Field1: next literal string
1061 -- -- Field2: not used
1062 -- -- Field3: not used
1063 -- -- Value: string value
1065 -- N_Attribute_Declaration,
1066 -- -- Name: attribute name
1067 -- -- Path_Name: not used
1068 -- -- Expr_Kind: attribute kind
1069 -- -- Field1: expression
1070 -- -- Field2: project of full associative array
1071 -- -- Field3: package of full associative array
1072 -- -- Value: associative array index
1073 -- -- (if an associative array element)
1075 -- N_Typed_Variable_Declaration,
1076 -- -- Name: variable name
1077 -- -- Path_Name: not used
1078 -- -- Expr_Kind: Single
1079 -- -- Field1: expression
1080 -- -- Field2: type of variable (N_String_Type_Declaration)
1081 -- -- Field3: next variable
1082 -- -- Value: not used
1084 -- N_Variable_Declaration,
1085 -- -- Name: variable name
1086 -- -- Path_Name: not used
1087 -- -- Expr_Kind: variable kind
1088 -- -- Field1: expression
1089 -- -- Field2: not used
1090 -- -- Field3 is used for next variable, instead of Field2,
1091 -- -- so that it is the same field for
1092 -- -- N_Variable_Declaration and
1093 -- -- N_Typed_Variable_Declaration
1094 -- -- Field3: next variable
1095 -- -- Value: not used
1098 -- -- Name: not used
1099 -- -- Path_Name: not used
1100 -- -- Expr_Kind: expression kind
1101 -- -- Field1: first term
1102 -- -- Field2: next expression in list
1103 -- -- Field3: not used
1104 -- -- Value: not used
1107 -- -- Name: not used
1108 -- -- Path_Name: not used
1109 -- -- Expr_Kind: term kind
1110 -- -- Field1: current term
1111 -- -- Field2: next term in the expression
1112 -- -- Field3: not used
1113 -- -- Value: not used
1115 -- N_Literal_String_List,
1116 -- -- Designates a list of string expressions between brackets
1117 -- -- separated by commas. The string expressions are not necessarily
1118 -- -- literal strings.
1119 -- -- Name: not used
1120 -- -- Path_Name: not used
1121 -- -- Expr_Kind: List
1122 -- -- Field1: first expression
1123 -- -- Field2: not used
1124 -- -- Field3: not used
1125 -- -- Value: not used
1127 -- N_Variable_Reference,
1128 -- -- Name: variable name
1129 -- -- Path_Name: not used
1130 -- -- Expr_Kind: variable kind
1131 -- -- Field1: project (if specified)
1132 -- -- Field2: package (if specified)
1133 -- -- Field3: type of variable (N_String_Type_Declaration), if any
1134 -- -- Value: not used
1136 -- N_External_Value,
1137 -- -- Name: not used
1138 -- -- Path_Name: not used
1139 -- -- Expr_Kind: Single
1140 -- -- Field1: Name of the external reference (literal string)
1141 -- -- Field2: Default (literal string)
1142 -- -- Field3: not used
1143 -- -- Value: not used
1145 -- N_Attribute_Reference,
1146 -- -- Name: attribute name
1147 -- -- Path_Name: not used
1148 -- -- Expr_Kind: attribute kind
1149 -- -- Field1: project
1150 -- -- Field2: package (if attribute of a package)
1151 -- -- Field3: not used
1152 -- -- Value: associative array index
1153 -- -- (if an associative array element)
1155 -- N_Case_Construction,
1156 -- -- Name: not used
1157 -- -- Path_Name: not used
1158 -- -- Expr_Kind: Undefined
1159 -- -- Field1: case variable reference
1160 -- -- Field2: first case item
1161 -- -- Field3: not used
1162 -- -- Value: not used
1165 -- -- Name: not used
1166 -- -- Path_Name: not used
1167 -- -- Expr_Kind: not used
1168 -- -- Field1: first choice (literal string), or Empty_Node
1169 -- -- for when others
1170 -- -- Field2: first declarative item
1171 -- -- Field3: next case item
1172 -- -- Value: not used
1175 -- -- Name: not used
1176 -- -- Path_Name: not used
1177 -- -- Expr_Kind: not used
1178 -- -- Field1: comment before the construct
1179 -- -- Field2: comment after the construct
1180 -- -- Field3: comment before the "end" of the construct
1181 -- -- Value: end of line comment
1182 -- -- Comments: comment after the "end" of the construct
1185 -- -- Name: not used
1186 -- -- Path_Name: not used
1187 -- -- Expr_Kind: not used
1188 -- -- Field1: not used
1189 -- -- Field2: not used
1190 -- -- Field3: not used
1191 -- -- Value: comment
1192 -- -- Flag1: comment is preceded by an empty line
1193 -- -- Flag2: comment is followed by an empty line
1194 -- -- Comments: next comment
1196 package Project_Node_Table is
1197 new GNAT.Dynamic_Tables
1198 (Table_Component_Type => Project_Node_Record,
1199 Table_Index_Type => Project_Node_Id,
1200 Table_Low_Bound => First_Node_Id,
1201 Table_Initial => Project_Nodes_Initial,
1202 Table_Increment => Project_Nodes_Increment);
1203 -- This table contains the syntactic tree of project data
1204 -- from project files.
1206 type Project_Name_And_Node is record
1208 -- Name of the project
1210 Node : Project_Node_Id;
1211 -- Node of the project in table Project_Nodes
1213 Canonical_Path : Path_Name_Type;
1214 -- Resolved and canonical path of a real project file.
1215 -- No_Name in case of virtual projects.
1218 -- True when the project is being extended by another project
1221 No_Project_Name_And_Node : constant Project_Name_And_Node :=
1224 Canonical_Path => No_Path,
1227 package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable
1228 (Header_Num => Header_Num,
1229 Element => Project_Name_And_Node,
1230 No_Element => No_Project_Name_And_Node,
1234 -- This hash table contains a mapping of project names to project nodes.
1235 -- Note that this hash table contains only the nodes whose Kind is
1236 -- N_Project. It is used to find the node of a project from its name,
1237 -- and to verify if a project has already been parsed, knowing its name.
1239 end Tree_Private_Part;
1241 type Project_Node_Tree_Data is record
1242 Project_Nodes : Tree_Private_Part.Project_Node_Table.Instance;
1243 Projects_HT : Tree_Private_Part.Projects_Htable.Instance;
1245 -- The data for a project node tree
1248 type Comment_Array is array (Positive range <>) of Comment_Data;
1249 type Comments_Ptr is access Comment_Array;
1251 type Comment_State is record
1252 End_Of_Line_Node : Project_Node_Id := Empty_Node;
1254 Previous_Line_Node : Project_Node_Id := Empty_Node;
1256 Previous_End_Node : Project_Node_Id := Empty_Node;
1258 Unkept_Comments : Boolean := False;
1260 Comments : Comments_Ptr := null;