1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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.
31 with Prj.Attr; use Prj.Attr;
32 with Prj.Com; use Prj.Com;
33 with Table; use Table;
34 with Types; use Types;
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
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)
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
51 Empty_Node : constant Project_Node_Id := Project_Node_Low_Bound;
52 -- Designates no node in table Project_Nodes
54 First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound + 1;
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.
61 subtype Package_Declaration_Id is Project_Node_Id;
62 -- Used to designate a node whose expected kind is N_Proect_Declaration
64 type Project_Node_Kind is
67 N_Project_Declaration,
69 N_Package_Declaration,
70 N_String_Type_Declaration,
72 N_Attribute_Declaration,
73 N_Typed_Variable_Declaration,
74 N_Variable_Declaration,
77 N_Literal_String_List,
80 N_Attribute_Reference,
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.
90 -- Initialize the Project File tree: empty the Project_Nodes table
91 -- and reset the Projects_Htable.
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.
99 function Hash (N : Project_Node_Id) return Header_Num;
100 -- Used for hash tables where the key is a Project_Node_Id
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.
112 type Comment_State is private;
113 -- A type to store the values of several global variables related to
116 procedure Save (S : out Comment_State);
117 -- Save in variable S the comment state. Called before scanning a new
120 procedure Restore (S : in Comment_State);
121 -- Restore the comment state to a previously saved value. Called after
122 -- scanning a project file.
124 procedure Reset_State;
125 -- Set the comment state to its initial value. Called before scanning a
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.
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
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.
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.
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
152 procedure Remove_Next_End_Node;
153 -- Remove the top of the end node stack.
155 ------------------------
156 -- Comment Processing --
157 ------------------------
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;
165 package Comments is new Table.Table
166 (Table_Component_Type => Comment_Data,
167 Table_Index_Type => Natural,
168 Table_Low_Bound => 1,
170 Table_Increment => 100,
171 Table_Name => "Prj.Tree.Comments");
172 -- A table to store the comments that may be stored is the tree
175 -- Scan the tokens and accumulate comments.
177 type Comment_Location is
178 (Before, After, Before_End, After_End, End_Of_Line);
180 procedure Add_Comments (To : Project_Node_Id; Where : Comment_Location);
181 -- Add comments to this node.
183 ----------------------
184 -- Access Functions --
185 ----------------------
187 -- The following query functions are part of the abstract interface
188 -- of the Project File tree
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
195 function Kind_Of (Node : Project_Node_Id) return Project_Node_Kind;
196 pragma Inline (Kind_Of);
197 -- Valid for all non empty nodes
199 function Location_Of (Node : Project_Node_Id) return Source_Ptr;
200 pragma Inline (Location_Of);
201 -- Valid for all non empty nodes
203 function First_Comment_After
204 (Node : Project_Node_Id) return Project_Node_Id;
205 -- Valid only for N_Comment_Zones nodes
207 function First_Comment_After_End
208 (Node : Project_Node_Id) return Project_Node_Id;
209 -- Valid only for N_Comment_Zones nodes
211 function First_Comment_Before
212 (Node : Project_Node_Id) return Project_Node_Id;
213 -- Valid only for N_Comment_Zones nodes
215 function First_Comment_Before_End
216 (Node : Project_Node_Id) return Project_Node_Id;
217 -- Valid only for N_Comment_Zones nodes
219 function Next_Comment (Node : Project_Node_Id) return Project_Node_Id;
220 -- Valid only for N_Comment nodes
222 function End_Of_Line_Comment (Node : Project_Node_Id) return Name_Id;
223 -- Valid only for non empty nodes
225 function Follows_Empty_Line (Node : Project_Node_Id) return Boolean;
226 -- Valid only for N_Comment nodes
228 function Is_Followed_By_Empty_Line (Node : Project_Node_Id) return Boolean;
229 -- Valid only for N_Comment nodes
231 function Project_File_Includes_Unkept_Comments
232 (Node : Project_Node_Id)
234 -- Valid only for N_Project nodes
236 function Directory_Of (Node : Project_Node_Id) return Name_Id;
237 pragma Inline (Directory_Of);
238 -- Only valid for N_Project nodes.
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.
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
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
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
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
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.
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
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
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
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
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
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
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.
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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.
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.
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
399 (Node : Project_Node_Id) return Project_Node_Id;
400 pragma Inline (First_Term);
401 -- Only valid for N_Expression nodes
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
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
414 (Node : Project_Node_Id) return Project_Node_Id;
415 pragma Inline (Next_Term);
416 -- Only valid for N_Term nodes
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
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.
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
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
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
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
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
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.
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
466 function Case_Insensitive (Node : Project_Node_Id) return Boolean;
467 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
473 -- The following procedures are part of the abstract interface of
474 -- the Project File tree.
476 -- Each Set_* procedure is valid only for the same Project_Node_Kind
477 -- nodes as the corresponding query function above.
479 procedure Set_Name_Of
480 (Node : Project_Node_Id;
482 pragma Inline (Set_Name_Of);
484 procedure Set_Kind_Of
485 (Node : Project_Node_Id;
486 To : Project_Node_Kind);
487 pragma Inline (Set_Kind_Of);
489 procedure Set_Location_Of
490 (Node : Project_Node_Id;
492 pragma Inline (Set_Location_Of);
494 procedure Set_First_Comment_After
495 (Node : Project_Node_Id;
496 To : Project_Node_Id);
497 pragma Inline (Set_First_Comment_After);
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);
504 procedure Set_First_Comment_Before
505 (Node : Project_Node_Id;
506 To : Project_Node_Id);
507 pragma Inline (Set_First_Comment_Before);
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);
514 procedure Set_Next_Comment
515 (Node : Project_Node_Id;
516 To : Project_Node_Id);
517 pragma Inline (Set_Next_Comment);
519 procedure Set_Project_File_Includes_Unkept_Comments
520 (Node : Project_Node_Id;
523 procedure Set_Directory_Of
524 (Node : Project_Node_Id;
526 pragma Inline (Set_Directory_Of);
528 procedure Set_Expression_Kind_Of
529 (Node : Project_Node_Id;
531 pragma Inline (Set_Expression_Kind_Of);
533 procedure Set_Is_Extending_All (Node : Project_Node_Id);
534 pragma Inline (Set_Is_Extending_All);
536 procedure Set_First_Variable_Of
537 (Node : Project_Node_Id;
538 To : Variable_Node_Id);
539 pragma Inline (Set_First_Variable_Of);
541 procedure Set_First_Package_Of
542 (Node : Project_Node_Id;
543 To : Package_Declaration_Id);
544 pragma Inline (Set_First_Package_Of);
546 procedure Set_Package_Id_Of
547 (Node : Project_Node_Id;
548 To : Package_Node_Id);
549 pragma Inline (Set_Package_Id_Of);
551 procedure Set_Path_Name_Of
552 (Node : Project_Node_Id;
554 pragma Inline (Set_Path_Name_Of);
556 procedure Set_String_Value_Of
557 (Node : Project_Node_Id;
559 pragma Inline (Set_String_Value_Of);
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);
566 procedure Set_Project_Declaration_Of
567 (Node : Project_Node_Id;
568 To : Project_Node_Id);
569 pragma Inline (Set_Project_Declaration_Of);
571 procedure Set_Extending_Project_Of
572 (Node : Project_Node_Id;
573 To : Project_Node_Id);
574 pragma Inline (Set_Extending_Project_Of);
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);
581 procedure Set_Extended_Project_Path_Of
582 (Node : Project_Node_Id;
584 pragma Inline (Set_Extended_Project_Path_Of);
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);
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);
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);
602 procedure Set_Extended_Project_Of
603 (Node : Project_Node_Id;
604 To : Project_Node_Id);
605 pragma Inline (Set_Extended_Project_Of);
607 procedure Set_Current_Item_Node
608 (Node : Project_Node_Id;
609 To : Project_Node_Id);
610 pragma Inline (Set_Current_Item_Node);
612 procedure Set_Next_Declarative_Item
613 (Node : Project_Node_Id;
614 To : Project_Node_Id);
615 pragma Inline (Set_Next_Declarative_Item);
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);
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);
627 procedure Set_First_Literal_String
628 (Node : Project_Node_Id;
629 To : Project_Node_Id);
630 pragma Inline (Set_First_Literal_String);
632 procedure Set_Next_String_Type
633 (Node : Project_Node_Id;
634 To : Project_Node_Id);
635 pragma Inline (Set_Next_String_Type);
637 procedure Set_Next_Literal_String
638 (Node : Project_Node_Id;
639 To : Project_Node_Id);
640 pragma Inline (Set_Next_Literal_String);
642 procedure Set_Expression_Of
643 (Node : Project_Node_Id;
644 To : Project_Node_Id);
645 pragma Inline (Set_Expression_Of);
647 procedure Set_Associative_Project_Of
648 (Node : Project_Node_Id;
649 To : Project_Node_Id);
650 pragma Inline (Set_Associative_Project_Of);
652 procedure Set_Associative_Package_Of
653 (Node : Project_Node_Id;
654 To : Project_Node_Id);
655 pragma Inline (Set_Associative_Package_Of);
657 procedure Set_Associative_Array_Index_Of
658 (Node : Project_Node_Id;
660 pragma Inline (Set_Associative_Array_Index_Of);
662 procedure Set_Next_Variable
663 (Node : Project_Node_Id;
664 To : Project_Node_Id);
665 pragma Inline (Set_Next_Variable);
667 procedure Set_First_Term
668 (Node : Project_Node_Id;
669 To : Project_Node_Id);
670 pragma Inline (Set_First_Term);
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);
677 procedure Set_Current_Term
678 (Node : Project_Node_Id;
679 To : Project_Node_Id);
680 pragma Inline (Set_Current_Term);
682 procedure Set_Next_Term
683 (Node : Project_Node_Id;
684 To : Project_Node_Id);
685 pragma Inline (Set_Next_Term);
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);
692 procedure Set_Package_Node_Of
693 (Node : Project_Node_Id;
694 To : Project_Node_Id);
695 pragma Inline (Set_Package_Node_Of);
697 procedure Set_String_Type_Of
698 (Node : Project_Node_Id;
699 To : Project_Node_Id);
700 pragma Inline (Set_String_Type_Of);
702 procedure Set_External_Reference_Of
703 (Node : Project_Node_Id;
704 To : Project_Node_Id);
705 pragma Inline (Set_External_Reference_Of);
707 procedure Set_External_Default_Of
708 (Node : Project_Node_Id;
709 To : Project_Node_Id);
710 pragma Inline (Set_External_Default_Of);
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);
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);
722 procedure Set_First_Choice_Of
723 (Node : Project_Node_Id;
724 To : Project_Node_Id);
725 pragma Inline (Set_First_Choice_Of);
727 procedure Set_Next_Case_Item
728 (Node : Project_Node_Id;
729 To : Project_Node_Id);
730 pragma Inline (Set_Next_Case_Item);
732 procedure Set_Case_Insensitive
733 (Node : Project_Node_Id;
736 -------------------------------
737 -- Restricted Access Section --
738 -------------------------------
740 package Tree_Private_Part is
742 -- This is conceptually in the private part.
743 -- However, for efficiency, some packages are accessing it directly.
745 type Project_Node_Record is record
747 Kind : Project_Node_Kind;
749 Location : Source_Ptr := No_Location;
751 Directory : Name_Id := No_Name;
752 -- Only for N_Project
754 Expr_Kind : Variable_Kind := Undefined;
755 -- See below for what Project_Node_Kind it is used
757 Variables : Variable_Node_Id := Empty_Node;
758 -- First variable in a project or a package
760 Packages : Package_Declaration_Id := Empty_Node;
761 -- First package declaration in a project
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.
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.
773 Name : Name_Id := No_Name;
774 -- See below for what Project_Node_Kind it is used
776 Path_Name : Name_Id := No_Name;
777 -- See below for what Project_Node_Kind it is used
779 Value : Name_Id := No_Name;
780 -- See below for what Project_Node_Kind it is used
782 Field1 : Project_Node_Id := Empty_Node;
783 -- See below the meaning for each Project_Node_Kind
785 Field2 : Project_Node_Id := Empty_Node;
786 -- See below the meaning for each Project_Node_Kind
788 Field3 : Project_Node_Id := Empty_Node;
789 -- See below the meaning for each Project_Node_Kind
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
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
804 Flag2 : Boolean := False;
805 -- This flag is significant only for:
806 -- N_Project - it indicates that the project "extends all" another
808 -- N_Comment - it indicates that the comment is followed by an
811 -- - it indicates that the originally imported project
812 -- is an extending all project.
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
819 -- For N_Comment, designates the next comment, if any.
823 -- type Project_Node_Kind is
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)
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
843 -- N_Project_Declaration,
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
852 -- N_Declarative_Item,
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
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
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
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
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)
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
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
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
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
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.
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
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
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
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)
978 -- N_Case_Construction,
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
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
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
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
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.
1029 type Project_Name_And_Node is record
1031 -- Name of the project
1033 Node : Project_Node_Id;
1034 -- Node of the project in table Project_Nodes
1037 -- True when the project is being extended by another project
1040 No_Project_Name_And_Node : constant Project_Name_And_Node :=
1041 (Name => No_Name, Node => Empty_Node, Extended => True);
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,
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
1056 end Tree_Private_Part;
1059 type Comment_Array is array (Positive range <>) of Comment_Data;
1060 type Comments_Ptr is access Comment_Array;
1062 type Comment_State is record
1063 End_Of_Line_Node : Project_Node_Id := Empty_Node;
1065 Previous_Line_Node : Project_Node_Id := Empty_Node;
1067 Previous_End_Node : Project_Node_Id := Empty_Node;
1069 Unkept_Comments : Boolean := False;
1071 Comments : Comments_Ptr := null;