1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This package defines the structure of the Project File tree.
33 with Prj.Attr; use Prj.Attr;
34 with Prj.Com; use Prj.Com;
35 with Types; use Types;
40 Project_Nodes_Initial : constant := 1_000;
41 -- Initial number of nodes in table Tree_Private_Part.Project_Nodes
42 Project_Nodes_Increment : constant := 100;
44 Project_Node_Low_Bound : constant := 0;
45 Project_Node_High_Bound : constant := 099_999_999; -- 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
53 First_Node_Id : constant Project_Node_Id := Project_Node_Low_Bound;
55 subtype Variable_Node_Id is Project_Node_Id;
56 -- Used to designate a node whose expected kind is
57 -- N_Typed_Variable_Declaration, N_Variable_Declaration or
58 -- N_Variable_Reference.
59 subtype Package_Declaration_Id is Project_Node_Id;
60 -- Used to designate a node whose expected kind is
61 -- N_Project_Declaration.
63 type Project_Node_Kind is
66 N_Project_Declaration,
68 N_Package_Declaration,
69 N_String_Type_Declaration,
71 N_Attribute_Declaration,
72 N_Typed_Variable_Declaration,
73 N_Variable_Declaration,
76 N_Literal_String_List,
79 N_Attribute_Reference,
82 -- Each node in the tree is of a Project_Node_Kind
83 -- For the signification of the fields in each node of a
84 -- Project_Node_Kind, look at package Tree_Private_Part.
87 -- Initialize the Project File tree: empty the Project_Nodes table
88 -- and reset the Projects_Htable.
90 function Default_Project_Node
91 (Of_Kind : Project_Node_Kind;
92 And_Expr_Kind : Variable_Kind := Undefined)
93 return Project_Node_Id;
94 -- Returns a Project_Node_Record with the specified Kind and
95 -- Expr_Kind; all the other components have default nil values.
97 ----------------------
98 -- Access Functions --
99 ----------------------
101 -- The following query functions are part of the abstract interface
102 -- of the Project File tree
104 function Name_Of (Node : Project_Node_Id) return Name_Id;
105 -- Valid for all non empty nodes. May return No_Name for nodes that have
108 function Kind_Of (Node : Project_Node_Id) return Project_Node_Kind;
109 -- Valid for all non empty nodes
111 function Location_Of (Node : Project_Node_Id) return Source_Ptr;
112 -- Valid for all non empty nodes
114 function Directory_Of (Node : Project_Node_Id) return Name_Id;
115 -- Only valid for N_Project nodes.
117 function Expression_Kind_Of (Node : Project_Node_Id) return Variable_Kind;
118 -- Only valid for N_Literal_String, N_Attribute_Declaration,
119 -- N_Variable_Declaration, N_Typed_Variable_Declaration, N_Expression,
120 -- N_Term, N_Variable_Reference or N_Attribute_Reference nodes.
122 function First_Variable_Of
123 (Node : Project_Node_Id)
124 return Variable_Node_Id;
125 -- Only valid for N_Project or N_Package_Declaration nodes
127 function First_Package_Of
128 (Node : Project_Node_Id)
129 return Package_Declaration_Id;
130 -- Only valid for N_Project nodes
132 function Package_Id_Of (Node : Project_Node_Id) return Package_Node_Id;
133 -- Only valid for N_Package_Declaration nodes
135 function Path_Name_Of (Node : Project_Node_Id) return Name_Id;
136 -- Only valid for N_Project and N_With_Clause nodes.
138 function String_Value_Of (Node : Project_Node_Id) return String_Id;
139 -- Only valid for N_With_Clause or N_Literal_String nodes.
141 function First_With_Clause_Of
142 (Node : Project_Node_Id)
143 return Project_Node_Id;
144 -- Only valid for N_Project nodes
146 function Project_Declaration_Of
147 (Node : Project_Node_Id)
148 return Project_Node_Id;
149 -- Only valid for N_Project nodes
151 function First_String_Type_Of
152 (Node : Project_Node_Id)
153 return Project_Node_Id;
154 -- Only valid for N_Project nodes
156 function Modified_Project_Path_Of
157 (Node : Project_Node_Id)
159 -- Only valid for N_With_Clause nodes
161 function Project_Node_Of
162 (Node : Project_Node_Id)
163 return Project_Node_Id;
164 -- Only valid for N_Project nodes
166 function Next_With_Clause_Of
167 (Node : Project_Node_Id)
168 return Project_Node_Id;
169 -- Only valid for N_With_Clause nodes
171 function First_Declarative_Item_Of
172 (Node : Project_Node_Id)
173 return Project_Node_Id;
174 -- Only valid for N_With_Clause nodes
176 function Modified_Project_Of
177 (Node : Project_Node_Id)
178 return Project_Node_Id;
179 -- Only valid for N_With_Clause nodes
181 function Current_Item_Node
182 (Node : Project_Node_Id)
183 return Project_Node_Id;
184 -- Only valid for N_Declarative_Item nodes
186 function Next_Declarative_Item
187 (Node : Project_Node_Id)
188 return Project_Node_Id;
189 -- Only valid for N_Declarative_Item node
191 function Project_Of_Renamed_Package_Of
192 (Node : Project_Node_Id)
193 return Project_Node_Id;
194 -- Only valid for N_Package_Declaration nodes.
195 -- May return Empty_Node.
197 function Next_Package_In_Project
198 (Node : Project_Node_Id)
199 return Project_Node_Id;
200 -- Only valid for N_Package_Declaration nodes
202 function First_Literal_String
203 (Node : Project_Node_Id)
204 return Project_Node_Id;
205 -- Only valid for N_String_Type_Declaration nodes
207 function Next_String_Type
208 (Node : Project_Node_Id)
209 return Project_Node_Id;
210 -- Only valid for N_String_Type_Declaration nodes
212 function Next_Literal_String
213 (Node : Project_Node_Id)
214 return Project_Node_Id;
215 -- Only valid for N_Literal_String nodes
217 function Expression_Of
218 (Node : Project_Node_Id)
219 return Project_Node_Id;
220 -- Only valid for N_Attribute_Declaration, N_Typed_Variable_Declaration
221 -- or N_Variable_Declaration nodes
223 function Value_Is_Valid
224 (For_Typed_Variable : Project_Node_Id;
227 -- Only valid for N_Typed_Variable_Declaration. Returns True if Value is
228 -- in the list of allowed strings for For_Typed_Variable. False otherwise.
230 function Associative_Array_Index_Of
231 (Node : Project_Node_Id)
233 -- Only valid for N_Attribute_Declaration.
234 -- Returns No_String for non associative array attributes.
236 function Next_Variable
237 (Node : Project_Node_Id)
238 return Project_Node_Id;
239 -- Only valid for N_Typed_Variable_Declaration or N_Variable_Declaration
243 (Node : Project_Node_Id)
244 return Project_Node_Id;
245 -- Only valid for N_Expression nodes
247 function Next_Expression_In_List
248 (Node : Project_Node_Id)
249 return Project_Node_Id;
250 -- Only valid for N_Expression nodes
252 function Current_Term
253 (Node : Project_Node_Id)
254 return Project_Node_Id;
255 -- Only valid for N_Term nodes
258 (Node : Project_Node_Id)
259 return Project_Node_Id;
260 -- Only valid for N_Term nodes
262 function First_Expression_In_List
263 (Node : Project_Node_Id)
264 return Project_Node_Id;
265 -- Only valid for N_Literal_String_List nodes
267 function Package_Node_Of
268 (Node : Project_Node_Id)
269 return Project_Node_Id;
270 -- Only valid for N_Variable_Reference or N_Attribute_Reference nodes.
271 -- May return Empty_Node.
273 function String_Type_Of
274 (Node : Project_Node_Id)
275 return Project_Node_Id;
276 -- Only valid for N_Variable_Reference or N_Typed_Variable_Declaration
279 function External_Reference_Of
280 (Node : Project_Node_Id)
281 return Project_Node_Id;
282 -- Only valid for N_External_Value nodes
284 function External_Default_Of
285 (Node : Project_Node_Id)
286 return Project_Node_Id;
287 -- Only valid for N_External_Value nodes
289 function Case_Variable_Reference_Of
290 (Node : Project_Node_Id)
291 return Project_Node_Id;
292 -- Only valid for N_Case_Construction nodes
294 function First_Case_Item_Of
295 (Node : Project_Node_Id)
296 return Project_Node_Id;
297 -- Only valid for N_Case_Construction nodes
299 function First_Choice_Of
300 (Node : Project_Node_Id)
301 return Project_Node_Id;
302 -- Only valid for N_Case_Item nodes
304 function Next_Case_Item
305 (Node : Project_Node_Id)
306 return Project_Node_Id;
307 -- Only valid for N_Case_Item nodes
309 function Case_Insensitive (Node : Project_Node_Id) return Boolean;
310 -- Only valid for N_Attribute_Declaration nodes
316 -- The following procedures are part of the abstract interface of
317 -- the Project File tree.
319 -- Each Set_* procedure is valid only for the same Project_Node_Kind
320 -- nodes as the corresponding query function above.
322 procedure Set_Name_Of
323 (Node : Project_Node_Id;
326 procedure Set_Kind_Of
327 (Node : Project_Node_Id;
328 To : Project_Node_Kind);
330 procedure Set_Location_Of
331 (Node : Project_Node_Id;
334 procedure Set_Directory_Of
335 (Node : Project_Node_Id;
338 procedure Set_Expression_Kind_Of
339 (Node : Project_Node_Id;
342 procedure Set_First_Variable_Of
343 (Node : Project_Node_Id;
344 To : Variable_Node_Id);
346 procedure Set_First_Package_Of
347 (Node : Project_Node_Id;
348 To : Package_Declaration_Id);
350 procedure Set_Package_Id_Of
351 (Node : Project_Node_Id;
352 To : Package_Node_Id);
354 procedure Set_Path_Name_Of
355 (Node : Project_Node_Id;
358 procedure Set_String_Value_Of
359 (Node : Project_Node_Id;
362 procedure Set_First_With_Clause_Of
363 (Node : Project_Node_Id;
364 To : Project_Node_Id);
366 procedure Set_Project_Declaration_Of
367 (Node : Project_Node_Id;
368 To : Project_Node_Id);
370 procedure Set_First_String_Type_Of
371 (Node : Project_Node_Id;
372 To : Project_Node_Id);
374 procedure Set_Modified_Project_Path_Of
375 (Node : Project_Node_Id;
378 procedure Set_Project_Node_Of
379 (Node : Project_Node_Id;
380 To : Project_Node_Id);
382 procedure Set_Next_With_Clause_Of
383 (Node : Project_Node_Id;
384 To : Project_Node_Id);
386 procedure Set_First_Declarative_Item_Of
387 (Node : Project_Node_Id;
388 To : Project_Node_Id);
390 procedure Set_Modified_Project_Of
391 (Node : Project_Node_Id;
392 To : Project_Node_Id);
394 procedure Set_Current_Item_Node
395 (Node : Project_Node_Id;
396 To : Project_Node_Id);
398 procedure Set_Next_Declarative_Item
399 (Node : Project_Node_Id;
400 To : Project_Node_Id);
402 procedure Set_Project_Of_Renamed_Package_Of
403 (Node : Project_Node_Id;
404 To : Project_Node_Id);
406 procedure Set_Next_Package_In_Project
407 (Node : Project_Node_Id;
408 To : Project_Node_Id);
410 procedure Set_First_Literal_String
411 (Node : Project_Node_Id;
412 To : Project_Node_Id);
414 procedure Set_Next_String_Type
415 (Node : Project_Node_Id;
416 To : Project_Node_Id);
418 procedure Set_Next_Literal_String
419 (Node : Project_Node_Id;
420 To : Project_Node_Id);
422 procedure Set_Expression_Of
423 (Node : Project_Node_Id;
424 To : Project_Node_Id);
426 procedure Set_Associative_Array_Index_Of
427 (Node : Project_Node_Id;
430 procedure Set_Next_Variable
431 (Node : Project_Node_Id;
432 To : Project_Node_Id);
434 procedure Set_First_Term
435 (Node : Project_Node_Id;
436 To : Project_Node_Id);
438 procedure Set_Next_Expression_In_List
439 (Node : Project_Node_Id;
440 To : Project_Node_Id);
442 procedure Set_Current_Term
443 (Node : Project_Node_Id;
444 To : Project_Node_Id);
446 procedure Set_Next_Term
447 (Node : Project_Node_Id;
448 To : Project_Node_Id);
450 procedure Set_First_Expression_In_List
451 (Node : Project_Node_Id;
452 To : Project_Node_Id);
454 procedure Set_Package_Node_Of
455 (Node : Project_Node_Id;
456 To : Project_Node_Id);
458 procedure Set_String_Type_Of
459 (Node : Project_Node_Id;
460 To : Project_Node_Id);
462 procedure Set_External_Reference_Of
463 (Node : Project_Node_Id;
464 To : Project_Node_Id);
466 procedure Set_External_Default_Of
467 (Node : Project_Node_Id;
468 To : Project_Node_Id);
470 procedure Set_Case_Variable_Reference_Of
471 (Node : Project_Node_Id;
472 To : Project_Node_Id);
474 procedure Set_First_Case_Item_Of
475 (Node : Project_Node_Id;
476 To : Project_Node_Id);
478 procedure Set_First_Choice_Of
479 (Node : Project_Node_Id;
480 To : Project_Node_Id);
482 procedure Set_Next_Case_Item
483 (Node : Project_Node_Id;
484 To : Project_Node_Id);
486 procedure Set_Case_Insensitive
487 (Node : Project_Node_Id;
490 -------------------------------
491 -- Restricted Access Section --
492 -------------------------------
494 package Tree_Private_Part is
496 -- This is conceptually in the private part.
497 -- However, for efficiency, some packages are accessing it directly.
499 type Project_Node_Record is record
501 Kind : Project_Node_Kind;
503 Location : Source_Ptr := No_Location;
505 Directory : Name_Id := No_Name;
506 -- Only for N_Project
508 Expr_Kind : Variable_Kind := Undefined;
509 -- See below for what Project_Node_Kind it is used
511 Variables : Variable_Node_Id := Empty_Node;
512 -- First variable in a project or a package
514 Packages : Package_Declaration_Id := Empty_Node;
515 -- First package declaration in a project
517 Pkg_Id : Package_Node_Id := Empty_Package;
518 -- Only use in Package_Declaration
520 Name : Name_Id := No_Name;
521 -- See below for what Project_Node_Kind it is used
523 Path_Name : Name_Id := No_Name;
524 -- See below for what Project_Node_Kind it is used
526 Value : String_Id := No_String;
527 -- See below for what Project_Node_Kind it is used
529 Field1 : Project_Node_Id := Empty_Node;
530 -- See below the meaning for each Project_Node_Kind
532 Field2 : Project_Node_Id := Empty_Node;
533 -- See below the meaning for each Project_Node_Kind
535 Field3 : Project_Node_Id := Empty_Node;
536 -- See below the meaning for each Project_Node_Kind
538 Case_Insensitive : Boolean := False;
539 -- Indicates, for an associative array attribute, that the
540 -- index is case insensitive.
544 -- type Project_Node_Kind is
547 -- -- Name: project name
548 -- -- Path_Name: project path name
549 -- -- Expr_Kind: Undefined
550 -- -- Field1: first with clause
551 -- -- Field2: project declaration
552 -- -- Field3: first string type
553 -- -- Value: modified project path name (if any)
556 -- -- Name: imported project name
557 -- -- Path_Name: imported project path name
558 -- -- Expr_Kind: Undefined
559 -- -- Field1: project node
560 -- -- Field2: next with clause
561 -- -- Field3: not used
562 -- -- Value: literal string withed
564 -- N_Project_Declaration,
566 -- -- Path_Name: not used
567 -- -- Expr_Kind: Undefined
568 -- -- Field1: first declarative item
569 -- -- Field2: modified project
570 -- -- Field3: not used
571 -- -- Value: not used
573 -- N_Declarative_Item,
575 -- -- Path_Name: not used
576 -- -- Expr_Kind: Undefined
577 -- -- Field1: current item node
578 -- -- Field2: next declarative item
579 -- -- Field3: not used
580 -- -- Value: not used
582 -- N_Package_Declaration,
583 -- -- Name: package name
584 -- -- Path_Name: not used
585 -- -- Expr_Kind: Undefined
586 -- -- Field1: project of renamed package (if any)
587 -- -- Field2: first declarative item
588 -- -- Field3: next package in project
589 -- -- Value: not used
591 -- N_String_Type_Declaration,
592 -- -- Name: type name
593 -- -- Path_Name: not used
594 -- -- Expr_Kind: Undefined
595 -- -- Field1: first literal string
596 -- -- Field2: next string type
597 -- -- Field3: not used
598 -- -- Value: not used
602 -- -- Path_Name: not used
603 -- -- Expr_Kind: Single
604 -- -- Field1: next literal string
605 -- -- Field2: not used
606 -- -- Field3: not used
607 -- -- Value: string value
609 -- N_Attribute_Declaration,
610 -- -- Name: attribute name
611 -- -- Path_Name: not used
612 -- -- Expr_Kind: attribute kind
613 -- -- Field1: expression
614 -- -- Field2: not used
615 -- -- Field3: not used
616 -- -- Value: associative array index
617 -- -- (if an associative array element)
619 -- N_Typed_Variable_Declaration,
620 -- -- Name: variable name
621 -- -- Path_Name: not used
622 -- -- Expr_Kind: Single
623 -- -- Field1: expression
624 -- -- Field2: type of variable (N_String_Type_Declaration)
625 -- -- Field3: next variable
626 -- -- Value: not used
628 -- N_Variable_Declaration,
629 -- -- Name: variable name
630 -- -- Path_Name: not used
631 -- -- Expr_Kind: variable kind
632 -- -- Field1: expression
633 -- -- Field2: not used
634 -- -- Field3 is used for next variable, instead of Field2,
635 -- -- so that it is the same field for
636 -- -- N_Variable_Declaration and
637 -- -- N_Typed_Variable_Declaration
638 -- -- Field3: next variable
639 -- -- Value: not used
643 -- -- Path_Name: not used
644 -- -- Expr_Kind: expression kind
645 -- -- Field1: first term
646 -- -- Field2: next expression in list
647 -- -- Field3: not used
648 -- -- Value: not used
652 -- -- Path_Name: not used
653 -- -- Expr_Kind: term kind
654 -- -- Field1: current term
655 -- -- Field2: next term in the expression
656 -- -- Field3: not used
657 -- -- Value: not used
659 -- N_Literal_String_List,
660 -- -- Designates a list of string expressions between brackets
661 -- -- separated by commas. The string expressions are not necessarily
662 -- -- literal strings.
664 -- -- Path_Name: not used
665 -- -- Expr_Kind: List
666 -- -- Field1: first expression
667 -- -- Field2: not used
668 -- -- Field3: not used
669 -- -- Value: not used
671 -- N_Variable_Reference,
672 -- -- Name: variable name
673 -- -- Path_Name: not used
674 -- -- Expr_Kind: variable kind
675 -- -- Field1: project (if specified)
676 -- -- Field2: package (if specified)
677 -- -- Field3: type of variable (N_String_Type_Declaration), if any
678 -- -- Value: not used
682 -- -- Path_Name: not used
683 -- -- Expr_Kind: Single
684 -- -- Field1: Name of the external reference (literal string)
685 -- -- Field2: Default (literal string)
686 -- -- Field3: not used
687 -- -- Value: not used
689 -- N_Attribute_Reference,
690 -- -- Name: attribute name
691 -- -- Path_Name: not used
692 -- -- Expr_Kind: attribute kind
693 -- -- Field1: project
694 -- -- Field2: package (if attribute of a package)
695 -- -- Field3: not used
696 -- -- Value: not used
698 -- N_Case_Construction,
700 -- -- Path_Name: not used
701 -- -- Expr_Kind: Undefined
702 -- -- Field1: case variable reference
703 -- -- Field2: first case item
704 -- -- Field3: not used
705 -- -- Value: not used
709 -- -- Path_Name: not used
710 -- -- Expr_Kind: not used
711 -- -- Field1: first choice (literal string)
712 -- -- Field2: first declarative item
713 -- -- Field3: next case item
714 -- -- Value: not used
716 package Project_Nodes is
717 new Table.Table (Table_Component_Type => Project_Node_Record,
718 Table_Index_Type => Project_Node_Id,
719 Table_Low_Bound => First_Node_Id,
720 Table_Initial => Project_Nodes_Initial,
721 Table_Increment => Project_Nodes_Increment,
722 Table_Name => "Project_Nodes");
723 -- This table contains the syntactic tree of project data
724 -- from project files.
726 type Project_Name_And_Node is record
728 -- Name of the project
729 Node : Project_Node_Id;
730 -- Node of the project in table Project_Nodes
732 -- True when the project is being modified by another project
735 No_Project_Name_And_Node : constant Project_Name_And_Node :=
736 (Name => No_Name, Node => Empty_Node, Modified => True);
738 package Projects_Htable is new GNAT.HTable.Simple_HTable
739 (Header_Num => Header_Num,
740 Element => Project_Name_And_Node,
741 No_Element => No_Project_Name_And_Node,
745 -- This hash table contains a mapping of project names to project nodes.
746 -- Note that this hash table contains only the nodes whose Kind is
747 -- N_Project. It is used to find the node of a project from its
748 -- name, and to verify if a project has already been parsed, knowing
751 end Tree_Private_Part;