1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2012, 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
;
32 with Prj
.Err
; use Prj
.Err
;
33 with Prj
.Ext
; use Prj
.Ext
;
34 with Prj
.Nmsc
; use Prj
.Nmsc
;
39 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
41 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
44 package body Prj
.Proc
is
46 package Processed_Projects
is new GNAT
.HTable
.Simple_HTable
47 (Header_Num
=> Header_Num
,
48 Element
=> Project_Id
,
49 No_Element
=> No_Project
,
53 -- This hash table contains all processed projects
55 package Unit_Htable
is new GNAT
.HTable
.Simple_HTable
56 (Header_Num
=> Header_Num
,
58 No_Element
=> No_Source
,
62 -- This hash table contains all processed projects
64 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
);
65 -- Concatenate two strings and returns another string if both
66 -- arguments are not null string.
68 -- In the following procedures, we are expected to guess the meaning of
69 -- the parameters from their names, this is never a good idea, comments
70 -- should be added precisely defining every formal ???
72 procedure Add_Attributes
73 (Project
: Project_Id
;
74 Project_Name
: Name_Id
;
75 Project_Dir
: Name_Id
;
76 Shared
: Shared_Project_Tree_Data_Access
;
77 Decl
: in out Declarations
;
78 First
: Attribute_Node_Id
;
79 Project_Level
: Boolean);
80 -- Add all attributes, starting with First, with their default values to
81 -- the package or project with declarations Decl.
84 (In_Tree
: Project_Tree_Ref
;
86 Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
87 Flags
: Processing_Flags
);
88 -- Set all projects to not checked, then call Recursive_Check for the
89 -- main project Project. Project is set to No_Project if errors occurred.
90 -- Current_Dir is for optimization purposes, avoiding extra system calls.
91 -- If Allow_Duplicate_Basenames, then files with the same base names are
92 -- authorized within a project for source-based languages (never for unit
95 procedure Copy_Package_Declarations
97 To
: in out Declarations
;
100 Shared
: Shared_Project_Tree_Data_Access
);
101 -- Copy a package declaration From to To for a renamed package. Change the
102 -- locations of all the attributes to New_Loc. When Restricted is
103 -- True, do not copy attributes Body, Spec, Implementation, Specification
104 -- and Linker_Options.
107 (Project
: Project_Id
;
108 Shared
: Shared_Project_Tree_Data_Access
;
109 From_Project_Node
: Project_Node_Id
;
110 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
111 Env
: Prj
.Tree
.Environment
;
113 First_Term
: Project_Node_Id
;
114 Kind
: Variable_Kind
) return Variable_Value
;
115 -- From N_Expression project node From_Project_Node, compute the value
116 -- of an expression and return it as a Variable_Value.
118 function Imported_Or_Extended_Project_From
119 (Project
: Project_Id
;
120 With_Name
: Name_Id
) return Project_Id
;
121 -- Find an imported or extended project of Project whose name is With_Name
123 function Package_From
124 (Project
: Project_Id
;
125 Shared
: Shared_Project_Tree_Data_Access
;
126 With_Name
: Name_Id
) return Package_Id
;
127 -- Find the package of Project whose name is With_Name
129 procedure Process_Declarative_Items
130 (Project
: Project_Id
;
131 In_Tree
: Project_Tree_Ref
;
132 From_Project_Node
: Project_Node_Id
;
133 Node_Tree
: Project_Node_Tree_Ref
;
134 Env
: Prj
.Tree
.Environment
;
136 Item
: Project_Node_Id
;
137 Child_Env
: in out Prj
.Tree
.Environment
);
138 -- Process declarative items starting with From_Project_Node, and put them
139 -- in declarations Decl. This is a recursive procedure; it calls itself for
140 -- a package declaration or a case construction.
142 -- Child_Env is the modified environment after seeing declarations like
143 -- "for External(...) use" or "for Project_Path use" in aggregate projects.
144 -- It should have been initialized first.
146 procedure Recursive_Process
147 (In_Tree
: Project_Tree_Ref
;
148 Project
: out Project_Id
;
149 Packages_To_Check
: String_List_Access
;
150 From_Project_Node
: Project_Node_Id
;
151 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
152 Env
: in out Prj
.Tree
.Environment
;
153 Extended_By
: Project_Id
;
154 From_Encapsulated_Lib
: Boolean);
155 -- Process project with node From_Project_Node in the tree. Do nothing if
156 -- From_Project_Node is Empty_Node. If project has already been processed,
157 -- simply return its project id. Otherwise create a new project id, mark it
158 -- as processed, call itself recursively for all imported projects and a
159 -- extended project, if any. Then process the declarative items of the
162 -- Is_Root_Project should be true only for the project that the user
163 -- explicitly loaded. In the context of aggregate projects, only that
164 -- project is allowed to modify the environment that will be used to load
165 -- projects (Child_Env).
167 -- From_Encapsulated_Lib is true if we are parsing a project from
168 -- encapsulated library dependencies.
170 function Get_Attribute_Index
171 (Tree
: Project_Node_Tree_Ref
;
172 Attr
: Project_Node_Id
;
173 Index
: Name_Id
) return Name_Id
;
174 -- Copy the index of the attribute into Name_Buffer, converting to lower
175 -- case if the attribute is case-insensitive.
181 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
) is
183 if To_Exp
= No_Name
or else To_Exp
= Empty_String
then
185 -- To_Exp is nil or empty. The result is Str
189 -- If Str is nil, then do not change To_Ext
191 elsif Str
/= No_Name
and then Str
/= Empty_String
then
193 S
: constant String := Get_Name_String
(Str
);
195 Get_Name_String
(To_Exp
);
196 Add_Str_To_Name_Buffer
(S
);
206 procedure Add_Attributes
207 (Project
: Project_Id
;
208 Project_Name
: Name_Id
;
209 Project_Dir
: Name_Id
;
210 Shared
: Shared_Project_Tree_Data_Access
;
211 Decl
: in out Declarations
;
212 First
: Attribute_Node_Id
;
213 Project_Level
: Boolean)
215 The_Attribute
: Attribute_Node_Id
:= First
;
218 while The_Attribute
/= Empty_Attribute
loop
219 if Attribute_Kind_Of
(The_Attribute
) = Single
then
221 New_Attribute
: Variable_Value
;
224 case Variable_Kind_Of
(The_Attribute
) is
226 -- Undefined should not happen
230 (False, "attribute with an undefined kind");
233 -- Single attributes have a default value of empty string
239 Location
=> No_Location
,
241 Value
=> Empty_String
,
244 -- Special cases of <project>'Name and
245 -- <project>'Project_Dir.
247 if Project_Level
then
248 if Attribute_Name_Of
(The_Attribute
) =
251 New_Attribute
.Value
:= Project_Name
;
253 elsif Attribute_Name_Of
(The_Attribute
) =
254 Snames
.Name_Project_Dir
256 New_Attribute
.Value
:= Project_Dir
;
260 -- List attributes have a default value of nil list
266 Location
=> No_Location
,
268 Values
=> Nil_String
);
272 Variable_Element_Table
.Increment_Last
273 (Shared
.Variable_Elements
);
274 Shared
.Variable_Elements
.Table
275 (Variable_Element_Table
.Last
(Shared
.Variable_Elements
)) :=
276 (Next
=> Decl
.Attributes
,
277 Name
=> Attribute_Name_Of
(The_Attribute
),
278 Value
=> New_Attribute
);
280 Variable_Element_Table
.Last
281 (Shared
.Variable_Elements
);
285 The_Attribute
:= Next_Attribute
(After
=> The_Attribute
);
294 (In_Tree
: Project_Tree_Ref
;
295 Project
: Project_Id
;
296 Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
297 Flags
: Processing_Flags
)
300 Process_Naming_Scheme
(In_Tree
, Project
, Node_Tree
, Flags
);
302 -- Set the Other_Part field for the units
308 Iter
: Source_Iterator
;
313 Iter
:= For_Each_Source
(In_Tree
);
315 Source1
:= Prj
.Element
(Iter
);
316 exit when Source1
= No_Source
;
318 if Source1
.Unit
/= No_Unit_Index
then
319 Name
:= Source1
.Unit
.Name
;
320 Source2
:= Unit_Htable
.Get
(Name
);
322 if Source2
= No_Source
then
323 Unit_Htable
.Set
(K
=> Name
, E
=> Source1
);
325 Unit_Htable
.Remove
(Name
);
334 -------------------------------
335 -- Copy_Package_Declarations --
336 -------------------------------
338 procedure Copy_Package_Declarations
339 (From
: Declarations
;
340 To
: in out Declarations
;
341 New_Loc
: Source_Ptr
;
342 Restricted
: Boolean;
343 Shared
: Shared_Project_Tree_Data_Access
)
346 V2
: Variable_Id
:= No_Variable
;
349 A2
: Array_Id
:= No_Array
;
351 E1
: Array_Element_Id
;
352 E2
: Array_Element_Id
:= No_Array_Element
;
356 -- To avoid references in error messages to attribute declarations in
357 -- an original package that has been renamed, copy all the attribute
358 -- declarations of the package and change all locations to New_Loc,
359 -- the location of the renamed package.
361 -- First single attributes
363 V1
:= From
.Attributes
;
364 while V1
/= No_Variable
loop
366 -- Copy the attribute
368 Var
:= Shared
.Variable_Elements
.Table
(V1
);
371 -- Do not copy the value of attribute Linker_Options if Restricted
373 if Restricted
and then Var
.Name
= Snames
.Name_Linker_Options
then
374 Var
.Value
.Values
:= Nil_String
;
377 -- Remove the Next component
379 Var
.Next
:= No_Variable
;
381 -- Change the location to New_Loc
383 Var
.Value
.Location
:= New_Loc
;
384 Variable_Element_Table
.Increment_Last
(Shared
.Variable_Elements
);
386 -- Put in new declaration
388 if To
.Attributes
= No_Variable
then
390 Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
392 Shared
.Variable_Elements
.Table
(V2
).Next
:=
393 Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
396 V2
:= Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
397 Shared
.Variable_Elements
.Table
(V2
) := Var
;
400 -- Then the associated array attributes
403 while A1
/= No_Array
loop
404 Arr
:= Shared
.Arrays
.Table
(A1
);
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 Elm
.Restricted
:= Restricted
;
442 -- Change the location
444 Elm
.Value
.Location
:= New_Loc
;
445 Array_Element_Table
.Increment_Last
(Shared
.Array_Elements
);
447 -- Create new array element
449 if Arr
.Value
= No_Array_Element
then
450 Arr
.Value
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
452 Shared
.Array_Elements
.Table
(E2
).Next
:=
453 Array_Element_Table
.Last
(Shared
.Array_Elements
);
456 E2
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
457 Shared
.Array_Elements
.Table
(E2
) := Elm
;
460 -- Finally, store the new array
462 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
)
695 and then 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
1341 ("package """ & Get_Name_String
(With_Name
) & """ not found");
1342 raise Program_Error
;
1354 (In_Tree
: Project_Tree_Ref
;
1355 Project
: out Project_Id
;
1356 Packages_To_Check
: String_List_Access
;
1357 Success
: out Boolean;
1358 From_Project_Node
: Project_Node_Id
;
1359 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
1360 Env
: in out Prj
.Tree
.Environment
;
1361 Reset_Tree
: Boolean := True)
1364 Process_Project_Tree_Phase_1
1365 (In_Tree
=> In_Tree
,
1368 From_Project_Node
=> From_Project_Node
,
1369 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1371 Packages_To_Check
=> Packages_To_Check
,
1372 Reset_Tree
=> Reset_Tree
);
1374 if Project_Qualifier_Of
1375 (From_Project_Node
, From_Project_Node_Tree
) /= Configuration
1377 Process_Project_Tree_Phase_2
1378 (In_Tree
=> In_Tree
,
1381 From_Project_Node
=> From_Project_Node
,
1382 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1387 -------------------------------
1388 -- Process_Declarative_Items --
1389 -------------------------------
1391 procedure Process_Declarative_Items
1392 (Project
: Project_Id
;
1393 In_Tree
: Project_Tree_Ref
;
1394 From_Project_Node
: Project_Node_Id
;
1395 Node_Tree
: Project_Node_Tree_Ref
;
1396 Env
: Prj
.Tree
.Environment
;
1398 Item
: Project_Node_Id
;
1399 Child_Env
: in out Prj
.Tree
.Environment
)
1401 Shared
: constant Shared_Project_Tree_Data_Access
:= In_Tree
.Shared
;
1403 procedure Check_Or_Set_Typed_Variable
1404 (Value
: in out Variable_Value
;
1405 Declaration
: Project_Node_Id
);
1406 -- Check whether Value is valid for this typed variable declaration. If
1407 -- it is an error, the behavior depends on the flags: either an error is
1408 -- reported, or a warning, or nothing. In the last two cases, the value
1409 -- of the variable is set to a valid value, replacing Value.
1411 procedure Process_Package_Declaration
1412 (Current_Item
: Project_Node_Id
);
1413 procedure Process_Attribute_Declaration
1414 (Current
: Project_Node_Id
);
1415 procedure Process_Case_Construction
1416 (Current_Item
: Project_Node_Id
);
1417 procedure Process_Associative_Array
1418 (Current_Item
: Project_Node_Id
);
1419 procedure Process_Expression
1420 (Current
: Project_Node_Id
);
1421 procedure Process_Expression_For_Associative_Array
1422 (Current
: Project_Node_Id
;
1423 New_Value
: Variable_Value
);
1424 procedure Process_Expression_Variable_Decl
1425 (Current_Item
: Project_Node_Id
;
1426 New_Value
: Variable_Value
);
1427 -- Process the various declarative items
1429 ---------------------------------
1430 -- Check_Or_Set_Typed_Variable --
1431 ---------------------------------
1433 procedure Check_Or_Set_Typed_Variable
1434 (Value
: in out Variable_Value
;
1435 Declaration
: Project_Node_Id
)
1437 Loc
: constant Source_Ptr
:= Location_Of
(Declaration
, Node_Tree
);
1439 Reset_Value
: Boolean := False;
1440 Current_String
: Project_Node_Id
;
1443 -- Report an error for an empty string
1445 if Value
.Value
= Empty_String
then
1446 Error_Msg_Name_1
:= Name_Of
(Declaration
, Node_Tree
);
1448 case Env
.Flags
.Allow_Invalid_External
is
1451 (Env
.Flags
, "no value defined for %%", Loc
, Project
);
1453 Reset_Value
:= True;
1455 (Env
.Flags
, "?no value defined for %%", Loc
, Project
);
1457 Reset_Value
:= True;
1461 -- Loop through all the valid strings for the
1462 -- string type and compare to the string value.
1465 First_Literal_String
1466 (String_Type_Of
(Declaration
, Node_Tree
), Node_Tree
);
1468 while Present
(Current_String
)
1470 String_Value_Of
(Current_String
, Node_Tree
) /= Value
.Value
1473 Next_Literal_String
(Current_String
, Node_Tree
);
1476 -- Report error if string value is not one for the string type
1478 if No
(Current_String
) then
1479 Error_Msg_Name_1
:= Value
.Value
;
1480 Error_Msg_Name_2
:= Name_Of
(Declaration
, Node_Tree
);
1482 case Env
.Flags
.Allow_Invalid_External
is
1485 (Env
.Flags
, "value %% is illegal for typed string %%",
1490 (Env
.Flags
, "?value %% is illegal for typed string %%",
1492 Reset_Value
:= True;
1495 Reset_Value
:= True;
1502 First_Literal_String
1503 (String_Type_Of
(Declaration
, Node_Tree
), Node_Tree
);
1504 Value
.Value
:= String_Value_Of
(Current_String
, Node_Tree
);
1506 end Check_Or_Set_Typed_Variable
;
1508 ---------------------------------
1509 -- Process_Package_Declaration --
1510 ---------------------------------
1512 procedure Process_Package_Declaration
1513 (Current_Item
: Project_Node_Id
)
1516 -- Do not process a package declaration that should be ignored
1518 if Expression_Kind_Of
(Current_Item
, Node_Tree
) /= Ignored
then
1520 -- Create the new package
1522 Package_Table
.Increment_Last
(Shared
.Packages
);
1525 New_Pkg
: constant Package_Id
:=
1526 Package_Table
.Last
(Shared
.Packages
);
1527 The_New_Package
: Package_Element
;
1529 Project_Of_Renamed_Package
: constant Project_Node_Id
:=
1530 Project_Of_Renamed_Package_Of
1531 (Current_Item
, Node_Tree
);
1534 -- Set the name of the new package
1536 The_New_Package
.Name
:= Name_Of
(Current_Item
, Node_Tree
);
1538 -- Insert the new package in the appropriate list
1540 if Pkg
/= No_Package
then
1541 The_New_Package
.Next
:=
1542 Shared
.Packages
.Table
(Pkg
).Decl
.Packages
;
1543 Shared
.Packages
.Table
(Pkg
).Decl
.Packages
:= New_Pkg
;
1546 The_New_Package
.Next
:= Project
.Decl
.Packages
;
1547 Project
.Decl
.Packages
:= New_Pkg
;
1550 Shared
.Packages
.Table
(New_Pkg
) := The_New_Package
;
1552 if Present
(Project_Of_Renamed_Package
) then
1554 -- Renamed or extending package
1557 Project_Name
: constant Name_Id
:=
1558 Name_Of
(Project_Of_Renamed_Package
,
1561 Renamed_Project
: constant Project_Id
:=
1562 Imported_Or_Extended_Project_From
1563 (Project
, Project_Name
);
1565 Renamed_Package
: constant Package_Id
:=
1567 (Renamed_Project
, Shared
,
1568 Name_Of
(Current_Item
, Node_Tree
));
1571 -- For a renamed package, copy the declarations of the
1572 -- renamed package, but set all the locations to the
1573 -- location of the package name in the renaming
1576 Copy_Package_Declarations
1577 (From
=> Shared
.Packages
.Table
1578 (Renamed_Package
).Decl
,
1579 To
=> Shared
.Packages
.Table
(New_Pkg
).Decl
,
1580 New_Loc
=> Location_Of
(Current_Item
, Node_Tree
),
1581 Restricted
=> False,
1586 -- Set the default values of the attributes
1591 Name_Id
(Project
.Directory
.Name
),
1593 Shared
.Packages
.Table
(New_Pkg
).Decl
,
1595 (Package_Id_Of
(Current_Item
, Node_Tree
)),
1596 Project_Level
=> False);
1599 -- Process declarative items (nothing to do when the package is
1600 -- renaming, as the first declarative item is null).
1602 Process_Declarative_Items
1603 (Project
=> Project
,
1605 From_Project_Node
=> From_Project_Node
,
1606 Node_Tree
=> Node_Tree
,
1610 First_Declarative_Item_Of
(Current_Item
, Node_Tree
),
1611 Child_Env
=> Child_Env
);
1614 end Process_Package_Declaration
;
1616 -------------------------------
1617 -- Process_Associative_Array --
1618 -------------------------------
1620 procedure Process_Associative_Array
1621 (Current_Item
: Project_Node_Id
)
1623 Current_Item_Name
: constant Name_Id
:=
1624 Name_Of
(Current_Item
, Node_Tree
);
1625 -- The name of the attribute
1627 Current_Location
: constant Source_Ptr
:=
1628 Location_Of
(Current_Item
, Node_Tree
);
1630 New_Array
: Array_Id
;
1631 -- The new associative array created
1633 Orig_Array
: Array_Id
;
1634 -- The associative array value
1636 Orig_Project_Name
: Name_Id
:= No_Name
;
1637 -- The name of the project where the associative array
1640 Orig_Project
: Project_Id
:= No_Project
;
1641 -- The id of the project where the associative array
1644 Orig_Package_Name
: Name_Id
:= No_Name
;
1645 -- The name of the package, if any, where the associative array value
1648 Orig_Package
: Package_Id
:= No_Package
;
1649 -- The id of the package, if any, where the associative array value
1652 New_Element
: Array_Element_Id
:= No_Array_Element
;
1653 -- Id of a new array element created
1655 Prev_Element
: Array_Element_Id
:= No_Array_Element
;
1656 -- Last new element id created
1658 Orig_Element
: Array_Element_Id
:= No_Array_Element
;
1659 -- Current array element in original associative array
1661 Next_Element
: Array_Element_Id
:= No_Array_Element
;
1662 -- Id of the array element that follows the new element. This is not
1663 -- always nil, because values for the associative array attribute may
1664 -- already have been declared, and the array elements declared are
1670 -- First find if the associative array attribute already has elements
1673 if Pkg
/= No_Package
then
1674 New_Array
:= Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
;
1676 New_Array
:= Project
.Decl
.Arrays
;
1679 while New_Array
/= No_Array
1680 and then Shared
.Arrays
.Table
(New_Array
).Name
/= Current_Item_Name
1682 New_Array
:= Shared
.Arrays
.Table
(New_Array
).Next
;
1685 -- If the attribute has never been declared add new entry in the
1686 -- arrays of the project/package and link it.
1688 if New_Array
= No_Array
then
1689 Array_Table
.Increment_Last
(Shared
.Arrays
);
1690 New_Array
:= Array_Table
.Last
(Shared
.Arrays
);
1692 if Pkg
/= No_Package
then
1693 Shared
.Arrays
.Table
(New_Array
) :=
1694 (Name
=> Current_Item_Name
,
1695 Location
=> Current_Location
,
1696 Value
=> No_Array_Element
,
1697 Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
);
1699 Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
:= New_Array
;
1702 Shared
.Arrays
.Table
(New_Array
) :=
1703 (Name
=> Current_Item_Name
,
1704 Location
=> Current_Location
,
1705 Value
=> No_Array_Element
,
1706 Next
=> Project
.Decl
.Arrays
);
1708 Project
.Decl
.Arrays
:= New_Array
;
1712 -- Find the project where the value is declared
1714 Orig_Project_Name
:=
1716 (Associative_Project_Of
(Current_Item
, Node_Tree
), Node_Tree
);
1718 Prj
:= In_Tree
.Projects
;
1719 while Prj
/= null loop
1720 if Prj
.Project
.Name
= Orig_Project_Name
then
1721 Orig_Project
:= Prj
.Project
;
1727 pragma Assert
(Orig_Project
/= No_Project
,
1728 "original project not found");
1730 if No
(Associative_Package_Of
(Current_Item
, Node_Tree
)) then
1731 Orig_Array
:= Orig_Project
.Decl
.Arrays
;
1734 -- If in a package, find the package where the value is declared
1736 Orig_Package_Name
:=
1738 (Associative_Package_Of
(Current_Item
, Node_Tree
), Node_Tree
);
1740 Orig_Package
:= Orig_Project
.Decl
.Packages
;
1741 pragma Assert
(Orig_Package
/= No_Package
,
1742 "original package not found");
1744 while Shared
.Packages
.Table
1745 (Orig_Package
).Name
/= Orig_Package_Name
1747 Orig_Package
:= Shared
.Packages
.Table
(Orig_Package
).Next
;
1748 pragma Assert
(Orig_Package
/= No_Package
,
1749 "original package not found");
1752 Orig_Array
:= Shared
.Packages
.Table
(Orig_Package
).Decl
.Arrays
;
1755 -- Now look for the array
1757 while Orig_Array
/= No_Array
1758 and then Shared
.Arrays
.Table
(Orig_Array
).Name
/= Current_Item_Name
1760 Orig_Array
:= Shared
.Arrays
.Table
(Orig_Array
).Next
;
1763 if Orig_Array
= No_Array
then
1766 "associative array value not found",
1767 Location_Of
(Current_Item
, Node_Tree
),
1771 Orig_Element
:= Shared
.Arrays
.Table
(Orig_Array
).Value
;
1773 -- Copy each array element
1775 while Orig_Element
/= No_Array_Element
loop
1777 -- Case of first element
1779 if Prev_Element
= No_Array_Element
then
1781 -- And there is no array element declared yet, create a new
1782 -- first array element.
1784 if Shared
.Arrays
.Table
(New_Array
).Value
=
1787 Array_Element_Table
.Increment_Last
1788 (Shared
.Array_Elements
);
1789 New_Element
:= Array_Element_Table
.Last
1790 (Shared
.Array_Elements
);
1791 Shared
.Arrays
.Table
(New_Array
).Value
:= New_Element
;
1792 Next_Element
:= No_Array_Element
;
1794 -- Otherwise, the new element is the first
1797 New_Element
:= Shared
.Arrays
.Table
(New_Array
).Value
;
1799 Shared
.Array_Elements
.Table
(New_Element
).Next
;
1802 -- Otherwise, reuse an existing element, or create
1803 -- one if necessary.
1807 Shared
.Array_Elements
.Table
(Prev_Element
).Next
;
1809 if Next_Element
= No_Array_Element
then
1810 Array_Element_Table
.Increment_Last
1811 (Shared
.Array_Elements
);
1812 New_Element
:= Array_Element_Table
.Last
1813 (Shared
.Array_Elements
);
1814 Shared
.Array_Elements
.Table
(Prev_Element
).Next
:=
1818 New_Element
:= Next_Element
;
1820 Shared
.Array_Elements
.Table
(New_Element
).Next
;
1824 -- Copy the value of the element
1826 Shared
.Array_Elements
.Table
(New_Element
) :=
1827 Shared
.Array_Elements
.Table
(Orig_Element
);
1828 Shared
.Array_Elements
.Table
(New_Element
).Value
.Project
1831 -- Adjust the Next link
1833 Shared
.Array_Elements
.Table
(New_Element
).Next
:= Next_Element
;
1835 -- Adjust the previous id for the next element
1837 Prev_Element
:= New_Element
;
1839 -- Go to the next element in the original array
1841 Orig_Element
:= Shared
.Array_Elements
.Table
(Orig_Element
).Next
;
1844 -- Make sure that the array ends here, in case there previously a
1845 -- greater number of elements.
1847 Shared
.Array_Elements
.Table
(New_Element
).Next
:= No_Array_Element
;
1849 end Process_Associative_Array
;
1851 ----------------------------------------------
1852 -- Process_Expression_For_Associative_Array --
1853 ----------------------------------------------
1855 procedure Process_Expression_For_Associative_Array
1856 (Current
: Project_Node_Id
;
1857 New_Value
: Variable_Value
)
1859 Name
: constant Name_Id
:= Name_Of
(Current
, Node_Tree
);
1860 Current_Location
: constant Source_Ptr
:=
1861 Location_Of
(Current
, Node_Tree
);
1863 Index_Name
: Name_Id
:=
1864 Associative_Array_Index_Of
(Current
, Node_Tree
);
1866 Source_Index
: constant Int
:=
1867 Source_Index_Of
(Current
, Node_Tree
);
1869 The_Array
: Array_Id
;
1870 Elem
: Array_Element_Id
:= No_Array_Element
;
1873 if Index_Name
/= All_Other_Names
then
1874 Index_Name
:= Get_Attribute_Index
(Node_Tree
, Current
, Index_Name
);
1877 -- Look for the array in the appropriate list
1879 if Pkg
/= No_Package
then
1880 The_Array
:= Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
;
1882 The_Array
:= Project
.Decl
.Arrays
;
1885 while The_Array
/= No_Array
1886 and then Shared
.Arrays
.Table
(The_Array
).Name
/= Name
1888 The_Array
:= Shared
.Arrays
.Table
(The_Array
).Next
;
1891 -- If the array cannot be found, create a new entry in the list.
1892 -- As The_Array_Element is initialized to No_Array_Element, a new
1893 -- element will be created automatically later
1895 if The_Array
= No_Array
then
1896 Array_Table
.Increment_Last
(Shared
.Arrays
);
1897 The_Array
:= Array_Table
.Last
(Shared
.Arrays
);
1899 if Pkg
/= No_Package
then
1900 Shared
.Arrays
.Table
(The_Array
) :=
1902 Location
=> Current_Location
,
1903 Value
=> No_Array_Element
,
1904 Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
);
1906 Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
:= The_Array
;
1909 Shared
.Arrays
.Table
(The_Array
) :=
1911 Location
=> Current_Location
,
1912 Value
=> No_Array_Element
,
1913 Next
=> Project
.Decl
.Arrays
);
1915 Project
.Decl
.Arrays
:= The_Array
;
1919 Elem
:= Shared
.Arrays
.Table
(The_Array
).Value
;
1922 -- Look in the list, if any, to find an element with the same index
1923 -- and same source index.
1925 while Elem
/= No_Array_Element
1927 (Shared
.Array_Elements
.Table
(Elem
).Index
/= Index_Name
1929 Shared
.Array_Elements
.Table
(Elem
).Src_Index
/= Source_Index
)
1931 Elem
:= Shared
.Array_Elements
.Table
(Elem
).Next
;
1934 -- If no such element were found, create a new one
1935 -- and insert it in the element list, with the
1938 if Elem
= No_Array_Element
then
1939 Array_Element_Table
.Increment_Last
(Shared
.Array_Elements
);
1940 Elem
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
1942 Shared
.Array_Elements
.Table
1944 (Index
=> Index_Name
,
1945 Restricted
=> False,
1946 Src_Index
=> Source_Index
,
1947 Index_Case_Sensitive
=>
1948 not Case_Insensitive
(Current
, Node_Tree
),
1950 Next
=> Shared
.Arrays
.Table
(The_Array
).Value
);
1952 Shared
.Arrays
.Table
(The_Array
).Value
:= Elem
;
1955 -- An element with the same index already exists, just replace its
1956 -- value with the new one.
1958 Shared
.Array_Elements
.Table
(Elem
).Value
:= New_Value
;
1961 if Name
= Snames
.Name_External
then
1962 if In_Tree
.Is_Root_Tree
then
1963 Add
(Child_Env
.External
,
1964 External_Name
=> Get_Name_String
(Index_Name
),
1965 Value
=> Get_Name_String
(New_Value
.Value
),
1966 Source
=> From_External_Attribute
);
1968 External_Name
=> Get_Name_String
(Index_Name
),
1969 Value
=> Get_Name_String
(New_Value
.Value
),
1970 Source
=> From_External_Attribute
);
1972 if Current_Verbosity
= High
then
1974 ("'for External' has no effect except in root aggregate ("
1975 & Get_Name_String
(Index_Name
) & ")", New_Value
.Value
);
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
);
1991 Is_Attribute
: constant Boolean :=
1992 Kind_Of
(Current_Item
, Node_Tree
) =
1993 N_Attribute_Declaration
;
1995 Var
: Variable_Id
:= No_Variable
;
1998 -- First, find the list where to find the variable or attribute
2000 if Is_Attribute
then
2001 if Pkg
/= No_Package
then
2002 Var
:= Shared
.Packages
.Table
(Pkg
).Decl
.Attributes
;
2004 Var
:= Project
.Decl
.Attributes
;
2008 if Pkg
/= No_Package
then
2009 Var
:= Shared
.Packages
.Table
(Pkg
).Decl
.Variables
;
2011 Var
:= Project
.Decl
.Variables
;
2015 -- Loop through the list, to find if it has already been declared
2017 while Var
/= No_Variable
2018 and then Shared
.Variable_Elements
.Table
(Var
).Name
/= Name
2020 Var
:= Shared
.Variable_Elements
.Table
(Var
).Next
;
2023 -- If it has not been declared, create a new entry in the list
2025 if Var
= No_Variable
then
2027 -- All single string attribute should already have been declared
2028 -- with a default empty string value.
2032 "illegal attribute declaration for " & Get_Name_String
(Name
));
2034 Variable_Element_Table
.Increment_Last
(Shared
.Variable_Elements
);
2035 Var
:= Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
2037 -- Put the new variable in the appropriate list
2039 if Pkg
/= No_Package
then
2040 Shared
.Variable_Elements
.Table
(Var
) :=
2041 (Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Variables
,
2043 Value
=> New_Value
);
2044 Shared
.Packages
.Table
(Pkg
).Decl
.Variables
:= Var
;
2047 Shared
.Variable_Elements
.Table
(Var
) :=
2048 (Next
=> Project
.Decl
.Variables
,
2050 Value
=> New_Value
);
2051 Project
.Decl
.Variables
:= Var
;
2054 -- If the variable/attribute has already been declared, just
2055 -- change the value.
2058 Shared
.Variable_Elements
.Table
(Var
).Value
:= New_Value
;
2061 if Is_Attribute
and then Name
= Snames
.Name_Project_Path
then
2062 if In_Tree
.Is_Root_Tree
then
2064 Val
: String_List_Id
:= New_Value
.Values
;
2066 while Val
/= Nil_String
loop
2067 Prj
.Env
.Add_Directories
2068 (Child_Env
.Project_Path
,
2070 (Shared
.String_Elements
.Table
(Val
).Value
));
2071 Val
:= Shared
.String_Elements
.Table
(Val
).Next
;
2076 if Current_Verbosity
= High
then
2078 ("'for Project_Path' has no effect except in"
2079 & " root aggregate");
2083 end Process_Expression_Variable_Decl
;
2085 ------------------------
2086 -- Process_Expression --
2087 ------------------------
2089 procedure Process_Expression
(Current
: Project_Node_Id
) is
2090 New_Value
: Variable_Value
:=
2092 (Project
=> Project
,
2094 From_Project_Node
=> From_Project_Node
,
2095 From_Project_Node_Tree
=> Node_Tree
,
2100 (Expression_Of
(Current
, Node_Tree
), Node_Tree
),
2102 Expression_Kind_Of
(Current
, Node_Tree
));
2105 -- Process a typed variable declaration
2107 if Kind_Of
(Current
, Node_Tree
) = N_Typed_Variable_Declaration
then
2108 Check_Or_Set_Typed_Variable
(New_Value
, Current
);
2111 if Kind_Of
(Current
, Node_Tree
) /= N_Attribute_Declaration
2112 or else Associative_Array_Index_Of
(Current
, Node_Tree
) = No_Name
2114 Process_Expression_Variable_Decl
(Current
, New_Value
);
2116 Process_Expression_For_Associative_Array
(Current
, New_Value
);
2118 end Process_Expression
;
2120 -----------------------------------
2121 -- Process_Attribute_Declaration --
2122 -----------------------------------
2124 procedure Process_Attribute_Declaration
(Current
: Project_Node_Id
) is
2126 if Expression_Of
(Current
, Node_Tree
) = Empty_Node
then
2127 Process_Associative_Array
(Current
);
2129 Process_Expression
(Current
);
2131 end Process_Attribute_Declaration
;
2133 -------------------------------
2134 -- Process_Case_Construction --
2135 -------------------------------
2137 procedure Process_Case_Construction
2138 (Current_Item
: Project_Node_Id
)
2140 The_Project
: Project_Id
:= Project
;
2141 -- The id of the project of the case variable
2143 The_Package
: Package_Id
:= Pkg
;
2144 -- The id of the package, if any, of the case variable
2146 The_Variable
: Variable_Value
:= Nil_Variable_Value
;
2147 -- The case variable
2149 Case_Value
: Name_Id
:= No_Name
;
2150 -- The case variable value
2152 Case_Item
: Project_Node_Id
:= Empty_Node
;
2153 Choice_String
: Project_Node_Id
:= Empty_Node
;
2154 Decl_Item
: Project_Node_Id
:= Empty_Node
;
2158 Variable_Node
: constant Project_Node_Id
:=
2159 Case_Variable_Reference_Of
2163 Var_Id
: Variable_Id
:= No_Variable
;
2164 Name
: Name_Id
:= No_Name
;
2167 -- If a project was specified for the case variable, get its id
2169 if Present
(Project_Node_Of
(Variable_Node
, Node_Tree
)) then
2172 (Project_Node_Of
(Variable_Node
, Node_Tree
), Node_Tree
);
2174 Imported_Or_Extended_Project_From
(Project
, Name
);
2177 -- If a package was specified for the case variable, get its id
2179 if Present
(Package_Node_Of
(Variable_Node
, Node_Tree
)) then
2182 (Package_Node_Of
(Variable_Node
, Node_Tree
), Node_Tree
);
2183 The_Package
:= Package_From
(The_Project
, Shared
, Name
);
2186 Name
:= Name_Of
(Variable_Node
, Node_Tree
);
2188 -- First, look for the case variable into the package, if any
2190 if The_Package
/= No_Package
then
2191 Name
:= Name_Of
(Variable_Node
, Node_Tree
);
2193 Var_Id
:= Shared
.Packages
.Table
(The_Package
).Decl
.Variables
;
2194 while Var_Id
/= No_Variable
2195 and then Shared
.Variable_Elements
.Table
(Var_Id
).Name
/= Name
2197 Var_Id
:= Shared
.Variable_Elements
.Table
(Var_Id
).Next
;
2201 -- If not found in the package, or if there is no package, look at
2202 -- the project level.
2204 if Var_Id
= No_Variable
2205 and then No
(Package_Node_Of
(Variable_Node
, Node_Tree
))
2207 Var_Id
:= The_Project
.Decl
.Variables
;
2208 while Var_Id
/= No_Variable
2209 and then Shared
.Variable_Elements
.Table
(Var_Id
).Name
/= Name
2211 Var_Id
:= Shared
.Variable_Elements
.Table
(Var_Id
).Next
;
2215 if Var_Id
= No_Variable
then
2217 -- Should never happen, because this has already been checked
2221 ("variable """ & Get_Name_String
(Name
) & """ not found");
2222 raise Program_Error
;
2225 -- Get the case variable
2227 The_Variable
:= Shared
.Variable_Elements
. Table
(Var_Id
).Value
;
2229 if The_Variable
.Kind
/= Single
then
2231 -- Should never happen, because this has already been checked
2234 Write_Line
("variable""" & Get_Name_String
(Name
) &
2235 """ is not a single string variable");
2236 raise Program_Error
;
2239 -- Get the case variable value
2241 Case_Value
:= The_Variable
.Value
;
2244 -- Now look into all the case items of the case construction
2246 Case_Item
:= First_Case_Item_Of
(Current_Item
, Node_Tree
);
2249 while Present
(Case_Item
) loop
2250 Choice_String
:= First_Choice_Of
(Case_Item
, Node_Tree
);
2252 -- When Choice_String is nil, it means that it is the
2253 -- "when others =>" alternative.
2255 if No
(Choice_String
) then
2256 Decl_Item
:= First_Declarative_Item_Of
(Case_Item
, Node_Tree
);
2257 exit Case_Item_Loop
;
2260 -- Look into all the alternative of this case item
2263 while Present
(Choice_String
) loop
2264 if Case_Value
= String_Value_Of
(Choice_String
, Node_Tree
) then
2266 First_Declarative_Item_Of
(Case_Item
, Node_Tree
);
2267 exit Case_Item_Loop
;
2270 Choice_String
:= Next_Literal_String
(Choice_String
, Node_Tree
);
2271 end loop Choice_Loop
;
2273 Case_Item
:= Next_Case_Item
(Case_Item
, Node_Tree
);
2274 end loop Case_Item_Loop
;
2276 -- If there is an alternative, then we process it
2278 if Present
(Decl_Item
) then
2279 Process_Declarative_Items
2280 (Project
=> Project
,
2282 From_Project_Node
=> From_Project_Node
,
2283 Node_Tree
=> Node_Tree
,
2287 Child_Env
=> Child_Env
);
2289 end Process_Case_Construction
;
2293 Current
, Decl
: Project_Node_Id
;
2294 Kind
: Project_Node_Kind
;
2296 -- Start of processing for Process_Declarative_Items
2300 while Present
(Decl
) loop
2301 Current
:= Current_Item_Node
(Decl
, Node_Tree
);
2302 Decl
:= Next_Declarative_Item
(Decl
, Node_Tree
);
2303 Kind
:= Kind_Of
(Current
, Node_Tree
);
2306 when N_Package_Declaration
=>
2307 Process_Package_Declaration
(Current
);
2309 -- Nothing to process for string type declaration
2311 when N_String_Type_Declaration
=>
2314 when N_Attribute_Declaration |
2315 N_Typed_Variable_Declaration |
2316 N_Variable_Declaration
=>
2317 Process_Attribute_Declaration
(Current
);
2319 when N_Case_Construction
=>
2320 Process_Case_Construction
(Current
);
2323 Write_Line
("Illegal declarative item: " & Kind
'Img);
2324 raise Program_Error
;
2327 end Process_Declarative_Items
;
2329 ----------------------------------
2330 -- Process_Project_Tree_Phase_1 --
2331 ----------------------------------
2333 procedure Process_Project_Tree_Phase_1
2334 (In_Tree
: Project_Tree_Ref
;
2335 Project
: out Project_Id
;
2336 Packages_To_Check
: String_List_Access
;
2337 Success
: out Boolean;
2338 From_Project_Node
: Project_Node_Id
;
2339 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2340 Env
: in out Prj
.Tree
.Environment
;
2341 Reset_Tree
: Boolean := True)
2346 -- Make sure there are no projects in the data structure
2348 Free_List
(In_Tree
.Projects
, Free_Project
=> True);
2351 Processed_Projects
.Reset
;
2353 -- And process the main project and all of the projects it depends on,
2356 Debug_Increase_Indent
("Process tree, phase 1");
2359 (Project
=> Project
,
2361 Packages_To_Check
=> Packages_To_Check
,
2362 From_Project_Node
=> From_Project_Node
,
2363 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2365 Extended_By
=> No_Project
,
2366 From_Encapsulated_Lib
=> False);
2369 Total_Errors_Detected
= 0
2371 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2373 if Current_Verbosity
= High
then
2374 Debug_Decrease_Indent
2375 ("Done Process tree, phase 1, Success=" & Success
'Img);
2377 end Process_Project_Tree_Phase_1
;
2379 ----------------------------------
2380 -- Process_Project_Tree_Phase_2 --
2381 ----------------------------------
2383 procedure Process_Project_Tree_Phase_2
2384 (In_Tree
: Project_Tree_Ref
;
2385 Project
: Project_Id
;
2386 Success
: out Boolean;
2387 From_Project_Node
: Project_Node_Id
;
2388 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2391 Obj_Dir
: Path_Name_Type
;
2392 Extending
: Project_Id
;
2393 Extending2
: Project_Id
;
2396 -- Start of processing for Process_Project_Tree_Phase_2
2401 Debug_Increase_Indent
("Process tree, phase 2", Project
.Name
);
2403 if Project
/= No_Project
then
2404 Check
(In_Tree
, Project
, From_Project_Node_Tree
, Env
.Flags
);
2407 -- If main project is an extending all project, set object directory of
2408 -- all virtual extending projects to object directory of main project.
2410 if Project
/= No_Project
2411 and then Is_Extending_All
(From_Project_Node
, From_Project_Node_Tree
)
2414 Object_Dir
: constant Path_Information
:= Project
.Object_Directory
;
2417 Prj
:= In_Tree
.Projects
;
2418 while Prj
/= null loop
2419 if Prj
.Project
.Virtual
then
2420 Prj
.Project
.Object_Directory
:= Object_Dir
;
2428 -- Check that no extending project shares its object directory with
2429 -- the project(s) it extends.
2431 if Project
/= No_Project
then
2432 Prj
:= In_Tree
.Projects
;
2433 while Prj
/= null loop
2434 Extending
:= Prj
.Project
.Extended_By
;
2436 if Extending
/= No_Project
then
2437 Obj_Dir
:= Prj
.Project
.Object_Directory
.Name
;
2439 -- Check that a project being extended does not share its
2440 -- object directory with any project that extends it, directly
2441 -- or indirectly, including a virtual extending project.
2443 -- Start with the project directly extending it
2445 Extending2
:= Extending
;
2446 while Extending2
/= No_Project
loop
2447 if Has_Ada_Sources
(Extending2
)
2448 and then Extending2
.Object_Directory
.Name
= Obj_Dir
2450 if Extending2
.Virtual
then
2451 Error_Msg_Name_1
:= Prj
.Project
.Display_Name
;
2454 "project %% cannot be extended by a virtual" &
2455 " project with the same object directory",
2456 Prj
.Project
.Location
, Project
);
2459 Error_Msg_Name_1
:= Extending2
.Display_Name
;
2460 Error_Msg_Name_2
:= Prj
.Project
.Display_Name
;
2463 "project %% cannot extend project %%",
2464 Extending2
.Location
, Project
);
2467 "\they share the same object directory",
2468 Extending2
.Location
, Project
);
2472 -- Continue with the next extending project, if any
2474 Extending2
:= Extending2
.Extended_By
;
2482 Debug_Decrease_Indent
("Done Process tree, phase 2");
2484 Success
:= Total_Errors_Detected
= 0
2486 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2487 end Process_Project_Tree_Phase_2
;
2489 -----------------------
2490 -- Recursive_Process --
2491 -----------------------
2493 procedure Recursive_Process
2494 (In_Tree
: Project_Tree_Ref
;
2495 Project
: out Project_Id
;
2496 Packages_To_Check
: String_List_Access
;
2497 From_Project_Node
: Project_Node_Id
;
2498 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2499 Env
: in out Prj
.Tree
.Environment
;
2500 Extended_By
: Project_Id
;
2501 From_Encapsulated_Lib
: Boolean)
2503 Shared
: constant Shared_Project_Tree_Data_Access
:= In_Tree
.Shared
;
2505 Child_Env
: Prj
.Tree
.Environment
;
2506 -- Only used for the root aggregate project (if any). This is left
2507 -- uninitialized otherwise.
2509 procedure Process_Imported_Projects
2510 (Imported
: in out Project_List
;
2511 Limited_With
: Boolean);
2512 -- Process imported projects. If Limited_With is True, then only
2513 -- projects processed through a "limited with" are processed, otherwise
2514 -- only projects imported through a standard "with" are processed.
2515 -- Imported is the id of the last imported project.
2517 procedure Process_Aggregated_Projects
;
2518 -- Process all the projects aggregated in List. This does nothing if the
2519 -- project is not an aggregate project.
2521 procedure Process_Extended_Project
;
2522 -- Process the extended project: inherit all packages from the extended
2523 -- project that are not explicitly defined or renamed. Also inherit the
2524 -- languages, if attribute Languages is not explicitly defined.
2526 -------------------------------
2527 -- Process_Imported_Projects --
2528 -------------------------------
2530 procedure Process_Imported_Projects
2531 (Imported
: in out Project_List
;
2532 Limited_With
: Boolean)
2534 With_Clause
: Project_Node_Id
;
2535 New_Project
: Project_Id
;
2536 Proj_Node
: Project_Node_Id
;
2540 First_With_Clause_Of
2541 (From_Project_Node
, From_Project_Node_Tree
);
2543 while Present
(With_Clause
) loop
2545 Non_Limited_Project_Node_Of
2546 (With_Clause
, From_Project_Node_Tree
);
2547 New_Project
:= No_Project
;
2549 if (Limited_With
and then No
(Proj_Node
))
2550 or else (not Limited_With
and then Present
(Proj_Node
))
2553 (In_Tree
=> In_Tree
,
2554 Project
=> New_Project
,
2555 Packages_To_Check
=> Packages_To_Check
,
2556 From_Project_Node
=>
2557 Project_Node_Of
(With_Clause
, From_Project_Node_Tree
),
2558 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2560 Extended_By
=> No_Project
,
2561 From_Encapsulated_Lib
=> From_Encapsulated_Lib
);
2563 if Imported
= null then
2564 Project
.Imported_Projects
:= new Project_List_Element
'
2565 (Project => New_Project,
2566 From_Encapsulated_Lib => False,
2568 Imported := Project.Imported_Projects;
2570 Imported.Next := new Project_List_Element'
2571 (Project
=> New_Project
,
2572 From_Encapsulated_Lib
=> False,
2574 Imported
:= Imported
.Next
;
2579 Next_With_Clause_Of
(With_Clause
, From_Project_Node_Tree
);
2581 end Process_Imported_Projects
;
2583 ---------------------------------
2584 -- Process_Aggregated_Projects --
2585 ---------------------------------
2587 procedure Process_Aggregated_Projects
is
2588 List
: Aggregated_Project_List
;
2589 Loaded_Project
: Prj
.Tree
.Project_Node_Id
;
2590 Success
: Boolean := True;
2591 Tree
: Project_Tree_Ref
;
2594 if Project
.Qualifier
not in Aggregate_Project
then
2598 Debug_Increase_Indent
("Process_Aggregated_Projects", Project
.Name
);
2600 Prj
.Nmsc
.Process_Aggregated_Projects
2603 Node_Tree
=> From_Project_Node_Tree
,
2604 Flags
=> Env
.Flags
);
2606 List
:= Project
.Aggregated_Projects
;
2607 while Success
and then List
/= null loop
2609 (In_Tree
=> From_Project_Node_Tree
,
2610 Project
=> Loaded_Project
,
2611 Packages_To_Check
=> Packages_To_Check
,
2612 Project_File_Name
=> Get_Name_String
(List
.Path
),
2613 Errout_Handling
=> Prj
.Part
.Never_Finalize
,
2614 Current_Directory
=> Get_Name_String
(Project
.Directory
.Name
),
2615 Is_Config_File
=> False,
2618 Success
:= not Prj
.Tree
.No
(Loaded_Project
);
2621 List
.Tree
:= new Project_Tree_Data
(Is_Root_Tree
=> False);
2622 Prj
.Initialize
(List
.Tree
);
2623 List
.Tree
.Shared
:= In_Tree
.Shared
;
2625 -- In aggregate library, aggregated projects are parsed using
2626 -- the aggregate library tree.
2628 if Project
.Qualifier
= Aggregate_Library
then
2634 -- We can only do the phase 1 of the processing, since we do
2635 -- not have access to the configuration file yet (this is
2636 -- called when doing phase 1 of the processing for the root
2637 -- aggregate project).
2639 if In_Tree
.Is_Root_Tree
then
2640 Process_Project_Tree_Phase_1
2642 Project
=> List
.Project
,
2643 Packages_To_Check
=> Packages_To_Check
,
2645 From_Project_Node
=> Loaded_Project
,
2646 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2648 Reset_Tree
=> False);
2650 -- use the same environment as the rest of the aggregated
2651 -- projects, ie the one that was setup by the root aggregate
2652 Process_Project_Tree_Phase_1
2654 Project
=> List
.Project
,
2655 Packages_To_Check
=> Packages_To_Check
,
2657 From_Project_Node
=> Loaded_Project
,
2658 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2660 Reset_Tree
=> False);
2664 Debug_Output
("Failed to parse", Name_Id
(List
.Path
));
2670 Debug_Decrease_Indent
("Done Process_Aggregated_Projects");
2671 end Process_Aggregated_Projects
;
2673 ------------------------------
2674 -- Process_Extended_Project --
2675 ------------------------------
2677 procedure Process_Extended_Project
is
2678 Extended_Pkg
: Package_Id
;
2679 Current_Pkg
: Package_Id
;
2680 Element
: Package_Element
;
2681 First
: constant Package_Id
:= Project
.Decl
.Packages
;
2682 Attribute1
: Variable_Id
;
2683 Attribute2
: Variable_Id
;
2684 Attr_Value1
: Variable
;
2685 Attr_Value2
: Variable
;
2688 Extended_Pkg
:= Project
.Extends
.Decl
.Packages
;
2689 while Extended_Pkg
/= No_Package
loop
2690 Element
:= Shared
.Packages
.Table
(Extended_Pkg
);
2692 Current_Pkg
:= First
;
2693 while Current_Pkg
/= No_Package
2695 Shared
.Packages
.Table
(Current_Pkg
).Name
/= Element
.Name
2697 Current_Pkg
:= Shared
.Packages
.Table
(Current_Pkg
).Next
;
2700 if Current_Pkg
= No_Package
then
2701 Package_Table
.Increment_Last
(Shared
.Packages
);
2702 Current_Pkg
:= Package_Table
.Last
(Shared
.Packages
);
2703 Shared
.Packages
.Table
(Current_Pkg
) :=
2704 (Name
=> Element
.Name
,
2705 Decl
=> No_Declarations
,
2706 Parent
=> No_Package
,
2707 Next
=> Project
.Decl
.Packages
);
2708 Project
.Decl
.Packages
:= Current_Pkg
;
2709 Copy_Package_Declarations
2710 (From
=> Element
.Decl
,
2711 To
=> Shared
.Packages
.Table
(Current_Pkg
).Decl
,
2712 New_Loc
=> No_Location
,
2717 Extended_Pkg
:= Element
.Next
;
2720 -- Check if attribute Languages is declared in the extending project
2722 Attribute1
:= Project
.Decl
.Attributes
;
2723 while Attribute1
/= No_Variable
loop
2724 Attr_Value1
:= Shared
.Variable_Elements
. Table
(Attribute1
);
2725 exit when Attr_Value1
.Name
= Snames
.Name_Languages
;
2726 Attribute1
:= Attr_Value1
.Next
;
2729 if Attribute1
= No_Variable
or else Attr_Value1
.Value
.Default
then
2731 -- Attribute Languages is not declared in the extending project.
2732 -- Check if it is declared in the project being extended.
2734 Attribute2
:= Project
.Extends
.Decl
.Attributes
;
2735 while Attribute2
/= No_Variable
loop
2736 Attr_Value2
:= Shared
.Variable_Elements
.Table
(Attribute2
);
2737 exit when Attr_Value2
.Name
= Snames
.Name_Languages
;
2738 Attribute2
:= Attr_Value2
.Next
;
2741 if Attribute2
/= No_Variable
2742 and then not Attr_Value2
.Value
.Default
2744 -- As attribute Languages is declared in the project being
2745 -- extended, copy its value for the extending project.
2747 if Attribute1
= No_Variable
then
2748 Variable_Element_Table
.Increment_Last
2749 (Shared
.Variable_Elements
);
2750 Attribute1
:= Variable_Element_Table
.Last
2751 (Shared
.Variable_Elements
);
2752 Attr_Value1
.Next
:= Project
.Decl
.Attributes
;
2753 Project
.Decl
.Attributes
:= Attribute1
;
2756 Attr_Value1
.Name
:= Snames
.Name_Languages
;
2757 Attr_Value1
.Value
:= Attr_Value2
.Value
;
2758 Shared
.Variable_Elements
.Table
(Attribute1
) := Attr_Value1
;
2761 end Process_Extended_Project
;
2763 -- Start of processing for Recursive_Process
2766 if No
(From_Project_Node
) then
2767 Project
:= No_Project
;
2771 Imported
, Mark
: Project_List
;
2772 Declaration_Node
: Project_Node_Id
:= Empty_Node
;
2774 Name
: constant Name_Id
:=
2775 Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
2777 Name_Node
: constant Tree_Private_Part
.Project_Name_And_Node
:=
2778 Tree_Private_Part
.Projects_Htable
.Get
2779 (From_Project_Node_Tree
.Projects_HT
, Name
);
2782 Project
:= Processed_Projects
.Get
(Name
);
2784 if Project
/= No_Project
then
2786 -- Make sure that, when a project is extended, the project id
2787 -- of the project extending it is recorded in its data, even
2788 -- when it has already been processed as an imported project.
2789 -- This is for virtually extended projects.
2791 if Extended_By
/= No_Project
then
2792 Project
.Extended_By
:= Extended_By
;
2801 (Project_Qualifier_Of
2802 (From_Project_Node, From_Project_Node_Tree)));
2804 -- Note that at this point we do not know yet if the project has
2805 -- been withed from an encapsulated library or not.
2808 new Project_List_Element'
2809 (Project
=> Project
,
2810 From_Encapsulated_Lib
=> False,
2811 Next
=> In_Tree
.Projects
);
2813 -- Keep track of this point
2815 Mark
:= In_Tree
.Projects
;
2817 Processed_Projects
.Set
(Name
, Project
);
2819 Project
.Name
:= Name
;
2820 Project
.Display_Name
:= Name_Node
.Display_Name
;
2821 Get_Name_String
(Name
);
2823 -- If name starts with the virtual prefix, flag the project as
2824 -- being a virtual extending project.
2826 if Name_Len
> Virtual_Prefix
'Length
2828 Name_Buffer
(1 .. Virtual_Prefix
'Length) = Virtual_Prefix
2830 Project
.Virtual
:= True;
2833 Project
.Path
.Display_Name
:=
2834 Path_Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
2835 Get_Name_String
(Project
.Path
.Display_Name
);
2836 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2837 Project
.Path
.Name
:= Name_Find
;
2840 Location_Of
(From_Project_Node
, From_Project_Node_Tree
);
2842 Project
.Directory
.Display_Name
:=
2843 Directory_Of
(From_Project_Node
, From_Project_Node_Tree
);
2844 Get_Name_String
(Project
.Directory
.Display_Name
);
2845 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2846 Project
.Directory
.Name
:= Name_Find
;
2848 Project
.Extended_By
:= Extended_By
;
2853 Name_Id
(Project
.Directory
.Name
),
2856 Prj
.Attr
.Attribute_First
,
2857 Project_Level
=> True);
2859 Process_Imported_Projects
(Imported
, Limited_With
=> False);
2861 if Project
.Qualifier
= Aggregate
and then In_Tree
.Is_Root_Tree
then
2862 Initialize_And_Copy
(Child_Env
, Copy_From
=> Env
);
2864 elsif Project
.Qualifier
= Aggregate_Library
then
2866 -- The child environment is the same as the current one
2871 -- No need to initialize Child_Env, since it will not be
2872 -- used anyway by Process_Declarative_Items (only the root
2873 -- aggregate can modify it, and it is never read anyway).
2879 Project_Declaration_Of
2880 (From_Project_Node
, From_Project_Node_Tree
);
2883 (In_Tree
=> In_Tree
,
2884 Project
=> Project
.Extends
,
2885 Packages_To_Check
=> Packages_To_Check
,
2886 From_Project_Node
=>
2888 (Declaration_Node
, From_Project_Node_Tree
),
2889 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2891 Extended_By
=> Project
,
2892 From_Encapsulated_Lib
=> From_Encapsulated_Lib
);
2894 Process_Declarative_Items
2895 (Project
=> Project
,
2897 From_Project_Node
=> From_Project_Node
,
2898 Node_Tree
=> From_Project_Node_Tree
,
2901 Item
=> First_Declarative_Item_Of
2902 (Declaration_Node
, From_Project_Node_Tree
),
2903 Child_Env
=> Child_Env
);
2905 if Project
.Extends
/= No_Project
then
2906 Process_Extended_Project
;
2909 Process_Imported_Projects
(Imported
, Limited_With
=> True);
2911 if Err_Vars
.Total_Errors_Detected
= 0 then
2912 Process_Aggregated_Projects
;
2915 -- At this point (after Process_Declarative_Items) we have the
2916 -- attribute values set, we can backtrace In_Tree.Project and
2917 -- set the From_Encapsulated_Library status.
2920 Lib_Standalone
: constant Prj
.Variable_Value
:=
2922 (Snames
.Name_Library_Standalone
,
2923 Project
.Decl
.Attributes
,
2925 List
: Project_List
:= In_Tree
.Projects
;
2926 Is_Encapsulated
: Boolean;
2929 Get_Name_String
(Lib_Standalone
.Value
);
2930 To_Lower
(Name_Buffer
(1 .. Name_Len
));
2932 Is_Encapsulated
:= Name_Buffer
(1 .. Name_Len
) = "encapsulated";
2934 if Is_Encapsulated
then
2935 while List
/= null and then List
/= Mark
loop
2936 List
.From_Encapsulated_Lib
:= Is_Encapsulated
;
2941 if Err_Vars
.Total_Errors_Detected
= 0 then
2943 -- For an aggregate library we add the aggregated projects
2944 -- as imported ones. This is necessary to give visibility
2945 -- to all sources from the aggregates from the aggregated
2946 -- library projects.
2948 if Project
.Qualifier
= Aggregate_Library
then
2950 L
: Aggregated_Project_List
;
2952 L
:= Project
.Aggregated_Projects
;
2953 while L
/= null loop
2954 Project
.Imported_Projects
:=
2955 new Project_List_Element
'
2956 (Project => L.Project,
2957 From_Encapsulated_Lib => Is_Encapsulated,
2959 Project.Imported_Projects);
2967 if Project.Qualifier = Aggregate and then In_Tree.Is_Root_Tree then
2972 end Recursive_Process;