1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars; use Err_Vars;
28 with Osint; use Osint;
29 with Output; use Output;
30 with Prj.Attr; use Prj.Attr;
31 with Prj.Err; use Prj.Err;
32 with Prj.Ext; use Prj.Ext;
33 with Prj.Nmsc; use Prj.Nmsc;
37 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
39 with GNAT.Case_Util; use GNAT.Case_Util;
42 package body Prj.Proc is
44 package Processed_Projects is new GNAT.HTable.Simple_HTable
45 (Header_Num => Header_Num,
46 Element => Project_Id,
47 No_Element => No_Project,
51 -- This hash table contains all processed projects
53 package Unit_Htable is new GNAT.HTable.Simple_HTable
54 (Header_Num => Header_Num,
56 No_Element => No_Source,
60 -- This hash table contains all processed projects
62 procedure Add (To_Exp : in out Name_Id; Str : Name_Id);
63 -- Concatenate two strings and returns another string if both
64 -- arguments are not null string.
66 -- In the following procedures, we are expected to guess the meaning of
67 -- the parameters from their names, this is never a good idea, comments
68 -- should be added precisely defining every formal ???
70 procedure Add_Attributes
71 (Project : Project_Id;
72 Project_Name : Name_Id;
73 Project_Dir : Name_Id;
74 Shared : Shared_Project_Tree_Data_Access;
75 Decl : in out Declarations;
76 First : Attribute_Node_Id;
77 Project_Level : Boolean);
78 -- Add all attributes, starting with First, with their default values to
79 -- the package or project with declarations Decl.
82 (In_Tree : Project_Tree_Ref;
84 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
85 Flags : Processing_Flags);
86 -- Set all projects to not checked, then call Recursive_Check for the
87 -- main project Project. Project is set to No_Project if errors occurred.
88 -- Current_Dir is for optimization purposes, avoiding extra system calls.
89 -- If Allow_Duplicate_Basenames, then files with the same base names are
90 -- authorized within a project for source-based languages (never for unit
93 procedure Copy_Package_Declarations
95 To : in out Declarations;
98 Shared : Shared_Project_Tree_Data_Access);
99 -- Copy a package declaration From to To for a renamed package. Change the
100 -- locations of all the attributes to New_Loc. When Restricted is
101 -- True, do not copy attributes Body, Spec, Implementation, Specification
102 -- and Linker_Options.
105 (Project : Project_Id;
106 Shared : Shared_Project_Tree_Data_Access;
107 From_Project_Node : Project_Node_Id;
108 From_Project_Node_Tree : Project_Node_Tree_Ref;
109 Env : Prj.Tree.Environment;
111 First_Term : Project_Node_Id;
112 Kind : Variable_Kind) return Variable_Value;
113 -- From N_Expression project node From_Project_Node, compute the value
114 -- of an expression and return it as a Variable_Value.
116 function Imported_Or_Extended_Project_From
117 (Project : Project_Id;
118 With_Name : Name_Id) return Project_Id;
119 -- Find an imported or extended project of Project whose name is With_Name
121 function Package_From
122 (Project : Project_Id;
123 Shared : Shared_Project_Tree_Data_Access;
124 With_Name : Name_Id) return Package_Id;
125 -- Find the package of Project whose name is With_Name
127 procedure Process_Declarative_Items
128 (Project : Project_Id;
129 In_Tree : Project_Tree_Ref;
130 From_Project_Node : Project_Node_Id;
131 Node_Tree : Project_Node_Tree_Ref;
132 Env : Prj.Tree.Environment;
134 Item : Project_Node_Id;
135 Child_Env : in out Prj.Tree.Environment);
136 -- Process declarative items starting with From_Project_Node, and put them
137 -- in declarations Decl. This is a recursive procedure; it calls itself for
138 -- a package declaration or a case construction.
140 -- Child_Env is the modified environment after seeing declarations like
141 -- "for External(...) use" or "for Project_Path use" in aggregate projects.
142 -- It should have been initialized first.
144 procedure Recursive_Process
145 (In_Tree : Project_Tree_Ref;
146 Project : out Project_Id;
147 From_Project_Node : Project_Node_Id;
148 From_Project_Node_Tree : Project_Node_Tree_Ref;
149 Env : in out Prj.Tree.Environment;
150 Extended_By : Project_Id);
151 -- Process project with node From_Project_Node in the tree. Do nothing if
152 -- From_Project_Node is Empty_Node. If project has already been processed,
153 -- simply return its project id. Otherwise create a new project id, mark it
154 -- as processed, call itself recursively for all imported projects and a
155 -- extended project, if any. Then process the declarative items of the
158 -- Is_Root_Project should be true only for the project that the user
159 -- explicitly loaded. In the context of aggregate projects, only that
160 -- project is allowed to modify the environment that will be used to load
161 -- projects (Child_Env).
163 function Get_Attribute_Index
164 (Tree : Project_Node_Tree_Ref;
165 Attr : Project_Node_Id;
166 Index : Name_Id) return Name_Id;
167 -- Copy the index of the attribute into Name_Buffer, converting to lower
168 -- case if the attribute is case-insensitive.
174 procedure Add (To_Exp : in out Name_Id; Str : Name_Id) is
176 if To_Exp = No_Name or else To_Exp = Empty_String then
178 -- To_Exp is nil or empty. The result is Str
182 -- If Str is nil, then do not change To_Ext
184 elsif Str /= No_Name and then Str /= Empty_String then
186 S : constant String := Get_Name_String (Str);
188 Get_Name_String (To_Exp);
189 Add_Str_To_Name_Buffer (S);
199 procedure Add_Attributes
200 (Project : Project_Id;
201 Project_Name : Name_Id;
202 Project_Dir : Name_Id;
203 Shared : Shared_Project_Tree_Data_Access;
204 Decl : in out Declarations;
205 First : Attribute_Node_Id;
206 Project_Level : Boolean)
208 The_Attribute : Attribute_Node_Id := First;
211 while The_Attribute /= Empty_Attribute loop
212 if Attribute_Kind_Of (The_Attribute) = Single then
214 New_Attribute : Variable_Value;
217 case Variable_Kind_Of (The_Attribute) is
219 -- Undefined should not happen
223 (False, "attribute with an undefined kind");
226 -- Single attributes have a default value of empty string
232 Location => No_Location,
234 Value => Empty_String,
237 -- Special cases of <project>'Name and
238 -- <project>'Project_Dir.
240 if Project_Level then
241 if Attribute_Name_Of (The_Attribute) =
244 New_Attribute.Value := Project_Name;
246 elsif Attribute_Name_Of (The_Attribute) =
247 Snames.Name_Project_Dir
249 New_Attribute.Value := Project_Dir;
253 -- List attributes have a default value of nil list
259 Location => No_Location,
261 Values => Nil_String);
265 Variable_Element_Table.Increment_Last
266 (Shared.Variable_Elements);
267 Shared.Variable_Elements.Table
268 (Variable_Element_Table.Last (Shared.Variable_Elements)) :=
269 (Next => Decl.Attributes,
270 Name => Attribute_Name_Of (The_Attribute),
271 Value => New_Attribute);
273 Variable_Element_Table.Last
274 (Shared.Variable_Elements);
278 The_Attribute := Next_Attribute (After => The_Attribute);
287 (In_Tree : Project_Tree_Ref;
288 Project : Project_Id;
289 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
290 Flags : Processing_Flags)
293 Process_Naming_Scheme (In_Tree, Project, Node_Tree, Flags);
295 -- Set the Other_Part field for the units
301 Iter : Source_Iterator;
306 Iter := For_Each_Source (In_Tree);
308 Source1 := Prj.Element (Iter);
309 exit when Source1 = No_Source;
311 if Source1.Unit /= No_Unit_Index then
312 Name := Source1.Unit.Name;
313 Source2 := Unit_Htable.Get (Name);
315 if Source2 = No_Source then
316 Unit_Htable.Set (K => Name, E => Source1);
318 Unit_Htable.Remove (Name);
327 -------------------------------
328 -- Copy_Package_Declarations --
329 -------------------------------
331 procedure Copy_Package_Declarations
332 (From : Declarations;
333 To : in out Declarations;
334 New_Loc : Source_Ptr;
335 Restricted : Boolean;
336 Shared : Shared_Project_Tree_Data_Access)
339 V2 : Variable_Id := No_Variable;
342 A2 : Array_Id := No_Array;
344 E1 : Array_Element_Id;
345 E2 : Array_Element_Id := No_Array_Element;
349 -- To avoid references in error messages to attribute declarations in
350 -- an original package that has been renamed, copy all the attribute
351 -- declarations of the package and change all locations to New_Loc,
352 -- the location of the renamed package.
354 -- First single attributes
356 V1 := From.Attributes;
357 while V1 /= No_Variable loop
359 -- Copy the attribute
361 Var := Shared.Variable_Elements.Table (V1);
364 -- Do not copy the value of attribute Linker_Options if Restricted
366 if Restricted and then Var.Name = Snames.Name_Linker_Options then
367 Var.Value.Values := Nil_String;
370 -- Remove the Next component
372 Var.Next := No_Variable;
374 -- Change the location to New_Loc
376 Var.Value.Location := New_Loc;
377 Variable_Element_Table.Increment_Last (Shared.Variable_Elements);
379 -- Put in new declaration
381 if To.Attributes = No_Variable then
383 Variable_Element_Table.Last (Shared.Variable_Elements);
385 Shared.Variable_Elements.Table (V2).Next :=
386 Variable_Element_Table.Last (Shared.Variable_Elements);
389 V2 := Variable_Element_Table.Last (Shared.Variable_Elements);
390 Shared.Variable_Elements.Table (V2) := Var;
393 -- Then the associated array attributes
396 while A1 /= No_Array loop
397 Arr := Shared.Arrays.Table (A1);
402 (Arr.Name /= Snames.Name_Body and then
403 Arr.Name /= Snames.Name_Spec and then
404 Arr.Name /= Snames.Name_Implementation and then
405 Arr.Name /= Snames.Name_Specification)
407 -- Remove the Next component
409 Arr.Next := No_Array;
410 Array_Table.Increment_Last (Shared.Arrays);
412 -- Create new Array declaration
414 if To.Arrays = No_Array then
415 To.Arrays := Array_Table.Last (Shared.Arrays);
417 Shared.Arrays.Table (A2).Next :=
418 Array_Table.Last (Shared.Arrays);
421 A2 := Array_Table.Last (Shared.Arrays);
423 -- Don't store the array as its first element has not been set yet
425 -- Copy the array elements of the array
428 Arr.Value := No_Array_Element;
429 while E1 /= No_Array_Element loop
431 -- Copy the array element
433 Elm := Shared.Array_Elements.Table (E1);
436 -- Remove the Next component
438 Elm.Next := No_Array_Element;
440 -- Change the location
442 Elm.Value.Location := New_Loc;
443 Array_Element_Table.Increment_Last (Shared.Array_Elements);
445 -- Create new array element
447 if Arr.Value = No_Array_Element then
449 Array_Element_Table.Last (Shared.Array_Elements);
451 Shared.Array_Elements.Table (E2).Next :=
452 Array_Element_Table.Last (Shared.Array_Elements);
455 E2 := Array_Element_Table.Last (Shared.Array_Elements);
456 Shared.Array_Elements.Table (E2) := Elm;
459 -- Finally, store the new array
461 Shared.Arrays.Table (A2) := Arr;
464 end Copy_Package_Declarations;
466 -------------------------
467 -- Get_Attribute_Index --
468 -------------------------
470 function Get_Attribute_Index
471 (Tree : Project_Node_Tree_Ref;
472 Attr : Project_Node_Id;
473 Index : Name_Id) return Name_Id
476 if Index = All_Other_Names
477 or else not Case_Insensitive (Attr, Tree)
482 Get_Name_String (Index);
483 To_Lower (Name_Buffer (1 .. Name_Len));
485 end Get_Attribute_Index;
492 (Project : Project_Id;
493 Shared : Shared_Project_Tree_Data_Access;
494 From_Project_Node : Project_Node_Id;
495 From_Project_Node_Tree : Project_Node_Tree_Ref;
496 Env : Prj.Tree.Environment;
498 First_Term : Project_Node_Id;
499 Kind : Variable_Kind) return Variable_Value
501 The_Term : Project_Node_Id;
502 -- The term in the expression list
504 The_Current_Term : Project_Node_Id := Empty_Node;
505 -- The current term node id
507 Result : Variable_Value (Kind => Kind);
508 -- The returned result
510 Last : String_List_Id := Nil_String;
511 -- Reference to the last string elements in Result, when Kind is List
514 Result.Project := Project;
515 Result.Location := Location_Of (First_Term, From_Project_Node_Tree);
517 -- Process each term of the expression, starting with First_Term
519 The_Term := First_Term;
520 while Present (The_Term) loop
521 The_Current_Term := Current_Term (The_Term, From_Project_Node_Tree);
523 case Kind_Of (The_Current_Term, From_Project_Node_Tree) is
525 when N_Literal_String =>
531 -- Should never happen
533 pragma Assert (False, "Undefined expression kind");
539 (The_Current_Term, From_Project_Node_Tree));
542 (The_Current_Term, From_Project_Node_Tree);
546 String_Element_Table.Increment_Last
547 (Shared.String_Elements);
549 if Last = Nil_String then
551 -- This can happen in an expression like () & "toto"
553 Result.Values := String_Element_Table.Last
554 (Shared.String_Elements);
557 Shared.String_Elements.Table
558 (Last).Next := String_Element_Table.Last
559 (Shared.String_Elements);
562 Last := String_Element_Table.Last
563 (Shared.String_Elements);
565 Shared.String_Elements.Table (Last) :=
566 (Value => String_Value_Of
568 From_Project_Node_Tree),
569 Index => Source_Index_Of
571 From_Project_Node_Tree),
572 Display_Value => No_Name,
573 Location => Location_Of
575 From_Project_Node_Tree),
580 when N_Literal_String_List =>
583 String_Node : Project_Node_Id :=
584 First_Expression_In_List
586 From_Project_Node_Tree);
588 Value : Variable_Value;
591 if Present (String_Node) then
593 -- If String_Node is nil, it is an empty list, there is
599 From_Project_Node => From_Project_Node,
600 From_Project_Node_Tree => From_Project_Node_Tree,
605 (String_Node, From_Project_Node_Tree),
607 String_Element_Table.Increment_Last
608 (Shared.String_Elements);
610 if Result.Values = Nil_String then
612 -- This literal string list is the first term in a
613 -- string list expression
616 String_Element_Table.Last
617 (Shared.String_Elements);
620 Shared.String_Elements.Table (Last).Next :=
621 String_Element_Table.Last (Shared.String_Elements);
625 String_Element_Table.Last (Shared.String_Elements);
627 Shared.String_Elements.Table (Last) :=
628 (Value => Value.Value,
629 Display_Value => No_Name,
630 Location => Value.Location,
633 Index => Value.Index);
636 -- Add the other element of the literal string list
637 -- one after the other.
640 Next_Expression_In_List
641 (String_Node, From_Project_Node_Tree);
643 exit when No (String_Node);
649 From_Project_Node => From_Project_Node,
650 From_Project_Node_Tree => From_Project_Node_Tree,
655 (String_Node, From_Project_Node_Tree),
658 String_Element_Table.Increment_Last
659 (Shared.String_Elements);
660 Shared.String_Elements.Table (Last).Next :=
661 String_Element_Table.Last (Shared.String_Elements);
662 Last := String_Element_Table.Last
663 (Shared.String_Elements);
664 Shared.String_Elements.Table (Last) :=
665 (Value => Value.Value,
666 Display_Value => No_Name,
667 Location => Value.Location,
670 Index => Value.Index);
675 when N_Variable_Reference | N_Attribute_Reference =>
678 The_Project : Project_Id := Project;
679 The_Package : Package_Id := Pkg;
680 The_Name : Name_Id := No_Name;
681 The_Variable_Id : Variable_Id := No_Variable;
682 The_Variable : Variable_Value;
683 Term_Project : constant Project_Node_Id :=
686 From_Project_Node_Tree);
687 Term_Package : constant Project_Node_Id :=
690 From_Project_Node_Tree);
691 Index : Name_Id := No_Name;
694 if Present (Term_Project) and then
695 Term_Project /= From_Project_Node
697 -- This variable or attribute comes from another project
700 Name_Of (Term_Project, From_Project_Node_Tree);
701 The_Project := Imported_Or_Extended_Project_From
703 With_Name => The_Name);
706 if Present (Term_Package) then
708 -- This is an attribute of a package
711 Name_Of (Term_Package, From_Project_Node_Tree);
713 The_Package := The_Project.Decl.Packages;
714 while The_Package /= No_Package
715 and then Shared.Packages.Table (The_Package).Name /=
719 Shared.Packages.Table (The_Package).Next;
723 (The_Package /= No_Package, "package not found.");
725 elsif Kind_Of (The_Current_Term, From_Project_Node_Tree) =
726 N_Attribute_Reference
728 The_Package := No_Package;
732 Name_Of (The_Current_Term, From_Project_Node_Tree);
734 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
735 N_Attribute_Reference
738 Associative_Array_Index_Of
739 (The_Current_Term, From_Project_Node_Tree);
742 -- If it is not an associative array attribute
744 if Index = No_Name then
746 -- It is not an associative array attribute
748 if The_Package /= No_Package then
750 -- First, if there is a package, look into the package
752 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
756 Shared.Packages.Table
757 (The_Package).Decl.Variables;
760 Shared.Packages.Table
761 (The_Package).Decl.Attributes;
764 while The_Variable_Id /= No_Variable
765 and then Shared.Variable_Elements.Table
766 (The_Variable_Id).Name /= The_Name
769 Shared.Variable_Elements.Table
770 (The_Variable_Id).Next;
775 if The_Variable_Id = No_Variable then
777 -- If we have not found it, look into the project
779 if Kind_Of (The_Current_Term, From_Project_Node_Tree) =
782 The_Variable_Id := The_Project.Decl.Variables;
784 The_Variable_Id := The_Project.Decl.Attributes;
787 while The_Variable_Id /= No_Variable
788 and then Shared.Variable_Elements.Table
789 (The_Variable_Id).Name /= The_Name
792 Shared.Variable_Elements.Table
793 (The_Variable_Id).Next;
798 pragma Assert (The_Variable_Id /= No_Variable,
799 "variable or attribute not found");
802 Shared.Variable_Elements.Table (The_Variable_Id).Value;
806 -- It is an associative array attribute
809 The_Array : Array_Id := No_Array;
810 The_Element : Array_Element_Id := No_Array_Element;
811 Array_Index : Name_Id := No_Name;
814 if The_Package /= No_Package then
816 Shared.Packages.Table (The_Package).Decl.Arrays;
818 The_Array := The_Project.Decl.Arrays;
821 while The_Array /= No_Array
822 and then Shared.Arrays.Table (The_Array).Name /=
825 The_Array := Shared.Arrays.Table (The_Array).Next;
828 if The_Array /= No_Array then
830 Shared.Arrays.Table (The_Array).Value;
833 (From_Project_Node_Tree,
837 while The_Element /= No_Array_Element
838 and then Shared.Array_Elements.Table
839 (The_Element).Index /= Array_Index
842 Shared.Array_Elements.Table (The_Element).Next;
847 if The_Element /= No_Array_Element then
849 Shared.Array_Elements.Table (The_Element).Value;
852 if Expression_Kind_Of
853 (The_Current_Term, From_Project_Node_Tree) =
859 Location => No_Location,
861 Values => Nil_String);
866 Location => No_Location,
868 Value => Empty_String,
879 -- Should never happen
881 pragma Assert (False, "undefined expression kind");
886 case The_Variable.Kind is
892 Add (Result.Value, The_Variable.Value);
896 -- Should never happen
900 "list cannot appear in single " &
901 "string expression");
906 case The_Variable.Kind is
912 String_Element_Table.Increment_Last
913 (Shared.String_Elements);
915 if Last = Nil_String then
917 -- This can happen in an expression such as
921 String_Element_Table.Last
922 (Shared.String_Elements);
925 Shared.String_Elements.Table (Last).Next :=
926 String_Element_Table.Last
927 (Shared.String_Elements);
931 String_Element_Table.Last
932 (Shared.String_Elements);
934 Shared.String_Elements.Table (Last) :=
935 (Value => The_Variable.Value,
936 Display_Value => No_Name,
937 Location => Location_Of
939 From_Project_Node_Tree),
947 The_List : String_List_Id :=
951 while The_List /= Nil_String loop
952 String_Element_Table.Increment_Last
953 (Shared.String_Elements);
955 if Last = Nil_String then
957 String_Element_Table.Last
958 (Shared.String_Elements);
962 String_Elements.Table (Last).Next :=
963 String_Element_Table.Last
964 (Shared.String_Elements);
969 String_Element_Table.Last
970 (Shared.String_Elements);
972 Shared.String_Elements.Table
975 Shared.String_Elements.Table
977 Display_Value => No_Name,
981 From_Project_Node_Tree),
986 The_List := Shared.String_Elements.Table
994 when N_External_Value =>
997 (External_Reference_Of
998 (The_Current_Term, From_Project_Node_Tree),
999 From_Project_Node_Tree));
1002 Name : constant Name_Id := Name_Find;
1003 Default : Name_Id := No_Name;
1004 Value : Name_Id := No_Name;
1005 Ext_List : Boolean := False;
1006 Str_List : String_List_Access := null;
1007 Def_Var : Variable_Value;
1009 Default_Node : constant Project_Node_Id :=
1012 From_Project_Node_Tree);
1015 -- If there is a default value for the external reference,
1018 if Present (Default_Node) then
1019 Def_Var := Expression
1020 (Project => Project,
1022 From_Project_Node => From_Project_Node,
1023 From_Project_Node_Tree => From_Project_Node_Tree,
1028 (Default_Node, From_Project_Node_Tree),
1031 if Def_Var /= Nil_Variable_Value then
1032 Default := Def_Var.Value;
1036 Ext_List := Expression_Kind_Of
1038 From_Project_Node_Tree) = List;
1041 Value := Prj.Ext.Value_Of (Env.External, Name, No_Name);
1043 if Value /= No_Name then
1045 Sep : constant String :=
1046 Get_Name_String (Default);
1047 First : Positive := 1;
1049 Done : Boolean := False;
1053 Get_Name_String (Value);
1056 or else Sep'Length = 0
1057 or else Name_Buffer (1 .. Name_Len) = Sep
1062 if not Done and then Name_Len < Sep'Length then
1066 (Name_Buffer (1 .. Name_Len)));
1071 if Name_Buffer (1 .. Sep'Length) = Sep then
1072 First := Sep'Length + 1;
1075 if Name_Len - First + 1 >= Sep'Length
1077 Name_Buffer (Name_Len - Sep'Length + 1 ..
1080 Name_Len := Name_Len - Sep'Length;
1083 if Name_Len = 0 then
1085 new String_List'(1 => new String'(""));
1092 -- Count the number of strings
1095 Saved : constant Positive := First;
1103 Name_Buffer (First .. Name_Len),
1107 First := Lst + Sep'Length;
1113 Str_List := new String_List (1 .. Nmb);
1115 -- Populate the string list
1122 Name_Buffer (First .. Name_Len),
1128 (Name_Buffer (First .. Name_Len));
1134 (Name_Buffer (First .. Lst - 1));
1136 First := Lst + Sep'Length;
1146 Value := Prj.Ext.Value_Of (Env.External, Name, Default);
1148 if Value = No_Name then
1149 if not Quiet_Output then
1151 (Env.Flags, "?undefined external reference",
1153 (The_Current_Term, From_Project_Node_Tree),
1157 Value := Empty_String;
1171 Add (Result.Value, Value);
1175 if not Ext_List or else Str_List /= null then
1176 String_Element_Table.Increment_Last
1177 (Shared.String_Elements);
1179 if Last = Nil_String then
1181 String_Element_Table.Last
1182 (Shared.String_Elements);
1185 Shared.String_Elements.Table (Last).Next
1186 := String_Element_Table.Last
1187 (Shared.String_Elements);
1190 Last := String_Element_Table.Last
1191 (Shared.String_Elements);
1194 for Ind in Str_List'Range loop
1196 Add_Str_To_Name_Buffer (Str_List (Ind).all);
1198 Shared.String_Elements.Table (Last) :=
1200 Display_Value => No_Name,
1204 From_Project_Node_Tree),
1209 if Ind /= Str_List'Last then
1210 String_Element_Table.Increment_Last
1211 (Shared.String_Elements);
1212 Shared.String_Elements.Table (Last).Next :=
1213 String_Element_Table.Last
1214 (Shared.String_Elements);
1215 Last := String_Element_Table.Last
1216 (Shared.String_Elements);
1221 Shared.String_Elements.Table (Last) :=
1223 Display_Value => No_Name,
1227 From_Project_Node_Tree),
1238 -- Should never happen
1242 "illegal node kind in an expression");
1243 raise Program_Error;
1247 The_Term := Next_Term (The_Term, From_Project_Node_Tree);
1253 ---------------------------------------
1254 -- Imported_Or_Extended_Project_From --
1255 ---------------------------------------
1257 function Imported_Or_Extended_Project_From
1258 (Project : Project_Id;
1259 With_Name : Name_Id) return Project_Id
1261 List : Project_List;
1262 Result : Project_Id;
1263 Temp_Result : Project_Id;
1266 -- First check if it is the name of an extended project
1268 Result := Project.Extends;
1269 while Result /= No_Project loop
1270 if Result.Name = With_Name then
1273 Result := Result.Extends;
1277 -- Then check the name of each imported project
1279 Temp_Result := No_Project;
1280 List := Project.Imported_Projects;
1281 while List /= null loop
1282 Result := List.Project;
1284 -- If the project is directly imported, then returns its ID
1286 if Result.Name = With_Name then
1290 -- If a project extending the project is imported, then keep this
1291 -- extending project as a possibility. It will be the returned ID
1292 -- if the project is not imported directly.
1298 Proj := Result.Extends;
1299 while Proj /= No_Project loop
1300 if Proj.Name = With_Name then
1301 Temp_Result := Result;
1305 Proj := Proj.Extends;
1312 pragma Assert (Temp_Result /= No_Project, "project not found");
1314 end Imported_Or_Extended_Project_From;
1320 function Package_From
1321 (Project : Project_Id;
1322 Shared : Shared_Project_Tree_Data_Access;
1323 With_Name : Name_Id) return Package_Id
1325 Result : Package_Id := Project.Decl.Packages;
1328 -- Check the name of each existing package of Project
1330 while Result /= No_Package
1331 and then Shared.Packages.Table (Result).Name /= With_Name
1333 Result := Shared.Packages.Table (Result).Next;
1336 if Result = No_Package then
1338 -- Should never happen
1340 Write_Line ("package """ & Get_Name_String (With_Name) &
1342 raise Program_Error;
1354 (In_Tree : Project_Tree_Ref;
1355 Project : out Project_Id;
1356 Success : out Boolean;
1357 From_Project_Node : Project_Node_Id;
1358 From_Project_Node_Tree : Project_Node_Tree_Ref;
1359 Env : in out Prj.Tree.Environment;
1360 Reset_Tree : Boolean := True)
1363 Process_Project_Tree_Phase_1
1364 (In_Tree => In_Tree,
1367 From_Project_Node => From_Project_Node,
1368 From_Project_Node_Tree => From_Project_Node_Tree,
1370 Reset_Tree => Reset_Tree);
1372 if Project_Qualifier_Of (From_Project_Node, From_Project_Node_Tree) /=
1375 Process_Project_Tree_Phase_2
1376 (In_Tree => In_Tree,
1379 From_Project_Node => From_Project_Node,
1380 From_Project_Node_Tree => From_Project_Node_Tree,
1385 -------------------------------
1386 -- Process_Declarative_Items --
1387 -------------------------------
1389 procedure Process_Declarative_Items
1390 (Project : Project_Id;
1391 In_Tree : Project_Tree_Ref;
1392 From_Project_Node : Project_Node_Id;
1393 Node_Tree : Project_Node_Tree_Ref;
1394 Env : Prj.Tree.Environment;
1396 Item : Project_Node_Id;
1397 Child_Env : in out Prj.Tree.Environment)
1399 Shared : constant Shared_Project_Tree_Data_Access :=
1402 procedure Check_Or_Set_Typed_Variable
1403 (Value : in out Variable_Value;
1404 Declaration : Project_Node_Id);
1405 -- Check whether Value is valid for this typed variable declaration. If
1406 -- it is an error, the behavior depends on the flags: either an error is
1407 -- reported, or a warning, or nothing. In the last two cases, the value
1408 -- of the variable is set to a valid value, replacing Value.
1410 procedure Process_Package_Declaration
1411 (Current_Item : Project_Node_Id);
1412 procedure Process_Attribute_Declaration
1413 (Current : Project_Node_Id);
1414 procedure Process_Case_Construction
1415 (Current_Item : Project_Node_Id);
1416 procedure Process_Associative_Array
1417 (Current_Item : Project_Node_Id);
1418 procedure Process_Expression
1419 (Current : Project_Node_Id);
1420 procedure Process_Expression_For_Associative_Array
1421 (Current : Project_Node_Id;
1422 New_Value : Variable_Value);
1423 procedure Process_Expression_Variable_Decl
1424 (Current_Item : Project_Node_Id;
1425 New_Value : Variable_Value);
1426 -- Process the various declarative items
1428 ---------------------------------
1429 -- Check_Or_Set_Typed_Variable --
1430 ---------------------------------
1432 procedure Check_Or_Set_Typed_Variable
1433 (Value : in out Variable_Value;
1434 Declaration : Project_Node_Id)
1436 Loc : constant Source_Ptr := Location_Of (Declaration, Node_Tree);
1438 Reset_Value : Boolean := False;
1439 Current_String : Project_Node_Id;
1442 -- Report an error for an empty string
1444 if Value.Value = Empty_String then
1445 Error_Msg_Name_1 := Name_Of (Declaration, Node_Tree);
1447 case Env.Flags.Allow_Invalid_External is
1450 (Env.Flags, "no value defined for %%", Loc, Project);
1452 Reset_Value := True;
1454 (Env.Flags, "?no value defined for %%", Loc, Project);
1456 Reset_Value := True;
1460 -- Loop through all the valid strings for the
1461 -- string type and compare to the string value.
1464 First_Literal_String
1465 (String_Type_Of (Declaration, Node_Tree), Node_Tree);
1467 while Present (Current_String)
1468 and then String_Value_Of (Current_String, Node_Tree) /=
1472 Next_Literal_String (Current_String, Node_Tree);
1475 -- Report error if string value is not one for the string type
1477 if No (Current_String) then
1478 Error_Msg_Name_1 := Value.Value;
1479 Error_Msg_Name_2 := Name_Of (Declaration, Node_Tree);
1481 case Env.Flags.Allow_Invalid_External is
1484 (Env.Flags, "value %% is illegal for typed string %%",
1489 (Env.Flags, "?value %% is illegal for typed string %%",
1491 Reset_Value := True;
1494 Reset_Value := True;
1501 First_Literal_String
1502 (String_Type_Of (Declaration, Node_Tree), Node_Tree);
1503 Value.Value := String_Value_Of (Current_String, Node_Tree);
1505 end Check_Or_Set_Typed_Variable;
1507 ---------------------------------
1508 -- Process_Package_Declaration --
1509 ---------------------------------
1511 procedure Process_Package_Declaration
1512 (Current_Item : Project_Node_Id)
1515 -- Do not process a package declaration that should be ignored
1517 if Expression_Kind_Of (Current_Item, Node_Tree) /= Ignored then
1519 -- Create the new package
1521 Package_Table.Increment_Last (Shared.Packages);
1524 New_Pkg : constant Package_Id :=
1525 Package_Table.Last (Shared.Packages);
1526 The_New_Package : Package_Element;
1528 Project_Of_Renamed_Package : constant Project_Node_Id :=
1529 Project_Of_Renamed_Package_Of
1530 (Current_Item, Node_Tree);
1533 -- Set the name of the new package
1535 The_New_Package.Name := Name_Of (Current_Item, Node_Tree);
1537 -- Insert the new package in the appropriate list
1539 if Pkg /= No_Package then
1540 The_New_Package.Next :=
1541 Shared.Packages.Table (Pkg).Decl.Packages;
1542 Shared.Packages.Table (Pkg).Decl.Packages := New_Pkg;
1545 The_New_Package.Next := Project.Decl.Packages;
1546 Project.Decl.Packages := New_Pkg;
1549 Shared.Packages.Table (New_Pkg) := The_New_Package;
1551 if Present (Project_Of_Renamed_Package) then
1553 -- Renamed or extending package
1556 Project_Name : constant Name_Id :=
1557 Name_Of (Project_Of_Renamed_Package, Node_Tree);
1559 Renamed_Project : constant Project_Id :=
1560 Imported_Or_Extended_Project_From
1561 (Project, Project_Name);
1563 Renamed_Package : constant Package_Id :=
1565 (Renamed_Project, Shared,
1566 Name_Of (Current_Item, Node_Tree));
1569 -- For a renamed package, copy the declarations of the
1570 -- renamed package, but set all the locations to the
1571 -- location of the package name in the renaming
1574 Copy_Package_Declarations
1575 (From => Shared.Packages.Table (Renamed_Package).Decl,
1576 To => Shared.Packages.Table (New_Pkg).Decl,
1577 New_Loc => Location_Of (Current_Item, Node_Tree),
1578 Restricted => False,
1583 -- Set the default values of the attributes
1588 Name_Id (Project.Directory.Name),
1590 Shared.Packages.Table (New_Pkg).Decl,
1592 (Package_Id_Of (Current_Item, Node_Tree)),
1593 Project_Level => False);
1596 -- Process declarative items (nothing to do when the package is
1597 -- renaming, as the first declarative item is null).
1599 Process_Declarative_Items
1600 (Project => Project,
1602 From_Project_Node => From_Project_Node,
1603 Node_Tree => Node_Tree,
1607 First_Declarative_Item_Of (Current_Item, Node_Tree),
1608 Child_Env => Child_Env);
1611 end Process_Package_Declaration;
1613 -------------------------------
1614 -- Process_Associative_Array --
1615 -------------------------------
1617 procedure Process_Associative_Array
1618 (Current_Item : Project_Node_Id)
1620 Current_Item_Name : constant Name_Id :=
1621 Name_Of (Current_Item, Node_Tree);
1622 -- The name of the attribute
1624 Current_Location : constant Source_Ptr :=
1625 Location_Of (Current_Item, Node_Tree);
1627 New_Array : Array_Id;
1628 -- The new associative array created
1630 Orig_Array : Array_Id;
1631 -- The associative array value
1633 Orig_Project_Name : Name_Id := No_Name;
1634 -- The name of the project where the associative array
1637 Orig_Project : Project_Id := No_Project;
1638 -- The id of the project where the associative array
1641 Orig_Package_Name : Name_Id := No_Name;
1642 -- The name of the package, if any, where the associative array value
1645 Orig_Package : Package_Id := No_Package;
1646 -- The id of the package, if any, where the associative array value
1649 New_Element : Array_Element_Id := No_Array_Element;
1650 -- Id of a new array element created
1652 Prev_Element : Array_Element_Id := No_Array_Element;
1653 -- Last new element id created
1655 Orig_Element : Array_Element_Id := No_Array_Element;
1656 -- Current array element in original associative array
1658 Next_Element : Array_Element_Id := No_Array_Element;
1659 -- Id of the array element that follows the new element. This is not
1660 -- always nil, because values for the associative array attribute may
1661 -- already have been declared, and the array elements declared are
1667 -- First find if the associative array attribute already has elements
1670 if Pkg /= No_Package then
1671 New_Array := Shared.Packages.Table (Pkg).Decl.Arrays;
1673 New_Array := Project.Decl.Arrays;
1676 while New_Array /= No_Array
1677 and then Shared.Arrays.Table (New_Array).Name /= Current_Item_Name
1679 New_Array := Shared.Arrays.Table (New_Array).Next;
1682 -- If the attribute has never been declared add new entry in the
1683 -- arrays of the project/package and link it.
1685 if New_Array = No_Array then
1686 Array_Table.Increment_Last (Shared.Arrays);
1687 New_Array := Array_Table.Last (Shared.Arrays);
1689 if Pkg /= No_Package then
1690 Shared.Arrays.Table (New_Array) :=
1691 (Name => Current_Item_Name,
1692 Location => Current_Location,
1693 Value => No_Array_Element,
1694 Next => Shared.Packages.Table (Pkg).Decl.Arrays);
1696 Shared.Packages.Table (Pkg).Decl.Arrays := New_Array;
1699 Shared.Arrays.Table (New_Array) :=
1700 (Name => Current_Item_Name,
1701 Location => Current_Location,
1702 Value => No_Array_Element,
1703 Next => Project.Decl.Arrays);
1705 Project.Decl.Arrays := New_Array;
1709 -- Find the project where the value is declared
1711 Orig_Project_Name :=
1713 (Associative_Project_Of (Current_Item, Node_Tree), Node_Tree);
1715 Prj := In_Tree.Projects;
1716 while Prj /= null loop
1717 if Prj.Project.Name = Orig_Project_Name then
1718 Orig_Project := Prj.Project;
1724 pragma Assert (Orig_Project /= No_Project,
1725 "original project not found");
1727 if No (Associative_Package_Of (Current_Item, Node_Tree)) then
1728 Orig_Array := Orig_Project.Decl.Arrays;
1731 -- If in a package, find the package where the value is declared
1733 Orig_Package_Name :=
1735 (Associative_Package_Of (Current_Item, Node_Tree), Node_Tree);
1737 Orig_Package := Orig_Project.Decl.Packages;
1738 pragma Assert (Orig_Package /= No_Package,
1739 "original package not found");
1741 while Shared.Packages.Table
1742 (Orig_Package).Name /= Orig_Package_Name
1744 Orig_Package := Shared.Packages.Table (Orig_Package).Next;
1745 pragma Assert (Orig_Package /= No_Package,
1746 "original package not found");
1749 Orig_Array := Shared.Packages.Table (Orig_Package).Decl.Arrays;
1752 -- Now look for the array
1754 while Orig_Array /= No_Array
1755 and then Shared.Arrays.Table (Orig_Array).Name /= Current_Item_Name
1757 Orig_Array := Shared.Arrays.Table (Orig_Array).Next;
1760 if Orig_Array = No_Array then
1763 "associative array value not found",
1764 Location_Of (Current_Item, Node_Tree),
1768 Orig_Element := Shared.Arrays.Table (Orig_Array).Value;
1770 -- Copy each array element
1772 while Orig_Element /= No_Array_Element loop
1774 -- Case of first element
1776 if Prev_Element = No_Array_Element then
1778 -- And there is no array element declared yet, create a new
1779 -- first array element.
1781 if Shared.Arrays.Table (New_Array).Value =
1784 Array_Element_Table.Increment_Last
1785 (Shared.Array_Elements);
1786 New_Element := Array_Element_Table.Last
1787 (Shared.Array_Elements);
1788 Shared.Arrays.Table (New_Array).Value := New_Element;
1789 Next_Element := No_Array_Element;
1791 -- Otherwise, the new element is the first
1794 New_Element := Shared.Arrays.Table (New_Array).Value;
1796 Shared.Array_Elements.Table (New_Element).Next;
1799 -- Otherwise, reuse an existing element, or create
1800 -- one if necessary.
1804 Shared.Array_Elements.Table (Prev_Element).Next;
1806 if Next_Element = No_Array_Element then
1807 Array_Element_Table.Increment_Last
1808 (Shared.Array_Elements);
1809 New_Element := Array_Element_Table.Last
1810 (Shared.Array_Elements);
1811 Shared.Array_Elements.Table (Prev_Element).Next :=
1815 New_Element := Next_Element;
1817 Shared.Array_Elements.Table (New_Element).Next;
1821 -- Copy the value of the element
1823 Shared.Array_Elements.Table (New_Element) :=
1824 Shared.Array_Elements.Table (Orig_Element);
1825 Shared.Array_Elements.Table (New_Element).Value.Project
1828 -- Adjust the Next link
1830 Shared.Array_Elements.Table (New_Element).Next := Next_Element;
1832 -- Adjust the previous id for the next element
1834 Prev_Element := New_Element;
1836 -- Go to the next element in the original array
1838 Orig_Element := Shared.Array_Elements.Table (Orig_Element).Next;
1841 -- Make sure that the array ends here, in case there previously a
1842 -- greater number of elements.
1844 Shared.Array_Elements.Table (New_Element).Next := No_Array_Element;
1846 end Process_Associative_Array;
1848 ----------------------------------------------
1849 -- Process_Expression_For_Associative_Array --
1850 ----------------------------------------------
1852 procedure Process_Expression_For_Associative_Array
1853 (Current : Project_Node_Id;
1854 New_Value : Variable_Value)
1856 Name : constant Name_Id := Name_Of (Current, Node_Tree);
1857 Current_Location : constant Source_Ptr :=
1858 Location_Of (Current, Node_Tree);
1860 Index_Name : Name_Id :=
1861 Associative_Array_Index_Of (Current, Node_Tree);
1863 Source_Index : constant Int :=
1864 Source_Index_Of (Current, Node_Tree);
1866 The_Array : Array_Id;
1867 Elem : Array_Element_Id := No_Array_Element;
1870 if Index_Name /= All_Other_Names then
1871 Index_Name := Get_Attribute_Index (Node_Tree, Current, Index_Name);
1874 -- Look for the array in the appropriate list
1876 if Pkg /= No_Package then
1877 The_Array := Shared.Packages.Table (Pkg).Decl.Arrays;
1879 The_Array := Project.Decl.Arrays;
1882 while The_Array /= No_Array
1883 and then Shared.Arrays.Table (The_Array).Name /= Name
1885 The_Array := Shared.Arrays.Table (The_Array).Next;
1888 -- If the array cannot be found, create a new entry in the list.
1889 -- As The_Array_Element is initialized to No_Array_Element, a new
1890 -- element will be created automatically later
1892 if The_Array = No_Array then
1893 Array_Table.Increment_Last (Shared.Arrays);
1894 The_Array := Array_Table.Last (Shared.Arrays);
1896 if Pkg /= No_Package then
1897 Shared.Arrays.Table (The_Array) :=
1899 Location => Current_Location,
1900 Value => No_Array_Element,
1901 Next => Shared.Packages.Table (Pkg).Decl.Arrays);
1903 Shared.Packages.Table (Pkg).Decl.Arrays := The_Array;
1906 Shared.Arrays.Table (The_Array) :=
1908 Location => Current_Location,
1909 Value => No_Array_Element,
1910 Next => Project.Decl.Arrays);
1912 Project.Decl.Arrays := The_Array;
1916 Elem := Shared.Arrays.Table (The_Array).Value;
1919 -- Look in the list, if any, to find an element with the same index
1920 -- and same source index.
1922 while Elem /= No_Array_Element
1924 (Shared.Array_Elements.Table (Elem).Index /= Index_Name
1926 Shared.Array_Elements.Table (Elem).Src_Index /= Source_Index)
1928 Elem := Shared.Array_Elements.Table (Elem).Next;
1931 -- If no such element were found, create a new one
1932 -- and insert it in the element list, with the
1935 if Elem = No_Array_Element then
1936 Array_Element_Table.Increment_Last (Shared.Array_Elements);
1937 Elem := Array_Element_Table.Last (Shared.Array_Elements);
1939 Shared.Array_Elements.Table
1941 (Index => Index_Name,
1942 Src_Index => Source_Index,
1943 Index_Case_Sensitive =>
1944 not Case_Insensitive (Current, Node_Tree),
1946 Next => Shared.Arrays.Table (The_Array).Value);
1948 Shared.Arrays.Table (The_Array).Value := Elem;
1951 -- An element with the same index already exists, just replace its
1952 -- value with the new one.
1954 Shared.Array_Elements.Table (Elem).Value := New_Value;
1957 if Name = Snames.Name_External then
1958 if In_Tree.Is_Root_Tree then
1959 Add (Child_Env.External,
1960 External_Name => Get_Name_String (Index_Name),
1961 Value => Get_Name_String (New_Value.Value),
1962 Source => From_External_Attribute);
1964 External_Name => Get_Name_String (Index_Name),
1965 Value => Get_Name_String (New_Value.Value),
1966 Source => From_External_Attribute);
1968 if Current_Verbosity = High then
1970 ("'for External' has no effect except in root aggregate ("
1971 & Get_Name_String (Index_Name) & ")", New_Value.Value);
1975 elsif Name = Snames.Name_Project_Path then
1977 ("Defined project path");
1979 end Process_Expression_For_Associative_Array;
1981 --------------------------------------
1982 -- Process_Expression_Variable_Decl --
1983 --------------------------------------
1985 procedure Process_Expression_Variable_Decl
1986 (Current_Item : Project_Node_Id;
1987 New_Value : Variable_Value)
1989 Name : constant Name_Id := Name_Of (Current_Item, Node_Tree);
1990 Var : Variable_Id := No_Variable;
1992 Is_Attribute : constant Boolean :=
1993 Kind_Of (Current_Item, Node_Tree) =
1994 N_Attribute_Declaration;
1997 -- First, find the list where to find the variable or attribute.
1999 if Is_Attribute then
2000 if Pkg /= No_Package then
2001 Var := Shared.Packages.Table (Pkg).Decl.Attributes;
2003 Var := Project.Decl.Attributes;
2007 if Pkg /= No_Package then
2008 Var := Shared.Packages.Table (Pkg).Decl.Variables;
2010 Var := Project.Decl.Variables;
2014 -- Loop through the list, to find if it has already been declared.
2016 while Var /= No_Variable
2017 and then Shared.Variable_Elements.Table (Var).Name /= Name
2019 Var := Shared.Variable_Elements.Table (Var).Next;
2022 -- If it has not been declared, create a new entry in the list
2024 if Var = No_Variable then
2026 -- All single string attribute should already have been declared
2027 -- with a default empty string value.
2031 "illegal attribute declaration for " & Get_Name_String (Name));
2033 Variable_Element_Table.Increment_Last (Shared.Variable_Elements);
2034 Var := Variable_Element_Table.Last (Shared.Variable_Elements);
2036 -- Put the new variable in the appropriate list
2038 if Pkg /= No_Package then
2039 Shared.Variable_Elements.Table (Var) :=
2040 (Next => Shared.Packages.Table (Pkg).Decl.Variables,
2042 Value => New_Value);
2043 Shared.Packages.Table (Pkg).Decl.Variables := Var;
2046 Shared.Variable_Elements.Table (Var) :=
2047 (Next => Project.Decl.Variables,
2049 Value => New_Value);
2050 Project.Decl.Variables := Var;
2053 -- If the variable/attribute has already been declared, just
2054 -- change the value.
2057 Shared.Variable_Elements.Table (Var).Value := New_Value;
2059 end Process_Expression_Variable_Decl;
2061 ------------------------
2062 -- Process_Expression --
2063 ------------------------
2065 procedure Process_Expression (Current : Project_Node_Id) is
2066 New_Value : Variable_Value :=
2068 (Project => Project,
2070 From_Project_Node => From_Project_Node,
2071 From_Project_Node_Tree => Node_Tree,
2076 (Expression_Of (Current, Node_Tree), Node_Tree),
2078 Expression_Kind_Of (Current, Node_Tree));
2081 -- Process a typed variable declaration
2083 if Kind_Of (Current, Node_Tree) = N_Typed_Variable_Declaration then
2084 Check_Or_Set_Typed_Variable (New_Value, Current);
2087 if Kind_Of (Current, Node_Tree) /= N_Attribute_Declaration
2088 or else Associative_Array_Index_Of (Current, Node_Tree) = No_Name
2090 Process_Expression_Variable_Decl (Current, New_Value);
2092 Process_Expression_For_Associative_Array (Current, New_Value);
2094 end Process_Expression;
2096 -----------------------------------
2097 -- Process_Attribute_Declaration --
2098 -----------------------------------
2100 procedure Process_Attribute_Declaration (Current : Project_Node_Id) is
2102 if Expression_Of (Current, Node_Tree) = Empty_Node then
2103 Process_Associative_Array (Current);
2105 Process_Expression (Current);
2107 end Process_Attribute_Declaration;
2109 -------------------------------
2110 -- Process_Case_Construction --
2111 -------------------------------
2113 procedure Process_Case_Construction
2114 (Current_Item : Project_Node_Id)
2116 The_Project : Project_Id := Project;
2117 -- The id of the project of the case variable
2119 The_Package : Package_Id := Pkg;
2120 -- The id of the package, if any, of the case variable
2122 The_Variable : Variable_Value := Nil_Variable_Value;
2123 -- The case variable
2125 Case_Value : Name_Id := No_Name;
2126 -- The case variable value
2128 Case_Item : Project_Node_Id := Empty_Node;
2129 Choice_String : Project_Node_Id := Empty_Node;
2130 Decl_Item : Project_Node_Id := Empty_Node;
2134 Variable_Node : constant Project_Node_Id :=
2135 Case_Variable_Reference_Of
2139 Var_Id : Variable_Id := No_Variable;
2140 Name : Name_Id := No_Name;
2143 -- If a project was specified for the case variable, get its id
2145 if Present (Project_Node_Of (Variable_Node, Node_Tree)) then
2148 (Project_Node_Of (Variable_Node, Node_Tree), Node_Tree);
2150 Imported_Or_Extended_Project_From (Project, Name);
2153 -- If a package was specified for the case variable, get its id
2155 if Present (Package_Node_Of (Variable_Node, Node_Tree)) then
2158 (Package_Node_Of (Variable_Node, Node_Tree), Node_Tree);
2159 The_Package := Package_From (The_Project, Shared, Name);
2162 Name := Name_Of (Variable_Node, Node_Tree);
2164 -- First, look for the case variable into the package, if any
2166 if The_Package /= No_Package then
2167 Name := Name_Of (Variable_Node, Node_Tree);
2169 Var_Id := Shared.Packages.Table (The_Package).Decl.Variables;
2170 while Var_Id /= No_Variable
2171 and then Shared.Variable_Elements.Table (Var_Id).Name /= Name
2173 Var_Id := Shared.Variable_Elements.Table (Var_Id).Next;
2177 -- If not found in the package, or if there is no package, look at
2178 -- the project level.
2180 if Var_Id = No_Variable
2181 and then No (Package_Node_Of (Variable_Node, Node_Tree))
2183 Var_Id := The_Project.Decl.Variables;
2184 while Var_Id /= No_Variable
2185 and then Shared.Variable_Elements.Table (Var_Id).Name /= Name
2187 Var_Id := Shared.Variable_Elements.Table (Var_Id).Next;
2191 if Var_Id = No_Variable then
2193 -- Should never happen, because this has already been checked
2197 ("variable """ & Get_Name_String (Name) & """ not found");
2198 raise Program_Error;
2201 -- Get the case variable
2203 The_Variable := Shared.Variable_Elements. Table (Var_Id).Value;
2205 if The_Variable.Kind /= Single then
2207 -- Should never happen, because this has already been checked
2210 Write_Line ("variable""" & Get_Name_String (Name) &
2211 """ is not a single string variable");
2212 raise Program_Error;
2215 -- Get the case variable value
2217 Case_Value := The_Variable.Value;
2220 -- Now look into all the case items of the case construction
2222 Case_Item := First_Case_Item_Of (Current_Item, Node_Tree);
2225 while Present (Case_Item) loop
2226 Choice_String := First_Choice_Of (Case_Item, Node_Tree);
2228 -- When Choice_String is nil, it means that it is the
2229 -- "when others =>" alternative.
2231 if No (Choice_String) then
2232 Decl_Item := First_Declarative_Item_Of (Case_Item, Node_Tree);
2233 exit Case_Item_Loop;
2236 -- Look into all the alternative of this case item
2239 while Present (Choice_String) loop
2240 if Case_Value = String_Value_Of (Choice_String, Node_Tree) then
2242 First_Declarative_Item_Of (Case_Item, Node_Tree);
2243 exit Case_Item_Loop;
2246 Choice_String := Next_Literal_String (Choice_String, Node_Tree);
2247 end loop Choice_Loop;
2249 Case_Item := Next_Case_Item (Case_Item, Node_Tree);
2250 end loop Case_Item_Loop;
2252 -- If there is an alternative, then we process it
2254 if Present (Decl_Item) then
2255 Process_Declarative_Items
2256 (Project => Project,
2258 From_Project_Node => From_Project_Node,
2259 Node_Tree => Node_Tree,
2263 Child_Env => Child_Env);
2265 end Process_Case_Construction;
2269 Current, Decl : Project_Node_Id;
2270 Kind : Project_Node_Kind;
2272 -- Start of processing for Process_Declarative_Items
2276 while Present (Decl) loop
2277 Current := Current_Item_Node (Decl, Node_Tree);
2278 Decl := Next_Declarative_Item (Decl, Node_Tree);
2279 Kind := Kind_Of (Current, Node_Tree);
2282 when N_Package_Declaration =>
2283 Process_Package_Declaration (Current);
2285 -- Nothing to process for string type declaration
2287 when N_String_Type_Declaration =>
2290 when N_Attribute_Declaration |
2291 N_Typed_Variable_Declaration |
2292 N_Variable_Declaration =>
2293 Process_Attribute_Declaration (Current);
2295 when N_Case_Construction =>
2296 Process_Case_Construction (Current);
2299 Write_Line ("Illegal declarative item: " & Kind'Img);
2300 raise Program_Error;
2303 end Process_Declarative_Items;
2305 ----------------------------------
2306 -- Process_Project_Tree_Phase_1 --
2307 ----------------------------------
2309 procedure Process_Project_Tree_Phase_1
2310 (In_Tree : Project_Tree_Ref;
2311 Project : out Project_Id;
2312 Success : out Boolean;
2313 From_Project_Node : Project_Node_Id;
2314 From_Project_Node_Tree : Project_Node_Tree_Ref;
2315 Env : in out Prj.Tree.Environment;
2316 Reset_Tree : Boolean := True)
2321 -- Make sure there are no projects in the data structure
2323 Free_List (In_Tree.Projects, Free_Project => True);
2326 Processed_Projects.Reset;
2328 -- And process the main project and all of the projects it depends on,
2331 Debug_Increase_Indent ("Process tree, phase 1");
2334 (Project => Project,
2336 From_Project_Node => From_Project_Node,
2337 From_Project_Node_Tree => From_Project_Node_Tree,
2339 Extended_By => No_Project);
2342 Total_Errors_Detected = 0
2344 (Warning_Mode /= Treat_As_Error or else Warnings_Detected = 0);
2346 if Current_Verbosity = High then
2347 Debug_Decrease_Indent ("Done Process tree, phase 1, Success="
2350 end Process_Project_Tree_Phase_1;
2352 ----------------------------------
2353 -- Process_Project_Tree_Phase_2 --
2354 ----------------------------------
2356 procedure Process_Project_Tree_Phase_2
2357 (In_Tree : Project_Tree_Ref;
2358 Project : Project_Id;
2359 Success : out Boolean;
2360 From_Project_Node : Project_Node_Id;
2361 From_Project_Node_Tree : Project_Node_Tree_Ref;
2364 Obj_Dir : Path_Name_Type;
2365 Extending : Project_Id;
2366 Extending2 : Project_Id;
2369 -- Start of processing for Process_Project_Tree_Phase_2
2374 Debug_Increase_Indent ("Process tree, phase 2", Project.Name);
2376 if Project /= No_Project then
2377 Check (In_Tree, Project, From_Project_Node_Tree, Env.Flags);
2380 -- If main project is an extending all project, set object directory of
2381 -- all virtual extending projects to object directory of main project.
2383 if Project /= No_Project
2385 Is_Extending_All (From_Project_Node, From_Project_Node_Tree)
2388 Object_Dir : constant Path_Information :=
2389 Project.Object_Directory;
2392 Prj := In_Tree.Projects;
2393 while Prj /= null loop
2394 if Prj.Project.Virtual then
2395 Prj.Project.Object_Directory := Object_Dir;
2403 -- Check that no extending project shares its object directory with
2404 -- the project(s) it extends.
2406 if Project /= No_Project then
2407 Prj := In_Tree.Projects;
2408 while Prj /= null loop
2409 Extending := Prj.Project.Extended_By;
2411 if Extending /= No_Project then
2412 Obj_Dir := Prj.Project.Object_Directory.Name;
2414 -- Check that a project being extended does not share its
2415 -- object directory with any project that extends it, directly
2416 -- or indirectly, including a virtual extending project.
2418 -- Start with the project directly extending it
2420 Extending2 := Extending;
2421 while Extending2 /= No_Project loop
2422 if Has_Ada_Sources (Extending2)
2423 and then Extending2.Object_Directory.Name = Obj_Dir
2425 if Extending2.Virtual then
2426 Error_Msg_Name_1 := Prj.Project.Display_Name;
2429 "project %% cannot be extended by a virtual" &
2430 " project with the same object directory",
2431 Prj.Project.Location, Project);
2434 Error_Msg_Name_1 := Extending2.Display_Name;
2435 Error_Msg_Name_2 := Prj.Project.Display_Name;
2438 "project %% cannot extend project %%",
2439 Extending2.Location, Project);
2442 "\they share the same object directory",
2443 Extending2.Location, Project);
2447 -- Continue with the next extending project, if any
2449 Extending2 := Extending2.Extended_By;
2457 Debug_Decrease_Indent ("Done Process tree, phase 2");
2460 Total_Errors_Detected = 0
2462 (Warning_Mode /= Treat_As_Error or else Warnings_Detected = 0);
2463 end Process_Project_Tree_Phase_2;
2465 -----------------------
2466 -- Recursive_Process --
2467 -----------------------
2469 procedure Recursive_Process
2470 (In_Tree : Project_Tree_Ref;
2471 Project : out Project_Id;
2472 From_Project_Node : Project_Node_Id;
2473 From_Project_Node_Tree : Project_Node_Tree_Ref;
2474 Env : in out Prj.Tree.Environment;
2475 Extended_By : Project_Id)
2477 Shared : constant Shared_Project_Tree_Data_Access :=
2480 Child_Env : Prj.Tree.Environment;
2481 -- Only used for the root aggregate project (if any). This is left
2482 -- uninitialized otherwise.
2484 procedure Process_Imported_Projects
2485 (Imported : in out Project_List;
2486 Limited_With : Boolean);
2487 -- Process imported projects. If Limited_With is True, then only
2488 -- projects processed through a "limited with" are processed, otherwise
2489 -- only projects imported through a standard "with" are processed.
2490 -- Imported is the id of the last imported project.
2492 procedure Process_Aggregated_Projects;
2493 -- Process all the projects aggregated in List. This does nothing if the
2494 -- project is not an aggregate project.
2496 procedure Process_Extended_Project;
2497 -- Process the extended project: inherit all packages from the extended
2498 -- project that are not explicitly defined or renamed. Also inherit the
2499 -- languages, if attribute Languages is not explicitly defined.
2501 -------------------------------
2502 -- Process_Imported_Projects --
2503 -------------------------------
2505 procedure Process_Imported_Projects
2506 (Imported : in out Project_List;
2507 Limited_With : Boolean)
2509 With_Clause : Project_Node_Id;
2510 New_Project : Project_Id;
2511 Proj_Node : Project_Node_Id;
2515 First_With_Clause_Of
2516 (From_Project_Node, From_Project_Node_Tree);
2518 while Present (With_Clause) loop
2520 Non_Limited_Project_Node_Of
2521 (With_Clause, From_Project_Node_Tree);
2522 New_Project := No_Project;
2524 if (Limited_With and then No (Proj_Node))
2525 or else (not Limited_With and then Present (Proj_Node))
2528 (In_Tree => In_Tree,
2529 Project => New_Project,
2530 From_Project_Node =>
2532 (With_Clause, From_Project_Node_Tree),
2533 From_Project_Node_Tree => From_Project_Node_Tree,
2535 Extended_By => No_Project);
2537 -- Imported is the id of the last imported project. If
2538 -- it is nil, then this imported project is our first.
2540 if Imported = null then
2541 Project.Imported_Projects :=
2542 new Project_List_Element'
2543 (Project => New_Project,
2545 Imported := Project.Imported_Projects;
2547 Imported.Next := new Project_List_Element'
2548 (Project => New_Project,
2550 Imported := Imported.Next;
2555 Next_With_Clause_Of (With_Clause, From_Project_Node_Tree);
2557 end Process_Imported_Projects;
2559 ---------------------------------
2560 -- Process_Aggregated_Projects --
2561 ---------------------------------
2563 procedure Process_Aggregated_Projects is
2564 List : Aggregated_Project_List;
2565 Loaded_Project : Prj.Tree.Project_Node_Id;
2566 Success : Boolean := True;
2568 if Project.Qualifier /= Aggregate then
2572 Debug_Increase_Indent ("Process_Aggregated_Projects", Project.Name);
2574 Prj.Nmsc.Process_Aggregated_Projects
2577 Node_Tree => From_Project_Node_Tree,
2578 Flags => Env.Flags);
2580 List := Project.Aggregated_Projects;
2581 while Success and then List /= null loop
2583 (In_Tree => From_Project_Node_Tree,
2584 Project => Loaded_Project,
2585 Project_File_Name => Get_Name_String (List.Path),
2586 Errout_Handling => Prj.Part.Never_Finalize,
2587 Current_Directory => Get_Name_String (Project.Directory.Name),
2588 Is_Config_File => False,
2591 Success := not Prj.Tree.No (Loaded_Project);
2594 List.Tree := new Project_Tree_Data (Is_Root_Tree => False);
2595 Prj.Initialize (List.Tree);
2596 List.Tree.Shared := In_Tree.Shared;
2598 -- We can only do the phase 1 of the processing, since we do
2599 -- not have access to the configuration file yet (this is
2600 -- called when doing phase 1 of the processing for the root
2601 -- aggregate project).
2603 if In_Tree.Is_Root_Tree then
2604 Process_Project_Tree_Phase_1
2605 (In_Tree => List.Tree,
2606 Project => List.Project,
2608 From_Project_Node => Loaded_Project,
2609 From_Project_Node_Tree => From_Project_Node_Tree,
2611 Reset_Tree => False);
2613 -- use the same environment as the rest of the aggregated
2614 -- projects, ie the one that was setup by the root aggregate
2615 Process_Project_Tree_Phase_1
2616 (In_Tree => List.Tree,
2617 Project => List.Project,
2619 From_Project_Node => Loaded_Project,
2620 From_Project_Node_Tree => From_Project_Node_Tree,
2622 Reset_Tree => False);
2625 Debug_Output ("Failed to parse", Name_Id (List.Path));
2631 Debug_Decrease_Indent ("Done Process_Aggregated_Projects");
2632 end Process_Aggregated_Projects;
2634 ------------------------------
2635 -- Process_Extended_Project --
2636 ------------------------------
2638 procedure Process_Extended_Project is
2639 Extended_Pkg : Package_Id;
2640 Current_Pkg : Package_Id;
2641 Element : Package_Element;
2642 First : constant Package_Id := Project.Decl.Packages;
2643 Attribute1 : Variable_Id;
2644 Attribute2 : Variable_Id;
2645 Attr_Value1 : Variable;
2646 Attr_Value2 : Variable;
2649 Extended_Pkg := Project.Extends.Decl.Packages;
2650 while Extended_Pkg /= No_Package loop
2651 Element := Shared.Packages.Table (Extended_Pkg);
2653 Current_Pkg := First;
2654 while Current_Pkg /= No_Package
2655 and then Shared.Packages.Table (Current_Pkg).Name /=
2658 Current_Pkg := Shared.Packages.Table (Current_Pkg).Next;
2661 if Current_Pkg = No_Package then
2662 Package_Table.Increment_Last (Shared.Packages);
2663 Current_Pkg := Package_Table.Last (Shared.Packages);
2664 Shared.Packages.Table (Current_Pkg) :=
2665 (Name => Element.Name,
2666 Decl => No_Declarations,
2667 Parent => No_Package,
2668 Next => Project.Decl.Packages);
2669 Project.Decl.Packages := Current_Pkg;
2670 Copy_Package_Declarations
2671 (From => Element.Decl,
2672 To => Shared.Packages.Table (Current_Pkg).Decl,
2673 New_Loc => No_Location,
2678 Extended_Pkg := Element.Next;
2681 -- Check if attribute Languages is declared in the extending project
2683 Attribute1 := Project.Decl.Attributes;
2684 while Attribute1 /= No_Variable loop
2685 Attr_Value1 := Shared.Variable_Elements. Table (Attribute1);
2686 exit when Attr_Value1.Name = Snames.Name_Languages;
2687 Attribute1 := Attr_Value1.Next;
2690 if Attribute1 = No_Variable
2691 or else Attr_Value1.Value.Default
2693 -- Attribute Languages is not declared in the extending project.
2694 -- Check if it is declared in the project being extended.
2696 Attribute2 := Project.Extends.Decl.Attributes;
2697 while Attribute2 /= No_Variable loop
2698 Attr_Value2 := Shared.Variable_Elements.Table (Attribute2);
2699 exit when Attr_Value2.Name = Snames.Name_Languages;
2700 Attribute2 := Attr_Value2.Next;
2703 if Attribute2 /= No_Variable and then
2704 not Attr_Value2.Value.Default
2706 -- As attribute Languages is declared in the project being
2707 -- extended, copy its value for the extending project.
2709 if Attribute1 = No_Variable then
2710 Variable_Element_Table.Increment_Last
2711 (Shared.Variable_Elements);
2712 Attribute1 := Variable_Element_Table.Last
2713 (Shared.Variable_Elements);
2714 Attr_Value1.Next := Project.Decl.Attributes;
2715 Project.Decl.Attributes := Attribute1;
2718 Attr_Value1.Name := Snames.Name_Languages;
2719 Attr_Value1.Value := Attr_Value2.Value;
2720 Shared.Variable_Elements.Table (Attribute1) := Attr_Value1;
2723 end Process_Extended_Project;
2725 -- Start of processing for Recursive_Process
2728 if No (From_Project_Node) then
2729 Project := No_Project;
2733 Imported : Project_List;
2734 Declaration_Node : Project_Node_Id := Empty_Node;
2736 Name : constant Name_Id :=
2737 Name_Of (From_Project_Node, From_Project_Node_Tree);
2739 Name_Node : constant Tree_Private_Part.Project_Name_And_Node :=
2740 Tree_Private_Part.Projects_Htable.Get
2741 (From_Project_Node_Tree.Projects_HT, Name);
2744 Project := Processed_Projects.Get (Name);
2746 if Project /= No_Project then
2748 -- Make sure that, when a project is extended, the project id
2749 -- of the project extending it is recorded in its data, even
2750 -- when it has already been processed as an imported project.
2751 -- This is for virtually extended projects.
2753 if Extended_By /= No_Project then
2754 Project.Extended_By := Extended_By;
2760 Project := new Project_Data'
2762 (Project_Qualifier_Of
2763 (From_Project_Node, From_Project_Node_Tree)));
2764 In_Tree.Projects := new Project_List_Element'
2765 (Project => Project,
2766 Next => In_Tree.Projects);
2768 Processed_Projects.Set (Name, Project);
2770 Project.Name := Name;
2771 Project.Display_Name := Name_Node.Display_Name;
2772 Get_Name_String (Name);
2774 -- If name starts with the virtual prefix, flag the project as
2775 -- being a virtual extending project.
2777 if Name_Len > Virtual_Prefix'Length
2778 and then Name_Buffer (1 .. Virtual_Prefix'Length) =
2781 Project.Virtual := True;
2784 Project.Path.Display_Name :=
2785 Path_Name_Of (From_Project_Node, From_Project_Node_Tree);
2786 Get_Name_String (Project.Path.Display_Name);
2787 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2788 Project.Path.Name := Name_Find;
2791 Location_Of (From_Project_Node, From_Project_Node_Tree);
2793 Project.Directory.Display_Name :=
2794 Directory_Of (From_Project_Node, From_Project_Node_Tree);
2795 Get_Name_String (Project.Directory.Display_Name);
2796 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2797 Project.Directory.Name := Name_Find;
2799 Project.Extended_By := Extended_By;
2804 Name_Id (Project.Directory.Name),
2807 Prj.Attr.Attribute_First,
2808 Project_Level => True);
2810 Process_Imported_Projects (Imported, Limited_With => False);
2812 if Project.Qualifier = Aggregate
2813 and then In_Tree.Is_Root_Tree
2815 Initialize_And_Copy (Child_Env, Copy_From => Env);
2817 -- No need to initialize Child_Env, since it will not be
2818 -- used anyway by Process_Declarative_Items (only the root
2819 -- aggregate can modify it, and it is never read anyway).
2824 Project_Declaration_Of
2825 (From_Project_Node, From_Project_Node_Tree);
2828 (In_Tree => In_Tree,
2829 Project => Project.Extends,
2830 From_Project_Node => Extended_Project_Of
2831 (Declaration_Node, From_Project_Node_Tree),
2832 From_Project_Node_Tree => From_Project_Node_Tree,
2834 Extended_By => Project);
2836 Process_Declarative_Items
2837 (Project => Project,
2839 From_Project_Node => From_Project_Node,
2840 Node_Tree => From_Project_Node_Tree,
2843 Item => First_Declarative_Item_Of
2844 (Declaration_Node, From_Project_Node_Tree),
2845 Child_Env => Child_Env);
2847 if Project.Extends /= No_Project then
2848 Process_Extended_Project;
2851 Process_Imported_Projects (Imported, Limited_With => True);
2853 if Err_Vars.Total_Errors_Detected = 0 then
2854 Process_Aggregated_Projects;
2857 if Project.Qualifier = Aggregate
2858 and then In_Tree.Is_Root_Tree
2864 end Recursive_Process;