1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2006, 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 with Err_Vars; use Err_Vars;
28 with Namet; use Namet;
30 with Osint; use Osint;
31 with Output; use Output;
32 with Prj.Attr; use Prj.Attr;
33 with Prj.Err; use Prj.Err;
34 with Prj.Ext; use Prj.Ext;
35 with Prj.Nmsc; use Prj.Nmsc;
36 with Sinput; use Sinput;
39 with GNAT.Case_Util; use GNAT.Case_Util;
42 package body Prj.Proc is
44 Error_Report : Put_Line_Access := null;
46 package Processed_Projects is new GNAT.HTable.Simple_HTable
47 (Header_Num => Header_Num,
48 Element => Project_Id,
49 No_Element => No_Project,
53 -- This hash table contains all processed projects
55 procedure Add (To_Exp : in out Name_Id; Str : Name_Id);
56 -- Concatenate two strings and returns another string if both
57 -- arguments are not null string.
59 procedure Add_Attributes
60 (Project : Project_Id;
61 In_Tree : Project_Tree_Ref;
62 Decl : in out Declarations;
63 First : Attribute_Node_Id);
64 -- Add all attributes, starting with First, with their default
65 -- values to the package or project with declarations Decl.
68 (In_Tree : Project_Tree_Ref;
69 Project : in out Project_Id;
70 Follow_Links : Boolean;
71 When_No_Sources : Error_Warning);
72 -- Set all projects to not checked, then call Recursive_Check for the
73 -- main project Project. Project is set to No_Project if errors occurred.
75 procedure Copy_Package_Declarations
77 To : in out Declarations;
79 In_Tree : Project_Tree_Ref);
80 -- Copy a package declaration From to To for a renamed package. Change the
81 -- locations of all the attributes to New_Loc.
84 (Project : Project_Id;
85 In_Tree : Project_Tree_Ref;
86 From_Project_Node : Project_Node_Id;
87 From_Project_Node_Tree : Project_Node_Tree_Ref;
89 First_Term : Project_Node_Id;
90 Kind : Variable_Kind) return Variable_Value;
91 -- From N_Expression project node From_Project_Node, compute the value
92 -- of an expression and return it as a Variable_Value.
94 function Imported_Or_Extended_Project_From
95 (Project : Project_Id;
96 In_Tree : Project_Tree_Ref;
97 With_Name : Name_Id) return Project_Id;
98 -- Find an imported or extended project of Project whose name is With_Name
100 function Package_From
101 (Project : Project_Id;
102 In_Tree : Project_Tree_Ref;
103 With_Name : Name_Id) return Package_Id;
104 -- Find the package of Project whose name is With_Name
106 procedure Process_Declarative_Items
107 (Project : Project_Id;
108 In_Tree : Project_Tree_Ref;
109 From_Project_Node : Project_Node_Id;
110 From_Project_Node_Tree : Project_Node_Tree_Ref;
112 Item : Project_Node_Id);
113 -- Process declarative items starting with From_Project_Node, and put them
114 -- in declarations Decl. This is a recursive procedure; it calls itself for
115 -- a package declaration or a case construction.
117 procedure Recursive_Process
118 (In_Tree : Project_Tree_Ref;
119 Project : out Project_Id;
120 From_Project_Node : Project_Node_Id;
121 From_Project_Node_Tree : Project_Node_Tree_Ref;
122 Extended_By : Project_Id);
123 -- Process project with node From_Project_Node in the tree.
124 -- Do nothing if From_Project_Node is Empty_Node.
125 -- If project has already been processed, simply return its project id.
126 -- Otherwise create a new project id, mark it as processed, call itself
127 -- recursively for all imported projects and a extended project, if any.
128 -- Then process the declarative items of the project.
130 procedure Recursive_Check
131 (Project : Project_Id;
132 In_Tree : Project_Tree_Ref;
133 Follow_Links : Boolean;
134 When_No_Sources : Error_Warning);
135 -- If Project is not marked as checked, mark it as checked, call
136 -- Check_Naming_Scheme for the project, then call itself for a
137 -- possible extended project and all the imported projects of Project.
143 procedure Add (To_Exp : in out Name_Id; Str : Name_Id) is
145 if To_Exp = Types.No_Name or else To_Exp = Empty_String then
147 -- To_Exp is nil or empty. The result is Str
151 -- If Str is nil, then do not change To_Ext
153 elsif Str /= No_Name and then Str /= Empty_String then
155 S : constant String := Get_Name_String (Str);
158 Get_Name_String (To_Exp);
159 Add_Str_To_Name_Buffer (S);
169 procedure Add_Attributes
170 (Project : Project_Id;
171 In_Tree : Project_Tree_Ref;
172 Decl : in out Declarations;
173 First : Attribute_Node_Id)
175 The_Attribute : Attribute_Node_Id := First;
178 while The_Attribute /= Empty_Attribute loop
179 if Attribute_Kind_Of (The_Attribute) = Single then
181 New_Attribute : Variable_Value;
184 case Variable_Kind_Of (The_Attribute) is
186 -- Undefined should not happen
190 (False, "attribute with an undefined kind");
193 -- Single attributes have a default value of empty string
199 Location => No_Location,
201 Value => Empty_String,
204 -- List attributes have a default value of nil list
210 Location => No_Location,
212 Values => Nil_String);
216 Variable_Element_Table.Increment_Last
217 (In_Tree.Variable_Elements);
218 In_Tree.Variable_Elements.Table
219 (Variable_Element_Table.Last
220 (In_Tree.Variable_Elements)) :=
221 (Next => Decl.Attributes,
222 Name => Attribute_Name_Of (The_Attribute),
223 Value => New_Attribute);
224 Decl.Attributes := Variable_Element_Table.Last
225 (In_Tree.Variable_Elements);
229 The_Attribute := Next_Attribute (After => The_Attribute);
238 (In_Tree : Project_Tree_Ref;
239 Project : in out Project_Id;
240 Follow_Links : Boolean;
241 When_No_Sources : Error_Warning)
244 -- Make sure that all projects are marked as not checked
246 for Index in Project_Table.First ..
247 Project_Table.Last (In_Tree.Projects)
249 In_Tree.Projects.Table (Index).Checked := False;
252 Recursive_Check (Project, In_Tree, Follow_Links, When_No_Sources);
255 -------------------------------
256 -- Copy_Package_Declarations --
257 -------------------------------
259 procedure Copy_Package_Declarations
260 (From : Declarations;
261 To : in out Declarations;
262 New_Loc : Source_Ptr;
263 In_Tree : Project_Tree_Ref)
265 V1 : Variable_Id := From.Attributes;
266 V2 : Variable_Id := No_Variable;
268 A1 : Array_Id := From.Arrays;
269 A2 : Array_Id := No_Array;
271 E1 : Array_Element_Id;
272 E2 : Array_Element_Id := No_Array_Element;
276 -- To avoid references in error messages to attribute declarations in
277 -- an original package that has been renamed, copy all the attribute
278 -- declarations of the package and change all locations to New_Loc,
279 -- the location of the renamed package.
281 -- First single attributes
283 while V1 /= No_Variable loop
285 -- Copy the attribute
287 Var := In_Tree.Variable_Elements.Table (V1);
290 -- Remove the Next component
292 Var.Next := No_Variable;
294 -- Change the location to New_Loc
296 Var.Value.Location := New_Loc;
297 Variable_Element_Table.Increment_Last (In_Tree.Variable_Elements);
299 -- Put in new declaration
301 if To.Attributes = No_Variable then
303 Variable_Element_Table.Last (In_Tree.Variable_Elements);
306 In_Tree.Variable_Elements.Table (V2).Next :=
307 Variable_Element_Table.Last (In_Tree.Variable_Elements);
310 V2 := Variable_Element_Table.Last (In_Tree.Variable_Elements);
311 In_Tree.Variable_Elements.Table (V2) := Var;
314 -- Then the associated array attributes
316 while A1 /= No_Array loop
320 Arr := In_Tree.Arrays.Table (A1);
323 -- Remove the Next component
325 Arr.Next := No_Array;
327 Array_Table.Increment_Last (In_Tree.Arrays);
329 -- Create new Array declaration
330 if To.Arrays = No_Array then
331 To.Arrays := Array_Table.Last (In_Tree.Arrays);
334 In_Tree.Arrays.Table (A2).Next :=
335 Array_Table.Last (In_Tree.Arrays);
338 A2 := Array_Table.Last (In_Tree.Arrays);
340 -- Don't store the array, as its first element has not been set yet
342 -- Copy the array elements of the array
345 Arr.Value := No_Array_Element;
347 while E1 /= No_Array_Element loop
349 -- Copy the array element
351 Elm := In_Tree.Array_Elements.Table (E1);
354 -- Remove the Next component
356 Elm.Next := No_Array_Element;
358 -- Change the location
360 Elm.Value.Location := New_Loc;
361 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
363 -- Create new array element
365 if Arr.Value = No_Array_Element then
366 Arr.Value := Array_Element_Table.Last (In_Tree.Array_Elements);
368 In_Tree.Array_Elements.Table (E2).Next :=
369 Array_Element_Table.Last (In_Tree.Array_Elements);
372 E2 := Array_Element_Table.Last (In_Tree.Array_Elements);
373 In_Tree.Array_Elements.Table (E2) := Elm;
376 -- Finally, store the new array
378 In_Tree.Arrays.Table (A2) := Arr;
380 end Copy_Package_Declarations;
387 (Project : Project_Id;
388 In_Tree : Project_Tree_Ref;
389 From_Project_Node : Project_Node_Id;
390 From_Project_Node_Tree : Project_Node_Tree_Ref;
392 First_Term : Project_Node_Id;
393 Kind : Variable_Kind) return Variable_Value
395 The_Term : Project_Node_Id := First_Term;
396 -- The term in the expression list
398 The_Current_Term : Project_Node_Id := Empty_Node;
399 -- The current term node id
401 Result : Variable_Value (Kind => Kind);
402 -- The returned result
404 Last : String_List_Id := Nil_String;
405 -- Reference to the last string elements in Result, when Kind is List
408 Result.Project := Project;
409 Result.Location := Location_Of (First_Term, From_Project_Node_Tree);
411 -- Process each term of the expression, starting with First_Term
413 while The_Term /= Empty_Node loop
414 The_Current_Term := Current_Term (The_Term, From_Project_Node_Tree);
416 case Kind_Of (The_Current_Term, From_Project_Node_Tree) is
418 when N_Literal_String =>
424 -- Should never happen
426 pragma Assert (False, "Undefined expression kind");
432 (The_Current_Term, From_Project_Node_Tree));
435 (The_Current_Term, From_Project_Node_Tree);
439 String_Element_Table.Increment_Last
440 (In_Tree.String_Elements);
442 if Last = Nil_String then
444 -- This can happen in an expression like () & "toto"
446 Result.Values := String_Element_Table.Last
447 (In_Tree.String_Elements);
450 In_Tree.String_Elements.Table
451 (Last).Next := String_Element_Table.Last
452 (In_Tree.String_Elements);
455 Last := String_Element_Table.Last
456 (In_Tree.String_Elements);
457 In_Tree.String_Elements.Table (Last) :=
461 From_Project_Node_Tree),
464 (The_Current_Term, From_Project_Node_Tree),
465 Display_Value => No_Name,
469 From_Project_Node_Tree),
474 when N_Literal_String_List =>
477 String_Node : Project_Node_Id :=
478 First_Expression_In_List
480 From_Project_Node_Tree);
482 Value : Variable_Value;
485 if String_Node /= Empty_Node then
487 -- If String_Node is nil, it is an empty list,
488 -- there is nothing to do
493 From_Project_Node => From_Project_Node,
494 From_Project_Node_Tree => From_Project_Node_Tree,
498 (String_Node, From_Project_Node_Tree),
500 String_Element_Table.Increment_Last
501 (In_Tree.String_Elements);
503 if Result.Values = Nil_String then
505 -- This literal string list is the first term
506 -- in a string list expression
509 String_Element_Table.Last (In_Tree.String_Elements);
512 In_Tree.String_Elements.Table
514 String_Element_Table.Last (In_Tree.String_Elements);
518 String_Element_Table.Last (In_Tree.String_Elements);
520 In_Tree.String_Elements.Table (Last) :=
521 (Value => Value.Value,
522 Display_Value => No_Name,
523 Location => Value.Location,
526 Index => Value.Index);
529 -- Add the other element of the literal string list
530 -- one after the other
533 Next_Expression_In_List
534 (String_Node, From_Project_Node_Tree);
536 exit when String_Node = Empty_Node;
542 From_Project_Node => From_Project_Node,
543 From_Project_Node_Tree => From_Project_Node_Tree,
547 (String_Node, From_Project_Node_Tree),
550 String_Element_Table.Increment_Last
551 (In_Tree.String_Elements);
552 In_Tree.String_Elements.Table
553 (Last).Next := String_Element_Table.Last
554 (In_Tree.String_Elements);
555 Last := String_Element_Table.Last
556 (In_Tree.String_Elements);
557 In_Tree.String_Elements.Table (Last) :=
558 (Value => Value.Value,
559 Display_Value => No_Name,
560 Location => Value.Location,
563 Index => Value.Index);
568 when N_Variable_Reference | N_Attribute_Reference =>
571 The_Project : Project_Id := Project;
572 The_Package : Package_Id := Pkg;
573 The_Name : Name_Id := No_Name;
574 The_Variable_Id : Variable_Id := No_Variable;
575 The_Variable : Variable_Value;
576 Term_Project : constant Project_Node_Id :=
578 (The_Current_Term, From_Project_Node_Tree);
579 Term_Package : constant Project_Node_Id :=
581 (The_Current_Term, From_Project_Node_Tree);
582 Index : Name_Id := No_Name;
585 if Term_Project /= Empty_Node and then
586 Term_Project /= From_Project_Node
588 -- This variable or attribute comes from another project
591 Name_Of (Term_Project, From_Project_Node_Tree);
592 The_Project := Imported_Or_Extended_Project_From
595 With_Name => The_Name);
598 if Term_Package /= Empty_Node then
600 -- This is an attribute of a package
603 Name_Of (Term_Package, From_Project_Node_Tree);
604 The_Package := In_Tree.Projects.Table
605 (The_Project).Decl.Packages;
607 while The_Package /= No_Package
608 and then In_Tree.Packages.Table
609 (The_Package).Name /= The_Name
612 In_Tree.Packages.Table
617 (The_Package /= No_Package,
618 "package not found.");
620 elsif Kind_Of (The_Current_Term, From_Project_Node_Tree) =
621 N_Attribute_Reference
623 The_Package := No_Package;
627 Name_Of (The_Current_Term, From_Project_Node_Tree);
629 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
630 N_Attribute_Reference
633 Associative_Array_Index_Of
634 (The_Current_Term, From_Project_Node_Tree);
637 -- If it is not an associative array attribute
639 if Index = No_Name then
641 -- It is not an associative array attribute
643 if The_Package /= No_Package then
645 -- First, if there is a package, look into the package
647 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
651 In_Tree.Packages.Table
652 (The_Package).Decl.Variables;
655 In_Tree.Packages.Table
656 (The_Package).Decl.Attributes;
659 while The_Variable_Id /= No_Variable
661 In_Tree.Variable_Elements.Table
662 (The_Variable_Id).Name /= The_Name
665 In_Tree.Variable_Elements.Table
666 (The_Variable_Id).Next;
671 if The_Variable_Id = No_Variable then
673 -- If we have not found it, look into the project
675 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
679 In_Tree.Projects.Table
680 (The_Project).Decl.Variables;
683 In_Tree.Projects.Table
684 (The_Project).Decl.Attributes;
687 while The_Variable_Id /= No_Variable
689 In_Tree.Variable_Elements.Table
690 (The_Variable_Id).Name /= The_Name
693 In_Tree.Variable_Elements.Table
694 (The_Variable_Id).Next;
699 pragma Assert (The_Variable_Id /= No_Variable,
700 "variable or attribute not found");
703 In_Tree.Variable_Elements.Table
704 (The_Variable_Id).Value;
708 -- It is an associative array attribute
711 The_Array : Array_Id := No_Array;
712 The_Element : Array_Element_Id := No_Array_Element;
713 Array_Index : Name_Id := No_Name;
716 if The_Package /= No_Package then
718 In_Tree.Packages.Table
719 (The_Package).Decl.Arrays;
722 In_Tree.Projects.Table
723 (The_Project).Decl.Arrays;
726 while The_Array /= No_Array
727 and then In_Tree.Arrays.Table
728 (The_Array).Name /= The_Name
730 The_Array := In_Tree.Arrays.Table
734 if The_Array /= No_Array then
735 The_Element := In_Tree.Arrays.Table
738 Get_Name_String (Index);
741 (The_Current_Term, From_Project_Node_Tree)
743 To_Lower (Name_Buffer (1 .. Name_Len));
746 Array_Index := Name_Find;
748 while The_Element /= No_Array_Element
750 In_Tree.Array_Elements.Table
751 (The_Element).Index /= Array_Index
754 In_Tree.Array_Elements.Table
760 if The_Element /= No_Array_Element then
762 In_Tree.Array_Elements.Table
766 if Expression_Kind_Of
767 (The_Current_Term, From_Project_Node_Tree) =
773 Location => No_Location,
775 Values => Nil_String);
780 Location => No_Location,
782 Value => Empty_String,
793 -- Should never happen
795 pragma Assert (False, "undefined expression kind");
800 case The_Variable.Kind is
806 Add (Result.Value, The_Variable.Value);
810 -- Should never happen
814 "list cannot appear in single " &
815 "string expression");
820 case The_Variable.Kind is
826 String_Element_Table.Increment_Last
827 (In_Tree.String_Elements);
829 if Last = Nil_String then
831 -- This can happen in an expression such as
835 String_Element_Table.Last
836 (In_Tree.String_Elements);
839 In_Tree.String_Elements.Table
841 String_Element_Table.Last
842 (In_Tree.String_Elements);
846 String_Element_Table.Last
847 (In_Tree.String_Elements);
849 In_Tree.String_Elements.Table (Last) :=
850 (Value => The_Variable.Value,
851 Display_Value => No_Name,
852 Location => Location_Of
854 From_Project_Node_Tree),
862 The_List : String_List_Id :=
866 while The_List /= Nil_String loop
867 String_Element_Table.Increment_Last
868 (In_Tree.String_Elements);
870 if Last = Nil_String then
872 String_Element_Table.Last
878 String_Elements.Table (Last).Next :=
879 String_Element_Table.Last
886 String_Element_Table.Last
887 (In_Tree.String_Elements);
889 In_Tree.String_Elements.Table (Last) :=
891 In_Tree.String_Elements.Table
893 Display_Value => No_Name,
897 From_Project_Node_Tree),
903 In_Tree. String_Elements.Table
911 when N_External_Value =>
914 (External_Reference_Of
915 (The_Current_Term, From_Project_Node_Tree),
916 From_Project_Node_Tree));
919 Name : constant Name_Id := Name_Find;
920 Default : Name_Id := No_Name;
921 Value : Name_Id := No_Name;
923 Def_Var : Variable_Value;
925 Default_Node : constant Project_Node_Id :=
927 (The_Current_Term, From_Project_Node_Tree);
930 -- If there is a default value for the external reference,
933 if Default_Node /= Empty_Node then
934 Def_Var := Expression
937 From_Project_Node => Default_Node,
938 From_Project_Node_Tree => From_Project_Node_Tree,
942 (Default_Node, From_Project_Node_Tree),
945 if Def_Var /= Nil_Variable_Value then
946 Default := Def_Var.Value;
950 Value := Prj.Ext.Value_Of (Name, Default);
952 if Value = No_Name then
953 if not Quiet_Output then
954 if Error_Report = null then
956 ("?undefined external reference",
958 (The_Current_Term, From_Project_Node_Tree));
961 ("warning: """ & Get_Name_String (Name) &
962 """ is an undefined external reference",
967 Value := Empty_String;
976 Add (Result.Value, Value);
979 String_Element_Table.Increment_Last
980 (In_Tree.String_Elements);
982 if Last = Nil_String then
983 Result.Values := String_Element_Table.Last
984 (In_Tree.String_Elements);
987 In_Tree.String_Elements.Table
988 (Last).Next := String_Element_Table.Last
989 (In_Tree.String_Elements);
992 Last := String_Element_Table.Last
993 (In_Tree.String_Elements);
994 In_Tree.String_Elements.Table (Last) :=
996 Display_Value => No_Name,
999 (The_Current_Term, From_Project_Node_Tree),
1009 -- Should never happen
1013 "illegal node kind in an expression");
1014 raise Program_Error;
1018 The_Term := Next_Term (The_Term, From_Project_Node_Tree);
1024 ---------------------------------------
1025 -- Imported_Or_Extended_Project_From --
1026 ---------------------------------------
1028 function Imported_Or_Extended_Project_From
1029 (Project : Project_Id;
1030 In_Tree : Project_Tree_Ref;
1031 With_Name : Name_Id) return Project_Id
1033 Data : constant Project_Data :=
1034 In_Tree.Projects.Table (Project);
1035 List : Project_List := Data.Imported_Projects;
1036 Result : Project_Id := No_Project;
1037 Temp_Result : Project_Id := No_Project;
1040 -- First check if it is the name of an extended project
1042 if Data.Extends /= No_Project
1043 and then In_Tree.Projects.Table (Data.Extends).Name =
1046 return Data.Extends;
1049 -- Then check the name of each imported project
1051 while List /= Empty_Project_List loop
1052 Result := In_Tree.Project_Lists.Table (List).Project;
1054 -- If the project is directly imported, then returns its ID
1057 In_Tree.Projects.Table (Result).Name = With_Name
1062 -- If a project extending the project is imported, then keep
1063 -- this extending project as a possibility. It will be the
1064 -- returned ID if the project is not imported directly.
1067 Proj : Project_Id :=
1068 In_Tree.Projects.Table (Result).Extends;
1070 while Proj /= No_Project loop
1071 if In_Tree.Projects.Table (Proj).Name =
1074 Temp_Result := Result;
1078 Proj := In_Tree.Projects.Table (Proj).Extends;
1082 List := In_Tree.Project_Lists.Table (List).Next;
1086 (Temp_Result /= No_Project,
1087 "project not found");
1091 end Imported_Or_Extended_Project_From;
1097 function Package_From
1098 (Project : Project_Id;
1099 In_Tree : Project_Tree_Ref;
1100 With_Name : Name_Id) return Package_Id
1102 Data : constant Project_Data :=
1103 In_Tree.Projects.Table (Project);
1104 Result : Package_Id := Data.Decl.Packages;
1107 -- Check the name of each existing package of Project
1109 while Result /= No_Package
1110 and then In_Tree.Packages.Table (Result).Name /= With_Name
1112 Result := In_Tree.Packages.Table (Result).Next;
1115 if Result = No_Package then
1117 -- Should never happen
1119 Write_Line ("package """ & Get_Name_String (With_Name) &
1121 raise Program_Error;
1133 (In_Tree : Project_Tree_Ref;
1134 Project : out Project_Id;
1135 Success : out Boolean;
1136 From_Project_Node : Project_Node_Id;
1137 From_Project_Node_Tree : Project_Node_Tree_Ref;
1138 Report_Error : Put_Line_Access;
1139 Follow_Links : Boolean := True;
1140 When_No_Sources : Error_Warning := Error)
1143 Extending : Project_Id;
1144 Extending2 : Project_Id;
1147 Error_Report := Report_Error;
1150 -- Make sure there is no projects in the data structure
1152 Project_Table.Set_Last (In_Tree.Projects, No_Project);
1153 Processed_Projects.Reset;
1155 -- And process the main project and all of the projects it depends on,
1159 (Project => Project,
1161 From_Project_Node => From_Project_Node,
1162 From_Project_Node_Tree => From_Project_Node_Tree,
1163 Extended_By => No_Project);
1165 if Project /= No_Project then
1166 Check (In_Tree, Project, Follow_Links, When_No_Sources);
1169 -- If main project is an extending all project, set the object
1170 -- directory of all virtual extending projects to the object directory
1171 -- of the main project.
1173 if Project /= No_Project
1174 and then Is_Extending_All (From_Project_Node, From_Project_Node_Tree)
1177 Object_Dir : constant Name_Id :=
1178 In_Tree.Projects.Table (Project).Object_Directory;
1181 Project_Table.First .. Project_Table.Last (In_Tree.Projects)
1183 if In_Tree.Projects.Table (Index).Virtual then
1184 In_Tree.Projects.Table (Index).Object_Directory :=
1191 -- Check that no extending project shares its object directory with
1192 -- the project(s) it extends.
1194 if Project /= No_Project then
1196 Project_Table.First .. Project_Table.Last (In_Tree.Projects)
1198 Extending := In_Tree.Projects.Table (Proj).Extended_By;
1200 if Extending /= No_Project then
1201 Obj_Dir := In_Tree.Projects.Table (Proj).Object_Directory;
1203 -- Check that a project being extended does not share its
1204 -- object directory with any project that extends it, directly
1205 -- or indirectly, including a virtual extending project.
1207 -- Start with the project directly extending it
1209 Extending2 := Extending;
1210 while Extending2 /= No_Project loop
1211 if In_Tree.Projects.Table (Extending2).Ada_Sources_Present
1213 In_Tree.Projects.Table (Extending2).Object_Directory =
1216 if In_Tree.Projects.Table (Extending2).Virtual then
1218 In_Tree.Projects.Table (Proj).Display_Name;
1220 if Error_Report = null then
1222 ("project { cannot be extended by a virtual " &
1223 "project with the same object directory",
1224 In_Tree.Projects.Table (Proj).Location);
1228 Get_Name_String (Error_Msg_Name_1) &
1229 """ cannot be extended by a virtual " &
1230 "project with the same object directory",
1236 In_Tree.Projects.Table (Extending2).Display_Name;
1238 In_Tree.Projects.Table (Proj).Display_Name;
1240 if Error_Report = null then
1242 ("project { cannot extend project {",
1243 In_Tree.Projects.Table (Extending2).Location);
1245 ("\they share the same object directory",
1246 In_Tree.Projects.Table (Extending2).Location);
1251 Get_Name_String (Error_Msg_Name_1) &
1252 """ cannot extend project """ &
1253 Get_Name_String (Error_Msg_Name_2) & """",
1256 ("they share the same object directory",
1262 -- Continue with the next extending project, if any
1265 In_Tree.Projects.Table (Extending2).Extended_By;
1272 Total_Errors_Detected = 0
1274 (Warning_Mode /= Treat_As_Error or else Warnings_Detected = 0);
1277 -------------------------------
1278 -- Process_Declarative_Items --
1279 -------------------------------
1281 procedure Process_Declarative_Items
1282 (Project : Project_Id;
1283 In_Tree : Project_Tree_Ref;
1284 From_Project_Node : Project_Node_Id;
1285 From_Project_Node_Tree : Project_Node_Tree_Ref;
1287 Item : Project_Node_Id)
1289 Current_Declarative_Item : Project_Node_Id := Item;
1290 Current_Item : Project_Node_Id := Empty_Node;
1293 -- For each declarative item
1295 while Current_Declarative_Item /= Empty_Node loop
1301 (Current_Declarative_Item, From_Project_Node_Tree);
1303 -- And set Current_Declarative_Item to the next declarative item
1304 -- ready for the next iteration.
1306 Current_Declarative_Item :=
1307 Next_Declarative_Item
1308 (Current_Declarative_Item, From_Project_Node_Tree);
1310 case Kind_Of (Current_Item, From_Project_Node_Tree) is
1312 when N_Package_Declaration =>
1313 -- Do not process a package declaration that should be ignored
1315 if Expression_Kind_Of
1316 (Current_Item, From_Project_Node_Tree) /= Ignored
1318 -- Create the new package
1320 Package_Table.Increment_Last (In_Tree.Packages);
1323 New_Pkg : constant Package_Id :=
1324 Package_Table.Last (In_Tree.Packages);
1325 The_New_Package : Package_Element;
1327 Project_Of_Renamed_Package :
1328 constant Project_Node_Id :=
1329 Project_Of_Renamed_Package_Of
1330 (Current_Item, From_Project_Node_Tree);
1333 -- Set the name of the new package
1335 The_New_Package.Name :=
1336 Name_Of (Current_Item, From_Project_Node_Tree);
1338 -- Insert the new package in the appropriate list
1340 if Pkg /= No_Package then
1341 The_New_Package.Next :=
1342 In_Tree.Packages.Table (Pkg).Decl.Packages;
1343 In_Tree.Packages.Table (Pkg).Decl.Packages :=
1346 The_New_Package.Next :=
1347 In_Tree.Projects.Table (Project).Decl.Packages;
1348 In_Tree.Projects.Table (Project).Decl.Packages :=
1352 In_Tree.Packages.Table (New_Pkg) :=
1355 if Project_Of_Renamed_Package /= Empty_Node then
1360 Project_Name : constant Name_Id :=
1362 (Project_Of_Renamed_Package,
1363 From_Project_Node_Tree);
1366 constant Project_Id :=
1367 Imported_Or_Extended_Project_From
1368 (Project, In_Tree, Project_Name);
1370 Renamed_Package : constant Package_Id :=
1372 (Renamed_Project, In_Tree,
1375 From_Project_Node_Tree));
1378 -- For a renamed package, copy the declarations of
1379 -- the renamed package, but set all the locations
1380 -- to the location of the package name in the
1381 -- renaming declaration.
1383 Copy_Package_Declarations
1385 In_Tree.Packages.Table (Renamed_Package).Decl,
1387 In_Tree.Packages.Table (New_Pkg).Decl,
1390 (Current_Item, From_Project_Node_Tree),
1391 In_Tree => In_Tree);
1394 -- Standard package declaration, not renaming
1397 -- Set the default values of the attributes
1401 In_Tree.Packages.Table (New_Pkg).Decl,
1404 (Current_Item, From_Project_Node_Tree)));
1406 -- And process declarative items of the new package
1408 Process_Declarative_Items
1409 (Project => Project,
1411 From_Project_Node => From_Project_Node,
1412 From_Project_Node_Tree => From_Project_Node_Tree,
1415 First_Declarative_Item_Of
1416 (Current_Item, From_Project_Node_Tree));
1421 when N_String_Type_Declaration =>
1423 -- There is nothing to process
1427 when N_Attribute_Declaration |
1428 N_Typed_Variable_Declaration |
1429 N_Variable_Declaration =>
1431 if Expression_Of (Current_Item, From_Project_Node_Tree) =
1435 -- It must be a full associative array attribute declaration
1438 Current_Item_Name : constant Name_Id :=
1439 Name_Of (Current_Item, From_Project_Node_Tree);
1440 -- The name of the attribute
1442 New_Array : Array_Id;
1443 -- The new associative array created
1445 Orig_Array : Array_Id;
1446 -- The associative array value
1448 Orig_Project_Name : Name_Id := No_Name;
1449 -- The name of the project where the associative array
1452 Orig_Project : Project_Id := No_Project;
1453 -- The id of the project where the associative array
1456 Orig_Package_Name : Name_Id := No_Name;
1457 -- The name of the package, if any, where the associative
1460 Orig_Package : Package_Id := No_Package;
1461 -- The id of the package, if any, where the associative
1464 New_Element : Array_Element_Id := No_Array_Element;
1465 -- Id of a new array element created
1467 Prev_Element : Array_Element_Id := No_Array_Element;
1468 -- Last new element id created
1470 Orig_Element : Array_Element_Id := No_Array_Element;
1471 -- Current array element in the original associative
1474 Next_Element : Array_Element_Id := No_Array_Element;
1475 -- Id of the array element that follows the new element.
1476 -- This is not always nil, because values for the
1477 -- associative array attribute may already have been
1478 -- declared, and the array elements declared are reused.
1481 -- First, find if the associative array attribute already
1482 -- has elements declared.
1484 if Pkg /= No_Package then
1485 New_Array := In_Tree.Packages.Table
1489 New_Array := In_Tree.Projects.Table
1490 (Project).Decl.Arrays;
1493 while New_Array /= No_Array
1494 and then In_Tree.Arrays.Table (New_Array).Name /=
1497 New_Array := In_Tree.Arrays.Table (New_Array).Next;
1500 -- If the attribute has never been declared add new entry
1501 -- in the arrays of the project/package and link it.
1503 if New_Array = No_Array then
1504 Array_Table.Increment_Last (In_Tree.Arrays);
1505 New_Array := Array_Table.Last (In_Tree.Arrays);
1507 if Pkg /= No_Package then
1508 In_Tree.Arrays.Table (New_Array) :=
1509 (Name => Current_Item_Name,
1510 Value => No_Array_Element,
1512 In_Tree.Packages.Table (Pkg).Decl.Arrays);
1514 In_Tree.Packages.Table (Pkg).Decl.Arrays :=
1518 In_Tree.Arrays.Table (New_Array) :=
1519 (Name => Current_Item_Name,
1520 Value => No_Array_Element,
1522 In_Tree.Projects.Table (Project).Decl.Arrays);
1524 In_Tree.Projects.Table (Project).Decl.Arrays :=
1529 -- Find the project where the value is declared
1531 Orig_Project_Name :=
1533 (Associative_Project_Of
1534 (Current_Item, From_Project_Node_Tree),
1535 From_Project_Node_Tree);
1537 for Index in Project_Table.First ..
1541 if In_Tree.Projects.Table (Index).Name =
1544 Orig_Project := Index;
1549 pragma Assert (Orig_Project /= No_Project,
1550 "original project not found");
1552 if Associative_Package_Of
1553 (Current_Item, From_Project_Node_Tree) = Empty_Node
1556 In_Tree.Projects.Table
1557 (Orig_Project).Decl.Arrays;
1560 -- If in a package, find the package where the
1561 -- value is declared.
1563 Orig_Package_Name :=
1565 (Associative_Package_Of
1566 (Current_Item, From_Project_Node_Tree),
1567 From_Project_Node_Tree);
1570 In_Tree.Projects.Table
1571 (Orig_Project).Decl.Packages;
1572 pragma Assert (Orig_Package /= No_Package,
1573 "original package not found");
1575 while In_Tree.Packages.Table
1576 (Orig_Package).Name /= Orig_Package_Name
1578 Orig_Package := In_Tree.Packages.Table
1579 (Orig_Package).Next;
1580 pragma Assert (Orig_Package /= No_Package,
1581 "original package not found");
1585 In_Tree.Packages.Table
1586 (Orig_Package).Decl.Arrays;
1589 -- Now look for the array
1591 while Orig_Array /= No_Array and then
1592 In_Tree.Arrays.Table (Orig_Array).Name /=
1595 Orig_Array := In_Tree.Arrays.Table
1599 if Orig_Array = No_Array then
1600 if Error_Report = null then
1602 ("associative array value cannot be found",
1604 (Current_Item, From_Project_Node_Tree));
1608 ("associative array value cannot be found",
1614 In_Tree.Arrays.Table (Orig_Array).Value;
1616 -- Copy each array element
1618 while Orig_Element /= No_Array_Element loop
1620 -- Case of first element
1622 if Prev_Element = No_Array_Element then
1624 -- And there is no array element declared yet,
1625 -- create a new first array element.
1627 if In_Tree.Arrays.Table (New_Array).Value =
1630 Array_Element_Table.Increment_Last
1631 (In_Tree.Array_Elements);
1632 New_Element := Array_Element_Table.Last
1633 (In_Tree.Array_Elements);
1634 In_Tree.Arrays.Table
1635 (New_Array).Value := New_Element;
1636 Next_Element := No_Array_Element;
1638 -- Otherwise, the new element is the first
1641 New_Element := In_Tree.Arrays.
1642 Table (New_Array).Value;
1644 In_Tree.Array_Elements.Table
1648 -- Otherwise, reuse an existing element, or create
1649 -- one if necessary.
1653 In_Tree.Array_Elements.Table
1654 (Prev_Element).Next;
1656 if Next_Element = No_Array_Element then
1657 Array_Element_Table.Increment_Last
1658 (In_Tree.Array_Elements);
1659 New_Element := Array_Element_Table.Last
1660 (In_Tree.Array_Elements);
1663 New_Element := Next_Element;
1665 In_Tree.Array_Elements.Table
1670 -- Copy the value of the element
1672 In_Tree.Array_Elements.Table
1674 In_Tree.Array_Elements.Table
1676 In_Tree.Array_Elements.Table
1677 (New_Element).Value.Project := Project;
1679 -- Adjust the Next link
1681 In_Tree.Array_Elements.Table
1682 (New_Element).Next := Next_Element;
1684 -- Adjust the previous id for the next element
1686 Prev_Element := New_Element;
1688 -- Go to the next element in the original array
1691 In_Tree.Array_Elements.Table
1692 (Orig_Element).Next;
1695 -- Make sure that the array ends here, in case there
1696 -- previously a greater number of elements.
1698 In_Tree.Array_Elements.Table
1699 (New_Element).Next := No_Array_Element;
1703 -- Declarations other that full associative arrays
1707 New_Value : constant Variable_Value :=
1709 (Project => Project,
1711 From_Project_Node => From_Project_Node,
1712 From_Project_Node_Tree => From_Project_Node_Tree,
1717 (Current_Item, From_Project_Node_Tree),
1718 From_Project_Node_Tree),
1721 (Current_Item, From_Project_Node_Tree));
1722 -- The expression value
1724 The_Variable : Variable_Id := No_Variable;
1726 Current_Item_Name : constant Name_Id :=
1727 Name_Of (Current_Item, From_Project_Node_Tree);
1730 -- Process a typed variable declaration
1732 if Kind_Of (Current_Item, From_Project_Node_Tree) =
1733 N_Typed_Variable_Declaration
1735 -- Report an error for an empty string
1737 if New_Value.Value = Empty_String then
1739 Name_Of (Current_Item, From_Project_Node_Tree);
1741 if Error_Report = null then
1743 ("no value defined for %",
1745 (Current_Item, From_Project_Node_Tree));
1749 ("no value defined for " &
1750 Get_Name_String (Error_Msg_Name_1),
1756 Current_String : Project_Node_Id :=
1757 First_Literal_String
1760 From_Project_Node_Tree),
1761 From_Project_Node_Tree);
1764 -- Loop through all the valid strings for the
1765 -- string type and compare to the string value.
1767 while Current_String /= Empty_Node
1770 (Current_String, From_Project_Node_Tree) /=
1775 (Current_String, From_Project_Node_Tree);
1778 -- Report an error if the string value is not
1779 -- one for the string type.
1781 if Current_String = Empty_Node then
1782 Error_Msg_Name_1 := New_Value.Value;
1785 (Current_Item, From_Project_Node_Tree);
1787 if Error_Report = null then
1789 ("value { is illegal for typed string %",
1792 From_Project_Node_Tree));
1797 Get_Name_String (Error_Msg_Name_1) &
1798 """ is illegal for typed string """ &
1799 Get_Name_String (Error_Msg_Name_2) &
1808 if Kind_Of (Current_Item, From_Project_Node_Tree) /=
1809 N_Attribute_Declaration
1811 Associative_Array_Index_Of
1812 (Current_Item, From_Project_Node_Tree) = No_Name
1814 -- Case of a variable declaration or of a not
1815 -- associative array attribute.
1817 -- First, find the list where to find the variable
1820 if Kind_Of (Current_Item, From_Project_Node_Tree) =
1821 N_Attribute_Declaration
1823 if Pkg /= No_Package then
1825 In_Tree.Packages.Table
1826 (Pkg).Decl.Attributes;
1829 In_Tree.Projects.Table
1830 (Project).Decl.Attributes;
1834 if Pkg /= No_Package then
1836 In_Tree.Packages.Table
1837 (Pkg).Decl.Variables;
1840 In_Tree.Projects.Table
1841 (Project).Decl.Variables;
1846 -- Loop through the list, to find if it has already
1849 while The_Variable /= No_Variable
1851 In_Tree.Variable_Elements.Table
1852 (The_Variable).Name /= Current_Item_Name
1855 In_Tree.Variable_Elements.Table
1856 (The_Variable).Next;
1859 -- If it has not been declared, create a new entry
1862 if The_Variable = No_Variable then
1864 -- All single string attribute should already have
1865 -- been declared with a default empty string value.
1868 (Kind_Of (Current_Item, From_Project_Node_Tree) /=
1869 N_Attribute_Declaration,
1870 "illegal attribute declaration");
1872 Variable_Element_Table.Increment_Last
1873 (In_Tree.Variable_Elements);
1874 The_Variable := Variable_Element_Table.Last
1875 (In_Tree.Variable_Elements);
1877 -- Put the new variable in the appropriate list
1879 if Pkg /= No_Package then
1880 In_Tree.Variable_Elements.Table (The_Variable) :=
1882 In_Tree.Packages.Table
1883 (Pkg).Decl.Variables,
1884 Name => Current_Item_Name,
1885 Value => New_Value);
1886 In_Tree.Packages.Table
1887 (Pkg).Decl.Variables := The_Variable;
1890 In_Tree.Variable_Elements.Table (The_Variable) :=
1892 In_Tree.Projects.Table
1893 (Project).Decl.Variables,
1894 Name => Current_Item_Name,
1895 Value => New_Value);
1896 In_Tree.Projects.Table
1897 (Project).Decl.Variables :=
1901 -- If the variable/attribute has already been
1902 -- declared, just change the value.
1905 In_Tree.Variable_Elements.Table
1906 (The_Variable).Value :=
1912 -- Associative array attribute
1914 -- Get the string index
1917 (Associative_Array_Index_Of
1918 (Current_Item, From_Project_Node_Tree));
1920 -- Put in lower case, if necessary
1923 (Current_Item, From_Project_Node_Tree)
1925 GNAT.Case_Util.To_Lower
1926 (Name_Buffer (1 .. Name_Len));
1930 The_Array : Array_Id;
1932 The_Array_Element : Array_Element_Id :=
1935 Index_Name : constant Name_Id := Name_Find;
1936 -- The name id of the index
1939 -- Look for the array in the appropriate list
1941 if Pkg /= No_Package then
1942 The_Array := In_Tree.Packages.Table
1946 The_Array := In_Tree.Projects.Table
1947 (Project).Decl.Arrays;
1951 The_Array /= No_Array
1952 and then In_Tree.Arrays.Table
1953 (The_Array).Name /= Current_Item_Name
1955 The_Array := In_Tree.Arrays.Table
1959 -- If the array cannot be found, create a new
1960 -- entry in the list. As The_Array_Element is
1961 -- initialized to No_Array_Element, a new element
1962 -- will be created automatically later.
1964 if The_Array = No_Array then
1965 Array_Table.Increment_Last
1967 The_Array := Array_Table.Last
1970 if Pkg /= No_Package then
1971 In_Tree.Arrays.Table
1973 (Name => Current_Item_Name,
1974 Value => No_Array_Element,
1976 In_Tree.Packages.Table
1979 In_Tree.Packages.Table
1980 (Pkg).Decl.Arrays :=
1984 In_Tree.Arrays.Table
1986 (Name => Current_Item_Name,
1987 Value => No_Array_Element,
1989 In_Tree.Projects.Table
1990 (Project).Decl.Arrays);
1992 In_Tree.Projects.Table
1993 (Project).Decl.Arrays :=
1997 -- Otherwise, initialize The_Array_Element as the
1998 -- head of the element list.
2001 The_Array_Element :=
2002 In_Tree.Arrays.Table
2006 -- Look in the list, if any, to find an element
2007 -- with the same index.
2009 while The_Array_Element /= No_Array_Element
2011 In_Tree.Array_Elements.Table
2012 (The_Array_Element).Index /= Index_Name
2014 The_Array_Element :=
2015 In_Tree.Array_Elements.Table
2016 (The_Array_Element).Next;
2019 -- If no such element were found, create a new
2020 -- one and insert it in the element list, with
2021 -- the propoer value.
2023 if The_Array_Element = No_Array_Element then
2024 Array_Element_Table.Increment_Last
2025 (In_Tree.Array_Elements);
2026 The_Array_Element := Array_Element_Table.Last
2027 (In_Tree.Array_Elements);
2029 In_Tree.Array_Elements.Table
2030 (The_Array_Element) :=
2031 (Index => Index_Name,
2034 (Current_Item, From_Project_Node_Tree),
2035 Index_Case_Sensitive =>
2036 not Case_Insensitive
2037 (Current_Item, From_Project_Node_Tree),
2039 Next => In_Tree.Arrays.Table
2041 In_Tree.Arrays.Table
2042 (The_Array).Value := The_Array_Element;
2044 -- An element with the same index already exists,
2045 -- just replace its value with the new one.
2048 In_Tree.Array_Elements.Table
2049 (The_Array_Element).Value := New_Value;
2056 when N_Case_Construction =>
2058 The_Project : Project_Id := Project;
2059 -- The id of the project of the case variable
2061 The_Package : Package_Id := Pkg;
2062 -- The id of the package, if any, of the case variable
2064 The_Variable : Variable_Value := Nil_Variable_Value;
2065 -- The case variable
2067 Case_Value : Name_Id := No_Name;
2068 -- The case variable value
2070 Case_Item : Project_Node_Id := Empty_Node;
2071 Choice_String : Project_Node_Id := Empty_Node;
2072 Decl_Item : Project_Node_Id := Empty_Node;
2076 Variable_Node : constant Project_Node_Id :=
2077 Case_Variable_Reference_Of
2079 From_Project_Node_Tree);
2081 Var_Id : Variable_Id := No_Variable;
2082 Name : Name_Id := No_Name;
2085 -- If a project were specified for the case variable,
2089 (Variable_Node, From_Project_Node_Tree) /= Empty_Node
2094 (Variable_Node, From_Project_Node_Tree),
2095 From_Project_Node_Tree);
2097 Imported_Or_Extended_Project_From
2098 (Project, In_Tree, Name);
2101 -- If a package were specified for the case variable,
2105 (Variable_Node, From_Project_Node_Tree) /= Empty_Node
2110 (Variable_Node, From_Project_Node_Tree),
2111 From_Project_Node_Tree);
2113 Package_From (The_Project, In_Tree, Name);
2116 Name := Name_Of (Variable_Node, From_Project_Node_Tree);
2118 -- First, look for the case variable into the package,
2121 if The_Package /= No_Package then
2122 Var_Id := In_Tree.Packages.Table
2123 (The_Package).Decl.Variables;
2125 Name_Of (Variable_Node, From_Project_Node_Tree);
2126 while Var_Id /= No_Variable
2128 In_Tree.Variable_Elements.Table
2129 (Var_Id).Name /= Name
2131 Var_Id := In_Tree.Variable_Elements.
2132 Table (Var_Id).Next;
2136 -- If not found in the package, or if there is no
2137 -- package, look at the project level.
2139 if Var_Id = No_Variable
2142 (Variable_Node, From_Project_Node_Tree) = Empty_Node
2144 Var_Id := In_Tree.Projects.Table
2145 (The_Project).Decl.Variables;
2146 while Var_Id /= No_Variable
2148 In_Tree.Variable_Elements.Table
2149 (Var_Id).Name /= Name
2151 Var_Id := In_Tree.Variable_Elements.
2152 Table (Var_Id).Next;
2156 if Var_Id = No_Variable then
2158 -- Should never happen, because this has already been
2159 -- checked during parsing.
2161 Write_Line ("variable """ &
2162 Get_Name_String (Name) &
2164 raise Program_Error;
2167 -- Get the case variable
2169 The_Variable := In_Tree.Variable_Elements.
2170 Table (Var_Id).Value;
2172 if The_Variable.Kind /= Single then
2174 -- Should never happen, because this has already been
2175 -- checked during parsing.
2177 Write_Line ("variable""" &
2178 Get_Name_String (Name) &
2179 """ is not a single string variable");
2180 raise Program_Error;
2183 -- Get the case variable value
2184 Case_Value := The_Variable.Value;
2187 -- Now look into all the case items of the case construction
2190 First_Case_Item_Of (Current_Item, From_Project_Node_Tree);
2192 while Case_Item /= Empty_Node loop
2194 First_Choice_Of (Case_Item, From_Project_Node_Tree);
2196 -- When Choice_String is nil, it means that it is
2197 -- the "when others =>" alternative.
2199 if Choice_String = Empty_Node then
2201 First_Declarative_Item_Of
2202 (Case_Item, From_Project_Node_Tree);
2203 exit Case_Item_Loop;
2206 -- Look into all the alternative of this case item
2209 while Choice_String /= Empty_Node loop
2212 (Choice_String, From_Project_Node_Tree)
2215 First_Declarative_Item_Of
2216 (Case_Item, From_Project_Node_Tree);
2217 exit Case_Item_Loop;
2222 (Choice_String, From_Project_Node_Tree);
2223 end loop Choice_Loop;
2226 Next_Case_Item (Case_Item, From_Project_Node_Tree);
2227 end loop Case_Item_Loop;
2229 -- If there is an alternative, then we process it
2231 if Decl_Item /= Empty_Node then
2232 Process_Declarative_Items
2233 (Project => Project,
2235 From_Project_Node => From_Project_Node,
2236 From_Project_Node_Tree => From_Project_Node_Tree,
2244 -- Should never happen
2246 Write_Line ("Illegal declarative item: " &
2247 Project_Node_Kind'Image
2249 (Current_Item, From_Project_Node_Tree)));
2250 raise Program_Error;
2253 end Process_Declarative_Items;
2255 ---------------------
2256 -- Recursive_Check --
2257 ---------------------
2259 procedure Recursive_Check
2260 (Project : Project_Id;
2261 In_Tree : Project_Tree_Ref;
2262 Follow_Links : Boolean;
2263 When_No_Sources : Error_Warning)
2265 Data : Project_Data;
2266 Imported_Project_List : Project_List := Empty_Project_List;
2269 -- Do nothing if Project is No_Project, or Project has already
2270 -- been marked as checked.
2272 if Project /= No_Project
2273 and then not In_Tree.Projects.Table (Project).Checked
2275 -- Mark project as checked, to avoid infinite recursion in
2276 -- ill-formed trees, where a project imports itself.
2278 In_Tree.Projects.Table (Project).Checked := True;
2280 Data := In_Tree.Projects.Table (Project);
2282 -- Call itself for a possible extended project.
2283 -- (if there is no extended project, then nothing happens).
2286 (Data.Extends, In_Tree, Follow_Links, When_No_Sources);
2288 -- Call itself for all imported projects
2290 Imported_Project_List := Data.Imported_Projects;
2291 while Imported_Project_List /= Empty_Project_List loop
2293 (In_Tree.Project_Lists.Table
2294 (Imported_Project_List).Project,
2295 In_Tree, Follow_Links, When_No_Sources);
2296 Imported_Project_List :=
2297 In_Tree.Project_Lists.Table
2298 (Imported_Project_List).Next;
2301 if Verbose_Mode then
2302 Write_Str ("Checking project file """);
2303 Write_Str (Get_Name_String (Data.Name));
2308 (Project, In_Tree, Error_Report, Follow_Links, When_No_Sources);
2310 end Recursive_Check;
2312 -----------------------
2313 -- Recursive_Process --
2314 -----------------------
2316 procedure Recursive_Process
2317 (In_Tree : Project_Tree_Ref;
2318 Project : out Project_Id;
2319 From_Project_Node : Project_Node_Id;
2320 From_Project_Node_Tree : Project_Node_Tree_Ref;
2321 Extended_By : Project_Id)
2323 With_Clause : Project_Node_Id;
2326 if From_Project_Node = Empty_Node then
2327 Project := No_Project;
2331 Processed_Data : Project_Data := Empty_Project (In_Tree);
2332 Imported : Project_List := Empty_Project_List;
2333 Declaration_Node : Project_Node_Id := Empty_Node;
2334 Tref : Source_Buffer_Ptr;
2335 Name : constant Name_Id :=
2337 (From_Project_Node, From_Project_Node_Tree);
2338 Location : Source_Ptr :=
2340 (From_Project_Node, From_Project_Node_Tree);
2343 Project := Processed_Projects.Get (Name);
2345 if Project /= No_Project then
2347 -- Make sure that, when a project is extended, the project id
2348 -- of the project extending it is recorded in its data, even
2349 -- when it has already been processed as an imported project.
2350 -- This is for virtually extended projects.
2352 if Extended_By /= No_Project then
2353 In_Tree.Projects.Table (Project).Extended_By := Extended_By;
2359 Project_Table.Increment_Last (In_Tree.Projects);
2360 Project := Project_Table.Last (In_Tree.Projects);
2361 Processed_Projects.Set (Name, Project);
2363 Processed_Data.Name := Name;
2365 Get_Name_String (Name);
2367 -- If name starts with the virtual prefix, flag the project as
2368 -- being a virtual extending project.
2370 if Name_Len > Virtual_Prefix'Length
2371 and then Name_Buffer (1 .. Virtual_Prefix'Length) =
2374 Processed_Data.Virtual := True;
2375 Processed_Data.Display_Name := Name;
2377 -- If there is no file, for example when the project node tree is
2378 -- built in memory by GPS, the Display_Name cannot be found in
2379 -- the source, so its value is the same as Name.
2381 elsif Location = No_Location then
2382 Processed_Data.Display_Name := Name;
2384 -- Get the spelling of the project name from the project file
2387 Tref := Source_Text (Get_Source_File_Index (Location));
2389 for J in 1 .. Name_Len loop
2390 Name_Buffer (J) := Tref (Location);
2391 Location := Location + 1;
2394 Processed_Data.Display_Name := Name_Find;
2397 Processed_Data.Display_Path_Name :=
2398 Path_Name_Of (From_Project_Node, From_Project_Node_Tree);
2399 Get_Name_String (Processed_Data.Display_Path_Name);
2400 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2401 Processed_Data.Path_Name := Name_Find;
2403 Processed_Data.Location :=
2404 Location_Of (From_Project_Node, From_Project_Node_Tree);
2406 Processed_Data.Display_Directory :=
2407 Directory_Of (From_Project_Node, From_Project_Node_Tree);
2408 Get_Name_String (Processed_Data.Display_Directory);
2409 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2410 Processed_Data.Directory := Name_Find;
2412 Processed_Data.Extended_By := Extended_By;
2415 (Project, In_Tree, Processed_Data.Decl, Attribute_First);
2417 First_With_Clause_Of (From_Project_Node, From_Project_Node_Tree);
2419 while With_Clause /= Empty_Node loop
2421 New_Project : Project_Id;
2422 New_Data : Project_Data;
2426 (In_Tree => In_Tree,
2427 Project => New_Project,
2428 From_Project_Node =>
2429 Project_Node_Of (With_Clause, From_Project_Node_Tree),
2430 From_Project_Node_Tree => From_Project_Node_Tree,
2431 Extended_By => No_Project);
2433 In_Tree.Projects.Table (New_Project);
2435 -- If we were the first project to import it,
2436 -- set First_Referred_By to us.
2438 if New_Data.First_Referred_By = No_Project then
2439 New_Data.First_Referred_By := Project;
2440 In_Tree.Projects.Table (New_Project) :=
2444 -- Add this project to our list of imported projects
2446 Project_List_Table.Increment_Last
2447 (In_Tree.Project_Lists);
2448 In_Tree.Project_Lists.Table
2449 (Project_List_Table.Last
2450 (In_Tree.Project_Lists)) :=
2451 (Project => New_Project, Next => Empty_Project_List);
2453 -- Imported is the id of the last imported project.
2454 -- If it is nil, then this imported project is our first.
2456 if Imported = Empty_Project_List then
2457 Processed_Data.Imported_Projects :=
2458 Project_List_Table.Last
2459 (In_Tree.Project_Lists);
2462 In_Tree.Project_Lists.Table
2463 (Imported).Next := Project_List_Table.Last
2464 (In_Tree.Project_Lists);
2467 Imported := Project_List_Table.Last
2468 (In_Tree.Project_Lists);
2471 Next_With_Clause_Of (With_Clause, From_Project_Node_Tree);
2476 Project_Declaration_Of
2477 (From_Project_Node, From_Project_Node_Tree);
2480 (In_Tree => In_Tree,
2481 Project => Processed_Data.Extends,
2482 From_Project_Node =>
2484 (Declaration_Node, From_Project_Node_Tree),
2485 From_Project_Node_Tree => From_Project_Node_Tree,
2486 Extended_By => Project);
2488 In_Tree.Projects.Table (Project) := Processed_Data;
2490 Process_Declarative_Items
2491 (Project => Project,
2493 From_Project_Node => From_Project_Node,
2494 From_Project_Node_Tree => From_Project_Node_Tree,
2497 First_Declarative_Item_Of
2498 (Declaration_Node, From_Project_Node_Tree));
2500 -- If it is an extending project, inherit all packages
2501 -- from the extended project that are not explicitely defined
2502 -- or renamed. Also inherit the languages, if attribute Languages
2503 -- is not explicitely defined.
2505 if Processed_Data.Extends /= No_Project then
2506 Processed_Data := In_Tree.Projects.Table (Project);
2509 Extended_Pkg : Package_Id :=
2510 In_Tree.Projects.Table
2511 (Processed_Data.Extends).Decl.Packages;
2512 Current_Pkg : Package_Id;
2513 Element : Package_Element;
2514 First : constant Package_Id :=
2515 Processed_Data.Decl.Packages;
2516 Attribute1 : Variable_Id;
2517 Attribute2 : Variable_Id;
2518 Attr_Value1 : Variable;
2519 Attr_Value2 : Variable;
2522 while Extended_Pkg /= No_Package loop
2524 In_Tree.Packages.Table (Extended_Pkg);
2526 Current_Pkg := First;
2529 exit when Current_Pkg = No_Package
2530 or else In_Tree.Packages.Table
2531 (Current_Pkg).Name = Element.Name;
2532 Current_Pkg := In_Tree.Packages.Table
2536 if Current_Pkg = No_Package then
2537 Package_Table.Increment_Last
2539 Current_Pkg := Package_Table.Last
2541 In_Tree.Packages.Table (Current_Pkg) :=
2542 (Name => Element.Name,
2543 Decl => Element.Decl,
2544 Parent => No_Package,
2545 Next => Processed_Data.Decl.Packages);
2546 Processed_Data.Decl.Packages := Current_Pkg;
2549 Extended_Pkg := Element.Next;
2552 -- Check if attribute Languages is declared in the
2553 -- extending project.
2555 Attribute1 := Processed_Data.Decl.Attributes;
2556 while Attribute1 /= No_Variable loop
2557 Attr_Value1 := In_Tree.Variable_Elements.
2559 exit when Attr_Value1.Name = Snames.Name_Languages;
2560 Attribute1 := Attr_Value1.Next;
2563 if Attribute1 = No_Variable or else
2564 Attr_Value1.Value.Default
2566 -- Attribute Languages is not declared in the extending
2567 -- project. Check if it is declared in the project being
2571 In_Tree.Projects.Table
2572 (Processed_Data.Extends).Decl.Attributes;
2574 while Attribute2 /= No_Variable loop
2575 Attr_Value2 := In_Tree.Variable_Elements.
2577 exit when Attr_Value2.Name = Snames.Name_Languages;
2578 Attribute2 := Attr_Value2.Next;
2581 if Attribute2 /= No_Variable and then
2582 not Attr_Value2.Value.Default
2584 -- As attribute Languages is declared in the project
2585 -- being extended, copy its value for the extending
2588 if Attribute1 = No_Variable then
2589 Variable_Element_Table.Increment_Last
2590 (In_Tree.Variable_Elements);
2591 Attribute1 := Variable_Element_Table.Last
2592 (In_Tree.Variable_Elements);
2593 Attr_Value1.Next := Processed_Data.Decl.Attributes;
2594 Processed_Data.Decl.Attributes := Attribute1;
2597 Attr_Value1.Name := Snames.Name_Languages;
2598 Attr_Value1.Value := Attr_Value2.Value;
2599 In_Tree.Variable_Elements.Table
2600 (Attribute1) := Attr_Value1;
2605 In_Tree.Projects.Table (Project) := Processed_Data;
2609 end Recursive_Process;