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