1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars; use Err_Vars;
28 with Osint; use Osint;
29 with Output; use Output;
30 with Prj.Attr; use Prj.Attr;
31 with Prj.Err; use Prj.Err;
32 with Prj.Ext; use Prj.Ext;
33 with Prj.Nmsc; use Prj.Nmsc;
34 with Sinput; use Sinput;
37 with GNAT.Case_Util; use GNAT.Case_Util;
40 package body Prj.Proc is
42 Error_Report : Put_Line_Access := null;
44 package Processed_Projects is new GNAT.HTable.Simple_HTable
45 (Header_Num => Header_Num,
46 Element => Project_Id,
47 No_Element => No_Project,
51 -- This hash table contains all processed projects
53 package Unit_Htable is new GNAT.HTable.Simple_HTable
54 (Header_Num => Header_Num,
56 No_Element => No_Source,
60 -- This hash table contains all processed projects
62 procedure Add (To_Exp : in out Name_Id; Str : Name_Id);
63 -- Concatenate two strings and returns another string if both
64 -- arguments are not null string.
66 procedure Add_Attributes
67 (Project : Project_Id;
68 Project_Name : Name_Id;
69 In_Tree : Project_Tree_Ref;
70 Decl : in out Declarations;
71 First : Attribute_Node_Id;
72 Project_Level : Boolean);
73 -- Add all attributes, starting with First, with their default
74 -- values to the package or project with declarations Decl.
77 (In_Tree : Project_Tree_Ref;
80 When_No_Sources : Error_Warning);
81 -- Set all projects to not checked, then call Recursive_Check for the
82 -- main project Project. Project is set to No_Project if errors occurred.
83 -- Current_Dir is for optimization purposes, avoiding extra system calls.
85 procedure Copy_Package_Declarations
87 To : in out Declarations;
89 In_Tree : Project_Tree_Ref);
90 -- Copy a package declaration From to To for a renamed package. Change the
91 -- locations of all the attributes to New_Loc.
94 (Project : Project_Id;
95 In_Tree : Project_Tree_Ref;
96 From_Project_Node : Project_Node_Id;
97 From_Project_Node_Tree : Project_Node_Tree_Ref;
99 First_Term : Project_Node_Id;
100 Kind : Variable_Kind) return Variable_Value;
101 -- From N_Expression project node From_Project_Node, compute the value
102 -- of an expression and return it as a Variable_Value.
104 function Imported_Or_Extended_Project_From
105 (Project : Project_Id;
106 In_Tree : Project_Tree_Ref;
107 With_Name : Name_Id) return Project_Id;
108 -- Find an imported or extended project of Project whose name is With_Name
110 function Package_From
111 (Project : Project_Id;
112 In_Tree : Project_Tree_Ref;
113 With_Name : Name_Id) return Package_Id;
114 -- Find the package of Project whose name is With_Name
116 procedure Process_Declarative_Items
117 (Project : Project_Id;
118 In_Tree : Project_Tree_Ref;
119 From_Project_Node : Project_Node_Id;
120 From_Project_Node_Tree : Project_Node_Tree_Ref;
122 Item : Project_Node_Id);
123 -- Process declarative items starting with From_Project_Node, and put them
124 -- in declarations Decl. This is a recursive procedure; it calls itself for
125 -- a package declaration or a case construction.
127 procedure Recursive_Process
128 (In_Tree : Project_Tree_Ref;
129 Project : out Project_Id;
130 From_Project_Node : Project_Node_Id;
131 From_Project_Node_Tree : Project_Node_Tree_Ref;
132 Extended_By : Project_Id);
133 -- Process project with node From_Project_Node in the tree.
134 -- Do nothing if From_Project_Node is Empty_Node.
135 -- If project has already been processed, simply return its project id.
136 -- Otherwise create a new project id, mark it as processed, call itself
137 -- recursively for all imported projects and a extended project, if any.
138 -- Then process the declarative items of the project.
140 procedure Recursive_Check
141 (Project : Project_Id;
142 In_Tree : Project_Tree_Ref;
143 Current_Dir : String;
144 When_No_Sources : Error_Warning);
145 -- If Project is not marked as checked, mark it as checked, call
146 -- Check_Naming_Scheme for the project, then call itself for a
147 -- possible extended project and all the imported projects of Project.
148 -- Current_Dir is for optimization purposes, avoiding extra system calls.
154 procedure Add (To_Exp : in out Name_Id; Str : Name_Id) is
156 if To_Exp = No_Name or else To_Exp = Empty_String then
158 -- To_Exp is nil or empty. The result is Str
162 -- If Str is nil, then do not change To_Ext
164 elsif Str /= No_Name and then Str /= Empty_String then
166 S : constant String := Get_Name_String (Str);
169 Get_Name_String (To_Exp);
170 Add_Str_To_Name_Buffer (S);
180 procedure Add_Attributes
181 (Project : Project_Id;
182 Project_Name : Name_Id;
183 In_Tree : Project_Tree_Ref;
184 Decl : in out Declarations;
185 First : Attribute_Node_Id;
186 Project_Level : Boolean)
188 The_Attribute : Attribute_Node_Id := First;
191 while The_Attribute /= Empty_Attribute loop
192 if Attribute_Kind_Of (The_Attribute) = Single then
194 New_Attribute : Variable_Value;
197 case Variable_Kind_Of (The_Attribute) is
199 -- Undefined should not happen
203 (False, "attribute with an undefined kind");
206 -- Single attributes have a default value of empty string
212 Location => No_Location,
214 Value => Empty_String,
217 -- Special case of <project>'Name
220 and then Attribute_Name_Of (The_Attribute) =
223 New_Attribute.Value := Project_Name;
226 -- List attributes have a default value of nil list
232 Location => No_Location,
234 Values => Nil_String);
238 Variable_Element_Table.Increment_Last
239 (In_Tree.Variable_Elements);
240 In_Tree.Variable_Elements.Table
241 (Variable_Element_Table.Last
242 (In_Tree.Variable_Elements)) :=
243 (Next => Decl.Attributes,
244 Name => Attribute_Name_Of (The_Attribute),
245 Value => New_Attribute);
246 Decl.Attributes := Variable_Element_Table.Last
247 (In_Tree.Variable_Elements);
251 The_Attribute := Next_Attribute (After => The_Attribute);
260 (In_Tree : Project_Tree_Ref;
261 Project : Project_Id;
262 Current_Dir : String;
263 When_No_Sources : Error_Warning)
266 -- Make sure that all projects are marked as not checked
268 for Index in Project_Table.First ..
269 Project_Table.Last (In_Tree.Projects)
271 In_Tree.Projects.Table (Index).Checked := False;
274 Recursive_Check (Project, In_Tree, Current_Dir, When_No_Sources);
276 -- Set the Other_Part field for the units
286 Source1 := In_Tree.First_Source;
287 while Source1 /= No_Source loop
288 Name := In_Tree.Sources.Table (Source1).Unit;
290 if Name /= No_Name then
291 Source2 := Unit_Htable.Get (Name);
293 if Source2 = No_Source then
294 Unit_Htable.Set (K => Name, E => Source1);
297 Unit_Htable.Remove (Name);
298 In_Tree.Sources.Table (Source1).Other_Part := Source2;
299 In_Tree.Sources.Table (Source2).Other_Part := Source1;
303 Source1 := In_Tree.Sources.Table (Source1).Next_In_Sources;
308 -------------------------------
309 -- Copy_Package_Declarations --
310 -------------------------------
312 procedure Copy_Package_Declarations
313 (From : Declarations;
314 To : in out Declarations;
315 New_Loc : Source_Ptr;
316 In_Tree : Project_Tree_Ref)
318 V1 : Variable_Id := From.Attributes;
319 V2 : Variable_Id := No_Variable;
321 A1 : Array_Id := From.Arrays;
322 A2 : Array_Id := No_Array;
324 E1 : Array_Element_Id;
325 E2 : Array_Element_Id := No_Array_Element;
329 -- To avoid references in error messages to attribute declarations in
330 -- an original package that has been renamed, copy all the attribute
331 -- declarations of the package and change all locations to New_Loc,
332 -- the location of the renamed package.
334 -- First single attributes
336 while V1 /= No_Variable loop
338 -- Copy the attribute
340 Var := In_Tree.Variable_Elements.Table (V1);
343 -- Remove the Next component
345 Var.Next := No_Variable;
347 -- Change the location to New_Loc
349 Var.Value.Location := New_Loc;
350 Variable_Element_Table.Increment_Last (In_Tree.Variable_Elements);
352 -- Put in new declaration
354 if To.Attributes = No_Variable then
356 Variable_Element_Table.Last (In_Tree.Variable_Elements);
359 In_Tree.Variable_Elements.Table (V2).Next :=
360 Variable_Element_Table.Last (In_Tree.Variable_Elements);
363 V2 := Variable_Element_Table.Last (In_Tree.Variable_Elements);
364 In_Tree.Variable_Elements.Table (V2) := Var;
367 -- Then the associated array attributes
369 while A1 /= No_Array loop
373 Arr := In_Tree.Arrays.Table (A1);
376 -- Remove the Next component
378 Arr.Next := No_Array;
380 Array_Table.Increment_Last (In_Tree.Arrays);
382 -- Create new Array declaration
383 if To.Arrays = No_Array then
384 To.Arrays := Array_Table.Last (In_Tree.Arrays);
387 In_Tree.Arrays.Table (A2).Next :=
388 Array_Table.Last (In_Tree.Arrays);
391 A2 := Array_Table.Last (In_Tree.Arrays);
393 -- Don't store the array, as its first element has not been set yet
395 -- Copy the array elements of the array
398 Arr.Value := No_Array_Element;
400 while E1 /= No_Array_Element loop
402 -- Copy the array element
404 Elm := In_Tree.Array_Elements.Table (E1);
407 -- Remove the Next component
409 Elm.Next := No_Array_Element;
411 -- Change the location
413 Elm.Value.Location := New_Loc;
414 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
416 -- Create new array element
418 if Arr.Value = No_Array_Element then
419 Arr.Value := Array_Element_Table.Last (In_Tree.Array_Elements);
421 In_Tree.Array_Elements.Table (E2).Next :=
422 Array_Element_Table.Last (In_Tree.Array_Elements);
425 E2 := Array_Element_Table.Last (In_Tree.Array_Elements);
426 In_Tree.Array_Elements.Table (E2) := Elm;
429 -- Finally, store the new array
431 In_Tree.Arrays.Table (A2) := Arr;
433 end Copy_Package_Declarations;
440 (Project : Project_Id;
441 In_Tree : Project_Tree_Ref;
442 From_Project_Node : Project_Node_Id;
443 From_Project_Node_Tree : Project_Node_Tree_Ref;
445 First_Term : Project_Node_Id;
446 Kind : Variable_Kind) return Variable_Value
448 The_Term : Project_Node_Id := First_Term;
449 -- The term in the expression list
451 The_Current_Term : Project_Node_Id := Empty_Node;
452 -- The current term node id
454 Result : Variable_Value (Kind => Kind);
455 -- The returned result
457 Last : String_List_Id := Nil_String;
458 -- Reference to the last string elements in Result, when Kind is List
461 Result.Project := Project;
462 Result.Location := Location_Of (First_Term, From_Project_Node_Tree);
464 -- Process each term of the expression, starting with First_Term
466 while The_Term /= Empty_Node loop
467 The_Current_Term := Current_Term (The_Term, From_Project_Node_Tree);
469 case Kind_Of (The_Current_Term, From_Project_Node_Tree) is
471 when N_Literal_String =>
477 -- Should never happen
479 pragma Assert (False, "Undefined expression kind");
485 (The_Current_Term, From_Project_Node_Tree));
488 (The_Current_Term, From_Project_Node_Tree);
492 String_Element_Table.Increment_Last
493 (In_Tree.String_Elements);
495 if Last = Nil_String then
497 -- This can happen in an expression like () & "toto"
499 Result.Values := String_Element_Table.Last
500 (In_Tree.String_Elements);
503 In_Tree.String_Elements.Table
504 (Last).Next := String_Element_Table.Last
505 (In_Tree.String_Elements);
508 Last := String_Element_Table.Last
509 (In_Tree.String_Elements);
510 In_Tree.String_Elements.Table (Last) :=
514 From_Project_Node_Tree),
517 (The_Current_Term, From_Project_Node_Tree),
518 Display_Value => No_Name,
522 From_Project_Node_Tree),
527 when N_Literal_String_List =>
530 String_Node : Project_Node_Id :=
531 First_Expression_In_List
533 From_Project_Node_Tree);
535 Value : Variable_Value;
538 if String_Node /= Empty_Node then
540 -- If String_Node is nil, it is an empty list,
541 -- there is nothing to do
546 From_Project_Node => From_Project_Node,
547 From_Project_Node_Tree => From_Project_Node_Tree,
551 (String_Node, From_Project_Node_Tree),
553 String_Element_Table.Increment_Last
554 (In_Tree.String_Elements);
556 if Result.Values = Nil_String then
558 -- This literal string list is the first term
559 -- in a string list expression
562 String_Element_Table.Last (In_Tree.String_Elements);
565 In_Tree.String_Elements.Table
567 String_Element_Table.Last (In_Tree.String_Elements);
571 String_Element_Table.Last (In_Tree.String_Elements);
573 In_Tree.String_Elements.Table (Last) :=
574 (Value => Value.Value,
575 Display_Value => No_Name,
576 Location => Value.Location,
579 Index => Value.Index);
582 -- Add the other element of the literal string list
583 -- one after the other
586 Next_Expression_In_List
587 (String_Node, From_Project_Node_Tree);
589 exit when String_Node = Empty_Node;
595 From_Project_Node => From_Project_Node,
596 From_Project_Node_Tree => From_Project_Node_Tree,
600 (String_Node, From_Project_Node_Tree),
603 String_Element_Table.Increment_Last
604 (In_Tree.String_Elements);
605 In_Tree.String_Elements.Table
606 (Last).Next := String_Element_Table.Last
607 (In_Tree.String_Elements);
608 Last := String_Element_Table.Last
609 (In_Tree.String_Elements);
610 In_Tree.String_Elements.Table (Last) :=
611 (Value => Value.Value,
612 Display_Value => No_Name,
613 Location => Value.Location,
616 Index => Value.Index);
621 when N_Variable_Reference | N_Attribute_Reference =>
624 The_Project : Project_Id := Project;
625 The_Package : Package_Id := Pkg;
626 The_Name : Name_Id := No_Name;
627 The_Variable_Id : Variable_Id := No_Variable;
628 The_Variable : Variable_Value;
629 Term_Project : constant Project_Node_Id :=
632 From_Project_Node_Tree);
633 Term_Package : constant Project_Node_Id :=
636 From_Project_Node_Tree);
637 Index : Name_Id := No_Name;
640 if Term_Project /= Empty_Node and then
641 Term_Project /= From_Project_Node
643 -- This variable or attribute comes from another project
646 Name_Of (Term_Project, From_Project_Node_Tree);
647 The_Project := Imported_Or_Extended_Project_From
650 With_Name => The_Name);
653 if Term_Package /= Empty_Node then
655 -- This is an attribute of a package
658 Name_Of (Term_Package, From_Project_Node_Tree);
659 The_Package := In_Tree.Projects.Table
660 (The_Project).Decl.Packages;
662 while The_Package /= No_Package
663 and then In_Tree.Packages.Table
664 (The_Package).Name /= The_Name
667 In_Tree.Packages.Table
672 (The_Package /= No_Package,
673 "package not found.");
675 elsif Kind_Of (The_Current_Term, From_Project_Node_Tree) =
676 N_Attribute_Reference
678 The_Package := No_Package;
682 Name_Of (The_Current_Term, From_Project_Node_Tree);
684 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
685 N_Attribute_Reference
688 Associative_Array_Index_Of
689 (The_Current_Term, From_Project_Node_Tree);
692 -- If it is not an associative array attribute
694 if Index = No_Name then
696 -- It is not an associative array attribute
698 if The_Package /= No_Package then
700 -- First, if there is a package, look into the package
702 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
706 In_Tree.Packages.Table
707 (The_Package).Decl.Variables;
710 In_Tree.Packages.Table
711 (The_Package).Decl.Attributes;
714 while The_Variable_Id /= No_Variable
716 In_Tree.Variable_Elements.Table
717 (The_Variable_Id).Name /= The_Name
720 In_Tree.Variable_Elements.Table
721 (The_Variable_Id).Next;
726 if The_Variable_Id = No_Variable then
728 -- If we have not found it, look into the project
730 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
734 In_Tree.Projects.Table
735 (The_Project).Decl.Variables;
738 In_Tree.Projects.Table
739 (The_Project).Decl.Attributes;
742 while The_Variable_Id /= No_Variable
744 In_Tree.Variable_Elements.Table
745 (The_Variable_Id).Name /= The_Name
748 In_Tree.Variable_Elements.Table
749 (The_Variable_Id).Next;
754 pragma Assert (The_Variable_Id /= No_Variable,
755 "variable or attribute not found");
758 In_Tree.Variable_Elements.Table
759 (The_Variable_Id).Value;
763 -- It is an associative array attribute
766 The_Array : Array_Id := No_Array;
767 The_Element : Array_Element_Id := No_Array_Element;
768 Array_Index : Name_Id := No_Name;
772 if The_Package /= No_Package then
774 In_Tree.Packages.Table
775 (The_Package).Decl.Arrays;
778 In_Tree.Projects.Table
779 (The_Project).Decl.Arrays;
782 while The_Array /= No_Array
783 and then In_Tree.Arrays.Table
784 (The_Array).Name /= The_Name
786 The_Array := In_Tree.Arrays.Table
790 if The_Array /= No_Array then
791 The_Element := In_Tree.Arrays.Table
794 Get_Name_String (Index);
798 (The_Current_Term, From_Project_Node_Tree);
800 -- In multi-language mode (gprbuild), the index is
801 -- always case insensitive if it does not include
804 if Get_Mode = Multi_Language and then not Lower then
807 for J in 1 .. Name_Len loop
808 if Name_Buffer (J) = '.' then
816 To_Lower (Name_Buffer (1 .. Name_Len));
819 Array_Index := Name_Find;
821 while The_Element /= No_Array_Element
823 In_Tree.Array_Elements.Table
824 (The_Element).Index /= Array_Index
827 In_Tree.Array_Elements.Table
833 if The_Element /= No_Array_Element then
835 In_Tree.Array_Elements.Table
839 if Expression_Kind_Of
840 (The_Current_Term, From_Project_Node_Tree) =
846 Location => No_Location,
848 Values => Nil_String);
853 Location => No_Location,
855 Value => Empty_String,
866 -- Should never happen
868 pragma Assert (False, "undefined expression kind");
873 case The_Variable.Kind is
879 Add (Result.Value, The_Variable.Value);
883 -- Should never happen
887 "list cannot appear in single " &
888 "string expression");
893 case The_Variable.Kind is
899 String_Element_Table.Increment_Last
900 (In_Tree.String_Elements);
902 if Last = Nil_String then
904 -- This can happen in an expression such as
908 String_Element_Table.Last
909 (In_Tree.String_Elements);
912 In_Tree.String_Elements.Table
914 String_Element_Table.Last
915 (In_Tree.String_Elements);
919 String_Element_Table.Last
920 (In_Tree.String_Elements);
922 In_Tree.String_Elements.Table (Last) :=
923 (Value => The_Variable.Value,
924 Display_Value => No_Name,
925 Location => Location_Of
927 From_Project_Node_Tree),
935 The_List : String_List_Id :=
939 while The_List /= Nil_String loop
940 String_Element_Table.Increment_Last
941 (In_Tree.String_Elements);
943 if Last = Nil_String then
945 String_Element_Table.Last
951 String_Elements.Table (Last).Next :=
952 String_Element_Table.Last
959 String_Element_Table.Last
960 (In_Tree.String_Elements);
962 In_Tree.String_Elements.Table (Last) :=
964 In_Tree.String_Elements.Table
966 Display_Value => No_Name,
970 From_Project_Node_Tree),
976 In_Tree. String_Elements.Table
984 when N_External_Value =>
987 (External_Reference_Of
988 (The_Current_Term, From_Project_Node_Tree),
989 From_Project_Node_Tree));
992 Name : constant Name_Id := Name_Find;
993 Default : Name_Id := No_Name;
994 Value : Name_Id := No_Name;
996 Def_Var : Variable_Value;
998 Default_Node : constant Project_Node_Id :=
1000 (The_Current_Term, From_Project_Node_Tree);
1003 -- If there is a default value for the external reference,
1006 if Default_Node /= Empty_Node then
1007 Def_Var := Expression
1008 (Project => Project,
1010 From_Project_Node => Default_Node,
1011 From_Project_Node_Tree => From_Project_Node_Tree,
1015 (Default_Node, From_Project_Node_Tree),
1018 if Def_Var /= Nil_Variable_Value then
1019 Default := Def_Var.Value;
1023 Value := Prj.Ext.Value_Of (Name, Default);
1025 if Value = No_Name then
1026 if not Quiet_Output then
1027 if Error_Report = null then
1029 ("?undefined external reference",
1031 (The_Current_Term, From_Project_Node_Tree));
1034 ("warning: """ & Get_Name_String (Name) &
1035 """ is an undefined external reference",
1040 Value := Empty_String;
1049 Add (Result.Value, Value);
1052 String_Element_Table.Increment_Last
1053 (In_Tree.String_Elements);
1055 if Last = Nil_String then
1056 Result.Values := String_Element_Table.Last
1057 (In_Tree.String_Elements);
1060 In_Tree.String_Elements.Table
1061 (Last).Next := String_Element_Table.Last
1062 (In_Tree.String_Elements);
1065 Last := String_Element_Table.Last
1066 (In_Tree.String_Elements);
1067 In_Tree.String_Elements.Table (Last) :=
1069 Display_Value => No_Name,
1072 (The_Current_Term, From_Project_Node_Tree),
1082 -- Should never happen
1086 "illegal node kind in an expression");
1087 raise Program_Error;
1091 The_Term := Next_Term (The_Term, From_Project_Node_Tree);
1097 ---------------------------------------
1098 -- Imported_Or_Extended_Project_From --
1099 ---------------------------------------
1101 function Imported_Or_Extended_Project_From
1102 (Project : Project_Id;
1103 In_Tree : Project_Tree_Ref;
1104 With_Name : Name_Id) return Project_Id
1106 Data : constant Project_Data := In_Tree.Projects.Table (Project);
1107 List : Project_List;
1108 Result : Project_Id;
1109 Temp_Result : Project_Id;
1112 -- First check if it is the name of an extended project
1114 Result := Data.Extends;
1115 while Result /= No_Project loop
1116 if In_Tree.Projects.Table (Result).Name = With_Name then
1119 Result := In_Tree.Projects.Table (Result).Extends;
1123 -- Then check the name of each imported project
1125 Temp_Result := No_Project;
1126 List := Data.Imported_Projects;
1127 while List /= Empty_Project_List loop
1128 Result := In_Tree.Project_Lists.Table (List).Project;
1130 -- If the project is directly imported, then returns its ID
1132 if In_Tree.Projects.Table (Result).Name = With_Name then
1136 -- If a project extending the project is imported, then keep this
1137 -- extending project as a possibility. It will be the returned ID
1138 -- if the project is not imported directly.
1141 Proj : Project_Id := In_Tree.Projects.Table (Result).Extends;
1144 while Proj /= No_Project loop
1145 if In_Tree.Projects.Table (Proj).Name = With_Name then
1146 Temp_Result := Result;
1150 Proj := In_Tree.Projects.Table (Proj).Extends;
1154 List := In_Tree.Project_Lists.Table (List).Next;
1157 pragma Assert (Temp_Result /= No_Project, "project not found");
1159 end Imported_Or_Extended_Project_From;
1165 function Package_From
1166 (Project : Project_Id;
1167 In_Tree : Project_Tree_Ref;
1168 With_Name : Name_Id) return Package_Id
1170 Data : constant Project_Data :=
1171 In_Tree.Projects.Table (Project);
1172 Result : Package_Id := Data.Decl.Packages;
1175 -- Check the name of each existing package of Project
1177 while Result /= No_Package
1178 and then In_Tree.Packages.Table (Result).Name /= With_Name
1180 Result := In_Tree.Packages.Table (Result).Next;
1183 if Result = No_Package then
1185 -- Should never happen
1187 Write_Line ("package """ & Get_Name_String (With_Name) &
1189 raise Program_Error;
1201 (In_Tree : Project_Tree_Ref;
1202 Project : out Project_Id;
1203 Success : out Boolean;
1204 From_Project_Node : Project_Node_Id;
1205 From_Project_Node_Tree : Project_Node_Tree_Ref;
1206 Report_Error : Put_Line_Access;
1207 When_No_Sources : Error_Warning := Error;
1208 Reset_Tree : Boolean := True;
1209 Current_Dir : String := "")
1212 Process_Project_Tree_Phase_1
1213 (In_Tree => In_Tree,
1216 From_Project_Node => From_Project_Node,
1217 From_Project_Node_Tree => From_Project_Node_Tree,
1218 Report_Error => Report_Error,
1219 Reset_Tree => Reset_Tree);
1221 if not In_Configuration then
1222 Process_Project_Tree_Phase_2
1223 (In_Tree => In_Tree,
1226 From_Project_Node => From_Project_Node,
1227 From_Project_Node_Tree => From_Project_Node_Tree,
1228 Report_Error => Report_Error,
1229 When_No_Sources => When_No_Sources,
1230 Current_Dir => Current_Dir);
1234 -------------------------------
1235 -- Process_Declarative_Items --
1236 -------------------------------
1238 procedure Process_Declarative_Items
1239 (Project : Project_Id;
1240 In_Tree : Project_Tree_Ref;
1241 From_Project_Node : Project_Node_Id;
1242 From_Project_Node_Tree : Project_Node_Tree_Ref;
1244 Item : Project_Node_Id)
1246 Current_Declarative_Item : Project_Node_Id;
1247 Current_Item : Project_Node_Id;
1250 -- Loop through declarative items
1252 Current_Item := Empty_Node;
1254 Current_Declarative_Item := Item;
1255 while Current_Declarative_Item /= Empty_Node loop
1261 (Current_Declarative_Item, From_Project_Node_Tree);
1263 -- And set Current_Declarative_Item to the next declarative item
1264 -- ready for the next iteration.
1266 Current_Declarative_Item :=
1267 Next_Declarative_Item
1268 (Current_Declarative_Item, From_Project_Node_Tree);
1270 case Kind_Of (Current_Item, From_Project_Node_Tree) is
1272 when N_Package_Declaration =>
1274 -- Do not process a package declaration that should be ignored
1276 if Expression_Kind_Of
1277 (Current_Item, From_Project_Node_Tree) /= Ignored
1279 -- Create the new package
1281 Package_Table.Increment_Last (In_Tree.Packages);
1284 New_Pkg : constant Package_Id :=
1285 Package_Table.Last (In_Tree.Packages);
1286 The_New_Package : Package_Element;
1288 Project_Of_Renamed_Package :
1289 constant Project_Node_Id :=
1290 Project_Of_Renamed_Package_Of
1291 (Current_Item, From_Project_Node_Tree);
1294 -- Set the name of the new package
1296 The_New_Package.Name :=
1297 Name_Of (Current_Item, From_Project_Node_Tree);
1299 -- Insert the new package in the appropriate list
1301 if Pkg /= No_Package then
1302 The_New_Package.Next :=
1303 In_Tree.Packages.Table (Pkg).Decl.Packages;
1304 In_Tree.Packages.Table (Pkg).Decl.Packages :=
1308 The_New_Package.Next :=
1309 In_Tree.Projects.Table (Project).Decl.Packages;
1310 In_Tree.Projects.Table (Project).Decl.Packages :=
1314 In_Tree.Packages.Table (New_Pkg) :=
1317 if Project_Of_Renamed_Package /= Empty_Node then
1322 Project_Name : constant Name_Id :=
1324 (Project_Of_Renamed_Package,
1325 From_Project_Node_Tree);
1328 constant Project_Id :=
1329 Imported_Or_Extended_Project_From
1330 (Project, In_Tree, Project_Name);
1332 Renamed_Package : constant Package_Id :=
1334 (Renamed_Project, In_Tree,
1337 From_Project_Node_Tree));
1340 -- For a renamed package, copy the declarations of
1341 -- the renamed package, but set all the locations
1342 -- to the location of the package name in the
1343 -- renaming declaration.
1345 Copy_Package_Declarations
1347 In_Tree.Packages.Table (Renamed_Package).Decl,
1349 In_Tree.Packages.Table (New_Pkg).Decl,
1352 (Current_Item, From_Project_Node_Tree),
1353 In_Tree => In_Tree);
1356 -- Standard package declaration, not renaming
1359 -- Set the default values of the attributes
1363 In_Tree.Projects.Table (Project).Name,
1365 In_Tree.Packages.Table (New_Pkg).Decl,
1368 (Current_Item, From_Project_Node_Tree)),
1369 Project_Level => False);
1371 -- And process declarative items of the new package
1373 Process_Declarative_Items
1374 (Project => Project,
1376 From_Project_Node => From_Project_Node,
1377 From_Project_Node_Tree => From_Project_Node_Tree,
1380 First_Declarative_Item_Of
1381 (Current_Item, From_Project_Node_Tree));
1386 when N_String_Type_Declaration =>
1388 -- There is nothing to process
1392 when N_Attribute_Declaration |
1393 N_Typed_Variable_Declaration |
1394 N_Variable_Declaration =>
1396 if Expression_Of (Current_Item, From_Project_Node_Tree) =
1400 -- It must be a full associative array attribute declaration
1403 Current_Item_Name : constant Name_Id :=
1406 From_Project_Node_Tree);
1407 -- The name of the attribute
1409 New_Array : Array_Id;
1410 -- The new associative array created
1412 Orig_Array : Array_Id;
1413 -- The associative array value
1415 Orig_Project_Name : Name_Id := No_Name;
1416 -- The name of the project where the associative array
1419 Orig_Project : Project_Id := No_Project;
1420 -- The id of the project where the associative array
1423 Orig_Package_Name : Name_Id := No_Name;
1424 -- The name of the package, if any, where the associative
1427 Orig_Package : Package_Id := No_Package;
1428 -- The id of the package, if any, where the associative
1431 New_Element : Array_Element_Id := No_Array_Element;
1432 -- Id of a new array element created
1434 Prev_Element : Array_Element_Id := No_Array_Element;
1435 -- Last new element id created
1437 Orig_Element : Array_Element_Id := No_Array_Element;
1438 -- Current array element in original associative array
1440 Next_Element : Array_Element_Id := No_Array_Element;
1441 -- Id of the array element that follows the new element.
1442 -- This is not always nil, because values for the
1443 -- associative array attribute may already have been
1444 -- declared, and the array elements declared are reused.
1447 -- First find if the associative array attribute already
1448 -- has elements declared.
1450 if Pkg /= No_Package then
1451 New_Array := In_Tree.Packages.Table
1455 New_Array := In_Tree.Projects.Table
1456 (Project).Decl.Arrays;
1459 while New_Array /= No_Array
1460 and then In_Tree.Arrays.Table (New_Array).Name /=
1463 New_Array := In_Tree.Arrays.Table (New_Array).Next;
1466 -- If the attribute has never been declared add new entry
1467 -- in the arrays of the project/package and link it.
1469 if New_Array = No_Array then
1470 Array_Table.Increment_Last (In_Tree.Arrays);
1471 New_Array := Array_Table.Last (In_Tree.Arrays);
1473 if Pkg /= No_Package then
1474 In_Tree.Arrays.Table (New_Array) :=
1475 (Name => Current_Item_Name,
1476 Value => No_Array_Element,
1478 In_Tree.Packages.Table (Pkg).Decl.Arrays);
1480 In_Tree.Packages.Table (Pkg).Decl.Arrays :=
1484 In_Tree.Arrays.Table (New_Array) :=
1485 (Name => Current_Item_Name,
1486 Value => No_Array_Element,
1488 In_Tree.Projects.Table (Project).Decl.Arrays);
1490 In_Tree.Projects.Table (Project).Decl.Arrays :=
1495 -- Find the project where the value is declared
1497 Orig_Project_Name :=
1499 (Associative_Project_Of
1500 (Current_Item, From_Project_Node_Tree),
1501 From_Project_Node_Tree);
1503 for Index in Project_Table.First ..
1507 if In_Tree.Projects.Table (Index).Name =
1510 Orig_Project := Index;
1515 pragma Assert (Orig_Project /= No_Project,
1516 "original project not found");
1518 if Associative_Package_Of
1519 (Current_Item, From_Project_Node_Tree) = Empty_Node
1522 In_Tree.Projects.Table
1523 (Orig_Project).Decl.Arrays;
1526 -- If in a package, find the package where the value
1529 Orig_Package_Name :=
1531 (Associative_Package_Of
1532 (Current_Item, From_Project_Node_Tree),
1533 From_Project_Node_Tree);
1536 In_Tree.Projects.Table
1537 (Orig_Project).Decl.Packages;
1538 pragma Assert (Orig_Package /= No_Package,
1539 "original package not found");
1541 while In_Tree.Packages.Table
1542 (Orig_Package).Name /= Orig_Package_Name
1544 Orig_Package := In_Tree.Packages.Table
1545 (Orig_Package).Next;
1546 pragma Assert (Orig_Package /= No_Package,
1547 "original package not found");
1551 In_Tree.Packages.Table
1552 (Orig_Package).Decl.Arrays;
1555 -- Now look for the array
1557 while Orig_Array /= No_Array
1558 and then In_Tree.Arrays.Table (Orig_Array).Name /=
1561 Orig_Array := In_Tree.Arrays.Table
1565 if Orig_Array = No_Array then
1566 if Error_Report = null then
1568 ("associative array value cannot be found",
1570 (Current_Item, From_Project_Node_Tree));
1573 ("associative array value cannot be found",
1579 In_Tree.Arrays.Table (Orig_Array).Value;
1581 -- Copy each array element
1583 while Orig_Element /= No_Array_Element loop
1585 -- Case of first element
1587 if Prev_Element = No_Array_Element then
1589 -- And there is no array element declared yet,
1590 -- create a new first array element.
1592 if In_Tree.Arrays.Table (New_Array).Value =
1595 Array_Element_Table.Increment_Last
1596 (In_Tree.Array_Elements);
1597 New_Element := Array_Element_Table.Last
1598 (In_Tree.Array_Elements);
1599 In_Tree.Arrays.Table
1600 (New_Array).Value := New_Element;
1601 Next_Element := No_Array_Element;
1603 -- Otherwise, the new element is the first
1606 New_Element := In_Tree.Arrays.
1607 Table (New_Array).Value;
1609 In_Tree.Array_Elements.Table
1613 -- Otherwise, reuse an existing element, or create
1614 -- one if necessary.
1618 In_Tree.Array_Elements.Table
1619 (Prev_Element).Next;
1621 if Next_Element = No_Array_Element then
1622 Array_Element_Table.Increment_Last
1623 (In_Tree.Array_Elements);
1625 Array_Element_Table.Last
1626 (In_Tree.Array_Elements);
1627 In_Tree.Array_Elements.Table
1628 (Prev_Element).Next := New_Element;
1631 New_Element := Next_Element;
1633 In_Tree.Array_Elements.Table
1638 -- Copy the value of the element
1640 In_Tree.Array_Elements.Table
1642 In_Tree.Array_Elements.Table (Orig_Element);
1643 In_Tree.Array_Elements.Table
1644 (New_Element).Value.Project := Project;
1646 -- Adjust the Next link
1648 In_Tree.Array_Elements.Table
1649 (New_Element).Next := Next_Element;
1651 -- Adjust the previous id for the next element
1653 Prev_Element := New_Element;
1655 -- Go to the next element in the original array
1658 In_Tree.Array_Elements.Table
1659 (Orig_Element).Next;
1662 -- Make sure that the array ends here, in case there
1663 -- previously a greater number of elements.
1665 In_Tree.Array_Elements.Table
1666 (New_Element).Next := No_Array_Element;
1670 -- Declarations other that full associative arrays
1674 New_Value : constant Variable_Value :=
1676 (Project => Project,
1678 From_Project_Node => From_Project_Node,
1679 From_Project_Node_Tree => From_Project_Node_Tree,
1684 (Current_Item, From_Project_Node_Tree),
1685 From_Project_Node_Tree),
1688 (Current_Item, From_Project_Node_Tree));
1689 -- The expression value
1691 The_Variable : Variable_Id := No_Variable;
1693 Current_Item_Name : constant Name_Id :=
1696 From_Project_Node_Tree);
1699 -- Process a typed variable declaration
1701 if Kind_Of (Current_Item, From_Project_Node_Tree) =
1702 N_Typed_Variable_Declaration
1704 -- Report an error for an empty string
1706 if New_Value.Value = Empty_String then
1708 Name_Of (Current_Item, From_Project_Node_Tree);
1710 if Error_Report = null then
1712 ("no value defined for %%",
1714 (Current_Item, From_Project_Node_Tree));
1717 ("no value defined for " &
1718 Get_Name_String (Error_Msg_Name_1),
1724 Current_String : Project_Node_Id;
1727 -- Loop through all the valid strings for the
1728 -- string type and compare to the string value.
1731 First_Literal_String
1732 (String_Type_Of (Current_Item,
1733 From_Project_Node_Tree),
1734 From_Project_Node_Tree);
1735 while Current_String /= Empty_Node
1738 (Current_String, From_Project_Node_Tree) /=
1743 (Current_String, From_Project_Node_Tree);
1746 -- Report an error if the string value is not
1747 -- one for the string type.
1749 if Current_String = Empty_Node then
1750 Error_Msg_Name_1 := New_Value.Value;
1753 (Current_Item, From_Project_Node_Tree);
1755 if Error_Report = null then
1757 ("value %% is illegal " &
1758 "for typed string %%",
1761 From_Project_Node_Tree));
1766 Get_Name_String (Error_Msg_Name_1) &
1767 """ is illegal for typed string """ &
1768 Get_Name_String (Error_Msg_Name_2) &
1779 if Kind_Of (Current_Item, From_Project_Node_Tree) /=
1780 N_Attribute_Declaration
1782 Associative_Array_Index_Of
1783 (Current_Item, From_Project_Node_Tree) = No_Name
1785 -- Case of a variable declaration or of a not
1786 -- associative array attribute.
1788 -- First, find the list where to find the variable
1791 if Kind_Of (Current_Item, From_Project_Node_Tree) =
1792 N_Attribute_Declaration
1794 if Pkg /= No_Package then
1796 In_Tree.Packages.Table
1797 (Pkg).Decl.Attributes;
1800 In_Tree.Projects.Table
1801 (Project).Decl.Attributes;
1805 if Pkg /= No_Package then
1807 In_Tree.Packages.Table
1808 (Pkg).Decl.Variables;
1811 In_Tree.Projects.Table
1812 (Project).Decl.Variables;
1817 -- Loop through the list, to find if it has already
1820 while The_Variable /= No_Variable
1822 In_Tree.Variable_Elements.Table
1823 (The_Variable).Name /= Current_Item_Name
1826 In_Tree.Variable_Elements.Table
1827 (The_Variable).Next;
1830 -- If it has not been declared, create a new entry
1833 if The_Variable = No_Variable then
1835 -- All single string attribute should already have
1836 -- been declared with a default empty string value.
1839 (Kind_Of (Current_Item, From_Project_Node_Tree) /=
1840 N_Attribute_Declaration,
1841 "illegal attribute declaration");
1843 Variable_Element_Table.Increment_Last
1844 (In_Tree.Variable_Elements);
1845 The_Variable := Variable_Element_Table.Last
1846 (In_Tree.Variable_Elements);
1848 -- Put the new variable in the appropriate list
1850 if Pkg /= No_Package then
1851 In_Tree.Variable_Elements.Table (The_Variable) :=
1853 In_Tree.Packages.Table
1854 (Pkg).Decl.Variables,
1855 Name => Current_Item_Name,
1856 Value => New_Value);
1857 In_Tree.Packages.Table
1858 (Pkg).Decl.Variables := The_Variable;
1861 In_Tree.Variable_Elements.Table (The_Variable) :=
1863 In_Tree.Projects.Table
1864 (Project).Decl.Variables,
1865 Name => Current_Item_Name,
1866 Value => New_Value);
1867 In_Tree.Projects.Table
1868 (Project).Decl.Variables :=
1872 -- If the variable/attribute has already been
1873 -- declared, just change the value.
1876 In_Tree.Variable_Elements.Table
1877 (The_Variable).Value := New_Value;
1880 -- Associative array attribute
1883 -- Get the string index
1886 (Associative_Array_Index_Of
1887 (Current_Item, From_Project_Node_Tree));
1889 -- Put in lower case, if necessary
1897 (Current_Item, From_Project_Node_Tree);
1899 -- In multi-language mode (gprbuild), the index is
1900 -- always case insensitive if it does not include
1903 if Get_Mode = Multi_Language and then not Lower then
1904 for J in 1 .. Name_Len loop
1905 if Name_Buffer (J) = '.' then
1913 GNAT.Case_Util.To_Lower
1914 (Name_Buffer (1 .. Name_Len));
1919 The_Array : Array_Id;
1921 The_Array_Element : Array_Element_Id :=
1924 Index_Name : constant Name_Id := Name_Find;
1925 -- The name id of the index
1928 -- Look for the array in the appropriate list
1930 if Pkg /= No_Package then
1932 In_Tree.Packages.Table (Pkg).Decl.Arrays;
1936 In_Tree.Projects.Table (Project).Decl.Arrays;
1940 The_Array /= No_Array
1942 In_Tree.Arrays.Table (The_Array).Name /=
1945 The_Array := In_Tree.Arrays.Table
1949 -- If the array cannot be found, create a new entry
1950 -- in the list. As The_Array_Element is initialized
1951 -- to No_Array_Element, a new element will be
1952 -- created automatically later
1954 if The_Array = No_Array then
1955 Array_Table.Increment_Last (In_Tree.Arrays);
1956 The_Array := Array_Table.Last (In_Tree.Arrays);
1958 if Pkg /= No_Package then
1959 In_Tree.Arrays.Table (The_Array) :=
1960 (Name => Current_Item_Name,
1961 Value => No_Array_Element,
1963 In_Tree.Packages.Table
1966 In_Tree.Packages.Table (Pkg).Decl.Arrays :=
1970 In_Tree.Arrays.Table (The_Array) :=
1971 (Name => Current_Item_Name,
1972 Value => No_Array_Element,
1974 In_Tree.Projects.Table
1975 (Project).Decl.Arrays);
1977 In_Tree.Projects.Table
1978 (Project).Decl.Arrays := The_Array;
1981 -- Otherwise initialize The_Array_Element as the
1982 -- head of the element list.
1985 The_Array_Element :=
1986 In_Tree.Arrays.Table (The_Array).Value;
1989 -- Look in the list, if any, to find an element
1990 -- with the same index.
1992 while The_Array_Element /= No_Array_Element
1994 In_Tree.Array_Elements.Table
1995 (The_Array_Element).Index /= Index_Name
1997 The_Array_Element :=
1998 In_Tree.Array_Elements.Table
1999 (The_Array_Element).Next;
2002 -- If no such element were found, create a new one
2003 -- and insert it in the element list, with the
2006 if The_Array_Element = No_Array_Element then
2007 Array_Element_Table.Increment_Last
2008 (In_Tree.Array_Elements);
2009 The_Array_Element := Array_Element_Table.Last
2010 (In_Tree.Array_Elements);
2012 In_Tree.Array_Elements.Table
2013 (The_Array_Element) :=
2014 (Index => Index_Name,
2017 (Current_Item, From_Project_Node_Tree),
2018 Index_Case_Sensitive =>
2019 not Case_Insensitive
2020 (Current_Item, From_Project_Node_Tree),
2022 Next => In_Tree.Arrays.Table
2024 In_Tree.Arrays.Table
2025 (The_Array).Value := The_Array_Element;
2027 -- An element with the same index already exists,
2028 -- just replace its value with the new one.
2031 In_Tree.Array_Elements.Table
2032 (The_Array_Element).Value := New_Value;
2039 when N_Case_Construction =>
2041 The_Project : Project_Id := Project;
2042 -- The id of the project of the case variable
2044 The_Package : Package_Id := Pkg;
2045 -- The id of the package, if any, of the case variable
2047 The_Variable : Variable_Value := Nil_Variable_Value;
2048 -- The case variable
2050 Case_Value : Name_Id := No_Name;
2051 -- The case variable value
2053 Case_Item : Project_Node_Id := Empty_Node;
2054 Choice_String : Project_Node_Id := Empty_Node;
2055 Decl_Item : Project_Node_Id := Empty_Node;
2059 Variable_Node : constant Project_Node_Id :=
2060 Case_Variable_Reference_Of
2062 From_Project_Node_Tree);
2064 Var_Id : Variable_Id := No_Variable;
2065 Name : Name_Id := No_Name;
2068 -- If a project was specified for the case variable,
2072 (Variable_Node, From_Project_Node_Tree) /= Empty_Node
2077 (Variable_Node, From_Project_Node_Tree),
2078 From_Project_Node_Tree);
2080 Imported_Or_Extended_Project_From
2081 (Project, In_Tree, Name);
2084 -- If a package were specified for the case variable,
2088 (Variable_Node, From_Project_Node_Tree) /= Empty_Node
2093 (Variable_Node, From_Project_Node_Tree),
2094 From_Project_Node_Tree);
2096 Package_From (The_Project, In_Tree, Name);
2099 Name := Name_Of (Variable_Node, From_Project_Node_Tree);
2101 -- First, look for the case variable into the package,
2104 if The_Package /= No_Package then
2105 Var_Id := In_Tree.Packages.Table
2106 (The_Package).Decl.Variables;
2108 Name_Of (Variable_Node, From_Project_Node_Tree);
2109 while Var_Id /= No_Variable
2111 In_Tree.Variable_Elements.Table
2112 (Var_Id).Name /= Name
2114 Var_Id := In_Tree.Variable_Elements.
2115 Table (Var_Id).Next;
2119 -- If not found in the package, or if there is no
2120 -- package, look at the project level.
2122 if Var_Id = No_Variable
2125 (Variable_Node, From_Project_Node_Tree) = Empty_Node
2127 Var_Id := In_Tree.Projects.Table
2128 (The_Project).Decl.Variables;
2129 while Var_Id /= No_Variable
2131 In_Tree.Variable_Elements.Table
2132 (Var_Id).Name /= Name
2134 Var_Id := In_Tree.Variable_Elements.
2135 Table (Var_Id).Next;
2139 if Var_Id = No_Variable then
2141 -- Should never happen, because this has already been
2142 -- checked during parsing.
2144 Write_Line ("variable """ &
2145 Get_Name_String (Name) &
2147 raise Program_Error;
2150 -- Get the case variable
2152 The_Variable := In_Tree.Variable_Elements.
2153 Table (Var_Id).Value;
2155 if The_Variable.Kind /= Single then
2157 -- Should never happen, because this has already been
2158 -- checked during parsing.
2160 Write_Line ("variable""" &
2161 Get_Name_String (Name) &
2162 """ is not a single string variable");
2163 raise Program_Error;
2166 -- Get the case variable value
2167 Case_Value := The_Variable.Value;
2170 -- Now look into all the case items of the case construction
2173 First_Case_Item_Of (Current_Item, From_Project_Node_Tree);
2175 while Case_Item /= Empty_Node loop
2177 First_Choice_Of (Case_Item, From_Project_Node_Tree);
2179 -- When Choice_String is nil, it means that it is
2180 -- the "when others =>" alternative.
2182 if Choice_String = Empty_Node then
2184 First_Declarative_Item_Of
2185 (Case_Item, From_Project_Node_Tree);
2186 exit Case_Item_Loop;
2189 -- Look into all the alternative of this case item
2192 while Choice_String /= Empty_Node loop
2195 (Choice_String, From_Project_Node_Tree)
2198 First_Declarative_Item_Of
2199 (Case_Item, From_Project_Node_Tree);
2200 exit Case_Item_Loop;
2205 (Choice_String, From_Project_Node_Tree);
2206 end loop Choice_Loop;
2209 Next_Case_Item (Case_Item, From_Project_Node_Tree);
2210 end loop Case_Item_Loop;
2212 -- If there is an alternative, then we process it
2214 if Decl_Item /= Empty_Node then
2215 Process_Declarative_Items
2216 (Project => Project,
2218 From_Project_Node => From_Project_Node,
2219 From_Project_Node_Tree => From_Project_Node_Tree,
2227 -- Should never happen
2229 Write_Line ("Illegal declarative item: " &
2230 Project_Node_Kind'Image
2232 (Current_Item, From_Project_Node_Tree)));
2233 raise Program_Error;
2236 end Process_Declarative_Items;
2238 ----------------------------------
2239 -- Process_Project_Tree_Phase_1 --
2240 ----------------------------------
2242 procedure Process_Project_Tree_Phase_1
2243 (In_Tree : Project_Tree_Ref;
2244 Project : out Project_Id;
2245 Success : out Boolean;
2246 From_Project_Node : Project_Node_Id;
2247 From_Project_Node_Tree : Project_Node_Tree_Ref;
2248 Report_Error : Put_Line_Access;
2249 Reset_Tree : Boolean := True)
2252 Error_Report := Report_Error;
2256 -- Make sure there are no projects in the data structure
2258 Project_Table.Set_Last (In_Tree.Projects, No_Project);
2261 Processed_Projects.Reset;
2263 -- And process the main project and all of the projects it depends on,
2267 (Project => Project,
2269 From_Project_Node => From_Project_Node,
2270 From_Project_Node_Tree => From_Project_Node_Tree,
2271 Extended_By => No_Project);
2274 Total_Errors_Detected = 0
2276 (Warning_Mode /= Treat_As_Error or else Warnings_Detected = 0);
2277 end Process_Project_Tree_Phase_1;
2279 ----------------------------------
2280 -- Process_Project_Tree_Phase_2 --
2281 ----------------------------------
2283 procedure Process_Project_Tree_Phase_2
2284 (In_Tree : Project_Tree_Ref;
2285 Project : Project_Id;
2286 Success : out Boolean;
2287 From_Project_Node : Project_Node_Id;
2288 From_Project_Node_Tree : Project_Node_Tree_Ref;
2289 Report_Error : Put_Line_Access;
2290 When_No_Sources : Error_Warning := Error;
2291 Current_Dir : String)
2293 Obj_Dir : Path_Name_Type;
2294 Extending : Project_Id;
2295 Extending2 : Project_Id;
2297 -- Start of processing for Process_Project_Tree_Phase_2
2300 Error_Report := Report_Error;
2303 if Project /= No_Project then
2304 Check (In_Tree, Project, Current_Dir, When_No_Sources);
2307 -- If main project is an extending all project, set the object
2308 -- directory of all virtual extending projects to the object
2309 -- directory of the main project.
2311 if Project /= No_Project
2313 Is_Extending_All (From_Project_Node, From_Project_Node_Tree)
2316 Object_Dir : constant Path_Name_Type :=
2317 In_Tree.Projects.Table
2318 (Project).Object_Directory;
2321 Project_Table.First .. Project_Table.Last (In_Tree.Projects)
2323 if In_Tree.Projects.Table (Index).Virtual then
2324 In_Tree.Projects.Table (Index).Object_Directory :=
2331 -- Check that no extending project shares its object directory with
2332 -- the project(s) it extends.
2334 if Project /= No_Project then
2336 Project_Table.First .. Project_Table.Last (In_Tree.Projects)
2338 Extending := In_Tree.Projects.Table (Proj).Extended_By;
2340 if Extending /= No_Project then
2341 Obj_Dir := In_Tree.Projects.Table (Proj).Object_Directory;
2343 -- Check that a project being extended does not share its
2344 -- object directory with any project that extends it, directly
2345 -- or indirectly, including a virtual extending project.
2347 -- Start with the project directly extending it
2349 Extending2 := Extending;
2350 while Extending2 /= No_Project loop
2351 if In_Tree.Projects.Table (Extending2).Ada_Sources /=
2354 In_Tree.Projects.Table (Extending2).Object_Directory =
2357 if In_Tree.Projects.Table (Extending2).Virtual then
2359 In_Tree.Projects.Table (Proj).Display_Name;
2361 if Error_Report = null then
2363 ("project %% cannot be extended by a virtual" &
2364 " project with the same object directory",
2365 In_Tree.Projects.Table (Proj).Location);
2369 Get_Name_String (Error_Msg_Name_1) &
2370 """ cannot be extended by a virtual " &
2371 "project with the same object directory",
2377 In_Tree.Projects.Table (Extending2).Display_Name;
2379 In_Tree.Projects.Table (Proj).Display_Name;
2381 if Error_Report = null then
2383 ("project %% cannot extend project %%",
2384 In_Tree.Projects.Table (Extending2).Location);
2386 ("\they share the same object directory",
2387 In_Tree.Projects.Table (Extending2).Location);
2392 Get_Name_String (Error_Msg_Name_1) &
2393 """ cannot extend project """ &
2394 Get_Name_String (Error_Msg_Name_2) & """",
2397 ("they share the same object directory",
2403 -- Continue with the next extending project, if any
2406 In_Tree.Projects.Table (Extending2).Extended_By;
2413 Total_Errors_Detected = 0
2415 (Warning_Mode /= Treat_As_Error or else Warnings_Detected = 0);
2416 end Process_Project_Tree_Phase_2;
2418 ---------------------
2419 -- Recursive_Check --
2420 ---------------------
2422 procedure Recursive_Check
2423 (Project : Project_Id;
2424 In_Tree : Project_Tree_Ref;
2425 Current_Dir : String;
2426 When_No_Sources : Error_Warning)
2428 Data : Project_Data;
2429 Imported_Project_List : Project_List := Empty_Project_List;
2432 -- Do nothing if Project is No_Project, or Project has already
2433 -- been marked as checked.
2435 if Project /= No_Project
2436 and then not In_Tree.Projects.Table (Project).Checked
2438 -- Mark project as checked, to avoid infinite recursion in
2439 -- ill-formed trees, where a project imports itself.
2441 In_Tree.Projects.Table (Project).Checked := True;
2443 Data := In_Tree.Projects.Table (Project);
2445 -- Call itself for a possible extended project.
2446 -- (if there is no extended project, then nothing happens).
2448 Recursive_Check (Data.Extends, In_Tree, Current_Dir, When_No_Sources);
2450 -- Call itself for all imported projects
2452 Imported_Project_List := Data.Imported_Projects;
2453 while Imported_Project_List /= Empty_Project_List loop
2455 (In_Tree.Project_Lists.Table
2456 (Imported_Project_List).Project,
2457 In_Tree, Current_Dir, When_No_Sources);
2458 Imported_Project_List :=
2459 In_Tree.Project_Lists.Table
2460 (Imported_Project_List).Next;
2463 if Verbose_Mode then
2464 Write_Str ("Checking project file """);
2465 Write_Str (Get_Name_String (Data.Name));
2470 (Project, In_Tree, Error_Report, When_No_Sources,
2473 end Recursive_Check;
2475 -----------------------
2476 -- Recursive_Process --
2477 -----------------------
2479 procedure Recursive_Process
2480 (In_Tree : Project_Tree_Ref;
2481 Project : out Project_Id;
2482 From_Project_Node : Project_Node_Id;
2483 From_Project_Node_Tree : Project_Node_Tree_Ref;
2484 Extended_By : Project_Id)
2486 With_Clause : Project_Node_Id;
2489 if From_Project_Node = Empty_Node then
2490 Project := No_Project;
2494 Processed_Data : Project_Data := Empty_Project (In_Tree);
2495 Imported : Project_List := Empty_Project_List;
2496 Declaration_Node : Project_Node_Id := Empty_Node;
2497 Tref : Source_Buffer_Ptr;
2498 Name : constant Name_Id :=
2500 (From_Project_Node, From_Project_Node_Tree);
2501 Location : Source_Ptr :=
2503 (From_Project_Node, From_Project_Node_Tree);
2506 Project := Processed_Projects.Get (Name);
2508 if Project /= No_Project then
2510 -- Make sure that, when a project is extended, the project id
2511 -- of the project extending it is recorded in its data, even
2512 -- when it has already been processed as an imported project.
2513 -- This is for virtually extended projects.
2515 if Extended_By /= No_Project then
2516 In_Tree.Projects.Table (Project).Extended_By := Extended_By;
2522 Project_Table.Increment_Last (In_Tree.Projects);
2523 Project := Project_Table.Last (In_Tree.Projects);
2524 Processed_Projects.Set (Name, Project);
2526 Processed_Data.Name := Name;
2527 Processed_Data.Qualifier :=
2528 Project_Qualifier_Of (From_Project_Node, From_Project_Node_Tree);
2529 In_Tree.Projects.Table (Project).Name := Name;
2530 In_Tree.Projects.Table (Project).Qualifier :=
2531 Processed_Data.Qualifier;
2533 Get_Name_String (Name);
2535 -- If name starts with the virtual prefix, flag the project as
2536 -- being a virtual extending project.
2538 if Name_Len > Virtual_Prefix'Length
2539 and then Name_Buffer (1 .. Virtual_Prefix'Length) =
2542 Processed_Data.Virtual := True;
2543 Processed_Data.Display_Name := Name;
2545 -- If there is no file, for example when the project node tree is
2546 -- built in memory by GPS, the Display_Name cannot be found in
2547 -- the source, so its value is the same as Name.
2549 elsif Location = No_Location then
2550 Processed_Data.Display_Name := Name;
2552 -- Get the spelling of the project name from the project file
2555 Tref := Source_Text (Get_Source_File_Index (Location));
2557 for J in 1 .. Name_Len loop
2558 Name_Buffer (J) := Tref (Location);
2559 Location := Location + 1;
2562 Processed_Data.Display_Name := Name_Find;
2565 Processed_Data.Display_Path_Name :=
2566 Path_Name_Of (From_Project_Node, From_Project_Node_Tree);
2567 Get_Name_String (Processed_Data.Display_Path_Name);
2568 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2569 Processed_Data.Path_Name := Name_Find;
2571 Processed_Data.Location :=
2572 Location_Of (From_Project_Node, From_Project_Node_Tree);
2574 Processed_Data.Display_Directory :=
2575 Directory_Of (From_Project_Node, From_Project_Node_Tree);
2576 Get_Name_String (Processed_Data.Display_Directory);
2577 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2578 Processed_Data.Directory := Name_Find;
2580 Processed_Data.Extended_By := Extended_By;
2586 Processed_Data.Decl,
2587 Prj.Attr.Attribute_First,
2588 Project_Level => True);
2590 -- Process non limited withed projects
2593 First_With_Clause_Of (From_Project_Node, From_Project_Node_Tree);
2594 while With_Clause /= Empty_Node loop
2596 New_Project : Project_Id;
2597 New_Data : Project_Data;
2598 Proj_Node : Project_Node_Id;
2602 Non_Limited_Project_Node_Of
2603 (With_Clause, From_Project_Node_Tree);
2605 if Proj_Node /= Empty_Node then
2607 (In_Tree => In_Tree,
2608 Project => New_Project,
2609 From_Project_Node =>
2611 (With_Clause, From_Project_Node_Tree),
2612 From_Project_Node_Tree => From_Project_Node_Tree,
2613 Extended_By => No_Project);
2616 In_Tree.Projects.Table (New_Project);
2618 -- If we were the first project to import it,
2619 -- set First_Referred_By to us.
2621 if New_Data.First_Referred_By = No_Project then
2622 New_Data.First_Referred_By := Project;
2623 In_Tree.Projects.Table (New_Project) :=
2627 -- Add this project to our list of imported projects
2629 Project_List_Table.Increment_Last
2630 (In_Tree.Project_Lists);
2632 In_Tree.Project_Lists.Table
2633 (Project_List_Table.Last
2634 (In_Tree.Project_Lists)) :=
2635 (Project => New_Project, Next => Empty_Project_List);
2637 -- Imported is the id of the last imported project. If it
2638 -- is nil, then this imported project is our first.
2640 if Imported = Empty_Project_List then
2641 Processed_Data.Imported_Projects :=
2642 Project_List_Table.Last
2643 (In_Tree.Project_Lists);
2646 In_Tree.Project_Lists.Table
2647 (Imported).Next := Project_List_Table.Last
2648 (In_Tree.Project_Lists);
2651 Imported := Project_List_Table.Last
2652 (In_Tree.Project_Lists);
2657 (With_Clause, From_Project_Node_Tree);
2662 Project_Declaration_Of
2663 (From_Project_Node, From_Project_Node_Tree);
2666 (In_Tree => In_Tree,
2667 Project => Processed_Data.Extends,
2668 From_Project_Node => Extended_Project_Of
2670 From_Project_Node_Tree),
2671 From_Project_Node_Tree => From_Project_Node_Tree,
2672 Extended_By => Project);
2674 In_Tree.Projects.Table (Project) := Processed_Data;
2676 Process_Declarative_Items
2677 (Project => Project,
2679 From_Project_Node => From_Project_Node,
2680 From_Project_Node_Tree => From_Project_Node_Tree,
2682 Item => First_Declarative_Item_Of
2684 From_Project_Node_Tree));
2686 -- If it is an extending project, inherit all packages
2687 -- from the extended project that are not explicitly defined
2688 -- or renamed. Also inherit the languages, if attribute Languages
2689 -- is not explicitly defined.
2691 Processed_Data := In_Tree.Projects.Table (Project);
2693 if Processed_Data.Extends /= No_Project then
2695 Extended_Pkg : Package_Id;
2696 Current_Pkg : Package_Id;
2697 Element : Package_Element;
2698 First : constant Package_Id :=
2699 Processed_Data.Decl.Packages;
2700 Attribute1 : Variable_Id;
2701 Attribute2 : Variable_Id;
2702 Attr_Value1 : Variable;
2703 Attr_Value2 : Variable;
2707 In_Tree.Projects.Table
2708 (Processed_Data.Extends).Decl.Packages;
2709 while Extended_Pkg /= No_Package loop
2711 In_Tree.Packages.Table (Extended_Pkg);
2713 Current_Pkg := First;
2714 while Current_Pkg /= No_Package
2715 and then In_Tree.Packages.Table (Current_Pkg).Name /=
2719 In_Tree.Packages.Table (Current_Pkg).Next;
2722 if Current_Pkg = No_Package then
2723 Package_Table.Increment_Last
2725 Current_Pkg := Package_Table.Last (In_Tree.Packages);
2726 In_Tree.Packages.Table (Current_Pkg) :=
2727 (Name => Element.Name,
2728 Decl => No_Declarations,
2729 Parent => No_Package,
2730 Next => Processed_Data.Decl.Packages);
2731 Processed_Data.Decl.Packages := Current_Pkg;
2732 Copy_Package_Declarations
2733 (From => Element.Decl,
2734 To => In_Tree.Packages.Table (Current_Pkg).Decl,
2735 New_Loc => No_Location,
2736 In_Tree => In_Tree);
2739 Extended_Pkg := Element.Next;
2742 -- Check if attribute Languages is declared in the
2743 -- extending project.
2745 Attribute1 := Processed_Data.Decl.Attributes;
2746 while Attribute1 /= No_Variable loop
2747 Attr_Value1 := In_Tree.Variable_Elements.
2749 exit when Attr_Value1.Name = Snames.Name_Languages;
2750 Attribute1 := Attr_Value1.Next;
2753 if Attribute1 = No_Variable or else
2754 Attr_Value1.Value.Default
2756 -- Attribute Languages is not declared in the extending
2757 -- project. Check if it is declared in the project being
2761 In_Tree.Projects.Table
2762 (Processed_Data.Extends).Decl.Attributes;
2763 while Attribute2 /= No_Variable loop
2764 Attr_Value2 := In_Tree.Variable_Elements.
2766 exit when Attr_Value2.Name = Snames.Name_Languages;
2767 Attribute2 := Attr_Value2.Next;
2770 if Attribute2 /= No_Variable and then
2771 not Attr_Value2.Value.Default
2773 -- As attribute Languages is declared in the project
2774 -- being extended, copy its value for the extending
2777 if Attribute1 = No_Variable then
2778 Variable_Element_Table.Increment_Last
2779 (In_Tree.Variable_Elements);
2780 Attribute1 := Variable_Element_Table.Last
2781 (In_Tree.Variable_Elements);
2782 Attr_Value1.Next := Processed_Data.Decl.Attributes;
2783 Processed_Data.Decl.Attributes := Attribute1;
2786 Attr_Value1.Name := Snames.Name_Languages;
2787 Attr_Value1.Value := Attr_Value2.Value;
2788 In_Tree.Variable_Elements.Table
2789 (Attribute1) := Attr_Value1;
2794 In_Tree.Projects.Table (Project) := Processed_Data;
2797 -- Process limited withed projects
2800 First_With_Clause_Of
2801 (From_Project_Node, From_Project_Node_Tree);
2802 while With_Clause /= Empty_Node loop
2804 New_Project : Project_Id;
2805 New_Data : Project_Data;
2806 Proj_Node : Project_Node_Id;
2810 Non_Limited_Project_Node_Of
2811 (With_Clause, From_Project_Node_Tree);
2813 if Proj_Node = Empty_Node then
2815 (In_Tree => In_Tree,
2816 Project => New_Project,
2817 From_Project_Node =>
2819 (With_Clause, From_Project_Node_Tree),
2820 From_Project_Node_Tree => From_Project_Node_Tree,
2821 Extended_By => No_Project);
2824 In_Tree.Projects.Table (New_Project);
2826 -- If we were the first project to import it, set
2827 -- First_Referred_By to us.
2829 if New_Data.First_Referred_By = No_Project then
2830 New_Data.First_Referred_By := Project;
2831 In_Tree.Projects.Table (New_Project) :=
2835 -- Add this project to our list of imported projects
2837 Project_List_Table.Increment_Last
2838 (In_Tree.Project_Lists);
2840 In_Tree.Project_Lists.Table
2841 (Project_List_Table.Last
2842 (In_Tree.Project_Lists)) :=
2843 (Project => New_Project, Next => Empty_Project_List);
2845 -- Imported is the id of the last imported project. If
2846 -- it is nil, then this imported project is our first.
2848 if Imported = Empty_Project_List then
2849 In_Tree.Projects.Table (Project).Imported_Projects :=
2850 Project_List_Table.Last
2851 (In_Tree.Project_Lists);
2853 In_Tree.Project_Lists.Table
2854 (Imported).Next := Project_List_Table.Last
2855 (In_Tree.Project_Lists);
2858 Imported := Project_List_Table.Last
2859 (In_Tree.Project_Lists);
2864 (With_Clause, From_Project_Node_Tree);
2869 end Recursive_Process;