1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2005 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
;
32 with Prj
.Attr
; use Prj
.Attr
;
36 type Project_Node_Tree_Data
;
37 type Project_Node_Tree_Ref
is access all Project_Node_Tree_Data
;
38 -- Type to designate a project node tree, so that several project node
39 -- trees can coexist in memory.
41 Project_Nodes_Initial
: constant := 1_000
;
42 Project_Nodes_Increment
: constant := 100;
43 -- Allocation parameters for initializing and extending number
44 -- of nodes in table Tree_Private_Part.Project_Nodes
46 Project_Node_Low_Bound
: constant := 0;
47 Project_Node_High_Bound
: constant := 099_999_999
;
48 -- Range of values for project node id's (in practice infinite)
50 type Project_Node_Id
is range
51 Project_Node_Low_Bound
.. Project_Node_High_Bound
;
52 -- The index of table Tree_Private_Part.Project_Nodes
54 Empty_Node
: constant Project_Node_Id
:= Project_Node_Low_Bound
;
55 -- Designates no node in table Project_Nodes
57 First_Node_Id
: constant Project_Node_Id
:= Project_Node_Low_Bound
+ 1;
59 subtype Variable_Node_Id
is Project_Node_Id
;
60 -- Used to designate a node whose expected kind is one of
61 -- N_Typed_Variable_Declaration, N_Variable_Declaration or
62 -- N_Variable_Reference.
64 subtype Package_Declaration_Id
is Project_Node_Id
;
65 -- Used to designate a node whose expected kind is N_Proect_Declaration
67 type Project_Node_Kind
is
70 N_Project_Declaration
,
72 N_Package_Declaration
,
73 N_String_Type_Declaration
,
75 N_Attribute_Declaration
,
76 N_Typed_Variable_Declaration
,
77 N_Variable_Declaration
,
80 N_Literal_String_List
,
83 N_Attribute_Reference
,
88 -- Each node in the tree is of a Project_Node_Kind
89 -- For the signification of the fields in each node of a
90 -- Project_Node_Kind, look at package Tree_Private_Part.
92 procedure Initialize
(Tree
: Project_Node_Tree_Ref
);
93 -- Initialize the Project File tree: empty the Project_Nodes table
94 -- and reset the Projects_Htable.
96 function Default_Project_Node
97 (In_Tree
: Project_Node_Tree_Ref
;
98 Of_Kind
: Project_Node_Kind
;
99 And_Expr_Kind
: Variable_Kind
:= Undefined
) return Project_Node_Id
;
100 -- Returns a Project_Node_Record with the specified Kind and
101 -- Expr_Kind; all the other components have default nil values.
103 function Hash
(N
: Project_Node_Id
) return Header_Num
;
104 -- Used for hash tables where the key is a Project_Node_Id
106 function Imported_Or_Extended_Project_Of
107 (Project
: Project_Node_Id
;
108 In_Tree
: Project_Node_Tree_Ref
;
109 With_Name
: Name_Id
) return Project_Node_Id
;
110 -- Return the node of a project imported or extended by project Project and
111 -- whose name is With_Name. Return Empty_Node if there is no such project.
117 type Comment_State
is private;
118 -- A type to store the values of several global variables related to
121 procedure Save
(S
: out Comment_State
);
122 -- Save in variable S the comment state. Called before scanning a new
125 procedure Restore
(S
: in Comment_State
);
126 -- Restore the comment state to a previously saved value. Called after
127 -- scanning a project file.
129 procedure Reset_State
;
130 -- Set the comment state to its initial value. Called before scanning a
133 function There_Are_Unkept_Comments
return Boolean;
134 -- Indicates that some of the comments in a project file could not be
135 -- stored in the parse tree.
137 procedure Set_Previous_Line_Node
(To
: Project_Node_Id
);
138 -- Indicate the node on the previous line. If there are comments
139 -- immediately following this line, then they should be associated with
142 procedure Set_Previous_End_Node
(To
: Project_Node_Id
);
143 -- Indicate that on the previous line the "end" belongs to node To.
144 -- If there are comments immediately following this "end" line, they
145 -- should be associated with this node.
147 procedure Set_End_Of_Line
(To
: Project_Node_Id
);
148 -- Indicate the node on the current line. If there is an end of line
149 -- comment, then it should be associated with this node.
151 procedure Set_Next_End_Node
(To
: Project_Node_Id
);
152 -- Put node To on the top of the end node stack. When an "end" line
153 -- is found with this node on the top of the end node stack, the comments,
154 -- if any, immediately preceding this "end" line will be associated with
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;
170 package Comments
is new Table
.Table
171 (Table_Component_Type
=> Comment_Data
,
172 Table_Index_Type
=> Natural,
173 Table_Low_Bound
=> 1,
175 Table_Increment
=> 100,
176 Table_Name
=> "Prj.Tree.Comments");
177 -- A table to store the comments that may be stored is the tree
179 procedure Scan
(In_Tree
: Project_Node_Tree_Ref
);
180 -- Scan the tokens and accumulate comments
182 type Comment_Location
is
183 (Before
, After
, Before_End
, After_End
, End_Of_Line
);
185 procedure Add_Comments
186 (To
: Project_Node_Id
;
187 In_Tree
: Project_Node_Tree_Ref
;
188 Where
: Comment_Location
);
189 -- Add comments to this node
191 ----------------------
192 -- Access Functions --
193 ----------------------
195 -- The following query functions are part of the abstract interface
196 -- of the Project File tree
199 (Node
: Project_Node_Id
;
200 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
201 pragma Inline
(Name_Of
);
202 -- Valid for all non empty nodes. May return No_Name for nodes that have
206 (Node
: Project_Node_Id
;
207 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Kind
;
208 pragma Inline
(Kind_Of
);
209 -- Valid for all non empty nodes
212 (Node
: Project_Node_Id
;
213 In_Tree
: Project_Node_Tree_Ref
) return Source_Ptr
;
214 pragma Inline
(Location_Of
);
215 -- Valid for all non empty nodes
217 function First_Comment_After
218 (Node
: Project_Node_Id
;
219 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
220 -- Valid only for N_Comment_Zones nodes
222 function First_Comment_After_End
223 (Node
: Project_Node_Id
;
224 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
225 -- Valid only for N_Comment_Zones nodes
227 function First_Comment_Before
228 (Node
: Project_Node_Id
;
229 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
230 -- Valid only for N_Comment_Zones nodes
232 function First_Comment_Before_End
233 (Node
: Project_Node_Id
;
234 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
235 -- Valid only for N_Comment_Zones nodes
237 function Next_Comment
238 (Node
: Project_Node_Id
;
239 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
240 -- Valid only for N_Comment nodes
242 function End_Of_Line_Comment
243 (Node
: Project_Node_Id
;
244 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
245 -- Valid only for non empty nodes
247 function Follows_Empty_Line
248 (Node
: Project_Node_Id
;
249 In_Tree
: Project_Node_Tree_Ref
) return Boolean;
250 -- Valid only for N_Comment nodes
252 function Is_Followed_By_Empty_Line
253 (Node
: Project_Node_Id
;
254 In_Tree
: Project_Node_Tree_Ref
) return Boolean;
255 -- Valid only for N_Comment nodes
257 function Project_File_Includes_Unkept_Comments
258 (Node
: Project_Node_Id
;
259 In_Tree
: Project_Node_Tree_Ref
)
261 -- Valid only for N_Project nodes
263 function Directory_Of
264 (Node
: Project_Node_Id
;
265 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
266 pragma Inline
(Directory_Of
);
267 -- Only valid for N_Project nodes
269 function Expression_Kind_Of
270 (Node
: Project_Node_Id
;
271 In_Tree
: Project_Node_Tree_Ref
) return Variable_Kind
;
272 pragma Inline
(Expression_Kind_Of
);
273 -- Only valid for N_Literal_String, N_Attribute_Declaration,
274 -- N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
275 -- N_Term, N_Variable_Reference or N_Attribute_Reference nodes.
277 function Is_Extending_All
278 (Node
: Project_Node_Id
;
279 In_Tree
: Project_Node_Tree_Ref
) return Boolean;
280 pragma Inline
(Is_Extending_All
);
281 -- Only valid for N_Project and N_With_Clause
283 function Is_Not_Last_In_List
284 (Node
: Project_Node_Id
;
285 In_Tree
: Project_Node_Tree_Ref
) return Boolean;
286 pragma Inline
(Is_Not_Last_In_List
);
287 -- Only valid for N_With_Clause
289 function First_Variable_Of
290 (Node
: Project_Node_Id
;
291 In_Tree
: Project_Node_Tree_Ref
) return Variable_Node_Id
;
292 pragma Inline
(First_Variable_Of
);
293 -- Only valid for N_Project or N_Package_Declaration nodes
295 function First_Package_Of
296 (Node
: Project_Node_Id
;
297 In_Tree
: Project_Node_Tree_Ref
) return Package_Declaration_Id
;
298 pragma Inline
(First_Package_Of
);
299 -- Only valid for N_Project nodes
301 function Package_Id_Of
302 (Node
: Project_Node_Id
;
303 In_Tree
: Project_Node_Tree_Ref
) return Package_Node_Id
;
304 pragma Inline
(Package_Id_Of
);
305 -- Only valid for N_Package_Declaration nodes
307 function Path_Name_Of
308 (Node
: Project_Node_Id
;
309 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
310 pragma Inline
(Path_Name_Of
);
311 -- Only valid for N_Project and N_With_Clause nodes
313 function String_Value_Of
314 (Node
: Project_Node_Id
;
315 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
316 pragma Inline
(String_Value_Of
);
317 -- Only valid for N_With_Clause, N_Literal_String nodes or N_Comment
319 function Source_Index_Of
320 (Node
: Project_Node_Id
;
321 In_Tree
: Project_Node_Tree_Ref
) return Int
;
322 pragma Inline
(Source_Index_Of
);
323 -- Only valid for N_Literal_String and N_Attribute_Declaration nodes
325 function First_With_Clause_Of
326 (Node
: Project_Node_Id
;
327 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
328 pragma Inline
(First_With_Clause_Of
);
329 -- Only valid for N_Project nodes
331 function Project_Declaration_Of
332 (Node
: Project_Node_Id
;
333 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
334 pragma Inline
(Project_Declaration_Of
);
335 -- Only valid for N_Project nodes
337 function Extending_Project_Of
338 (Node
: Project_Node_Id
;
339 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
340 pragma Inline
(Extending_Project_Of
);
341 -- Only valid for N_Project_Declaration nodes
343 function First_String_Type_Of
344 (Node
: Project_Node_Id
;
345 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
346 pragma Inline
(First_String_Type_Of
);
347 -- Only valid for N_Project nodes
349 function Extended_Project_Path_Of
350 (Node
: Project_Node_Id
;
351 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
352 pragma Inline
(Extended_Project_Path_Of
);
353 -- Only valid for N_With_Clause nodes
355 function Project_Node_Of
356 (Node
: Project_Node_Id
;
357 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
358 pragma Inline
(Project_Node_Of
);
359 -- Only valid for N_With_Clause, N_Variable_Reference and
360 -- N_Attribute_Reference nodes.
362 function Non_Limited_Project_Node_Of
363 (Node
: Project_Node_Id
;
364 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
365 pragma Inline
(Non_Limited_Project_Node_Of
);
366 -- Only valid for N_With_Clause nodes. Returns Empty_Node for limited
367 -- imported project files, otherwise returns the same result as
370 function Next_With_Clause_Of
371 (Node
: Project_Node_Id
;
372 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
373 pragma Inline
(Next_With_Clause_Of
);
374 -- Only valid for N_With_Clause nodes
376 function First_Declarative_Item_Of
377 (Node
: Project_Node_Id
;
378 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
379 pragma Inline
(First_Declarative_Item_Of
);
380 -- Only valid for N_With_Clause nodes
382 function Extended_Project_Of
383 (Node
: Project_Node_Id
;
384 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
385 pragma Inline
(Extended_Project_Of
);
386 -- Only valid for N_Project_Declaration nodes
388 function Current_Item_Node
389 (Node
: Project_Node_Id
;
390 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
391 pragma Inline
(Current_Item_Node
);
392 -- Only valid for N_Declarative_Item nodes
394 function Next_Declarative_Item
395 (Node
: Project_Node_Id
;
396 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
397 pragma Inline
(Next_Declarative_Item
);
398 -- Only valid for N_Declarative_Item node
400 function Project_Of_Renamed_Package_Of
401 (Node
: Project_Node_Id
;
402 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
403 pragma Inline
(Project_Of_Renamed_Package_Of
);
404 -- Only valid for N_Package_Declaration nodes.
405 -- May return Empty_Node.
407 function Next_Package_In_Project
408 (Node
: Project_Node_Id
;
409 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
410 pragma Inline
(Next_Package_In_Project
);
411 -- Only valid for N_Package_Declaration nodes
413 function First_Literal_String
414 (Node
: Project_Node_Id
;
415 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
416 pragma Inline
(First_Literal_String
);
417 -- Only valid for N_String_Type_Declaration nodes
419 function Next_String_Type
420 (Node
: Project_Node_Id
;
421 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
422 pragma Inline
(Next_String_Type
);
423 -- Only valid for N_String_Type_Declaration nodes
425 function Next_Literal_String
426 (Node
: Project_Node_Id
;
427 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
428 pragma Inline
(Next_Literal_String
);
429 -- Only valid for N_Literal_String nodes
431 function Expression_Of
432 (Node
: Project_Node_Id
;
433 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
434 pragma Inline
(Expression_Of
);
435 -- Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
436 -- or N_Variable_Declaration nodes
438 function Associative_Project_Of
439 (Node
: Project_Node_Id
;
440 In_Tree
: Project_Node_Tree_Ref
)
441 return Project_Node_Id
;
442 pragma Inline
(Associative_Project_Of
);
443 -- Only valid for N_Attribute_Declaration nodes
445 function Associative_Package_Of
446 (Node
: Project_Node_Id
;
447 In_Tree
: Project_Node_Tree_Ref
)
448 return Project_Node_Id
;
449 pragma Inline
(Associative_Package_Of
);
450 -- Only valid for N_Attribute_Declaration nodes
452 function Value_Is_Valid
453 (For_Typed_Variable
: Project_Node_Id
;
454 In_Tree
: Project_Node_Tree_Ref
;
455 Value
: Name_Id
) return Boolean;
456 pragma Inline
(Value_Is_Valid
);
457 -- Only valid for N_Typed_Variable_Declaration. Returns True if Value is
458 -- in the list of allowed strings for For_Typed_Variable. False otherwise.
460 function Associative_Array_Index_Of
461 (Node
: Project_Node_Id
;
462 In_Tree
: Project_Node_Tree_Ref
) return Name_Id
;
463 pragma Inline
(Associative_Array_Index_Of
);
464 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference.
465 -- Returns No_String for non associative array attributes.
467 function Next_Variable
468 (Node
: Project_Node_Id
;
469 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
470 pragma Inline
(Next_Variable
);
471 -- Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
475 (Node
: Project_Node_Id
;
476 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
477 pragma Inline
(First_Term
);
478 -- Only valid for N_Expression nodes
480 function Next_Expression_In_List
481 (Node
: Project_Node_Id
;
482 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
483 pragma Inline
(Next_Expression_In_List
);
484 -- Only valid for N_Expression nodes
486 function Current_Term
487 (Node
: Project_Node_Id
;
488 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
489 pragma Inline
(Current_Term
);
490 -- Only valid for N_Term nodes
493 (Node
: Project_Node_Id
;
494 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
495 pragma Inline
(Next_Term
);
496 -- Only valid for N_Term nodes
498 function First_Expression_In_List
499 (Node
: Project_Node_Id
;
500 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
501 pragma Inline
(First_Expression_In_List
);
502 -- Only valid for N_Literal_String_List nodes
504 function Package_Node_Of
505 (Node
: Project_Node_Id
;
506 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
507 pragma Inline
(Package_Node_Of
);
508 -- Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
509 -- May return Empty_Node.
511 function String_Type_Of
512 (Node
: Project_Node_Id
;
513 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
514 pragma Inline
(String_Type_Of
);
515 -- Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
518 function External_Reference_Of
519 (Node
: Project_Node_Id
;
520 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
521 pragma Inline
(External_Reference_Of
);
522 -- Only valid for N_External_Value nodes
524 function External_Default_Of
525 (Node
: Project_Node_Id
;
526 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
527 pragma Inline
(External_Default_Of
);
528 -- Only valid for N_External_Value nodes
530 function Case_Variable_Reference_Of
531 (Node
: Project_Node_Id
;
532 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
533 pragma Inline
(Case_Variable_Reference_Of
);
534 -- Only valid for N_Case_Construction nodes
536 function First_Case_Item_Of
537 (Node
: Project_Node_Id
;
538 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
539 pragma Inline
(First_Case_Item_Of
);
540 -- Only valid for N_Case_Construction nodes
542 function First_Choice_Of
543 (Node
: Project_Node_Id
;
544 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
545 pragma Inline
(First_Choice_Of
);
546 -- Return the first choice in a N_Case_Item, or Empty_Node if
547 -- this is when others.
549 function Next_Case_Item
550 (Node
: Project_Node_Id
;
551 In_Tree
: Project_Node_Tree_Ref
) return Project_Node_Id
;
552 pragma Inline
(Next_Case_Item
);
553 -- Only valid for N_Case_Item nodes
555 function Case_Insensitive
556 (Node
: Project_Node_Id
;
557 In_Tree
: Project_Node_Tree_Ref
) return Boolean;
558 -- Only valid for N_Attribute_Declaration and N_Attribute_Reference nodes
564 -- The following procedures are part of the abstract interface of
565 -- the Project File tree.
567 -- Each Set_* procedure is valid only for the same Project_Node_Kind
568 -- nodes as the corresponding query function above.
570 procedure Set_Name_Of
571 (Node
: Project_Node_Id
;
572 In_Tree
: Project_Node_Tree_Ref
;
574 pragma Inline
(Set_Name_Of
);
576 procedure Set_Kind_Of
577 (Node
: Project_Node_Id
;
578 In_Tree
: Project_Node_Tree_Ref
;
579 To
: Project_Node_Kind
);
580 pragma Inline
(Set_Kind_Of
);
582 procedure Set_Location_Of
583 (Node
: Project_Node_Id
;
584 In_Tree
: Project_Node_Tree_Ref
;
586 pragma Inline
(Set_Location_Of
);
588 procedure Set_First_Comment_After
589 (Node
: Project_Node_Id
;
590 In_Tree
: Project_Node_Tree_Ref
;
591 To
: Project_Node_Id
);
592 pragma Inline
(Set_First_Comment_After
);
594 procedure Set_First_Comment_After_End
595 (Node
: Project_Node_Id
;
596 In_Tree
: Project_Node_Tree_Ref
;
597 To
: Project_Node_Id
);
598 pragma Inline
(Set_First_Comment_After_End
);
600 procedure Set_First_Comment_Before
601 (Node
: Project_Node_Id
;
602 In_Tree
: Project_Node_Tree_Ref
;
603 To
: Project_Node_Id
);
604 pragma Inline
(Set_First_Comment_Before
);
606 procedure Set_First_Comment_Before_End
607 (Node
: Project_Node_Id
;
608 In_Tree
: Project_Node_Tree_Ref
;
609 To
: Project_Node_Id
);
610 pragma Inline
(Set_First_Comment_Before_End
);
612 procedure Set_Next_Comment
613 (Node
: Project_Node_Id
;
614 In_Tree
: Project_Node_Tree_Ref
;
615 To
: Project_Node_Id
);
616 pragma Inline
(Set_Next_Comment
);
618 procedure Set_Project_File_Includes_Unkept_Comments
619 (Node
: Project_Node_Id
;
620 In_Tree
: Project_Node_Tree_Ref
;
623 procedure Set_Directory_Of
624 (Node
: Project_Node_Id
;
625 In_Tree
: Project_Node_Tree_Ref
;
627 pragma Inline
(Set_Directory_Of
);
629 procedure Set_Expression_Kind_Of
630 (Node
: Project_Node_Id
;
631 In_Tree
: Project_Node_Tree_Ref
;
633 pragma Inline
(Set_Expression_Kind_Of
);
635 procedure Set_Is_Extending_All
636 (Node
: Project_Node_Id
;
637 In_Tree
: Project_Node_Tree_Ref
);
638 pragma Inline
(Set_Is_Extending_All
);
640 procedure Set_Is_Not_Last_In_List
641 (Node
: Project_Node_Id
;
642 In_Tree
: Project_Node_Tree_Ref
);
643 pragma Inline
(Set_Is_Not_Last_In_List
);
645 procedure Set_First_Variable_Of
646 (Node
: Project_Node_Id
;
647 In_Tree
: Project_Node_Tree_Ref
;
648 To
: Variable_Node_Id
);
649 pragma Inline
(Set_First_Variable_Of
);
651 procedure Set_First_Package_Of
652 (Node
: Project_Node_Id
;
653 In_Tree
: Project_Node_Tree_Ref
;
654 To
: Package_Declaration_Id
);
655 pragma Inline
(Set_First_Package_Of
);
657 procedure Set_Package_Id_Of
658 (Node
: Project_Node_Id
;
659 In_Tree
: Project_Node_Tree_Ref
;
660 To
: Package_Node_Id
);
661 pragma Inline
(Set_Package_Id_Of
);
663 procedure Set_Path_Name_Of
664 (Node
: Project_Node_Id
;
665 In_Tree
: Project_Node_Tree_Ref
;
667 pragma Inline
(Set_Path_Name_Of
);
669 procedure Set_String_Value_Of
670 (Node
: Project_Node_Id
;
671 In_Tree
: Project_Node_Tree_Ref
;
673 pragma Inline
(Set_String_Value_Of
);
675 procedure Set_First_With_Clause_Of
676 (Node
: Project_Node_Id
;
677 In_Tree
: Project_Node_Tree_Ref
;
678 To
: Project_Node_Id
);
679 pragma Inline
(Set_First_With_Clause_Of
);
681 procedure Set_Project_Declaration_Of
682 (Node
: Project_Node_Id
;
683 In_Tree
: Project_Node_Tree_Ref
;
684 To
: Project_Node_Id
);
685 pragma Inline
(Set_Project_Declaration_Of
);
687 procedure Set_Extending_Project_Of
688 (Node
: Project_Node_Id
;
689 In_Tree
: Project_Node_Tree_Ref
;
690 To
: Project_Node_Id
);
691 pragma Inline
(Set_Extending_Project_Of
);
693 procedure Set_First_String_Type_Of
694 (Node
: Project_Node_Id
;
695 In_Tree
: Project_Node_Tree_Ref
;
696 To
: Project_Node_Id
);
697 pragma Inline
(Set_First_String_Type_Of
);
699 procedure Set_Extended_Project_Path_Of
700 (Node
: Project_Node_Id
;
701 In_Tree
: Project_Node_Tree_Ref
;
703 pragma Inline
(Set_Extended_Project_Path_Of
);
705 procedure Set_Project_Node_Of
706 (Node
: Project_Node_Id
;
707 In_Tree
: Project_Node_Tree_Ref
;
708 To
: Project_Node_Id
;
709 Limited_With
: Boolean := False);
710 pragma Inline
(Set_Project_Node_Of
);
712 procedure Set_Next_With_Clause_Of
713 (Node
: Project_Node_Id
;
714 In_Tree
: Project_Node_Tree_Ref
;
715 To
: Project_Node_Id
);
716 pragma Inline
(Set_Next_With_Clause_Of
);
718 procedure Set_First_Declarative_Item_Of
719 (Node
: Project_Node_Id
;
720 In_Tree
: Project_Node_Tree_Ref
;
721 To
: Project_Node_Id
);
722 pragma Inline
(Set_First_Declarative_Item_Of
);
724 procedure Set_Extended_Project_Of
725 (Node
: Project_Node_Id
;
726 In_Tree
: Project_Node_Tree_Ref
;
727 To
: Project_Node_Id
);
728 pragma Inline
(Set_Extended_Project_Of
);
730 procedure Set_Current_Item_Node
731 (Node
: Project_Node_Id
;
732 In_Tree
: Project_Node_Tree_Ref
;
733 To
: Project_Node_Id
);
734 pragma Inline
(Set_Current_Item_Node
);
736 procedure Set_Next_Declarative_Item
737 (Node
: Project_Node_Id
;
738 In_Tree
: Project_Node_Tree_Ref
;
739 To
: Project_Node_Id
);
740 pragma Inline
(Set_Next_Declarative_Item
);
742 procedure Set_Project_Of_Renamed_Package_Of
743 (Node
: Project_Node_Id
;
744 In_Tree
: Project_Node_Tree_Ref
;
745 To
: Project_Node_Id
);
746 pragma Inline
(Set_Project_Of_Renamed_Package_Of
);
748 procedure Set_Next_Package_In_Project
749 (Node
: Project_Node_Id
;
750 In_Tree
: Project_Node_Tree_Ref
;
751 To
: Project_Node_Id
);
752 pragma Inline
(Set_Next_Package_In_Project
);
754 procedure Set_First_Literal_String
755 (Node
: Project_Node_Id
;
756 In_Tree
: Project_Node_Tree_Ref
;
757 To
: Project_Node_Id
);
758 pragma Inline
(Set_First_Literal_String
);
760 procedure Set_Next_String_Type
761 (Node
: Project_Node_Id
;
762 In_Tree
: Project_Node_Tree_Ref
;
763 To
: Project_Node_Id
);
764 pragma Inline
(Set_Next_String_Type
);
766 procedure Set_Next_Literal_String
767 (Node
: Project_Node_Id
;
768 In_Tree
: Project_Node_Tree_Ref
;
769 To
: Project_Node_Id
);
770 pragma Inline
(Set_Next_Literal_String
);
772 procedure Set_Expression_Of
773 (Node
: Project_Node_Id
;
774 In_Tree
: Project_Node_Tree_Ref
;
775 To
: Project_Node_Id
);
776 pragma Inline
(Set_Expression_Of
);
778 procedure Set_Associative_Project_Of
779 (Node
: Project_Node_Id
;
780 In_Tree
: Project_Node_Tree_Ref
;
781 To
: Project_Node_Id
);
782 pragma Inline
(Set_Associative_Project_Of
);
784 procedure Set_Associative_Package_Of
785 (Node
: Project_Node_Id
;
786 In_Tree
: Project_Node_Tree_Ref
;
787 To
: Project_Node_Id
);
788 pragma Inline
(Set_Associative_Package_Of
);
790 procedure Set_Associative_Array_Index_Of
791 (Node
: Project_Node_Id
;
792 In_Tree
: Project_Node_Tree_Ref
;
794 pragma Inline
(Set_Associative_Array_Index_Of
);
796 procedure Set_Next_Variable
797 (Node
: Project_Node_Id
;
798 In_Tree
: Project_Node_Tree_Ref
;
799 To
: Project_Node_Id
);
800 pragma Inline
(Set_Next_Variable
);
802 procedure Set_First_Term
803 (Node
: Project_Node_Id
;
804 In_Tree
: Project_Node_Tree_Ref
;
805 To
: Project_Node_Id
);
806 pragma Inline
(Set_First_Term
);
808 procedure Set_Next_Expression_In_List
809 (Node
: Project_Node_Id
;
810 In_Tree
: Project_Node_Tree_Ref
;
811 To
: Project_Node_Id
);
812 pragma Inline
(Set_Next_Expression_In_List
);
814 procedure Set_Current_Term
815 (Node
: Project_Node_Id
;
816 In_Tree
: Project_Node_Tree_Ref
;
817 To
: Project_Node_Id
);
818 pragma Inline
(Set_Current_Term
);
820 procedure Set_Next_Term
821 (Node
: Project_Node_Id
;
822 In_Tree
: Project_Node_Tree_Ref
;
823 To
: Project_Node_Id
);
824 pragma Inline
(Set_Next_Term
);
826 procedure Set_First_Expression_In_List
827 (Node
: Project_Node_Id
;
828 In_Tree
: Project_Node_Tree_Ref
;
829 To
: Project_Node_Id
);
830 pragma Inline
(Set_First_Expression_In_List
);
832 procedure Set_Package_Node_Of
833 (Node
: Project_Node_Id
;
834 In_Tree
: Project_Node_Tree_Ref
;
835 To
: Project_Node_Id
);
836 pragma Inline
(Set_Package_Node_Of
);
838 procedure Set_Source_Index_Of
839 (Node
: Project_Node_Id
;
840 In_Tree
: Project_Node_Tree_Ref
;
842 pragma Inline
(Set_Source_Index_Of
);
844 procedure Set_String_Type_Of
845 (Node
: Project_Node_Id
;
846 In_Tree
: Project_Node_Tree_Ref
;
847 To
: Project_Node_Id
);
848 pragma Inline
(Set_String_Type_Of
);
850 procedure Set_External_Reference_Of
851 (Node
: Project_Node_Id
;
852 In_Tree
: Project_Node_Tree_Ref
;
853 To
: Project_Node_Id
);
854 pragma Inline
(Set_External_Reference_Of
);
856 procedure Set_External_Default_Of
857 (Node
: Project_Node_Id
;
858 In_Tree
: Project_Node_Tree_Ref
;
859 To
: Project_Node_Id
);
860 pragma Inline
(Set_External_Default_Of
);
862 procedure Set_Case_Variable_Reference_Of
863 (Node
: Project_Node_Id
;
864 In_Tree
: Project_Node_Tree_Ref
;
865 To
: Project_Node_Id
);
866 pragma Inline
(Set_Case_Variable_Reference_Of
);
868 procedure Set_First_Case_Item_Of
869 (Node
: Project_Node_Id
;
870 In_Tree
: Project_Node_Tree_Ref
;
871 To
: Project_Node_Id
);
872 pragma Inline
(Set_First_Case_Item_Of
);
874 procedure Set_First_Choice_Of
875 (Node
: Project_Node_Id
;
876 In_Tree
: Project_Node_Tree_Ref
;
877 To
: Project_Node_Id
);
878 pragma Inline
(Set_First_Choice_Of
);
880 procedure Set_Next_Case_Item
881 (Node
: Project_Node_Id
;
882 In_Tree
: Project_Node_Tree_Ref
;
883 To
: Project_Node_Id
);
884 pragma Inline
(Set_Next_Case_Item
);
886 procedure Set_Case_Insensitive
887 (Node
: Project_Node_Id
;
888 In_Tree
: Project_Node_Tree_Ref
;
891 -------------------------------
892 -- Restricted Access Section --
893 -------------------------------
895 package Tree_Private_Part
is
897 -- This is conceptually in the private part.
898 -- However, for efficiency, some packages are accessing it directly.
900 type Project_Node_Record
is record
902 Kind
: Project_Node_Kind
;
904 Location
: Source_Ptr
:= No_Location
;
906 Directory
: Name_Id
:= No_Name
;
907 -- Only for N_Project
909 Expr_Kind
: Variable_Kind
:= Undefined
;
910 -- See below for what Project_Node_Kind it is used
912 Variables
: Variable_Node_Id
:= Empty_Node
;
913 -- First variable in a project or a package
915 Packages
: Package_Declaration_Id
:= Empty_Node
;
916 -- First package declaration in a project
918 Pkg_Id
: Package_Node_Id
:= Empty_Package
;
919 -- Only used for N_Package_Declaration
920 -- The component Pkg_Id is an entry into the table Package_Attributes
921 -- (in Prj.Attr). It is used to indicate all the attributes of the
922 -- package with their characteristics.
924 -- The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes
925 -- are built once and for all through a call (from Prj.Initialize)
926 -- to procedure Prj.Attr.Initialize. It is never modified after that.
928 Name
: Name_Id
:= No_Name
;
929 -- See below for what Project_Node_Kind it is used
931 Src_Index
: Int
:= 0;
932 -- Index of a unit in a multi-unit source.
933 -- Onli for some N_Attribute_Declaration and N_Literal_String.
935 Path_Name
: Name_Id
:= No_Name
;
936 -- See below for what Project_Node_Kind it is used
938 Value
: Name_Id
:= No_Name
;
939 -- See below for what Project_Node_Kind it is used
941 Field1
: Project_Node_Id
:= Empty_Node
;
942 -- See below the meaning for each Project_Node_Kind
944 Field2
: Project_Node_Id
:= Empty_Node
;
945 -- See below the meaning for each Project_Node_Kind
947 Field3
: Project_Node_Id
:= Empty_Node
;
948 -- See below the meaning for each Project_Node_Kind
950 Flag1
: Boolean := False;
951 -- This flag is significant only for:
952 -- N_Attribute_Declaration and N_Atribute_Reference
953 -- It indicates for an associative array attribute, that the
954 -- index is case insensitive.
955 -- N_Comment - it indicates that the comment is preceded by an
957 -- N_Project - it indicates that there are comments in the project
958 -- source that cannot be kept in the tree.
959 -- N_Project_Declaration
960 -- - it indicates that there are unkept comments in the
963 -- - it indicates that this is not the last with in a
964 -- with clause. It is set for "A", but not for "B" in
969 Flag2
: Boolean := False;
970 -- This flag is significant only for:
971 -- N_Project - it indicates that the project "extends all" another
973 -- N_Comment - it indicates that the comment is followed by an
976 -- - it indicates that the originally imported project
977 -- is an extending all project.
979 Comments
: Project_Node_Id
:= Empty_Node
;
980 -- For nodes other that N_Comment_Zones or N_Comment, designates the
981 -- comment zones associated with the node.
982 -- for N_Comment_Zones, designates the comment after the "end" of
984 -- For N_Comment, designates the next comment, if any.
988 -- type Project_Node_Kind is
991 -- -- Name: project name
992 -- -- Path_Name: project path name
993 -- -- Expr_Kind: Undefined
994 -- -- Field1: first with clause
995 -- -- Field2: project declaration
996 -- -- Field3: first string type
997 -- -- Value: extended project path name (if any)
1000 -- -- Name: imported project name
1001 -- -- Path_Name: imported project path name
1002 -- -- Expr_Kind: Undefined
1003 -- -- Field1: project node
1004 -- -- Field2: next with clause
1005 -- -- Field3: project node or empty if "limited with"
1006 -- -- Value: literal string withed
1008 -- N_Project_Declaration,
1009 -- -- Name: not used
1010 -- -- Path_Name: not used
1011 -- -- Expr_Kind: Undefined
1012 -- -- Field1: first declarative item
1013 -- -- Field2: extended project
1014 -- -- Field3: extending project
1015 -- -- Value: not used
1017 -- N_Declarative_Item,
1018 -- -- Name: not used
1019 -- -- Path_Name: not used
1020 -- -- Expr_Kind: Undefined
1021 -- -- Field1: current item node
1022 -- -- Field2: next declarative item
1023 -- -- Field3: not used
1024 -- -- Value: not used
1026 -- N_Package_Declaration,
1027 -- -- Name: package name
1028 -- -- Path_Name: not used
1029 -- -- Expr_Kind: Undefined
1030 -- -- Field1: project of renamed package (if any)
1031 -- -- Field2: first declarative item
1032 -- -- Field3: next package in project
1033 -- -- Value: not used
1035 -- N_String_Type_Declaration,
1036 -- -- Name: type name
1037 -- -- Path_Name: not used
1038 -- -- Expr_Kind: Undefined
1039 -- -- Field1: first literal string
1040 -- -- Field2: next string type
1041 -- -- Field3: not used
1042 -- -- Value: not used
1044 -- N_Literal_String,
1045 -- -- Name: not used
1046 -- -- Path_Name: not used
1047 -- -- Expr_Kind: Single
1048 -- -- Field1: next literal string
1049 -- -- Field2: not used
1050 -- -- Field3: not used
1051 -- -- Value: string value
1053 -- N_Attribute_Declaration,
1054 -- -- Name: attribute name
1055 -- -- Path_Name: not used
1056 -- -- Expr_Kind: attribute kind
1057 -- -- Field1: expression
1058 -- -- Field2: project of full associative array
1059 -- -- Field3: package of full associative array
1060 -- -- Value: associative array index
1061 -- -- (if an associative array element)
1063 -- N_Typed_Variable_Declaration,
1064 -- -- Name: variable name
1065 -- -- Path_Name: not used
1066 -- -- Expr_Kind: Single
1067 -- -- Field1: expression
1068 -- -- Field2: type of variable (N_String_Type_Declaration)
1069 -- -- Field3: next variable
1070 -- -- Value: not used
1072 -- N_Variable_Declaration,
1073 -- -- Name: variable name
1074 -- -- Path_Name: not used
1075 -- -- Expr_Kind: variable kind
1076 -- -- Field1: expression
1077 -- -- Field2: not used
1078 -- -- Field3 is used for next variable, instead of Field2,
1079 -- -- so that it is the same field for
1080 -- -- N_Variable_Declaration and
1081 -- -- N_Typed_Variable_Declaration
1082 -- -- Field3: next variable
1083 -- -- Value: not used
1086 -- -- Name: not used
1087 -- -- Path_Name: not used
1088 -- -- Expr_Kind: expression kind
1089 -- -- Field1: first term
1090 -- -- Field2: next expression in list
1091 -- -- Field3: not used
1092 -- -- Value: not used
1095 -- -- Name: not used
1096 -- -- Path_Name: not used
1097 -- -- Expr_Kind: term kind
1098 -- -- Field1: current term
1099 -- -- Field2: next term in the expression
1100 -- -- Field3: not used
1101 -- -- Value: not used
1103 -- N_Literal_String_List,
1104 -- -- Designates a list of string expressions between brackets
1105 -- -- separated by commas. The string expressions are not necessarily
1106 -- -- literal strings.
1107 -- -- Name: not used
1108 -- -- Path_Name: not used
1109 -- -- Expr_Kind: List
1110 -- -- Field1: first expression
1111 -- -- Field2: not used
1112 -- -- Field3: not used
1113 -- -- Value: not used
1115 -- N_Variable_Reference,
1116 -- -- Name: variable name
1117 -- -- Path_Name: not used
1118 -- -- Expr_Kind: variable kind
1119 -- -- Field1: project (if specified)
1120 -- -- Field2: package (if specified)
1121 -- -- Field3: type of variable (N_String_Type_Declaration), if any
1122 -- -- Value: not used
1124 -- N_External_Value,
1125 -- -- Name: not used
1126 -- -- Path_Name: not used
1127 -- -- Expr_Kind: Single
1128 -- -- Field1: Name of the external reference (literal string)
1129 -- -- Field2: Default (literal string)
1130 -- -- Field3: not used
1131 -- -- Value: not used
1133 -- N_Attribute_Reference,
1134 -- -- Name: attribute name
1135 -- -- Path_Name: not used
1136 -- -- Expr_Kind: attribute kind
1137 -- -- Field1: project
1138 -- -- Field2: package (if attribute of a package)
1139 -- -- Field3: not used
1140 -- -- Value: associative array index
1141 -- -- (if an associative array element)
1143 -- N_Case_Construction,
1144 -- -- Name: not used
1145 -- -- Path_Name: not used
1146 -- -- Expr_Kind: Undefined
1147 -- -- Field1: case variable reference
1148 -- -- Field2: first case item
1149 -- -- Field3: not used
1150 -- -- Value: not used
1153 -- -- Name: not used
1154 -- -- Path_Name: not used
1155 -- -- Expr_Kind: not used
1156 -- -- Field1: first choice (literal string), or Empty_Node
1157 -- -- for when others
1158 -- -- Field2: first declarative item
1159 -- -- Field3: next case item
1160 -- -- Value: not used
1163 -- -- Name: not used
1164 -- -- Path_Name: not used
1165 -- -- Expr_Kind: not used
1166 -- -- Field1: comment before the construct
1167 -- -- Field2: comment after the construct
1168 -- -- Field3: comment before the "end" of the construct
1169 -- -- Value: end of line comment
1170 -- -- Comments: comment after the "end" of the construct
1173 -- -- Name: not used
1174 -- -- Path_Name: not used
1175 -- -- Expr_Kind: not used
1176 -- -- Field1: not used
1177 -- -- Field2: not used
1178 -- -- Field3: not used
1179 -- -- Value: comment
1180 -- -- Flag1: comment is preceded by an empty line
1181 -- -- Flag2: comment is followed by an empty line
1182 -- -- Comments: next comment
1184 package Project_Node_Table
is
1185 new GNAT
.Dynamic_Tables
1186 (Table_Component_Type
=> Project_Node_Record
,
1187 Table_Index_Type
=> Project_Node_Id
,
1188 Table_Low_Bound
=> First_Node_Id
,
1189 Table_Initial
=> Project_Nodes_Initial
,
1190 Table_Increment
=> Project_Nodes_Increment
);
1191 -- This table contains the syntactic tree of project data
1192 -- from project files.
1194 type Project_Name_And_Node
is record
1196 -- Name of the project
1198 Node
: Project_Node_Id
;
1199 -- Node of the project in table Project_Nodes
1201 Canonical_Path
: Name_Id
;
1202 -- Resolved and canonical path of the project file
1205 -- True when the project is being extended by another project
1208 No_Project_Name_And_Node
: constant Project_Name_And_Node
:=
1211 Canonical_Path
=> No_Name
,
1214 package Projects_Htable
is new GNAT
.Dynamic_HTables
.Simple_HTable
1215 (Header_Num
=> Header_Num
,
1216 Element
=> Project_Name_And_Node
,
1217 No_Element
=> No_Project_Name_And_Node
,
1221 -- This hash table contains a mapping of project names to project nodes.
1222 -- Note that this hash table contains only the nodes whose Kind is
1223 -- N_Project. It is used to find the node of a project from its
1224 -- name, and to verify if a project has already been parsed, knowing
1227 end Tree_Private_Part
;
1229 type Project_Node_Tree_Data
is record
1230 Project_Nodes
: Tree_Private_Part
.Project_Node_Table
.Instance
;
1231 Projects_HT
: Tree_Private_Part
.Projects_Htable
.Instance
;
1233 -- The data for a project node tree
1236 type Comment_Array
is array (Positive range <>) of Comment_Data
;
1237 type Comments_Ptr
is access Comment_Array
;
1239 type Comment_State
is record
1240 End_Of_Line_Node
: Project_Node_Id
:= Empty_Node
;
1242 Previous_Line_Node
: Project_Node_Id
:= Empty_Node
;
1244 Previous_End_Node
: Project_Node_Id
:= Empty_Node
;
1246 Unkept_Comments
: Boolean := False;
1248 Comments
: Comments_Ptr
:= null;