1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2003 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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.Com; use Prj.Com;
34 with Prj.Err; use Prj.Err;
35 with Prj.Ext; use Prj.Ext;
36 with Prj.Nmsc; use Prj.Nmsc;
38 with GNAT.Case_Util; use GNAT.Case_Util;
41 package body Prj.Proc is
43 Error_Report : Put_Line_Access := null;
45 package Processed_Projects is new GNAT.HTable.Simple_HTable
46 (Header_Num => Header_Num,
47 Element => Project_Id,
48 No_Element => No_Project,
52 -- This hash table contains all processed projects
54 procedure Add (To_Exp : in out Name_Id; Str : Name_Id);
55 -- Concatenate two strings and returns another string if both
56 -- arguments are not null string.
58 procedure Add_Attributes
59 (Project : Project_Id;
60 Decl : in out Declarations;
61 First : Attribute_Node_Id);
62 -- Add all attributes, starting with First, with their default
63 -- values to the package or project with declarations Decl.
66 (Project : Project_Id;
67 From_Project_Node : Project_Node_Id;
69 First_Term : Project_Node_Id;
70 Kind : Variable_Kind) return Variable_Value;
71 -- From N_Expression project node From_Project_Node, compute the value
72 -- of an expression and return it as a Variable_Value.
74 function Imported_Or_Extended_Project_From
75 (Project : Project_Id;
76 With_Name : Name_Id) return Project_Id;
77 -- Find an imported or extended project of Project whose name is With_Name
80 (Project : Project_Id;
81 With_Name : Name_Id) return Package_Id;
82 -- Find the package of Project whose name is With_Name
84 procedure Process_Declarative_Items
85 (Project : Project_Id;
86 From_Project_Node : Project_Node_Id;
88 Item : Project_Node_Id);
89 -- Process declarative items starting with From_Project_Node, and put them
90 -- in declarations Decl. This is a recursive procedure; it calls itself for
91 -- a package declaration or a case construction.
93 procedure Recursive_Process
94 (Project : out Project_Id;
95 From_Project_Node : Project_Node_Id;
96 Extended_By : Project_Id);
97 -- Process project with node From_Project_Node in the tree.
98 -- Do nothing if From_Project_Node is Empty_Node.
99 -- If project has already been processed, simply return its project id.
100 -- Otherwise create a new project id, mark it as processed, call itself
101 -- recursively for all imported projects and a extended project, if any.
102 -- Then process the declarative items of the project.
104 procedure Check (Project : in out Project_Id);
105 -- Set all projects to not checked, then call Recursive_Check for the
106 -- main project Project. Project is set to No_Project if errors occurred.
108 procedure Recursive_Check (Project : Project_Id);
109 -- If Project is not marked as checked, mark it as checked, call
110 -- Check_Naming_Scheme for the project, then call itself for a
111 -- possible extended project and all the imported projects of Project.
117 procedure Add (To_Exp : in out Name_Id; Str : Name_Id) is
119 if To_Exp = Types.No_Name or else To_Exp = Empty_String then
121 -- To_Exp is nil or empty. The result is Str.
125 -- If Str is nil, then do not change To_Ext
127 elsif Str /= No_Name and then Str /= Empty_String then
129 S : constant String := Get_Name_String (Str);
132 Get_Name_String (To_Exp);
133 Add_Str_To_Name_Buffer (S);
143 procedure Add_Attributes
144 (Project : Project_Id;
145 Decl : in out Declarations;
146 First : Attribute_Node_Id)
148 The_Attribute : Attribute_Node_Id := First;
149 Attribute_Data : Attribute_Record;
152 while The_Attribute /= Empty_Attribute loop
153 Attribute_Data := Attributes.Table (The_Attribute);
155 if Attribute_Data.Kind_2 = Single then
157 New_Attribute : Variable_Value;
160 case Attribute_Data.Kind_1 is
162 -- Undefined should not happen
166 (False, "attribute with an undefined kind");
169 -- Single attributes have a default value of empty string
175 Location => No_Location,
177 Value => Empty_String);
179 -- List attributes have a default value of nil list
185 Location => No_Location,
187 Values => Nil_String);
191 Variable_Elements.Increment_Last;
192 Variable_Elements.Table (Variable_Elements.Last) :=
193 (Next => Decl.Attributes,
194 Name => Attribute_Data.Name,
195 Value => New_Attribute);
196 Decl.Attributes := Variable_Elements.Last;
200 The_Attribute := Attributes.Table (The_Attribute).Next;
208 procedure Check (Project : in out Project_Id) is
210 -- Make sure that all projects are marked as not checked
212 for Index in 1 .. Projects.Last loop
213 Projects.Table (Index).Checked := False;
216 Recursive_Check (Project);
225 (Project : Project_Id;
226 From_Project_Node : Project_Node_Id;
228 First_Term : Project_Node_Id;
229 Kind : Variable_Kind) return Variable_Value
231 The_Term : Project_Node_Id := First_Term;
232 -- The term in the expression list
234 The_Current_Term : Project_Node_Id := Empty_Node;
235 -- The current term node id
237 Result : Variable_Value (Kind => Kind);
238 -- The returned result
240 Last : String_List_Id := Nil_String;
241 -- Reference to the last string elements in Result, when Kind is List.
244 Result.Project := Project;
245 Result.Location := Location_Of (First_Term);
247 -- Process each term of the expression, starting with First_Term
249 while The_Term /= Empty_Node loop
250 The_Current_Term := Current_Term (The_Term);
252 case Kind_Of (The_Current_Term) is
254 when N_Literal_String =>
260 -- Should never happen
262 pragma Assert (False, "Undefined expression kind");
266 Add (Result.Value, String_Value_Of (The_Current_Term));
270 String_Elements.Increment_Last;
272 if Last = Nil_String then
274 -- This can happen in an expression such as
277 Result.Values := String_Elements.Last;
280 String_Elements.Table (Last).Next :=
281 String_Elements.Last;
284 Last := String_Elements.Last;
285 String_Elements.Table (Last) :=
286 (Value => String_Value_Of (The_Current_Term),
287 Display_Value => No_Name,
288 Location => Location_Of (The_Current_Term),
294 when N_Literal_String_List =>
297 String_Node : Project_Node_Id :=
298 First_Expression_In_List (The_Current_Term);
300 Value : Variable_Value;
303 if String_Node /= Empty_Node then
305 -- If String_Node is nil, it is an empty list,
306 -- there is nothing to do
310 From_Project_Node => From_Project_Node,
312 First_Term => Tree.First_Term (String_Node),
314 String_Elements.Increment_Last;
316 if Result.Values = Nil_String then
318 -- This literal string list is the first term
319 -- in a string list expression
321 Result.Values := String_Elements.Last;
324 String_Elements.Table (Last).Next :=
325 String_Elements.Last;
328 Last := String_Elements.Last;
329 String_Elements.Table (Last) :=
330 (Value => Value.Value,
331 Display_Value => No_Name,
332 Location => Value.Location,
337 -- Add the other element of the literal string list
338 -- one after the other
341 Next_Expression_In_List (String_Node);
343 exit when String_Node = Empty_Node;
348 From_Project_Node => From_Project_Node,
350 First_Term => Tree.First_Term (String_Node),
353 String_Elements.Increment_Last;
354 String_Elements.Table (Last).Next :=
355 String_Elements.Last;
356 Last := String_Elements.Last;
357 String_Elements.Table (Last) :=
358 (Value => Value.Value,
359 Display_Value => No_Name,
360 Location => Value.Location,
369 when N_Variable_Reference | N_Attribute_Reference =>
372 The_Project : Project_Id := Project;
373 The_Package : Package_Id := Pkg;
374 The_Name : Name_Id := No_Name;
375 The_Variable_Id : Variable_Id := No_Variable;
376 The_Variable : Variable_Value;
377 Term_Project : constant Project_Node_Id :=
378 Project_Node_Of (The_Current_Term);
379 Term_Package : constant Project_Node_Id :=
380 Package_Node_Of (The_Current_Term);
381 Index : Name_Id := No_Name;
384 if Term_Project /= Empty_Node and then
385 Term_Project /= From_Project_Node
387 -- This variable or attribute comes from another project
389 The_Name := Name_Of (Term_Project);
390 The_Project := Imported_Or_Extended_Project_From
392 With_Name => The_Name);
395 if Term_Package /= Empty_Node then
397 -- This is an attribute of a package
399 The_Name := Name_Of (Term_Package);
400 The_Package := Projects.Table (The_Project).Decl.Packages;
402 while The_Package /= No_Package
403 and then Packages.Table (The_Package).Name /= The_Name
405 The_Package := Packages.Table (The_Package).Next;
409 (The_Package /= No_Package,
410 "package not found.");
412 elsif Kind_Of (The_Current_Term) = N_Attribute_Reference then
413 The_Package := No_Package;
416 The_Name := Name_Of (The_Current_Term);
418 if Kind_Of (The_Current_Term) = N_Attribute_Reference then
419 Index := Associative_Array_Index_Of (The_Current_Term);
422 -- If it is not an associative array attribute
424 if Index = No_Name then
426 -- It is not an associative array attribute
428 if The_Package /= No_Package then
430 -- First, if there is a package, look into the package
433 Kind_Of (The_Current_Term) = N_Variable_Reference
436 Packages.Table (The_Package).Decl.Variables;
440 Packages.Table (The_Package).Decl.Attributes;
443 while The_Variable_Id /= No_Variable
445 Variable_Elements.Table (The_Variable_Id).Name /=
449 Variable_Elements.Table (The_Variable_Id).Next;
454 if The_Variable_Id = No_Variable then
456 -- If we have not found it, look into the project
459 Kind_Of (The_Current_Term) = N_Variable_Reference
462 Projects.Table (The_Project).Decl.Variables;
466 Projects.Table (The_Project).Decl.Attributes;
469 while The_Variable_Id /= No_Variable
471 Variable_Elements.Table (The_Variable_Id).Name /=
475 Variable_Elements.Table (The_Variable_Id).Next;
480 pragma Assert (The_Variable_Id /= No_Variable,
481 "variable or attribute not found");
483 The_Variable := Variable_Elements.Table
484 (The_Variable_Id).Value;
488 -- It is an associative array attribute
491 The_Array : Array_Id := No_Array;
492 The_Element : Array_Element_Id := No_Array_Element;
493 Array_Index : Name_Id := No_Name;
495 if The_Package /= No_Package then
497 Packages.Table (The_Package).Decl.Arrays;
501 Projects.Table (The_Project).Decl.Arrays;
504 while The_Array /= No_Array
505 and then Arrays.Table (The_Array).Name /= The_Name
507 The_Array := Arrays.Table (The_Array).Next;
510 if The_Array /= No_Array then
511 The_Element := Arrays.Table (The_Array).Value;
513 Get_Name_String (Index);
515 if Case_Insensitive (The_Current_Term) then
516 To_Lower (Name_Buffer (1 .. Name_Len));
519 Array_Index := Name_Find;
521 while The_Element /= No_Array_Element
522 and then Array_Elements.Table (The_Element).Index
526 Array_Elements.Table (The_Element).Next;
531 if The_Element /= No_Array_Element then
533 Array_Elements.Table (The_Element).Value;
537 Expression_Kind_Of (The_Current_Term) = List
542 Location => No_Location,
544 Values => Nil_String);
550 Location => No_Location,
552 Value => Empty_String);
562 -- Should never happen
564 pragma Assert (False, "undefined expression kind");
569 case The_Variable.Kind is
575 Add (Result.Value, The_Variable.Value);
579 -- Should never happen
583 "list cannot appear in single " &
584 "string expression");
589 case The_Variable.Kind is
595 String_Elements.Increment_Last;
597 if Last = Nil_String then
599 -- This can happen in an expression such as
602 Result.Values := String_Elements.Last;
605 String_Elements.Table (Last).Next :=
606 String_Elements.Last;
609 Last := String_Elements.Last;
610 String_Elements.Table (Last) :=
611 (Value => The_Variable.Value,
612 Display_Value => No_Name,
613 Location => Location_Of (The_Current_Term),
620 The_List : String_List_Id :=
624 while The_List /= Nil_String loop
625 String_Elements.Increment_Last;
627 if Last = Nil_String then
628 Result.Values := String_Elements.Last;
631 String_Elements.Table (Last).Next :=
632 String_Elements.Last;
636 Last := String_Elements.Last;
637 String_Elements.Table (Last) :=
639 String_Elements.Table
641 Display_Value => No_Name,
642 Location => Location_Of
647 String_Elements.Table (The_List).Next;
654 when N_External_Value =>
656 (String_Value_Of (External_Reference_Of (The_Current_Term)));
659 Name : constant Name_Id := Name_Find;
660 Default : Name_Id := No_Name;
661 Value : Name_Id := No_Name;
663 Default_Node : constant Project_Node_Id :=
664 External_Default_Of (The_Current_Term);
667 if Default_Node /= Empty_Node then
668 Default := String_Value_Of (Default_Node);
671 Value := Prj.Ext.Value_Of (Name, Default);
673 if Value = No_Name then
674 if not Opt.Quiet_Output then
675 if Error_Report = null then
677 ("?undefined external reference",
678 Location_Of (The_Current_Term));
682 ("warning: """ & Get_Name_String (Name) &
683 """ is an undefined external reference",
688 Value := Empty_String;
698 Add (Result.Value, Value);
701 String_Elements.Increment_Last;
703 if Last = Nil_String then
704 Result.Values := String_Elements.Last;
707 String_Elements.Table (Last).Next :=
708 String_Elements.Last;
711 Last := String_Elements.Last;
712 String_Elements.Table (Last) :=
714 Display_Value => No_Name,
715 Location => Location_Of (The_Current_Term),
724 -- Should never happen
728 "illegal node kind in an expression");
733 The_Term := Next_Term (The_Term);
739 ---------------------------------------
740 -- Imported_Or_Extended_Project_From --
741 ---------------------------------------
743 function Imported_Or_Extended_Project_From
744 (Project : Project_Id;
745 With_Name : Name_Id) return Project_Id
747 Data : constant Project_Data := Projects.Table (Project);
748 List : Project_List := Data.Imported_Projects;
751 -- First check if it is the name of a extended project
753 if Data.Extends /= No_Project
754 and then Projects.Table (Data.Extends).Name = With_Name
759 -- Then check the name of each imported project
761 while List /= Empty_Project_List
764 (Project_Lists.Table (List).Project).Name /= With_Name
767 List := Project_Lists.Table (List).Next;
771 (List /= Empty_Project_List,
772 "project not found");
774 return Project_Lists.Table (List).Project;
776 end Imported_Or_Extended_Project_From;
782 function Package_From
783 (Project : Project_Id;
784 With_Name : Name_Id) return Package_Id
786 Data : constant Project_Data := Projects.Table (Project);
787 Result : Package_Id := Data.Decl.Packages;
790 -- Check the name of each existing package of Project
792 while Result /= No_Package
794 Packages.Table (Result).Name /= With_Name
796 Result := Packages.Table (Result).Next;
799 if Result = No_Package then
800 -- Should never happen
801 Write_Line ("package """ & Get_Name_String (With_Name) &
815 (Project : out Project_Id;
816 Success : out Boolean;
817 From_Project_Node : Project_Node_Id;
818 Report_Error : Put_Line_Access)
821 Extending : Project_Id;
824 Error_Report := Report_Error;
827 -- Make sure there is no projects in the data structure
829 Projects.Set_Last (No_Project);
830 Processed_Projects.Reset;
832 -- And process the main project and all of the projects it depends on,
837 From_Project_Node => From_Project_Node,
838 Extended_By => No_Project);
840 if Project /= No_Project then
844 -- If main project is an extending all project, set the object
845 -- directory of all virtual extending projects to the object directory
846 -- of the main project.
848 if Project /= No_Project
849 and then Is_Extending_All (From_Project_Node)
852 Object_Dir : constant Name_Id :=
853 Projects.Table (Project).Object_Directory;
855 for Index in Projects.First .. Projects.Last loop
856 if Projects.Table (Index).Virtual then
857 Projects.Table (Index).Object_Directory := Object_Dir;
863 -- Check that no extended project shares its object directory with
866 if Project /= No_Project then
867 for Extended in 1 .. Projects.Last loop
868 Extending := Projects.Table (Extended).Extended_By;
870 if Extending /= No_Project then
871 Obj_Dir := Projects.Table (Extended).Object_Directory;
873 for Prj in 1 .. Projects.Last loop
875 and then Projects.Table (Prj).Sources_Present
876 and then Projects.Table (Prj).Object_Directory = Obj_Dir
878 if Projects.Table (Extending).Virtual then
879 Error_Msg_Name_1 := Projects.Table (Extended).Name;
881 if Error_Report = null then
883 ("project % cannot be extended by " &
885 Projects.Table (Extending).Location);
890 Get_Name_String (Error_Msg_Name_1) &
891 """ cannot be extended by a virtual project",
896 Error_Msg_Name_1 := Projects.Table (Extending).Name;
897 Error_Msg_Name_2 := Projects.Table (Extended).Name;
899 if Error_Report = null then
900 Error_Msg ("project % cannot extend project %",
901 Projects.Table (Extending).Location);
906 Get_Name_String (Error_Msg_Name_1) &
907 """ cannot extend project """ &
908 Get_Name_String (Error_Msg_Name_2) & '"',
913 Error_Msg_Name_1 := Projects.Table (Extended).Name;
914 Error_Msg_Name_2 := Projects.Table (Prj).Name;
916 if Error_Report = null then
918 ("\project % has the same object directory " &
920 Projects.Table (Extending).Location);
925 Get_Name_String (Error_Msg_Name_1) &
926 """ has the same object directory as project """ &
927 Get_Name_String (Error_Msg_Name_2) & '"',
931 Project := No_Project;
939 Success := Total_Errors_Detected <= 0;
942 -------------------------------
943 -- Process_Declarative_Items --
944 -------------------------------
946 procedure Process_Declarative_Items
947 (Project : Project_Id;
948 From_Project_Node : Project_Node_Id;
950 Item : Project_Node_Id)
952 Current_Declarative_Item : Project_Node_Id := Item;
953 Current_Item : Project_Node_Id := Empty_Node;
956 -- For each declarative item
958 while Current_Declarative_Item /= Empty_Node loop
962 Current_Item := Current_Item_Node (Current_Declarative_Item);
964 -- And set Current_Declarative_Item to the next declarative item
965 -- ready for the next iteration.
967 Current_Declarative_Item := Next_Declarative_Item
968 (Current_Declarative_Item);
970 case Kind_Of (Current_Item) is
972 when N_Package_Declaration =>
973 -- Do not process a package declaration that should be ignored
975 if Expression_Kind_Of (Current_Item) /= Ignored then
976 -- Create the new package
978 Packages.Increment_Last;
981 New_Pkg : constant Package_Id := Packages.Last;
982 The_New_Package : Package_Element;
984 Project_Of_Renamed_Package : constant Project_Node_Id :=
985 Project_Of_Renamed_Package_Of
989 -- Set the name of the new package
991 The_New_Package.Name := Name_Of (Current_Item);
993 -- Insert the new package in the appropriate list
995 if Pkg /= No_Package then
996 The_New_Package.Next :=
997 Packages.Table (Pkg).Decl.Packages;
998 Packages.Table (Pkg).Decl.Packages := New_Pkg;
1000 The_New_Package.Next :=
1001 Projects.Table (Project).Decl.Packages;
1002 Projects.Table (Project).Decl.Packages := New_Pkg;
1005 Packages.Table (New_Pkg) := The_New_Package;
1007 if Project_Of_Renamed_Package /= Empty_Node then
1012 Project_Name : constant Name_Id :=
1014 (Project_Of_Renamed_Package);
1016 Renamed_Project : constant Project_Id :=
1017 Imported_Or_Extended_Project_From
1018 (Project, Project_Name);
1020 Renamed_Package : constant Package_Id :=
1023 Name_Of (Current_Item));
1026 -- For a renamed package, set declarations to
1027 -- the declarations of the renamed package.
1029 Packages.Table (New_Pkg).Decl :=
1030 Packages.Table (Renamed_Package).Decl;
1033 -- Standard package declaration, not renaming
1036 -- Set the default values of the attributes
1040 Packages.Table (New_Pkg).Decl,
1041 Package_Attributes.Table
1042 (Package_Id_Of (Current_Item)).First_Attribute);
1044 -- And process declarative items of the new package
1046 Process_Declarative_Items
1047 (Project => Project,
1048 From_Project_Node => From_Project_Node,
1050 Item => First_Declarative_Item_Of
1056 when N_String_Type_Declaration =>
1058 -- There is nothing to process
1062 when N_Attribute_Declaration |
1063 N_Typed_Variable_Declaration |
1064 N_Variable_Declaration =>
1066 if Expression_Of (Current_Item) = Empty_Node then
1068 -- It must be a full associative array attribute declaration
1071 Current_Item_Name : constant Name_Id :=
1072 Name_Of (Current_Item);
1073 -- The name of the attribute
1075 New_Array : Array_Id;
1076 -- The new associative array created
1078 Orig_Array : Array_Id;
1079 -- The associative array value
1081 Orig_Project_Name : Name_Id := No_Name;
1082 -- The name of the project where the associative array
1085 Orig_Project : Project_Id := No_Project;
1086 -- The id of the project where the associative array
1089 Orig_Package_Name : Name_Id := No_Name;
1090 -- The name of the package, if any, where the associative
1093 Orig_Package : Package_Id := No_Package;
1094 -- The id of the package, if any, where the associative
1097 New_Element : Array_Element_Id := No_Array_Element;
1098 -- Id of a new array element created
1100 Prev_Element : Array_Element_Id := No_Array_Element;
1101 -- Last new element id created
1103 Orig_Element : Array_Element_Id := No_Array_Element;
1104 -- Current array element in the original associative
1107 Next_Element : Array_Element_Id := No_Array_Element;
1108 -- Id of the array element that follows the new element.
1109 -- This is not always nil, because values for the
1110 -- associative array attribute may already have been
1111 -- declared, and the array elements declared are reused.
1114 -- First, find if the associative array attribute already
1115 -- has elements declared.
1117 if Pkg /= No_Package then
1118 New_Array := Packages.Table (Pkg).Decl.Arrays;
1121 New_Array := Projects.Table (Project).Decl.Arrays;
1124 while New_Array /= No_Array and then
1125 Arrays.Table (New_Array).Name /= Current_Item_Name
1127 New_Array := Arrays.Table (New_Array).Next;
1130 -- If the attribute has never been declared add new entry
1131 -- in the arrays of the project/package and link it.
1133 if New_Array = No_Array then
1134 Arrays.Increment_Last;
1135 New_Array := Arrays.Last;
1137 if Pkg /= No_Package then
1138 Arrays.Table (New_Array) :=
1139 (Name => Current_Item_Name,
1140 Value => No_Array_Element,
1141 Next => Packages.Table (Pkg).Decl.Arrays);
1142 Packages.Table (Pkg).Decl.Arrays := New_Array;
1145 Arrays.Table (New_Array) :=
1146 (Name => Current_Item_Name,
1147 Value => No_Array_Element,
1148 Next => Projects.Table (Project).Decl.Arrays);
1149 Projects.Table (Project).Decl.Arrays := New_Array;
1153 -- Find the project where the value is declared
1155 Orig_Project_Name :=
1156 Name_Of (Associative_Project_Of (Current_Item));
1158 for Index in Projects.First .. Projects.Last loop
1159 if Projects.Table (Index).Name = Orig_Project_Name then
1160 Orig_Project := Index;
1165 pragma Assert (Orig_Project /= No_Project,
1166 "original project not found");
1168 if Associative_Package_Of (Current_Item) = Empty_Node then
1170 Projects.Table (Orig_Project).Decl.Arrays;
1173 -- If in a package, find the package where the
1174 -- value is declared.
1176 Orig_Package_Name :=
1177 Name_Of (Associative_Package_Of (Current_Item));
1179 Projects.Table (Orig_Project).Decl.Packages;
1180 pragma Assert (Orig_Package /= No_Package,
1181 "original package not found");
1183 while Packages.Table (Orig_Package).Name /=
1186 Orig_Package := Packages.Table (Orig_Package).Next;
1187 pragma Assert (Orig_Package /= No_Package,
1188 "original package not found");
1192 Packages.Table (Orig_Package).Decl.Arrays;
1195 -- Now look for the array
1197 while Orig_Array /= No_Array and then
1198 Arrays.Table (Orig_Array).Name /= Current_Item_Name
1200 Orig_Array := Arrays.Table (Orig_Array).Next;
1203 if Orig_Array = No_Array then
1204 if Error_Report = null then
1206 ("associative array value cannot be found",
1207 Location_Of (Current_Item));
1211 ("associative array value cannot be found",
1216 Orig_Element := Arrays.Table (Orig_Array).Value;
1218 -- Copy each array element
1220 while Orig_Element /= No_Array_Element loop
1221 -- If it is the first element ...
1223 if Prev_Element = No_Array_Element then
1224 -- And there is no array element declared yet,
1225 -- create a new first array element.
1227 if Arrays.Table (New_Array).Value =
1230 Array_Elements.Increment_Last;
1231 New_Element := Array_Elements.Last;
1232 Arrays.Table (New_Array).Value := New_Element;
1233 Next_Element := No_Array_Element;
1235 -- Otherwise, the new element is the first
1238 New_Element := Arrays.Table (New_Array).Value;
1240 Array_Elements.Table (New_Element).Next;
1243 -- Otherwise, reuse an existing element, or create
1244 -- one if necessary.
1248 Array_Elements.Table (Prev_Element).Next;
1250 if Next_Element = No_Array_Element then
1251 Array_Elements.Increment_Last;
1252 New_Element := Array_Elements.Last;
1255 New_Element := Next_Element;
1257 Array_Elements.Table (New_Element).Next;
1261 -- Copy the value of the element
1263 Array_Elements.Table (New_Element) :=
1264 Array_Elements.Table (Orig_Element);
1265 Array_Elements.Table (New_Element).Value.Project :=
1268 -- Adjust the Next link
1270 Array_Elements.Table (New_Element).Next :=
1273 -- Adjust the previous id for the next element
1275 Prev_Element := New_Element;
1277 -- Go to the next element in the original array
1279 Array_Elements.Table (Orig_Element).Next;
1282 -- Make sure that the array ends here, in case there
1283 -- previously a greater number of elements.
1285 Array_Elements.Table (New_Element).Next :=
1290 -- Declarations other that full associative arrays
1294 New_Value : constant Variable_Value :=
1296 (Project => Project,
1297 From_Project_Node => From_Project_Node,
1300 Tree.First_Term (Expression_Of
1303 Expression_Kind_Of (Current_Item));
1304 -- The expression value
1306 The_Variable : Variable_Id := No_Variable;
1308 Current_Item_Name : constant Name_Id :=
1309 Name_Of (Current_Item);
1312 -- Process a typed variable declaration
1315 Kind_Of (Current_Item) = N_Typed_Variable_Declaration
1317 -- Report an error for an empty string
1319 if New_Value.Value = Empty_String then
1320 Error_Msg_Name_1 := Name_Of (Current_Item);
1322 if Error_Report = null then
1324 ("no value defined for %",
1325 Location_Of (Current_Item));
1329 ("no value defined for " &
1330 Get_Name_String (Error_Msg_Name_1),
1336 Current_String : Project_Node_Id :=
1337 First_Literal_String
1342 -- Loop through all the valid strings for
1343 -- the string type and compare to the string
1346 while Current_String /= Empty_Node
1347 and then String_Value_Of (Current_String) /=
1351 Next_Literal_String (Current_String);
1354 -- Report an error if the string value is not
1355 -- one for the string type.
1357 if Current_String = Empty_Node then
1358 Error_Msg_Name_1 := New_Value.Value;
1359 Error_Msg_Name_2 := Name_Of (Current_Item);
1361 if Error_Report = null then
1363 ("value { is illegal for typed string %",
1364 Location_Of (Current_Item));
1369 Get_Name_String (Error_Msg_Name_1) &
1370 """ is illegal for typed string """ &
1371 Get_Name_String (Error_Msg_Name_2) &
1380 if Kind_Of (Current_Item) /= N_Attribute_Declaration
1382 Associative_Array_Index_Of (Current_Item) = No_Name
1384 -- Case of a variable declaration or of a not
1385 -- associative array attribute.
1387 -- First, find the list where to find the variable
1391 Kind_Of (Current_Item) = N_Attribute_Declaration
1393 if Pkg /= No_Package then
1395 Packages.Table (Pkg).Decl.Attributes;
1399 Projects.Table (Project).Decl.Attributes;
1403 if Pkg /= No_Package then
1405 Packages.Table (Pkg).Decl.Variables;
1409 Projects.Table (Project).Decl.Variables;
1414 -- Loop through the list, to find if it has already
1418 The_Variable /= No_Variable
1420 Variable_Elements.Table (The_Variable).Name /=
1424 Variable_Elements.Table (The_Variable).Next;
1427 -- If it has not been declared, create a new entry
1430 if The_Variable = No_Variable then
1431 -- All single string attribute should already have
1432 -- been declared with a default empty string value.
1435 (Kind_Of (Current_Item) /=
1436 N_Attribute_Declaration,
1437 "illegal attribute declaration");
1439 Variable_Elements.Increment_Last;
1440 The_Variable := Variable_Elements.Last;
1442 -- Put the new variable in the appropriate list
1444 if Pkg /= No_Package then
1445 Variable_Elements.Table (The_Variable) :=
1447 Packages.Table (Pkg).Decl.Variables,
1448 Name => Current_Item_Name,
1449 Value => New_Value);
1450 Packages.Table (Pkg).Decl.Variables :=
1454 Variable_Elements.Table (The_Variable) :=
1456 Projects.Table (Project).Decl.Variables,
1457 Name => Current_Item_Name,
1458 Value => New_Value);
1459 Projects.Table (Project).Decl.Variables :=
1463 -- If the variable/attribute has already been
1464 -- declared, just change the value.
1467 Variable_Elements.Table (The_Variable).Value :=
1473 -- Associative array attribute
1475 -- Get the string index
1478 (Associative_Array_Index_Of (Current_Item));
1480 -- Put in lower case, if necessary
1482 if Case_Insensitive (Current_Item) then
1483 GNAT.Case_Util.To_Lower
1484 (Name_Buffer (1 .. Name_Len));
1488 The_Array : Array_Id;
1490 The_Array_Element : Array_Element_Id :=
1493 Index_Name : constant Name_Id := Name_Find;
1494 -- The name id of the index
1497 -- Look for the array in the appropriate list
1499 if Pkg /= No_Package then
1500 The_Array := Packages.Table (Pkg).Decl.Arrays;
1503 The_Array := Projects.Table
1504 (Project).Decl.Arrays;
1508 The_Array /= No_Array
1509 and then Arrays.Table (The_Array).Name /=
1512 The_Array := Arrays.Table (The_Array).Next;
1515 -- If the array cannot be found, create a new
1516 -- entry in the list. As The_Array_Element is
1517 -- initialized to No_Array_Element, a new element
1518 -- will be created automatically later.
1520 if The_Array = No_Array then
1521 Arrays.Increment_Last;
1522 The_Array := Arrays.Last;
1524 if Pkg /= No_Package then
1525 Arrays.Table (The_Array) :=
1526 (Name => Current_Item_Name,
1527 Value => No_Array_Element,
1528 Next => Packages.Table (Pkg).Decl.Arrays);
1529 Packages.Table (Pkg).Decl.Arrays := The_Array;
1532 Arrays.Table (The_Array) :=
1533 (Name => Current_Item_Name,
1534 Value => No_Array_Element,
1536 Projects.Table (Project).Decl.Arrays);
1537 Projects.Table (Project).Decl.Arrays :=
1541 -- Otherwise, initialize The_Array_Element as the
1542 -- head of the element list.
1545 The_Array_Element :=
1546 Arrays.Table (The_Array).Value;
1549 -- Look in the list, if any, to find an element
1550 -- with the same index.
1552 while The_Array_Element /= No_Array_Element
1554 Array_Elements.Table (The_Array_Element).Index /=
1557 The_Array_Element :=
1558 Array_Elements.Table (The_Array_Element).Next;
1561 -- If no such element were found, create a new
1562 -- one and insert it in the element list, with
1563 -- the propoer value.
1565 if The_Array_Element = No_Array_Element then
1566 Array_Elements.Increment_Last;
1567 The_Array_Element := Array_Elements.Last;
1569 Array_Elements.Table (The_Array_Element) :=
1570 (Index => Index_Name,
1571 Index_Case_Sensitive =>
1572 not Case_Insensitive (Current_Item),
1574 Next => Arrays.Table (The_Array).Value);
1575 Arrays.Table (The_Array).Value :=
1578 -- An element with the same index already exists,
1579 -- just replace its value with the new one.
1582 Array_Elements.Table (The_Array_Element).Value :=
1590 when N_Case_Construction =>
1592 The_Project : Project_Id := Project;
1593 -- The id of the project of the case variable
1595 The_Package : Package_Id := Pkg;
1596 -- The id of the package, if any, of the case variable
1598 The_Variable : Variable_Value := Nil_Variable_Value;
1599 -- The case variable
1601 Case_Value : Name_Id := No_Name;
1602 -- The case variable value
1604 Case_Item : Project_Node_Id := Empty_Node;
1605 Choice_String : Project_Node_Id := Empty_Node;
1606 Decl_Item : Project_Node_Id := Empty_Node;
1610 Variable_Node : constant Project_Node_Id :=
1611 Case_Variable_Reference_Of
1614 Var_Id : Variable_Id := No_Variable;
1615 Name : Name_Id := No_Name;
1618 -- If a project were specified for the case variable,
1621 if Project_Node_Of (Variable_Node) /= Empty_Node then
1622 Name := Name_Of (Project_Node_Of (Variable_Node));
1624 Imported_Or_Extended_Project_From (Project, Name);
1627 -- If a package were specified for the case variable,
1630 if Package_Node_Of (Variable_Node) /= Empty_Node then
1631 Name := Name_Of (Package_Node_Of (Variable_Node));
1632 The_Package := Package_From (The_Project, Name);
1635 Name := Name_Of (Variable_Node);
1637 -- First, look for the case variable into the package,
1640 if The_Package /= No_Package then
1641 Var_Id := Packages.Table (The_Package).Decl.Variables;
1642 Name := Name_Of (Variable_Node);
1643 while Var_Id /= No_Variable
1645 Variable_Elements.Table (Var_Id).Name /= Name
1647 Var_Id := Variable_Elements.Table (Var_Id).Next;
1651 -- If not found in the package, or if there is no
1652 -- package, look at the project level.
1654 if Var_Id = No_Variable
1655 and then Package_Node_Of (Variable_Node) = Empty_Node
1657 Var_Id := Projects.Table (The_Project).Decl.Variables;
1658 while Var_Id /= No_Variable
1660 Variable_Elements.Table (Var_Id).Name /= Name
1662 Var_Id := Variable_Elements.Table (Var_Id).Next;
1666 if Var_Id = No_Variable then
1668 -- Should never happen, because this has already been
1669 -- checked during parsing.
1671 Write_Line ("variable """ &
1672 Get_Name_String (Name) &
1674 raise Program_Error;
1677 -- Get the case variable
1679 The_Variable := Variable_Elements.Table (Var_Id).Value;
1681 if The_Variable.Kind /= Single then
1683 -- Should never happen, because this has already been
1684 -- checked during parsing.
1686 Write_Line ("variable""" &
1687 Get_Name_String (Name) &
1688 """ is not a single string variable");
1689 raise Program_Error;
1692 -- Get the case variable value
1693 Case_Value := The_Variable.Value;
1696 -- Now look into all the case items of the case construction
1698 Case_Item := First_Case_Item_Of (Current_Item);
1700 while Case_Item /= Empty_Node loop
1701 Choice_String := First_Choice_Of (Case_Item);
1703 -- When Choice_String is nil, it means that it is
1704 -- the "when others =>" alternative.
1706 if Choice_String = Empty_Node then
1707 Decl_Item := First_Declarative_Item_Of (Case_Item);
1708 exit Case_Item_Loop;
1711 -- Look into all the alternative of this case item
1714 while Choice_String /= Empty_Node loop
1716 Case_Value = String_Value_Of (Choice_String)
1719 First_Declarative_Item_Of (Case_Item);
1720 exit Case_Item_Loop;
1724 Next_Literal_String (Choice_String);
1725 end loop Choice_Loop;
1726 Case_Item := Next_Case_Item (Case_Item);
1727 end loop Case_Item_Loop;
1729 -- If there is an alternative, then we process it
1731 if Decl_Item /= Empty_Node then
1732 Process_Declarative_Items
1733 (Project => Project,
1734 From_Project_Node => From_Project_Node,
1742 -- Should never happen
1744 Write_Line ("Illegal declarative item: " &
1745 Project_Node_Kind'Image (Kind_Of (Current_Item)));
1746 raise Program_Error;
1749 end Process_Declarative_Items;
1751 ---------------------
1752 -- Recursive_Check --
1753 ---------------------
1755 procedure Recursive_Check (Project : Project_Id) is
1756 Data : Project_Data;
1757 Imported_Project_List : Project_List := Empty_Project_List;
1760 -- Do nothing if Project is No_Project, or Project has already
1761 -- been marked as checked.
1763 if Project /= No_Project
1764 and then not Projects.Table (Project).Checked
1766 -- Mark project as checked, to avoid infinite recursion in
1767 -- ill-formed trees, where a project imports itself.
1769 Projects.Table (Project).Checked := True;
1771 Data := Projects.Table (Project);
1773 -- Call itself for a possible extended project.
1774 -- (if there is no extended project, then nothing happens).
1776 Recursive_Check (Data.Extends);
1778 -- Call itself for all imported projects
1780 Imported_Project_List := Data.Imported_Projects;
1781 while Imported_Project_List /= Empty_Project_List loop
1783 (Project_Lists.Table (Imported_Project_List).Project);
1784 Imported_Project_List :=
1785 Project_Lists.Table (Imported_Project_List).Next;
1788 if Opt.Verbose_Mode then
1789 Write_Str ("Checking project file """);
1790 Write_Str (Get_Name_String (Data.Name));
1794 Prj.Nmsc.Ada_Check (Project, Error_Report);
1796 end Recursive_Check;
1798 -----------------------
1799 -- Recursive_Process --
1800 -----------------------
1802 procedure Recursive_Process
1803 (Project : out Project_Id;
1804 From_Project_Node : Project_Node_Id;
1805 Extended_By : Project_Id)
1807 With_Clause : Project_Node_Id;
1810 if From_Project_Node = Empty_Node then
1811 Project := No_Project;
1815 Processed_Data : Project_Data := Empty_Project;
1816 Imported : Project_List := Empty_Project_List;
1817 Declaration_Node : Project_Node_Id := Empty_Node;
1818 Name : constant Name_Id :=
1819 Name_Of (From_Project_Node);
1822 Project := Processed_Projects.Get (Name);
1824 if Project /= No_Project then
1828 Projects.Increment_Last;
1829 Project := Projects.Last;
1830 Processed_Projects.Set (Name, Project);
1832 Processed_Data.Name := Name;
1834 Get_Name_String (Name);
1836 -- If name starts with the virtual prefix, flag the project as
1837 -- being a virtual extending project.
1839 if Name_Len > Virtual_Prefix'Length
1840 and then Name_Buffer (1 .. Virtual_Prefix'Length) =
1843 Processed_Data.Virtual := True;
1846 Processed_Data.Display_Path_Name :=
1847 Path_Name_Of (From_Project_Node);
1848 Get_Name_String (Processed_Data.Display_Path_Name);
1849 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1850 Processed_Data.Path_Name := Name_Find;
1852 Processed_Data.Location := Location_Of (From_Project_Node);
1854 Processed_Data.Display_Directory :=
1855 Directory_Of (From_Project_Node);
1856 Get_Name_String (Processed_Data.Display_Directory);
1857 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1858 Processed_Data.Directory := Name_Find;
1860 Processed_Data.Extended_By := Extended_By;
1861 Processed_Data.Naming := Standard_Naming_Data;
1863 Add_Attributes (Project, Processed_Data.Decl, Attribute_First);
1864 With_Clause := First_With_Clause_Of (From_Project_Node);
1866 while With_Clause /= Empty_Node loop
1868 New_Project : Project_Id;
1869 New_Data : Project_Data;
1873 (Project => New_Project,
1874 From_Project_Node => Project_Node_Of (With_Clause),
1875 Extended_By => No_Project);
1876 New_Data := Projects.Table (New_Project);
1878 -- If we were the first project to import it,
1879 -- set First_Referred_By to us.
1881 if New_Data.First_Referred_By = No_Project then
1882 New_Data.First_Referred_By := Project;
1883 Projects.Table (New_Project) := New_Data;
1886 -- Add this project to our list of imported projects
1888 Project_Lists.Increment_Last;
1889 Project_Lists.Table (Project_Lists.Last) :=
1890 (Project => New_Project, Next => Empty_Project_List);
1892 -- Imported is the id of the last imported project.
1893 -- If it is nil, then this imported project is our first.
1895 if Imported = Empty_Project_List then
1896 Processed_Data.Imported_Projects := Project_Lists.Last;
1899 Project_Lists.Table (Imported).Next := Project_Lists.Last;
1902 Imported := Project_Lists.Last;
1904 With_Clause := Next_With_Clause_Of (With_Clause);
1908 Declaration_Node := Project_Declaration_Of (From_Project_Node);
1911 (Project => Processed_Data.Extends,
1912 From_Project_Node => Extended_Project_Of (Declaration_Node),
1913 Extended_By => Project);
1915 Projects.Table (Project) := Processed_Data;
1917 Process_Declarative_Items
1918 (Project => Project,
1919 From_Project_Node => From_Project_Node,
1921 Item => First_Declarative_Item_Of
1922 (Declaration_Node));
1924 -- If it is an extending project, inherit all packages
1925 -- from the extended project that are not explicitely defined
1928 if Processed_Data.Extends /= No_Project then
1929 Processed_Data := Projects.Table (Project);
1932 Extended_Pkg : Package_Id :=
1934 (Processed_Data.Extends).Decl.Packages;
1935 Current_Pkg : Package_Id;
1936 Element : Package_Element;
1937 First : constant Package_Id :=
1938 Processed_Data.Decl.Packages;
1941 while Extended_Pkg /= No_Package loop
1942 Element := Packages.Table (Extended_Pkg);
1944 Current_Pkg := First;
1947 exit when Current_Pkg = No_Package
1948 or else Packages.Table (Current_Pkg).Name
1950 Current_Pkg := Packages.Table (Current_Pkg).Next;
1953 if Current_Pkg = No_Package then
1954 Packages.Increment_Last;
1955 Current_Pkg := Packages.Last;
1956 Packages.Table (Current_Pkg) :=
1957 (Name => Element.Name,
1958 Decl => Element.Decl,
1959 Parent => No_Package,
1960 Next => Processed_Data.Decl.Packages);
1961 Processed_Data.Decl.Packages := Current_Pkg;
1964 Extended_Pkg := Element.Next;
1968 Projects.Table (Project) := Processed_Data;
1972 end Recursive_Process;