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 (Decl : in out Declarations;
60 First : Attribute_Node_Id);
61 -- Add all attributes, starting with First, with their default
62 -- values to the package or project with declarations Decl.
65 (Project : Project_Id;
66 From_Project_Node : Project_Node_Id;
68 First_Term : Project_Node_Id;
70 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;
78 -- Find an imported or extended project of Project whose name is With_Name
81 (Project : Project_Id;
84 -- Find the package of Project whose name is With_Name
86 procedure Process_Declarative_Items
87 (Project : Project_Id;
88 From_Project_Node : Project_Node_Id;
90 Item : Project_Node_Id);
91 -- Process declarative items starting with From_Project_Node, and put them
92 -- in declarations Decl. This is a recursive procedure; it calls itself for
93 -- a package declaration or a case construction.
95 procedure Recursive_Process
96 (Project : out Project_Id;
97 From_Project_Node : Project_Node_Id;
98 Extended_By : Project_Id);
99 -- Process project with node From_Project_Node in the tree.
100 -- Do nothing if From_Project_Node is Empty_Node.
101 -- If project has already been processed, simply return its project id.
102 -- Otherwise create a new project id, mark it as processed, call itself
103 -- recursively for all imported projects and a extended project, if any.
104 -- Then process the declarative items of the project.
106 procedure Check (Project : in out Project_Id);
107 -- Set all projects to not checked, then call Recursive_Check for the
108 -- main project Project. Project is set to No_Project if errors occurred.
110 procedure Recursive_Check (Project : Project_Id);
111 -- If Project is not marked as checked, mark it as checked, call
112 -- Check_Naming_Scheme for the project, then call itself for a
113 -- possible extended project and all the imported projects of Project.
119 procedure Add (To_Exp : in out Name_Id; Str : Name_Id) is
121 if To_Exp = Types.No_Name or else To_Exp = Empty_String then
123 -- To_Exp is nil or empty. The result is Str.
127 -- If Str is nil, then do not change To_Ext
129 elsif Str /= No_Name and then Str /= Empty_String then
131 S : constant String := Get_Name_String (Str);
134 Get_Name_String (To_Exp);
135 Add_Str_To_Name_Buffer (S);
145 procedure Add_Attributes
146 (Decl : in out Declarations;
147 First : Attribute_Node_Id)
149 The_Attribute : Attribute_Node_Id := First;
150 Attribute_Data : Attribute_Record;
153 while The_Attribute /= Empty_Attribute loop
154 Attribute_Data := Attributes.Table (The_Attribute);
156 if Attribute_Data.Kind_2 = Single then
158 New_Attribute : Variable_Value;
161 case Attribute_Data.Kind_1 is
163 -- Undefined should not happen
167 (False, "attribute with an undefined kind");
170 -- 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
184 Location => No_Location,
186 Values => Nil_String);
190 Variable_Elements.Increment_Last;
191 Variable_Elements.Table (Variable_Elements.Last) :=
192 (Next => Decl.Attributes,
193 Name => Attribute_Data.Name,
194 Value => New_Attribute);
195 Decl.Attributes := Variable_Elements.Last;
199 The_Attribute := Attributes.Table (The_Attribute).Next;
207 procedure Check (Project : in out Project_Id) is
209 -- Make sure that all projects are marked as not checked
211 for Index in 1 .. Projects.Last loop
212 Projects.Table (Index).Checked := False;
215 Recursive_Check (Project);
224 (Project : Project_Id;
225 From_Project_Node : Project_Node_Id;
227 First_Term : Project_Node_Id;
228 Kind : Variable_Kind)
229 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.Location := Location_Of (First_Term);
246 -- Process each term of the expression, starting with First_Term
248 while The_Term /= Empty_Node loop
249 The_Current_Term := Current_Term (The_Term);
251 case Kind_Of (The_Current_Term) is
253 when N_Literal_String =>
259 -- Should never happen
261 pragma Assert (False, "Undefined expression kind");
265 Add (Result.Value, String_Value_Of (The_Current_Term));
269 String_Elements.Increment_Last;
271 if Last = Nil_String then
273 -- This can happen in an expression such as
276 Result.Values := String_Elements.Last;
279 String_Elements.Table (Last).Next :=
280 String_Elements.Last;
283 Last := String_Elements.Last;
284 String_Elements.Table (Last) :=
285 (Value => String_Value_Of (The_Current_Term),
286 Display_Value => No_Name,
287 Location => Location_Of (The_Current_Term),
293 when N_Literal_String_List =>
296 String_Node : Project_Node_Id :=
297 First_Expression_In_List (The_Current_Term);
299 Value : Variable_Value;
302 if String_Node /= Empty_Node then
304 -- If String_Node is nil, it is an empty list,
305 -- there is nothing to do
309 From_Project_Node => From_Project_Node,
311 First_Term => Tree.First_Term (String_Node),
313 String_Elements.Increment_Last;
315 if Result.Values = Nil_String then
317 -- This literal string list is the first term
318 -- in a string list expression
320 Result.Values := String_Elements.Last;
323 String_Elements.Table (Last).Next :=
324 String_Elements.Last;
327 Last := String_Elements.Last;
328 String_Elements.Table (Last) :=
329 (Value => Value.Value,
330 Display_Value => No_Name,
331 Location => Value.Location,
336 -- Add the other element of the literal string list
337 -- one after the other
340 Next_Expression_In_List (String_Node);
342 exit when String_Node = Empty_Node;
347 From_Project_Node => From_Project_Node,
349 First_Term => Tree.First_Term (String_Node),
352 String_Elements.Increment_Last;
353 String_Elements.Table (Last).Next :=
354 String_Elements.Last;
355 Last := String_Elements.Last;
356 String_Elements.Table (Last) :=
357 (Value => Value.Value,
358 Display_Value => No_Name,
359 Location => Value.Location,
368 when N_Variable_Reference | N_Attribute_Reference =>
371 The_Project : Project_Id := Project;
372 The_Package : Package_Id := Pkg;
373 The_Name : Name_Id := No_Name;
374 The_Variable_Id : Variable_Id := No_Variable;
375 The_Variable : Variable_Value;
376 Term_Project : constant Project_Node_Id :=
377 Project_Node_Of (The_Current_Term);
378 Term_Package : constant Project_Node_Id :=
379 Package_Node_Of (The_Current_Term);
380 Index : Name_Id := No_Name;
383 if Term_Project /= Empty_Node and then
384 Term_Project /= From_Project_Node
386 -- This variable or attribute comes from another project
388 The_Name := Name_Of (Term_Project);
389 The_Project := Imported_Or_Extended_Project_From
391 With_Name => The_Name);
394 if Term_Package /= Empty_Node then
396 -- This is an attribute of a package
398 The_Name := Name_Of (Term_Package);
399 The_Package := Projects.Table (The_Project).Decl.Packages;
401 while The_Package /= No_Package
402 and then Packages.Table (The_Package).Name /= The_Name
404 The_Package := Packages.Table (The_Package).Next;
408 (The_Package /= No_Package,
409 "package not found.");
411 elsif Kind_Of (The_Current_Term) = N_Attribute_Reference then
412 The_Package := No_Package;
415 The_Name := Name_Of (The_Current_Term);
417 if Kind_Of (The_Current_Term) = N_Attribute_Reference then
418 Index := Associative_Array_Index_Of (The_Current_Term);
421 -- If it is not an associative array attribute
423 if Index = No_Name then
425 -- It is not an associative array attribute
427 if The_Package /= No_Package then
429 -- First, if there is a package, look into the package
432 Kind_Of (The_Current_Term) = N_Variable_Reference
435 Packages.Table (The_Package).Decl.Variables;
439 Packages.Table (The_Package).Decl.Attributes;
442 while The_Variable_Id /= No_Variable
444 Variable_Elements.Table (The_Variable_Id).Name /=
448 Variable_Elements.Table (The_Variable_Id).Next;
453 if The_Variable_Id = No_Variable then
455 -- If we have not found it, look into the project
458 Kind_Of (The_Current_Term) = N_Variable_Reference
461 Projects.Table (The_Project).Decl.Variables;
465 Projects.Table (The_Project).Decl.Attributes;
468 while The_Variable_Id /= No_Variable
470 Variable_Elements.Table (The_Variable_Id).Name /=
474 Variable_Elements.Table (The_Variable_Id).Next;
479 pragma Assert (The_Variable_Id /= No_Variable,
480 "variable or attribute not found");
482 The_Variable := Variable_Elements.Table
483 (The_Variable_Id).Value;
487 -- It is an associative array attribute
490 The_Array : Array_Id := No_Array;
491 The_Element : Array_Element_Id := No_Array_Element;
492 Array_Index : Name_Id := No_Name;
494 if The_Package /= No_Package then
496 Packages.Table (The_Package).Decl.Arrays;
500 Projects.Table (The_Project).Decl.Arrays;
503 while The_Array /= No_Array
504 and then Arrays.Table (The_Array).Name /= The_Name
506 The_Array := Arrays.Table (The_Array).Next;
509 if The_Array /= No_Array then
510 The_Element := Arrays.Table (The_Array).Value;
512 Get_Name_String (Index);
514 if Case_Insensitive (The_Current_Term) then
515 To_Lower (Name_Buffer (1 .. Name_Len));
518 Array_Index := Name_Find;
520 while The_Element /= No_Array_Element
521 and then Array_Elements.Table (The_Element).Index
525 Array_Elements.Table (The_Element).Next;
530 if The_Element /= No_Array_Element then
532 Array_Elements.Table (The_Element).Value;
536 Expression_Kind_Of (The_Current_Term) = List
540 Location => No_Location,
542 Values => Nil_String);
547 Location => No_Location,
549 Value => Empty_String);
559 -- Should never happen
561 pragma Assert (False, "undefined expression kind");
566 case The_Variable.Kind is
572 Add (Result.Value, The_Variable.Value);
576 -- Should never happen
580 "list cannot appear in single " &
581 "string expression");
586 case The_Variable.Kind is
592 String_Elements.Increment_Last;
594 if Last = Nil_String then
596 -- This can happen in an expression such as
599 Result.Values := String_Elements.Last;
602 String_Elements.Table (Last).Next :=
603 String_Elements.Last;
606 Last := String_Elements.Last;
607 String_Elements.Table (Last) :=
608 (Value => The_Variable.Value,
609 Display_Value => No_Name,
610 Location => Location_Of (The_Current_Term),
617 The_List : String_List_Id :=
621 while The_List /= Nil_String loop
622 String_Elements.Increment_Last;
624 if Last = Nil_String then
625 Result.Values := String_Elements.Last;
628 String_Elements.Table (Last).Next :=
629 String_Elements.Last;
633 Last := String_Elements.Last;
634 String_Elements.Table (Last) :=
636 String_Elements.Table
638 Display_Value => No_Name,
639 Location => Location_Of
644 String_Elements.Table (The_List).Next;
651 when N_External_Value =>
653 (String_Value_Of (External_Reference_Of (The_Current_Term)));
656 Name : constant Name_Id := Name_Find;
657 Default : Name_Id := No_Name;
658 Value : Name_Id := No_Name;
660 Default_Node : constant Project_Node_Id :=
661 External_Default_Of (The_Current_Term);
664 if Default_Node /= Empty_Node then
665 Default := String_Value_Of (Default_Node);
668 Value := Prj.Ext.Value_Of (Name, Default);
670 if Value = No_Name then
671 if not Opt.Quiet_Output then
672 if Error_Report = null then
674 ("?undefined external reference",
675 Location_Of (The_Current_Term));
679 ("warning: """ & Get_Name_String (Name) &
680 """ is an undefined external reference",
685 Value := Empty_String;
695 Add (Result.Value, Value);
698 String_Elements.Increment_Last;
700 if Last = Nil_String then
701 Result.Values := String_Elements.Last;
704 String_Elements.Table (Last).Next :=
705 String_Elements.Last;
708 Last := String_Elements.Last;
709 String_Elements.Table (Last) :=
711 Display_Value => No_Name,
712 Location => Location_Of (The_Current_Term),
721 -- Should never happen
725 "illegal node kind in an expression");
730 The_Term := Next_Term (The_Term);
736 ---------------------------------------
737 -- Imported_Or_Extended_Project_From --
738 ---------------------------------------
740 function Imported_Or_Extended_Project_From
741 (Project : Project_Id;
745 Data : constant Project_Data := Projects.Table (Project);
746 List : Project_List := Data.Imported_Projects;
749 -- First check if it is the name of a extended project
751 if Data.Extends /= No_Project
752 and then Projects.Table (Data.Extends).Name = With_Name
757 -- Then check the name of each imported project
759 while List /= Empty_Project_List
762 (Project_Lists.Table (List).Project).Name /= With_Name
765 List := Project_Lists.Table (List).Next;
769 (List /= Empty_Project_List,
770 "project not found");
772 return Project_Lists.Table (List).Project;
774 end Imported_Or_Extended_Project_From;
780 function Package_From
781 (Project : Project_Id;
785 Data : constant Project_Data := Projects.Table (Project);
786 Result : Package_Id := Data.Decl.Packages;
789 -- Check the name of each existing package of Project
791 while Result /= No_Package
793 Packages.Table (Result).Name /= With_Name
795 Result := Packages.Table (Result).Next;
798 if Result = No_Package then
799 -- Should never happen
800 Write_Line ("package """ & Get_Name_String (With_Name) &
814 (Project : out Project_Id;
815 Success : out Boolean;
816 From_Project_Node : Project_Node_Id;
817 Report_Error : Put_Line_Access)
820 Extending : Project_Id;
823 Error_Report := Report_Error;
826 -- Make sure there is no projects in the data structure
828 Projects.Set_Last (No_Project);
829 Processed_Projects.Reset;
831 -- And process the main project and all of the projects it depends on,
836 From_Project_Node => From_Project_Node,
837 Extended_By => No_Project);
839 if Project /= No_Project then
843 -- Check that no extended project shares its object directory with
846 if Project /= No_Project then
847 for Extended in 1 .. Projects.Last loop
848 Extending := Projects.Table (Extended).Extended_By;
850 if Extending /= No_Project then
851 Obj_Dir := Projects.Table (Extended).Object_Directory;
853 for Prj in 1 .. Projects.Last loop
855 and then Projects.Table (Prj).Sources_Present
856 and then Projects.Table (Prj).Object_Directory = Obj_Dir
858 Error_Msg_Name_1 := Projects.Table (Extending).Name;
859 Error_Msg_Name_2 := Projects.Table (Extended).Name;
861 if Error_Report = null then
862 Error_Msg ("project % cannot extend project %",
863 Projects.Table (Extending).Location);
868 Get_Name_String (Error_Msg_Name_1) &
869 """ cannot extend project """ &
870 Get_Name_String (Error_Msg_Name_2) & '"',
874 Error_Msg_Name_1 := Projects.Table (Extended).Name;
875 Error_Msg_Name_2 := Projects.Table (Prj).Name;
877 if Error_Report = null then
879 ("\project % has the same object directory " &
881 Projects.Table (Extending).Location);
886 Get_Name_String (Error_Msg_Name_1) &
887 """ has the same object directory as project """ &
888 Get_Name_String (Error_Msg_Name_2) & '"',
892 Project := No_Project;
900 Success := Total_Errors_Detected <= 0;
903 -------------------------------
904 -- Process_Declarative_Items --
905 -------------------------------
907 procedure Process_Declarative_Items
908 (Project : Project_Id;
909 From_Project_Node : Project_Node_Id;
911 Item : Project_Node_Id)
913 Current_Declarative_Item : Project_Node_Id := Item;
914 Current_Item : Project_Node_Id := Empty_Node;
917 -- For each declarative item
919 while Current_Declarative_Item /= Empty_Node loop
923 Current_Item := Current_Item_Node (Current_Declarative_Item);
925 -- And set Current_Declarative_Item to the next declarative item
926 -- ready for the next iteration.
928 Current_Declarative_Item := Next_Declarative_Item
929 (Current_Declarative_Item);
931 case Kind_Of (Current_Item) is
933 when N_Package_Declaration =>
934 -- Do not process a package declaration that should be ignored
936 if Expression_Kind_Of (Current_Item) /= Ignored then
937 -- Create the new package
939 Packages.Increment_Last;
942 New_Pkg : constant Package_Id := Packages.Last;
943 The_New_Package : Package_Element;
945 Project_Of_Renamed_Package : constant Project_Node_Id :=
946 Project_Of_Renamed_Package_Of
950 -- Set the name of the new package
952 The_New_Package.Name := Name_Of (Current_Item);
954 -- Insert the new package in the appropriate list
956 if Pkg /= No_Package then
957 The_New_Package.Next :=
958 Packages.Table (Pkg).Decl.Packages;
959 Packages.Table (Pkg).Decl.Packages := New_Pkg;
961 The_New_Package.Next :=
962 Projects.Table (Project).Decl.Packages;
963 Projects.Table (Project).Decl.Packages := New_Pkg;
966 Packages.Table (New_Pkg) := The_New_Package;
968 if Project_Of_Renamed_Package /= Empty_Node then
973 Project_Name : constant Name_Id :=
975 (Project_Of_Renamed_Package);
977 Renamed_Project : constant Project_Id :=
978 Imported_Or_Extended_Project_From
979 (Project, Project_Name);
981 Renamed_Package : constant Package_Id :=
984 Name_Of (Current_Item));
987 -- For a renamed package, set declarations to
988 -- the declarations of the renamed package.
990 Packages.Table (New_Pkg).Decl :=
991 Packages.Table (Renamed_Package).Decl;
994 -- Standard package declaration, not renaming
997 -- Set the default values of the attributes
1000 (Packages.Table (New_Pkg).Decl,
1001 Package_Attributes.Table
1002 (Package_Id_Of (Current_Item)).First_Attribute);
1004 -- And process declarative items of the new package
1006 Process_Declarative_Items
1007 (Project => Project,
1008 From_Project_Node => From_Project_Node,
1010 Item => First_Declarative_Item_Of
1016 when N_String_Type_Declaration =>
1018 -- There is nothing to process
1022 when N_Attribute_Declaration |
1023 N_Typed_Variable_Declaration |
1024 N_Variable_Declaration =>
1026 if Expression_Of (Current_Item) = Empty_Node then
1028 -- It must be a full associative array attribute declaration
1031 Current_Item_Name : constant Name_Id :=
1032 Name_Of (Current_Item);
1033 -- The name of the attribute
1035 New_Array : Array_Id;
1036 -- The new associative array created
1038 Orig_Array : Array_Id;
1039 -- The associative array value
1041 Orig_Project_Name : Name_Id := No_Name;
1042 -- The name of the project where the associative array
1045 Orig_Project : Project_Id := No_Project;
1046 -- The id of the project where the associative array
1049 Orig_Package_Name : Name_Id := No_Name;
1050 -- The name of the package, if any, where the associative
1053 Orig_Package : Package_Id := No_Package;
1054 -- The id of the package, if any, where the associative
1057 New_Element : Array_Element_Id := No_Array_Element;
1058 -- Id of a new array element created
1060 Prev_Element : Array_Element_Id := No_Array_Element;
1061 -- Last new element id created
1063 Orig_Element : Array_Element_Id := No_Array_Element;
1064 -- Current array element in the original associative
1067 Next_Element : Array_Element_Id := No_Array_Element;
1068 -- Id of the array element that follows the new element.
1069 -- This is not always nil, because values for the
1070 -- associative array attribute may already have been
1071 -- declared, and the array elements declared are reused.
1074 -- First, find if the associative array attribute already
1075 -- has elements declared.
1077 if Pkg /= No_Package then
1078 New_Array := Packages.Table (Pkg).Decl.Arrays;
1081 New_Array := Projects.Table (Project).Decl.Arrays;
1084 while New_Array /= No_Array and then
1085 Arrays.Table (New_Array).Name /= Current_Item_Name
1087 New_Array := Arrays.Table (New_Array).Next;
1090 -- If the attribute has never been declared add new entry
1091 -- in the arrays of the project/package and link it.
1093 if New_Array = No_Array then
1094 Arrays.Increment_Last;
1095 New_Array := Arrays.Last;
1097 if Pkg /= No_Package then
1098 Arrays.Table (New_Array) :=
1099 (Name => Current_Item_Name,
1100 Value => No_Array_Element,
1101 Next => Packages.Table (Pkg).Decl.Arrays);
1102 Packages.Table (Pkg).Decl.Arrays := New_Array;
1105 Arrays.Table (New_Array) :=
1106 (Name => Current_Item_Name,
1107 Value => No_Array_Element,
1108 Next => Projects.Table (Project).Decl.Arrays);
1109 Projects.Table (Project).Decl.Arrays := New_Array;
1113 -- Find the project where the value is declared
1115 Orig_Project_Name :=
1116 Name_Of (Associative_Project_Of (Current_Item));
1118 for Index in Projects.First .. Projects.Last loop
1119 if Projects.Table (Index).Name = Orig_Project_Name then
1120 Orig_Project := Index;
1125 pragma Assert (Orig_Project /= No_Project,
1126 "original project not found");
1128 if Associative_Package_Of (Current_Item) = Empty_Node then
1130 Projects.Table (Orig_Project).Decl.Arrays;
1133 -- If in a package, find the package where the
1134 -- value is declared.
1136 Orig_Package_Name :=
1137 Name_Of (Associative_Package_Of (Current_Item));
1139 Projects.Table (Orig_Project).Decl.Packages;
1140 pragma Assert (Orig_Package /= No_Package,
1141 "original package not found");
1143 while Packages.Table (Orig_Package).Name /=
1146 Orig_Package := Packages.Table (Orig_Package).Next;
1147 pragma Assert (Orig_Package /= No_Package,
1148 "original package not found");
1152 Packages.Table (Orig_Package).Decl.Arrays;
1155 -- Now look for the array
1157 while Orig_Array /= No_Array and then
1158 Arrays.Table (Orig_Array).Name /= Current_Item_Name
1160 Orig_Array := Arrays.Table (Orig_Array).Next;
1163 if Orig_Array = No_Array then
1164 if Error_Report = null then
1166 ("associative array value cannot be found",
1167 Location_Of (Current_Item));
1171 ("associative array value cannot be found",
1176 Orig_Element := Arrays.Table (Orig_Array).Value;
1178 -- Copy each array element
1180 while Orig_Element /= No_Array_Element loop
1181 -- If it is the first element ...
1183 if Prev_Element = No_Array_Element then
1184 -- And there is no array element declared yet,
1185 -- create a new first array element.
1187 if Arrays.Table (New_Array).Value =
1190 Array_Elements.Increment_Last;
1191 New_Element := Array_Elements.Last;
1192 Arrays.Table (New_Array).Value := New_Element;
1193 Next_Element := No_Array_Element;
1195 -- Otherwise, the new element is the first
1198 New_Element := Arrays.Table (New_Array).Value;
1200 Array_Elements.Table (New_Element).Next;
1203 -- Otherwise, reuse an existing element, or create
1204 -- one if necessary.
1208 Array_Elements.Table (Prev_Element).Next;
1210 if Next_Element = No_Array_Element then
1211 Array_Elements.Increment_Last;
1212 New_Element := Array_Elements.Last;
1215 New_Element := Next_Element;
1217 Array_Elements.Table (New_Element).Next;
1221 -- Copy the value of the element
1223 Array_Elements.Table (New_Element) :=
1224 Array_Elements.Table (Orig_Element);
1226 -- Adjust the Next link
1228 Array_Elements.Table (New_Element).Next :=
1231 -- Adjust the previous id for the next element
1233 Prev_Element := New_Element;
1235 -- Go to the next element in the original array
1237 Array_Elements.Table (Orig_Element).Next;
1240 -- Make sure that the array ends here, in case there
1241 -- previously a greater number of elements.
1243 Array_Elements.Table (New_Element).Next :=
1248 -- Declarations other that full associative arrays
1252 New_Value : constant Variable_Value :=
1254 (Project => Project,
1255 From_Project_Node => From_Project_Node,
1258 Tree.First_Term (Expression_Of
1261 Expression_Kind_Of (Current_Item));
1262 -- The expression value
1264 The_Variable : Variable_Id := No_Variable;
1266 Current_Item_Name : constant Name_Id :=
1267 Name_Of (Current_Item);
1270 -- Process a typed variable declaration
1273 Kind_Of (Current_Item) = N_Typed_Variable_Declaration
1275 -- Report an error for an empty string
1277 if New_Value.Value = Empty_String then
1278 Error_Msg_Name_1 := Name_Of (Current_Item);
1280 if Error_Report = null then
1282 ("no value defined for %",
1283 Location_Of (Current_Item));
1287 ("no value defined for " &
1288 Get_Name_String (Error_Msg_Name_1),
1294 Current_String : Project_Node_Id :=
1295 First_Literal_String
1300 -- Loop through all the valid strings for
1301 -- the string type and compare to the string
1304 while Current_String /= Empty_Node
1305 and then String_Value_Of (Current_String) /=
1309 Next_Literal_String (Current_String);
1312 -- Report an error if the string value is not
1313 -- one for the string type.
1315 if Current_String = Empty_Node then
1316 Error_Msg_Name_1 := New_Value.Value;
1317 Error_Msg_Name_2 := Name_Of (Current_Item);
1319 if Error_Report = null then
1321 ("value { is illegal for typed string %",
1322 Location_Of (Current_Item));
1327 Get_Name_String (Error_Msg_Name_1) &
1328 """ is illegal for typed string """ &
1329 Get_Name_String (Error_Msg_Name_2) &
1338 if Kind_Of (Current_Item) /= N_Attribute_Declaration
1340 Associative_Array_Index_Of (Current_Item) = No_Name
1342 -- Case of a variable declaration or of a not
1343 -- associative array attribute.
1345 -- First, find the list where to find the variable
1349 Kind_Of (Current_Item) = N_Attribute_Declaration
1351 if Pkg /= No_Package then
1353 Packages.Table (Pkg).Decl.Attributes;
1357 Projects.Table (Project).Decl.Attributes;
1361 if Pkg /= No_Package then
1363 Packages.Table (Pkg).Decl.Variables;
1367 Projects.Table (Project).Decl.Variables;
1372 -- Loop through the list, to find if it has already
1376 The_Variable /= No_Variable
1378 Variable_Elements.Table (The_Variable).Name /=
1382 Variable_Elements.Table (The_Variable).Next;
1385 -- If it has not been declared, create a new entry
1388 if The_Variable = No_Variable then
1389 -- All single string attribute should already have
1390 -- been declared with a default empty string value.
1393 (Kind_Of (Current_Item) /=
1394 N_Attribute_Declaration,
1395 "illegal attribute declaration");
1397 Variable_Elements.Increment_Last;
1398 The_Variable := Variable_Elements.Last;
1400 -- Put the new variable in the appropriate list
1402 if Pkg /= No_Package then
1403 Variable_Elements.Table (The_Variable) :=
1405 Packages.Table (Pkg).Decl.Variables,
1406 Name => Current_Item_Name,
1407 Value => New_Value);
1408 Packages.Table (Pkg).Decl.Variables :=
1412 Variable_Elements.Table (The_Variable) :=
1414 Projects.Table (Project).Decl.Variables,
1415 Name => Current_Item_Name,
1416 Value => New_Value);
1417 Projects.Table (Project).Decl.Variables :=
1421 -- If the variable/attribute has already been
1422 -- declared, just change the value.
1425 Variable_Elements.Table (The_Variable).Value :=
1431 -- Associative array attribute
1433 -- Get the string index
1436 (Associative_Array_Index_Of (Current_Item));
1438 -- Put in lower case, if necessary
1440 if Case_Insensitive (Current_Item) then
1441 GNAT.Case_Util.To_Lower
1442 (Name_Buffer (1 .. Name_Len));
1446 The_Array : Array_Id;
1448 The_Array_Element : Array_Element_Id :=
1451 Index_Name : constant Name_Id := Name_Find;
1452 -- The name id of the index
1455 -- Look for the array in the appropriate list
1457 if Pkg /= No_Package then
1458 The_Array := Packages.Table (Pkg).Decl.Arrays;
1461 The_Array := Projects.Table
1462 (Project).Decl.Arrays;
1466 The_Array /= No_Array
1467 and then Arrays.Table (The_Array).Name /=
1470 The_Array := Arrays.Table (The_Array).Next;
1473 -- If the array cannot be found, create a new
1474 -- entry in the list. As The_Array_Element is
1475 -- initialized to No_Array_Element, a new element
1476 -- will be created automatically later.
1478 if The_Array = No_Array then
1479 Arrays.Increment_Last;
1480 The_Array := Arrays.Last;
1482 if Pkg /= No_Package then
1483 Arrays.Table (The_Array) :=
1484 (Name => Current_Item_Name,
1485 Value => No_Array_Element,
1486 Next => Packages.Table (Pkg).Decl.Arrays);
1487 Packages.Table (Pkg).Decl.Arrays := The_Array;
1490 Arrays.Table (The_Array) :=
1491 (Name => Current_Item_Name,
1492 Value => No_Array_Element,
1494 Projects.Table (Project).Decl.Arrays);
1495 Projects.Table (Project).Decl.Arrays :=
1499 -- Otherwise, initialize The_Array_Element as the
1500 -- head of the element list.
1503 The_Array_Element :=
1504 Arrays.Table (The_Array).Value;
1507 -- Look in the list, if any, to find an element
1508 -- with the same index.
1510 while The_Array_Element /= No_Array_Element
1512 Array_Elements.Table (The_Array_Element).Index /=
1515 The_Array_Element :=
1516 Array_Elements.Table (The_Array_Element).Next;
1519 -- If no such element were found, create a new
1520 -- one and insert it in the element list, with
1521 -- the propoer value.
1523 if The_Array_Element = No_Array_Element then
1524 Array_Elements.Increment_Last;
1525 The_Array_Element := Array_Elements.Last;
1527 Array_Elements.Table (The_Array_Element) :=
1528 (Index => Index_Name,
1529 Index_Case_Sensitive =>
1530 not Case_Insensitive (Current_Item),
1532 Next => Arrays.Table (The_Array).Value);
1533 Arrays.Table (The_Array).Value :=
1536 -- An element with the same index already exists,
1537 -- just replace its value with the new one.
1540 Array_Elements.Table (The_Array_Element).Value :=
1548 when N_Case_Construction =>
1550 The_Project : Project_Id := Project;
1551 -- The id of the project of the case variable
1553 The_Package : Package_Id := Pkg;
1554 -- The id of the package, if any, of the case variable
1556 The_Variable : Variable_Value := Nil_Variable_Value;
1557 -- The case variable
1559 Case_Value : Name_Id := No_Name;
1560 -- The case variable value
1562 Case_Item : Project_Node_Id := Empty_Node;
1563 Choice_String : Project_Node_Id := Empty_Node;
1564 Decl_Item : Project_Node_Id := Empty_Node;
1568 Variable_Node : constant Project_Node_Id :=
1569 Case_Variable_Reference_Of
1572 Var_Id : Variable_Id := No_Variable;
1573 Name : Name_Id := No_Name;
1576 -- If a project were specified for the case variable,
1579 if Project_Node_Of (Variable_Node) /= Empty_Node then
1580 Name := Name_Of (Project_Node_Of (Variable_Node));
1582 Imported_Or_Extended_Project_From (Project, Name);
1585 -- If a package were specified for the case variable,
1588 if Package_Node_Of (Variable_Node) /= Empty_Node then
1589 Name := Name_Of (Package_Node_Of (Variable_Node));
1590 The_Package := Package_From (The_Project, Name);
1593 Name := Name_Of (Variable_Node);
1595 -- First, look for the case variable into the package,
1598 if The_Package /= No_Package then
1599 Var_Id := Packages.Table (The_Package).Decl.Variables;
1600 Name := Name_Of (Variable_Node);
1601 while Var_Id /= No_Variable
1603 Variable_Elements.Table (Var_Id).Name /= Name
1605 Var_Id := Variable_Elements.Table (Var_Id).Next;
1609 -- If not found in the package, or if there is no
1610 -- package, look at the project level.
1612 if Var_Id = No_Variable
1613 and then Package_Node_Of (Variable_Node) = Empty_Node
1615 Var_Id := Projects.Table (The_Project).Decl.Variables;
1616 while Var_Id /= No_Variable
1618 Variable_Elements.Table (Var_Id).Name /= Name
1620 Var_Id := Variable_Elements.Table (Var_Id).Next;
1624 if Var_Id = No_Variable then
1626 -- Should never happen, because this has already been
1627 -- checked during parsing.
1629 Write_Line ("variable """ &
1630 Get_Name_String (Name) &
1632 raise Program_Error;
1635 -- Get the case variable
1637 The_Variable := Variable_Elements.Table (Var_Id).Value;
1639 if The_Variable.Kind /= Single then
1641 -- Should never happen, because this has already been
1642 -- checked during parsing.
1644 Write_Line ("variable""" &
1645 Get_Name_String (Name) &
1646 """ is not a single string variable");
1647 raise Program_Error;
1650 -- Get the case variable value
1651 Case_Value := The_Variable.Value;
1654 -- Now look into all the case items of the case construction
1656 Case_Item := First_Case_Item_Of (Current_Item);
1658 while Case_Item /= Empty_Node loop
1659 Choice_String := First_Choice_Of (Case_Item);
1661 -- When Choice_String is nil, it means that it is
1662 -- the "when others =>" alternative.
1664 if Choice_String = Empty_Node then
1665 Decl_Item := First_Declarative_Item_Of (Case_Item);
1666 exit Case_Item_Loop;
1669 -- Look into all the alternative of this case item
1672 while Choice_String /= Empty_Node loop
1674 Case_Value = String_Value_Of (Choice_String)
1677 First_Declarative_Item_Of (Case_Item);
1678 exit Case_Item_Loop;
1682 Next_Literal_String (Choice_String);
1683 end loop Choice_Loop;
1684 Case_Item := Next_Case_Item (Case_Item);
1685 end loop Case_Item_Loop;
1687 -- If there is an alternative, then we process it
1689 if Decl_Item /= Empty_Node then
1690 Process_Declarative_Items
1691 (Project => Project,
1692 From_Project_Node => From_Project_Node,
1700 -- Should never happen
1702 Write_Line ("Illegal declarative item: " &
1703 Project_Node_Kind'Image (Kind_Of (Current_Item)));
1704 raise Program_Error;
1707 end Process_Declarative_Items;
1709 ---------------------
1710 -- Recursive_Check --
1711 ---------------------
1713 procedure Recursive_Check (Project : Project_Id) is
1714 Data : Project_Data;
1715 Imported_Project_List : Project_List := Empty_Project_List;
1718 -- Do nothing if Project is No_Project, or Project has already
1719 -- been marked as checked.
1721 if Project /= No_Project
1722 and then not Projects.Table (Project).Checked
1724 -- Mark project as checked, to avoid infinite recursion in
1725 -- ill-formed trees, where a project imports itself.
1727 Projects.Table (Project).Checked := True;
1729 Data := Projects.Table (Project);
1731 -- Call itself for a possible extended project.
1732 -- (if there is no extended project, then nothing happens).
1734 Recursive_Check (Data.Extends);
1736 -- Call itself for all imported projects
1738 Imported_Project_List := Data.Imported_Projects;
1739 while Imported_Project_List /= Empty_Project_List loop
1741 (Project_Lists.Table (Imported_Project_List).Project);
1742 Imported_Project_List :=
1743 Project_Lists.Table (Imported_Project_List).Next;
1746 if Opt.Verbose_Mode then
1747 Write_Str ("Checking project file """);
1748 Write_Str (Get_Name_String (Data.Name));
1752 Prj.Nmsc.Ada_Check (Project, Error_Report);
1754 end Recursive_Check;
1756 -----------------------
1757 -- Recursive_Process --
1758 -----------------------
1760 procedure Recursive_Process
1761 (Project : out Project_Id;
1762 From_Project_Node : Project_Node_Id;
1763 Extended_By : Project_Id)
1765 With_Clause : Project_Node_Id;
1768 if From_Project_Node = Empty_Node then
1769 Project := No_Project;
1773 Processed_Data : Project_Data := Empty_Project;
1774 Imported : Project_List := Empty_Project_List;
1775 Declaration_Node : Project_Node_Id := Empty_Node;
1776 Name : constant Name_Id :=
1777 Name_Of (From_Project_Node);
1780 Project := Processed_Projects.Get (Name);
1782 if Project /= No_Project then
1786 Projects.Increment_Last;
1787 Project := Projects.Last;
1788 Processed_Projects.Set (Name, Project);
1790 Processed_Data.Name := Name;
1792 Processed_Data.Display_Path_Name :=
1793 Path_Name_Of (From_Project_Node);
1794 Get_Name_String (Processed_Data.Display_Path_Name);
1795 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1796 Processed_Data.Path_Name := Name_Find;
1798 Processed_Data.Location := Location_Of (From_Project_Node);
1800 Processed_Data.Display_Directory :=
1801 Directory_Of (From_Project_Node);
1802 Get_Name_String (Processed_Data.Display_Directory);
1803 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1804 Processed_Data.Directory := Name_Find;
1806 Processed_Data.Extended_By := Extended_By;
1807 Processed_Data.Naming := Standard_Naming_Data;
1809 Add_Attributes (Processed_Data.Decl, Attribute_First);
1810 With_Clause := First_With_Clause_Of (From_Project_Node);
1812 while With_Clause /= Empty_Node loop
1814 New_Project : Project_Id;
1815 New_Data : Project_Data;
1819 (Project => New_Project,
1820 From_Project_Node => Project_Node_Of (With_Clause),
1821 Extended_By => No_Project);
1822 New_Data := Projects.Table (New_Project);
1824 -- If we were the first project to import it,
1825 -- set First_Referred_By to us.
1827 if New_Data.First_Referred_By = No_Project then
1828 New_Data.First_Referred_By := Project;
1829 Projects.Table (New_Project) := New_Data;
1832 -- Add this project to our list of imported projects
1834 Project_Lists.Increment_Last;
1835 Project_Lists.Table (Project_Lists.Last) :=
1836 (Project => New_Project, Next => Empty_Project_List);
1838 -- Imported is the id of the last imported project.
1839 -- If it is nil, then this imported project is our first.
1841 if Imported = Empty_Project_List then
1842 Processed_Data.Imported_Projects := Project_Lists.Last;
1845 Project_Lists.Table (Imported).Next := Project_Lists.Last;
1848 Imported := Project_Lists.Last;
1850 With_Clause := Next_With_Clause_Of (With_Clause);
1854 Declaration_Node := Project_Declaration_Of (From_Project_Node);
1857 (Project => Processed_Data.Extends,
1858 From_Project_Node => Extended_Project_Of (Declaration_Node),
1859 Extended_By => Project);
1861 Projects.Table (Project) := Processed_Data;
1863 Process_Declarative_Items
1864 (Project => Project,
1865 From_Project_Node => From_Project_Node,
1867 Item => First_Declarative_Item_Of
1868 (Declaration_Node));
1870 -- If it is an extending project, inherit all packages
1871 -- from the extended project that are not explicitely defined
1874 if Processed_Data.Extends /= No_Project then
1875 Processed_Data := Projects.Table (Project);
1878 Extended_Pkg : Package_Id :=
1880 (Processed_Data.Extends).Decl.Packages;
1881 Current_Pkg : Package_Id;
1882 Element : Package_Element;
1883 First : constant Package_Id :=
1884 Processed_Data.Decl.Packages;
1887 while Extended_Pkg /= No_Package loop
1888 Element := Packages.Table (Extended_Pkg);
1890 Current_Pkg := First;
1893 exit when Current_Pkg = No_Package
1894 or else Packages.Table (Current_Pkg).Name
1896 Current_Pkg := Packages.Table (Current_Pkg).Next;
1899 if Current_Pkg = No_Package then
1900 Packages.Increment_Last;
1901 Current_Pkg := Packages.Last;
1902 Packages.Table (Current_Pkg) :=
1903 (Name => Element.Name,
1904 Decl => Element.Decl,
1905 Parent => No_Package,
1906 Next => Processed_Data.Decl.Packages);
1907 Processed_Data.Decl.Packages := Current_Pkg;
1910 Extended_Pkg := Element.Next;
1914 Projects.Table (Project) := Processed_Data;
1918 end Recursive_Process;