1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2004 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;
822 Extending2 : Project_Id;
825 Error_Report := Report_Error;
828 -- Make sure there is no projects in the data structure
830 Projects.Set_Last (No_Project);
831 Processed_Projects.Reset;
833 -- And process the main project and all of the projects it depends on,
838 From_Project_Node => From_Project_Node,
839 Extended_By => No_Project);
841 if Project /= No_Project then
845 -- If main project is an extending all project, set the object
846 -- directory of all virtual extending projects to the object directory
847 -- of the main project.
849 if Project /= No_Project
850 and then Is_Extending_All (From_Project_Node)
853 Object_Dir : constant Name_Id :=
854 Projects.Table (Project).Object_Directory;
856 for Index in Projects.First .. Projects.Last loop
857 if Projects.Table (Index).Virtual then
858 Projects.Table (Index).Object_Directory := Object_Dir;
864 -- Check that no extended project shares its object directory with
865 -- another extended project or with its extending project(s).
867 if Project /= No_Project then
868 for Extended in 1 .. Projects.Last loop
869 Extending := Projects.Table (Extended).Extended_By;
871 if Extending /= No_Project then
872 Obj_Dir := Projects.Table (Extended).Object_Directory;
874 -- Check that a project being extended does not share its
875 -- object directory with any project that extends it, directly
876 -- or indirectly, including a virtual extending project.
878 -- Start with the project directly extending it
880 Extending2 := Extending;
882 while Extending2 /= No_Project loop
883 if Projects.Table (Extending2).Sources_Present
885 Projects.Table (Extending2).Object_Directory = Obj_Dir
887 if Projects.Table (Extending2).Virtual then
888 Error_Msg_Name_1 := Projects.Table (Extended).Name;
890 if Error_Report = null then
892 ("project % cannot be extended by a virtual " &
893 "project with the same object directory",
894 Projects.Table (Extended).Location);
899 Get_Name_String (Error_Msg_Name_1) &
900 """ cannot be extended by a virtual " &
901 "project with the same object directory",
907 Projects.Table (Extending2).Name;
908 Error_Msg_Name_2 := Projects.Table (Extended).Name;
910 if Error_Report = null then
912 ("project % cannot extend project %",
913 Projects.Table (Extending2).Location);
915 ("\they share the same object directory",
916 Projects.Table (Extending2).Location);
921 Get_Name_String (Error_Msg_Name_1) &
922 """ cannot extend project """ &
923 Get_Name_String (Error_Msg_Name_2) & """",
926 ("they share the same object directory",
932 -- Continue with the next extending project, if any
934 Extending2 := Projects.Table (Extending2).Extended_By;
937 -- Check that two projects being extended do not share their
938 -- project directories.
940 for Prj in Extended + 1 .. Projects.Last loop
941 Extending2 := Projects.Table (Prj).Extended_By;
943 if Extending2 /= No_Project
944 and then Projects.Table (Prj).Sources_Present
945 and then Projects.Table (Prj).Object_Directory = Obj_Dir
946 and then not Projects.Table (Extending).Virtual
948 Error_Msg_Name_1 := Projects.Table (Extending).Name;
949 Error_Msg_Name_2 := Projects.Table (Extended).Name;
951 if Error_Report = null then
952 Error_Msg ("project % cannot extend project %",
953 Projects.Table (Extending).Location);
958 Get_Name_String (Error_Msg_Name_1) &
959 """ cannot extend project """ &
960 Get_Name_String (Error_Msg_Name_2) & '"',
964 Error_Msg_Name_1 := Projects.Table (Extended).Name;
965 Error_Msg_Name_2 := Projects.Table (Prj).Name;
967 if Error_Report = null then
969 ("\project % has the same object directory " &
971 Projects.Table (Extending).Location);
976 Get_Name_String (Error_Msg_Name_1) &
977 """ has the same object directory as project """ &
978 Get_Name_String (Error_Msg_Name_2) & """,",
982 Error_Msg_Name_1 := Projects.Table (Extending2).Name;
984 if Error_Report = null then
986 ("\which is extended by project %",
987 Projects.Table (Extending).Location);
991 ("which is extended by project """ &
992 Get_Name_String (Error_Msg_Name_1) & '"',
996 Project := No_Project;
1004 Success := Total_Errors_Detected <= 0;
1007 -------------------------------
1008 -- Process_Declarative_Items --
1009 -------------------------------
1011 procedure Process_Declarative_Items
1012 (Project : Project_Id;
1013 From_Project_Node : Project_Node_Id;
1015 Item : Project_Node_Id)
1017 Current_Declarative_Item : Project_Node_Id := Item;
1018 Current_Item : Project_Node_Id := Empty_Node;
1021 -- For each declarative item
1023 while Current_Declarative_Item /= Empty_Node loop
1027 Current_Item := Current_Item_Node (Current_Declarative_Item);
1029 -- And set Current_Declarative_Item to the next declarative item
1030 -- ready for the next iteration.
1032 Current_Declarative_Item := Next_Declarative_Item
1033 (Current_Declarative_Item);
1035 case Kind_Of (Current_Item) is
1037 when N_Package_Declaration =>
1038 -- Do not process a package declaration that should be ignored
1040 if Expression_Kind_Of (Current_Item) /= Ignored then
1041 -- Create the new package
1043 Packages.Increment_Last;
1046 New_Pkg : constant Package_Id := Packages.Last;
1047 The_New_Package : Package_Element;
1049 Project_Of_Renamed_Package : constant Project_Node_Id :=
1050 Project_Of_Renamed_Package_Of
1054 -- Set the name of the new package
1056 The_New_Package.Name := Name_Of (Current_Item);
1058 -- Insert the new package in the appropriate list
1060 if Pkg /= No_Package then
1061 The_New_Package.Next :=
1062 Packages.Table (Pkg).Decl.Packages;
1063 Packages.Table (Pkg).Decl.Packages := New_Pkg;
1065 The_New_Package.Next :=
1066 Projects.Table (Project).Decl.Packages;
1067 Projects.Table (Project).Decl.Packages := New_Pkg;
1070 Packages.Table (New_Pkg) := The_New_Package;
1072 if Project_Of_Renamed_Package /= Empty_Node then
1077 Project_Name : constant Name_Id :=
1079 (Project_Of_Renamed_Package);
1081 Renamed_Project : constant Project_Id :=
1082 Imported_Or_Extended_Project_From
1083 (Project, Project_Name);
1085 Renamed_Package : constant Package_Id :=
1088 Name_Of (Current_Item));
1091 -- For a renamed package, set declarations to
1092 -- the declarations of the renamed package.
1094 Packages.Table (New_Pkg).Decl :=
1095 Packages.Table (Renamed_Package).Decl;
1098 -- Standard package declaration, not renaming
1101 -- Set the default values of the attributes
1105 Packages.Table (New_Pkg).Decl,
1106 Package_Attributes.Table
1107 (Package_Id_Of (Current_Item)).First_Attribute);
1109 -- And process declarative items of the new package
1111 Process_Declarative_Items
1112 (Project => Project,
1113 From_Project_Node => From_Project_Node,
1115 Item => First_Declarative_Item_Of
1121 when N_String_Type_Declaration =>
1123 -- There is nothing to process
1127 when N_Attribute_Declaration |
1128 N_Typed_Variable_Declaration |
1129 N_Variable_Declaration =>
1131 if Expression_Of (Current_Item) = Empty_Node then
1133 -- It must be a full associative array attribute declaration
1136 Current_Item_Name : constant Name_Id :=
1137 Name_Of (Current_Item);
1138 -- The name of the attribute
1140 New_Array : Array_Id;
1141 -- The new associative array created
1143 Orig_Array : Array_Id;
1144 -- The associative array value
1146 Orig_Project_Name : Name_Id := No_Name;
1147 -- The name of the project where the associative array
1150 Orig_Project : Project_Id := No_Project;
1151 -- The id of the project where the associative array
1154 Orig_Package_Name : Name_Id := No_Name;
1155 -- The name of the package, if any, where the associative
1158 Orig_Package : Package_Id := No_Package;
1159 -- The id of the package, if any, where the associative
1162 New_Element : Array_Element_Id := No_Array_Element;
1163 -- Id of a new array element created
1165 Prev_Element : Array_Element_Id := No_Array_Element;
1166 -- Last new element id created
1168 Orig_Element : Array_Element_Id := No_Array_Element;
1169 -- Current array element in the original associative
1172 Next_Element : Array_Element_Id := No_Array_Element;
1173 -- Id of the array element that follows the new element.
1174 -- This is not always nil, because values for the
1175 -- associative array attribute may already have been
1176 -- declared, and the array elements declared are reused.
1179 -- First, find if the associative array attribute already
1180 -- has elements declared.
1182 if Pkg /= No_Package then
1183 New_Array := Packages.Table (Pkg).Decl.Arrays;
1186 New_Array := Projects.Table (Project).Decl.Arrays;
1189 while New_Array /= No_Array and then
1190 Arrays.Table (New_Array).Name /= Current_Item_Name
1192 New_Array := Arrays.Table (New_Array).Next;
1195 -- If the attribute has never been declared add new entry
1196 -- in the arrays of the project/package and link it.
1198 if New_Array = No_Array then
1199 Arrays.Increment_Last;
1200 New_Array := Arrays.Last;
1202 if Pkg /= No_Package then
1203 Arrays.Table (New_Array) :=
1204 (Name => Current_Item_Name,
1205 Value => No_Array_Element,
1206 Next => Packages.Table (Pkg).Decl.Arrays);
1207 Packages.Table (Pkg).Decl.Arrays := New_Array;
1210 Arrays.Table (New_Array) :=
1211 (Name => Current_Item_Name,
1212 Value => No_Array_Element,
1213 Next => Projects.Table (Project).Decl.Arrays);
1214 Projects.Table (Project).Decl.Arrays := New_Array;
1218 -- Find the project where the value is declared
1220 Orig_Project_Name :=
1221 Name_Of (Associative_Project_Of (Current_Item));
1223 for Index in Projects.First .. Projects.Last loop
1224 if Projects.Table (Index).Name = Orig_Project_Name then
1225 Orig_Project := Index;
1230 pragma Assert (Orig_Project /= No_Project,
1231 "original project not found");
1233 if Associative_Package_Of (Current_Item) = Empty_Node then
1235 Projects.Table (Orig_Project).Decl.Arrays;
1238 -- If in a package, find the package where the
1239 -- value is declared.
1241 Orig_Package_Name :=
1242 Name_Of (Associative_Package_Of (Current_Item));
1244 Projects.Table (Orig_Project).Decl.Packages;
1245 pragma Assert (Orig_Package /= No_Package,
1246 "original package not found");
1248 while Packages.Table (Orig_Package).Name /=
1251 Orig_Package := Packages.Table (Orig_Package).Next;
1252 pragma Assert (Orig_Package /= No_Package,
1253 "original package not found");
1257 Packages.Table (Orig_Package).Decl.Arrays;
1260 -- Now look for the array
1262 while Orig_Array /= No_Array and then
1263 Arrays.Table (Orig_Array).Name /= Current_Item_Name
1265 Orig_Array := Arrays.Table (Orig_Array).Next;
1268 if Orig_Array = No_Array then
1269 if Error_Report = null then
1271 ("associative array value cannot be found",
1272 Location_Of (Current_Item));
1276 ("associative array value cannot be found",
1281 Orig_Element := Arrays.Table (Orig_Array).Value;
1283 -- Copy each array element
1285 while Orig_Element /= No_Array_Element loop
1286 -- If it is the first element ...
1288 if Prev_Element = No_Array_Element then
1289 -- And there is no array element declared yet,
1290 -- create a new first array element.
1292 if Arrays.Table (New_Array).Value =
1295 Array_Elements.Increment_Last;
1296 New_Element := Array_Elements.Last;
1297 Arrays.Table (New_Array).Value := New_Element;
1298 Next_Element := No_Array_Element;
1300 -- Otherwise, the new element is the first
1303 New_Element := Arrays.Table (New_Array).Value;
1305 Array_Elements.Table (New_Element).Next;
1308 -- Otherwise, reuse an existing element, or create
1309 -- one if necessary.
1313 Array_Elements.Table (Prev_Element).Next;
1315 if Next_Element = No_Array_Element then
1316 Array_Elements.Increment_Last;
1317 New_Element := Array_Elements.Last;
1320 New_Element := Next_Element;
1322 Array_Elements.Table (New_Element).Next;
1326 -- Copy the value of the element
1328 Array_Elements.Table (New_Element) :=
1329 Array_Elements.Table (Orig_Element);
1330 Array_Elements.Table (New_Element).Value.Project :=
1333 -- Adjust the Next link
1335 Array_Elements.Table (New_Element).Next :=
1338 -- Adjust the previous id for the next element
1340 Prev_Element := New_Element;
1342 -- Go to the next element in the original array
1344 Array_Elements.Table (Orig_Element).Next;
1347 -- Make sure that the array ends here, in case there
1348 -- previously a greater number of elements.
1350 Array_Elements.Table (New_Element).Next :=
1355 -- Declarations other that full associative arrays
1359 New_Value : constant Variable_Value :=
1361 (Project => Project,
1362 From_Project_Node => From_Project_Node,
1365 Tree.First_Term (Expression_Of
1368 Expression_Kind_Of (Current_Item));
1369 -- The expression value
1371 The_Variable : Variable_Id := No_Variable;
1373 Current_Item_Name : constant Name_Id :=
1374 Name_Of (Current_Item);
1377 -- Process a typed variable declaration
1380 Kind_Of (Current_Item) = N_Typed_Variable_Declaration
1382 -- Report an error for an empty string
1384 if New_Value.Value = Empty_String then
1385 Error_Msg_Name_1 := Name_Of (Current_Item);
1387 if Error_Report = null then
1389 ("no value defined for %",
1390 Location_Of (Current_Item));
1394 ("no value defined for " &
1395 Get_Name_String (Error_Msg_Name_1),
1401 Current_String : Project_Node_Id :=
1402 First_Literal_String
1407 -- Loop through all the valid strings for
1408 -- the string type and compare to the string
1411 while Current_String /= Empty_Node
1412 and then String_Value_Of (Current_String) /=
1416 Next_Literal_String (Current_String);
1419 -- Report an error if the string value is not
1420 -- one for the string type.
1422 if Current_String = Empty_Node then
1423 Error_Msg_Name_1 := New_Value.Value;
1424 Error_Msg_Name_2 := Name_Of (Current_Item);
1426 if Error_Report = null then
1428 ("value { is illegal for typed string %",
1429 Location_Of (Current_Item));
1434 Get_Name_String (Error_Msg_Name_1) &
1435 """ is illegal for typed string """ &
1436 Get_Name_String (Error_Msg_Name_2) &
1445 if Kind_Of (Current_Item) /= N_Attribute_Declaration
1447 Associative_Array_Index_Of (Current_Item) = No_Name
1449 -- Case of a variable declaration or of a not
1450 -- associative array attribute.
1452 -- First, find the list where to find the variable
1456 Kind_Of (Current_Item) = N_Attribute_Declaration
1458 if Pkg /= No_Package then
1460 Packages.Table (Pkg).Decl.Attributes;
1464 Projects.Table (Project).Decl.Attributes;
1468 if Pkg /= No_Package then
1470 Packages.Table (Pkg).Decl.Variables;
1474 Projects.Table (Project).Decl.Variables;
1479 -- Loop through the list, to find if it has already
1483 The_Variable /= No_Variable
1485 Variable_Elements.Table (The_Variable).Name /=
1489 Variable_Elements.Table (The_Variable).Next;
1492 -- If it has not been declared, create a new entry
1495 if The_Variable = No_Variable then
1496 -- All single string attribute should already have
1497 -- been declared with a default empty string value.
1500 (Kind_Of (Current_Item) /=
1501 N_Attribute_Declaration,
1502 "illegal attribute declaration");
1504 Variable_Elements.Increment_Last;
1505 The_Variable := Variable_Elements.Last;
1507 -- Put the new variable in the appropriate list
1509 if Pkg /= No_Package then
1510 Variable_Elements.Table (The_Variable) :=
1512 Packages.Table (Pkg).Decl.Variables,
1513 Name => Current_Item_Name,
1514 Value => New_Value);
1515 Packages.Table (Pkg).Decl.Variables :=
1519 Variable_Elements.Table (The_Variable) :=
1521 Projects.Table (Project).Decl.Variables,
1522 Name => Current_Item_Name,
1523 Value => New_Value);
1524 Projects.Table (Project).Decl.Variables :=
1528 -- If the variable/attribute has already been
1529 -- declared, just change the value.
1532 Variable_Elements.Table (The_Variable).Value :=
1538 -- Associative array attribute
1540 -- Get the string index
1543 (Associative_Array_Index_Of (Current_Item));
1545 -- Put in lower case, if necessary
1547 if Case_Insensitive (Current_Item) then
1548 GNAT.Case_Util.To_Lower
1549 (Name_Buffer (1 .. Name_Len));
1553 The_Array : Array_Id;
1555 The_Array_Element : Array_Element_Id :=
1558 Index_Name : constant Name_Id := Name_Find;
1559 -- The name id of the index
1562 -- Look for the array in the appropriate list
1564 if Pkg /= No_Package then
1565 The_Array := Packages.Table (Pkg).Decl.Arrays;
1568 The_Array := Projects.Table
1569 (Project).Decl.Arrays;
1573 The_Array /= No_Array
1574 and then Arrays.Table (The_Array).Name /=
1577 The_Array := Arrays.Table (The_Array).Next;
1580 -- If the array cannot be found, create a new
1581 -- entry in the list. As The_Array_Element is
1582 -- initialized to No_Array_Element, a new element
1583 -- will be created automatically later.
1585 if The_Array = No_Array then
1586 Arrays.Increment_Last;
1587 The_Array := Arrays.Last;
1589 if Pkg /= No_Package then
1590 Arrays.Table (The_Array) :=
1591 (Name => Current_Item_Name,
1592 Value => No_Array_Element,
1593 Next => Packages.Table (Pkg).Decl.Arrays);
1594 Packages.Table (Pkg).Decl.Arrays := The_Array;
1597 Arrays.Table (The_Array) :=
1598 (Name => Current_Item_Name,
1599 Value => No_Array_Element,
1601 Projects.Table (Project).Decl.Arrays);
1602 Projects.Table (Project).Decl.Arrays :=
1606 -- Otherwise, initialize The_Array_Element as the
1607 -- head of the element list.
1610 The_Array_Element :=
1611 Arrays.Table (The_Array).Value;
1614 -- Look in the list, if any, to find an element
1615 -- with the same index.
1617 while The_Array_Element /= No_Array_Element
1619 Array_Elements.Table (The_Array_Element).Index /=
1622 The_Array_Element :=
1623 Array_Elements.Table (The_Array_Element).Next;
1626 -- If no such element were found, create a new
1627 -- one and insert it in the element list, with
1628 -- the propoer value.
1630 if The_Array_Element = No_Array_Element then
1631 Array_Elements.Increment_Last;
1632 The_Array_Element := Array_Elements.Last;
1634 Array_Elements.Table (The_Array_Element) :=
1635 (Index => Index_Name,
1636 Index_Case_Sensitive =>
1637 not Case_Insensitive (Current_Item),
1639 Next => Arrays.Table (The_Array).Value);
1640 Arrays.Table (The_Array).Value :=
1643 -- An element with the same index already exists,
1644 -- just replace its value with the new one.
1647 Array_Elements.Table (The_Array_Element).Value :=
1655 when N_Case_Construction =>
1657 The_Project : Project_Id := Project;
1658 -- The id of the project of the case variable
1660 The_Package : Package_Id := Pkg;
1661 -- The id of the package, if any, of the case variable
1663 The_Variable : Variable_Value := Nil_Variable_Value;
1664 -- The case variable
1666 Case_Value : Name_Id := No_Name;
1667 -- The case variable value
1669 Case_Item : Project_Node_Id := Empty_Node;
1670 Choice_String : Project_Node_Id := Empty_Node;
1671 Decl_Item : Project_Node_Id := Empty_Node;
1675 Variable_Node : constant Project_Node_Id :=
1676 Case_Variable_Reference_Of
1679 Var_Id : Variable_Id := No_Variable;
1680 Name : Name_Id := No_Name;
1683 -- If a project were specified for the case variable,
1686 if Project_Node_Of (Variable_Node) /= Empty_Node then
1687 Name := Name_Of (Project_Node_Of (Variable_Node));
1689 Imported_Or_Extended_Project_From (Project, Name);
1692 -- If a package were specified for the case variable,
1695 if Package_Node_Of (Variable_Node) /= Empty_Node then
1696 Name := Name_Of (Package_Node_Of (Variable_Node));
1697 The_Package := Package_From (The_Project, Name);
1700 Name := Name_Of (Variable_Node);
1702 -- First, look for the case variable into the package,
1705 if The_Package /= No_Package then
1706 Var_Id := Packages.Table (The_Package).Decl.Variables;
1707 Name := Name_Of (Variable_Node);
1708 while Var_Id /= No_Variable
1710 Variable_Elements.Table (Var_Id).Name /= Name
1712 Var_Id := Variable_Elements.Table (Var_Id).Next;
1716 -- If not found in the package, or if there is no
1717 -- package, look at the project level.
1719 if Var_Id = No_Variable
1720 and then Package_Node_Of (Variable_Node) = Empty_Node
1722 Var_Id := Projects.Table (The_Project).Decl.Variables;
1723 while Var_Id /= No_Variable
1725 Variable_Elements.Table (Var_Id).Name /= Name
1727 Var_Id := Variable_Elements.Table (Var_Id).Next;
1731 if Var_Id = No_Variable then
1733 -- Should never happen, because this has already been
1734 -- checked during parsing.
1736 Write_Line ("variable """ &
1737 Get_Name_String (Name) &
1739 raise Program_Error;
1742 -- Get the case variable
1744 The_Variable := Variable_Elements.Table (Var_Id).Value;
1746 if The_Variable.Kind /= Single then
1748 -- Should never happen, because this has already been
1749 -- checked during parsing.
1751 Write_Line ("variable""" &
1752 Get_Name_String (Name) &
1753 """ is not a single string variable");
1754 raise Program_Error;
1757 -- Get the case variable value
1758 Case_Value := The_Variable.Value;
1761 -- Now look into all the case items of the case construction
1763 Case_Item := First_Case_Item_Of (Current_Item);
1765 while Case_Item /= Empty_Node loop
1766 Choice_String := First_Choice_Of (Case_Item);
1768 -- When Choice_String is nil, it means that it is
1769 -- the "when others =>" alternative.
1771 if Choice_String = Empty_Node then
1772 Decl_Item := First_Declarative_Item_Of (Case_Item);
1773 exit Case_Item_Loop;
1776 -- Look into all the alternative of this case item
1779 while Choice_String /= Empty_Node loop
1781 Case_Value = String_Value_Of (Choice_String)
1784 First_Declarative_Item_Of (Case_Item);
1785 exit Case_Item_Loop;
1789 Next_Literal_String (Choice_String);
1790 end loop Choice_Loop;
1791 Case_Item := Next_Case_Item (Case_Item);
1792 end loop Case_Item_Loop;
1794 -- If there is an alternative, then we process it
1796 if Decl_Item /= Empty_Node then
1797 Process_Declarative_Items
1798 (Project => Project,
1799 From_Project_Node => From_Project_Node,
1807 -- Should never happen
1809 Write_Line ("Illegal declarative item: " &
1810 Project_Node_Kind'Image (Kind_Of (Current_Item)));
1811 raise Program_Error;
1814 end Process_Declarative_Items;
1816 ---------------------
1817 -- Recursive_Check --
1818 ---------------------
1820 procedure Recursive_Check (Project : Project_Id) is
1821 Data : Project_Data;
1822 Imported_Project_List : Project_List := Empty_Project_List;
1825 -- Do nothing if Project is No_Project, or Project has already
1826 -- been marked as checked.
1828 if Project /= No_Project
1829 and then not Projects.Table (Project).Checked
1831 -- Mark project as checked, to avoid infinite recursion in
1832 -- ill-formed trees, where a project imports itself.
1834 Projects.Table (Project).Checked := True;
1836 Data := Projects.Table (Project);
1838 -- Call itself for a possible extended project.
1839 -- (if there is no extended project, then nothing happens).
1841 Recursive_Check (Data.Extends);
1843 -- Call itself for all imported projects
1845 Imported_Project_List := Data.Imported_Projects;
1846 while Imported_Project_List /= Empty_Project_List loop
1848 (Project_Lists.Table (Imported_Project_List).Project);
1849 Imported_Project_List :=
1850 Project_Lists.Table (Imported_Project_List).Next;
1853 if Opt.Verbose_Mode then
1854 Write_Str ("Checking project file """);
1855 Write_Str (Get_Name_String (Data.Name));
1859 Prj.Nmsc.Ada_Check (Project, Error_Report);
1861 end Recursive_Check;
1863 -----------------------
1864 -- Recursive_Process --
1865 -----------------------
1867 procedure Recursive_Process
1868 (Project : out Project_Id;
1869 From_Project_Node : Project_Node_Id;
1870 Extended_By : Project_Id)
1872 With_Clause : Project_Node_Id;
1875 if From_Project_Node = Empty_Node then
1876 Project := No_Project;
1880 Processed_Data : Project_Data := Empty_Project;
1881 Imported : Project_List := Empty_Project_List;
1882 Declaration_Node : Project_Node_Id := Empty_Node;
1883 Name : constant Name_Id :=
1884 Name_Of (From_Project_Node);
1887 Project := Processed_Projects.Get (Name);
1889 if Project /= No_Project then
1893 Projects.Increment_Last;
1894 Project := Projects.Last;
1895 Processed_Projects.Set (Name, Project);
1897 Processed_Data.Name := Name;
1899 Get_Name_String (Name);
1901 -- If name starts with the virtual prefix, flag the project as
1902 -- being a virtual extending project.
1904 if Name_Len > Virtual_Prefix'Length
1905 and then Name_Buffer (1 .. Virtual_Prefix'Length) =
1908 Processed_Data.Virtual := True;
1911 Processed_Data.Display_Path_Name :=
1912 Path_Name_Of (From_Project_Node);
1913 Get_Name_String (Processed_Data.Display_Path_Name);
1914 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1915 Processed_Data.Path_Name := Name_Find;
1917 Processed_Data.Location := Location_Of (From_Project_Node);
1919 Processed_Data.Display_Directory :=
1920 Directory_Of (From_Project_Node);
1921 Get_Name_String (Processed_Data.Display_Directory);
1922 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1923 Processed_Data.Directory := Name_Find;
1925 Processed_Data.Extended_By := Extended_By;
1926 Processed_Data.Naming := Standard_Naming_Data;
1928 Add_Attributes (Project, Processed_Data.Decl, Attribute_First);
1929 With_Clause := First_With_Clause_Of (From_Project_Node);
1931 while With_Clause /= Empty_Node loop
1933 New_Project : Project_Id;
1934 New_Data : Project_Data;
1938 (Project => New_Project,
1939 From_Project_Node => Project_Node_Of (With_Clause),
1940 Extended_By => No_Project);
1941 New_Data := Projects.Table (New_Project);
1943 -- If we were the first project to import it,
1944 -- set First_Referred_By to us.
1946 if New_Data.First_Referred_By = No_Project then
1947 New_Data.First_Referred_By := Project;
1948 Projects.Table (New_Project) := New_Data;
1951 -- Add this project to our list of imported projects
1953 Project_Lists.Increment_Last;
1954 Project_Lists.Table (Project_Lists.Last) :=
1955 (Project => New_Project, Next => Empty_Project_List);
1957 -- Imported is the id of the last imported project.
1958 -- If it is nil, then this imported project is our first.
1960 if Imported = Empty_Project_List then
1961 Processed_Data.Imported_Projects := Project_Lists.Last;
1964 Project_Lists.Table (Imported).Next := Project_Lists.Last;
1967 Imported := Project_Lists.Last;
1969 With_Clause := Next_With_Clause_Of (With_Clause);
1973 Declaration_Node := Project_Declaration_Of (From_Project_Node);
1976 (Project => Processed_Data.Extends,
1977 From_Project_Node => Extended_Project_Of (Declaration_Node),
1978 Extended_By => Project);
1980 Projects.Table (Project) := Processed_Data;
1982 Process_Declarative_Items
1983 (Project => Project,
1984 From_Project_Node => From_Project_Node,
1986 Item => First_Declarative_Item_Of
1987 (Declaration_Node));
1989 -- If it is an extending project, inherit all packages
1990 -- from the extended project that are not explicitely defined
1993 if Processed_Data.Extends /= No_Project then
1994 Processed_Data := Projects.Table (Project);
1997 Extended_Pkg : Package_Id :=
1999 (Processed_Data.Extends).Decl.Packages;
2000 Current_Pkg : Package_Id;
2001 Element : Package_Element;
2002 First : constant Package_Id :=
2003 Processed_Data.Decl.Packages;
2006 while Extended_Pkg /= No_Package loop
2007 Element := Packages.Table (Extended_Pkg);
2009 Current_Pkg := First;
2012 exit when Current_Pkg = No_Package
2013 or else Packages.Table (Current_Pkg).Name
2015 Current_Pkg := Packages.Table (Current_Pkg).Next;
2018 if Current_Pkg = No_Package then
2019 Packages.Increment_Last;
2020 Current_Pkg := Packages.Last;
2021 Packages.Table (Current_Pkg) :=
2022 (Name => Element.Name,
2023 Decl => Element.Decl,
2024 Parent => No_Package,
2025 Next => Processed_Data.Decl.Packages);
2026 Processed_Data.Decl.Packages := Current_Pkg;
2029 Extended_Pkg := Element.Next;
2033 Projects.Table (Project) := Processed_Data;
2037 end Recursive_Process;