1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2015, 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 Atree
; use Atree
;
27 with Err_Vars
; use Err_Vars
;
29 with Osint
; use Osint
;
30 with Output
; use Output
;
31 with Prj
.Attr
; use Prj
.Attr
;
33 with Prj
.Err
; use Prj
.Err
;
34 with Prj
.Ext
; use Prj
.Ext
;
35 with Prj
.Nmsc
; use Prj
.Nmsc
;
40 with Ada
.Containers
.Vectors
;
41 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
43 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
46 package body Prj
.Proc
is
48 package Processed_Projects
is new GNAT
.HTable
.Simple_HTable
49 (Header_Num
=> Header_Num
,
50 Element
=> Project_Id
,
51 No_Element
=> No_Project
,
55 -- This hash table contains all processed projects
57 package Unit_Htable
is new GNAT
.HTable
.Simple_HTable
58 (Header_Num
=> Header_Num
,
60 No_Element
=> No_Source
,
64 -- This hash table contains all processed projects
66 package Runtime_Defaults
is new GNAT
.HTable
.Simple_HTable
67 (Header_Num
=> Prj
.Header_Num
,
69 No_Element
=> No_Name
,
73 -- Stores the default values of 'Runtime names for the various languages
75 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
);
76 -- Concatenate two strings and returns another string if both
77 -- arguments are not null string.
79 -- In the following procedures, we are expected to guess the meaning of
80 -- the parameters from their names, this is never a good idea, comments
81 -- should be added precisely defining every formal ???
83 procedure Add_Attributes
84 (Project
: Project_Id
;
85 Project_Name
: Name_Id
;
86 Project_Dir
: Name_Id
;
87 Shared
: Shared_Project_Tree_Data_Access
;
88 Decl
: in out Declarations
;
89 First
: Attribute_Node_Id
;
90 Project_Level
: Boolean);
91 -- Add all attributes, starting with First, with their default values to
92 -- the package or project with declarations Decl.
95 (In_Tree
: Project_Tree_Ref
;
97 Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
98 Flags
: Processing_Flags
);
99 -- Set all projects to not checked, then call Recursive_Check for the
100 -- main project Project. Project is set to No_Project if errors occurred.
101 -- Current_Dir is for optimization purposes, avoiding extra system calls.
102 -- If Allow_Duplicate_Basenames, then files with the same base names are
103 -- authorized within a project for source-based languages (never for unit
106 procedure Copy_Package_Declarations
107 (From
: Declarations
;
108 To
: in out Declarations
;
109 New_Loc
: Source_Ptr
;
110 Restricted
: Boolean;
111 Shared
: Shared_Project_Tree_Data_Access
);
112 -- Copy a package declaration From to To for a renamed package. Change the
113 -- locations of all the attributes to New_Loc. When Restricted is
114 -- True, do not copy attributes Body, Spec, Implementation, Specification
115 -- and Linker_Options.
118 (Project
: Project_Id
;
119 Shared
: Shared_Project_Tree_Data_Access
;
120 From_Project_Node
: Project_Node_Id
;
121 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
122 Env
: Prj
.Tree
.Environment
;
124 First_Term
: Project_Node_Id
;
125 Kind
: Variable_Kind
) return Variable_Value
;
126 -- From N_Expression project node From_Project_Node, compute the value
127 -- of an expression and return it as a Variable_Value.
129 function Imported_Or_Extended_Project_From
130 (Project
: Project_Id
;
132 No_Extending
: Boolean := False) return Project_Id
;
133 -- Find an imported or extended project of Project whose name is With_Name.
134 -- When No_Extending is True, do not look for extending projects, returns
135 -- the exact project whose name is With_Name.
137 function Package_From
138 (Project
: Project_Id
;
139 Shared
: Shared_Project_Tree_Data_Access
;
140 With_Name
: Name_Id
) return Package_Id
;
141 -- Find the package of Project whose name is With_Name
143 procedure Process_Declarative_Items
144 (Project
: Project_Id
;
145 In_Tree
: Project_Tree_Ref
;
146 From_Project_Node
: Project_Node_Id
;
147 Node_Tree
: Project_Node_Tree_Ref
;
148 Env
: Prj
.Tree
.Environment
;
150 Item
: Project_Node_Id
;
151 Child_Env
: in out Prj
.Tree
.Environment
);
152 -- Process declarative items starting with From_Project_Node, and put them
153 -- in declarations Decl. This is a recursive procedure; it calls itself for
154 -- a package declaration or a case construction.
156 -- Child_Env is the modified environment after seeing declarations like
157 -- "for External(...) use" or "for Project_Path use" in aggregate projects.
158 -- It should have been initialized first.
160 procedure Recursive_Process
161 (In_Tree
: Project_Tree_Ref
;
162 Project
: out Project_Id
;
163 Packages_To_Check
: String_List_Access
;
164 From_Project_Node
: Project_Node_Id
;
165 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
166 Env
: in out Prj
.Tree
.Environment
;
167 Extended_By
: Project_Id
;
168 From_Encapsulated_Lib
: Boolean;
169 On_New_Tree_Loaded
: Tree_Loaded_Callback
:= null);
170 -- Process project with node From_Project_Node in the tree. Do nothing if
171 -- From_Project_Node is Empty_Node. If project has already been processed,
172 -- simply return its project id. Otherwise create a new project id, mark it
173 -- as processed, call itself recursively for all imported projects and a
174 -- extended project, if any. Then process the declarative items of the
177 -- Is_Root_Project should be true only for the project that the user
178 -- explicitly loaded. In the context of aggregate projects, only that
179 -- project is allowed to modify the environment that will be used to load
180 -- projects (Child_Env).
182 -- From_Encapsulated_Lib is true if we are parsing a project from
183 -- encapsulated library dependencies.
185 -- If specified, On_New_Tree_Loaded is called after each aggregated project
186 -- has been processed succesfully.
188 function Get_Attribute_Index
189 (Tree
: Project_Node_Tree_Ref
;
190 Attr
: Project_Node_Id
;
191 Index
: Name_Id
) return Name_Id
;
192 -- Copy the index of the attribute into Name_Buffer, converting to lower
193 -- case if the attribute is case-insensitive.
199 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
) is
201 if To_Exp
= No_Name
or else To_Exp
= Empty_String
then
203 -- To_Exp is nil or empty. The result is Str
207 -- If Str is nil, then do not change To_Ext
209 elsif Str
/= No_Name
and then Str
/= Empty_String
then
211 S
: constant String := Get_Name_String
(Str
);
213 Get_Name_String
(To_Exp
);
214 Add_Str_To_Name_Buffer
(S
);
224 procedure Add_Attributes
225 (Project
: Project_Id
;
226 Project_Name
: Name_Id
;
227 Project_Dir
: Name_Id
;
228 Shared
: Shared_Project_Tree_Data_Access
;
229 Decl
: in out Declarations
;
230 First
: Attribute_Node_Id
;
231 Project_Level
: Boolean)
233 The_Attribute
: Attribute_Node_Id
:= First
;
236 while The_Attribute
/= Empty_Attribute
loop
237 if Attribute_Kind_Of
(The_Attribute
) = Single
then
239 New_Attribute
: Variable_Value
;
242 case Variable_Kind_Of
(The_Attribute
) is
244 -- Undefined should not happen
248 (False, "attribute with an undefined kind");
251 -- Single attributes have a default value of empty string
257 Location
=> No_Location
,
259 Value
=> Empty_String
,
262 -- Special cases of <project>'Name and
263 -- <project>'Project_Dir.
265 if Project_Level
then
266 if Attribute_Name_Of
(The_Attribute
) =
269 New_Attribute
.Value
:= Project_Name
;
271 elsif Attribute_Name_Of
(The_Attribute
) =
272 Snames
.Name_Project_Dir
274 New_Attribute
.Value
:= Project_Dir
;
278 -- List attributes have a default value of nil list
284 Location
=> No_Location
,
286 Values
=> Nil_String
);
290 Variable_Element_Table
.Increment_Last
291 (Shared
.Variable_Elements
);
292 Shared
.Variable_Elements
.Table
293 (Variable_Element_Table
.Last
(Shared
.Variable_Elements
)) :=
294 (Next
=> Decl
.Attributes
,
295 Name
=> Attribute_Name_Of
(The_Attribute
),
296 Value
=> New_Attribute
);
298 Variable_Element_Table
.Last
299 (Shared
.Variable_Elements
);
303 The_Attribute
:= Next_Attribute
(After
=> The_Attribute
);
312 (In_Tree
: Project_Tree_Ref
;
313 Project
: Project_Id
;
314 Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
315 Flags
: Processing_Flags
)
318 Process_Naming_Scheme
(In_Tree
, Project
, Node_Tree
, Flags
);
320 -- Set the Other_Part field for the units
326 Iter
: Source_Iterator
;
331 Iter
:= For_Each_Source
(In_Tree
);
333 Source1
:= Prj
.Element
(Iter
);
334 exit when Source1
= No_Source
;
336 if Source1
.Unit
/= No_Unit_Index
then
337 Name
:= Source1
.Unit
.Name
;
338 Source2
:= Unit_Htable
.Get
(Name
);
340 if Source2
= No_Source
then
341 Unit_Htable
.Set
(K
=> Name
, E
=> Source1
);
343 Unit_Htable
.Remove
(Name
);
352 -------------------------------
353 -- Copy_Package_Declarations --
354 -------------------------------
356 procedure Copy_Package_Declarations
357 (From
: Declarations
;
358 To
: in out Declarations
;
359 New_Loc
: Source_Ptr
;
360 Restricted
: Boolean;
361 Shared
: Shared_Project_Tree_Data_Access
)
364 V2
: Variable_Id
:= No_Variable
;
367 A2
: Array_Id
:= No_Array
;
369 E1
: Array_Element_Id
;
370 E2
: Array_Element_Id
:= No_Array_Element
;
374 -- To avoid references in error messages to attribute declarations in
375 -- an original package that has been renamed, copy all the attribute
376 -- declarations of the package and change all locations to New_Loc,
377 -- the location of the renamed package.
379 -- First single attributes
381 V1
:= From
.Attributes
;
382 while V1
/= No_Variable
loop
384 -- Copy the attribute
386 Var
:= Shared
.Variable_Elements
.Table
(V1
);
389 -- Do not copy the value of attribute Linker_Options if Restricted
391 if Restricted
and then Var
.Name
= Snames
.Name_Linker_Options
then
392 Var
.Value
.Values
:= Nil_String
;
395 -- Remove the Next component
397 Var
.Next
:= No_Variable
;
399 -- Change the location to New_Loc
401 Var
.Value
.Location
:= New_Loc
;
402 Variable_Element_Table
.Increment_Last
(Shared
.Variable_Elements
);
404 -- Put in new declaration
406 if To
.Attributes
= No_Variable
then
408 Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
410 Shared
.Variable_Elements
.Table
(V2
).Next
:=
411 Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
414 V2
:= Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
415 Shared
.Variable_Elements
.Table
(V2
) := Var
;
418 -- Then the associated array attributes
421 while A1
/= No_Array
loop
422 Arr
:= Shared
.Arrays
.Table
(A1
);
425 -- Remove the Next component
427 Arr
.Next
:= No_Array
;
428 Array_Table
.Increment_Last
(Shared
.Arrays
);
430 -- Create new Array declaration
432 if To
.Arrays
= No_Array
then
433 To
.Arrays
:= Array_Table
.Last
(Shared
.Arrays
);
435 Shared
.Arrays
.Table
(A2
).Next
:=
436 Array_Table
.Last
(Shared
.Arrays
);
439 A2
:= Array_Table
.Last
(Shared
.Arrays
);
441 -- Don't store the array as its first element has not been set yet
443 -- Copy the array elements of the array
446 Arr
.Value
:= No_Array_Element
;
447 while E1
/= No_Array_Element
loop
449 -- Copy the array element
451 Elm
:= Shared
.Array_Elements
.Table
(E1
);
454 -- Remove the Next component
456 Elm
.Next
:= No_Array_Element
;
458 Elm
.Restricted
:= Restricted
;
460 -- Change the location
462 Elm
.Value
.Location
:= New_Loc
;
463 Array_Element_Table
.Increment_Last
(Shared
.Array_Elements
);
465 -- Create new array element
467 if Arr
.Value
= No_Array_Element
then
468 Arr
.Value
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
470 Shared
.Array_Elements
.Table
(E2
).Next
:=
471 Array_Element_Table
.Last
(Shared
.Array_Elements
);
474 E2
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
475 Shared
.Array_Elements
.Table
(E2
) := Elm
;
478 -- Finally, store the new array
480 Shared
.Arrays
.Table
(A2
) := Arr
;
482 end Copy_Package_Declarations
;
484 -------------------------
485 -- Get_Attribute_Index --
486 -------------------------
488 function Get_Attribute_Index
489 (Tree
: Project_Node_Tree_Ref
;
490 Attr
: Project_Node_Id
;
491 Index
: Name_Id
) return Name_Id
494 if Index
= All_Other_Names
495 or else not Case_Insensitive
(Attr
, Tree
)
500 Get_Name_String
(Index
);
501 To_Lower
(Name_Buffer
(1 .. Name_Len
));
503 end Get_Attribute_Index
;
510 (Project
: Project_Id
;
511 Shared
: Shared_Project_Tree_Data_Access
;
512 From_Project_Node
: Project_Node_Id
;
513 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
514 Env
: Prj
.Tree
.Environment
;
516 First_Term
: Project_Node_Id
;
517 Kind
: Variable_Kind
) return Variable_Value
519 The_Term
: Project_Node_Id
;
520 -- The term in the expression list
522 The_Current_Term
: Project_Node_Id
:= Empty_Node
;
523 -- The current term node id
525 Result
: Variable_Value
(Kind
=> Kind
);
526 -- The returned result
528 Last
: String_List_Id
:= Nil_String
;
529 -- Reference to the last string elements in Result, when Kind is List
531 Current_Term_Kind
: Project_Node_Kind
;
534 Result
.Project
:= Project
;
535 Result
.Location
:= Location_Of
(First_Term
, From_Project_Node_Tree
);
537 -- Process each term of the expression, starting with First_Term
539 The_Term
:= First_Term
;
540 while Present
(The_Term
) loop
541 The_Current_Term
:= Current_Term
(The_Term
, From_Project_Node_Tree
);
543 if The_Current_Term
/= Empty_Node
then
545 Kind_Of
(The_Current_Term
, From_Project_Node_Tree
);
547 case Current_Term_Kind
is
549 when N_Literal_String
=>
553 -- Should never happen
555 pragma Assert
(False, "Undefined expression kind");
561 (The_Current_Term
, From_Project_Node_Tree
));
564 (The_Current_Term
, From_Project_Node_Tree
);
568 String_Element_Table
.Increment_Last
569 (Shared
.String_Elements
);
571 if Last
= Nil_String
then
573 -- This can happen in an expression like () & "toto"
575 Result
.Values
:= String_Element_Table
.Last
576 (Shared
.String_Elements
);
579 Shared
.String_Elements
.Table
580 (Last
).Next
:= String_Element_Table
.Last
581 (Shared
.String_Elements
);
584 Last
:= String_Element_Table
.Last
585 (Shared
.String_Elements
);
587 Shared
.String_Elements
.Table
(Last
) :=
588 (Value
=> String_Value_Of
590 From_Project_Node_Tree
),
591 Index
=> Source_Index_Of
593 From_Project_Node_Tree
),
594 Display_Value
=> No_Name
,
595 Location
=> Location_Of
597 From_Project_Node_Tree
),
602 when N_Literal_String_List
=>
604 String_Node
: Project_Node_Id
:=
605 First_Expression_In_List
607 From_Project_Node_Tree
);
609 Value
: Variable_Value
;
612 if Present
(String_Node
) then
614 -- If String_Node is nil, it is an empty list, there is
620 From_Project_Node
=> From_Project_Node
,
621 From_Project_Node_Tree
=> From_Project_Node_Tree
,
626 (String_Node
, From_Project_Node_Tree
),
628 String_Element_Table
.Increment_Last
629 (Shared
.String_Elements
);
631 if Result
.Values
= Nil_String
then
633 -- This literal string list is the first term in a
634 -- string list expression
637 String_Element_Table
.Last
638 (Shared
.String_Elements
);
641 Shared
.String_Elements
.Table
(Last
).Next
:=
642 String_Element_Table
.Last
(Shared
.String_Elements
);
646 String_Element_Table
.Last
(Shared
.String_Elements
);
648 Shared
.String_Elements
.Table
(Last
) :=
649 (Value
=> Value
.Value
,
650 Display_Value
=> No_Name
,
651 Location
=> Value
.Location
,
654 Index
=> Value
.Index
);
657 -- Add the other element of the literal string list
658 -- one after the other.
661 Next_Expression_In_List
662 (String_Node
, From_Project_Node_Tree
);
664 exit when No
(String_Node
);
670 From_Project_Node
=> From_Project_Node
,
671 From_Project_Node_Tree
=> From_Project_Node_Tree
,
676 (String_Node
, From_Project_Node_Tree
),
679 String_Element_Table
.Increment_Last
680 (Shared
.String_Elements
);
681 Shared
.String_Elements
.Table
(Last
).Next
:=
682 String_Element_Table
.Last
(Shared
.String_Elements
);
683 Last
:= String_Element_Table
.Last
684 (Shared
.String_Elements
);
685 Shared
.String_Elements
.Table
(Last
) :=
686 (Value
=> Value
.Value
,
687 Display_Value
=> No_Name
,
688 Location
=> Value
.Location
,
691 Index
=> Value
.Index
);
696 when N_Variable_Reference | N_Attribute_Reference
=>
698 The_Project
: Project_Id
:= Project
;
699 The_Package
: Package_Id
:= Pkg
;
700 The_Name
: Name_Id
:= No_Name
;
701 The_Variable_Id
: Variable_Id
:= No_Variable
;
702 The_Variable
: Variable_Value
;
703 Term_Project
: constant Project_Node_Id
:=
706 From_Project_Node_Tree
);
707 Term_Package
: constant Project_Node_Id
:=
710 From_Project_Node_Tree
);
711 Index
: Name_Id
:= No_Name
;
714 <<Object_Dir_Restart
>>
715 The_Project
:= Project
;
718 The_Variable_Id
:= No_Variable
;
721 if Present
(Term_Project
)
722 and then Term_Project
/= From_Project_Node
724 -- This variable or attribute comes from another project
727 Name_Of
(Term_Project
, From_Project_Node_Tree
);
728 The_Project
:= Imported_Or_Extended_Project_From
730 With_Name
=> The_Name
,
731 No_Extending
=> True);
734 if Present
(Term_Package
) then
736 -- This is an attribute of a package
739 Name_Of
(Term_Package
, From_Project_Node_Tree
);
741 The_Package
:= The_Project
.Decl
.Packages
;
742 while The_Package
/= No_Package
743 and then Shared
.Packages
.Table
(The_Package
).Name
/=
747 Shared
.Packages
.Table
(The_Package
).Next
;
751 (The_Package
/= No_Package
, "package not found.");
753 elsif Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) =
754 N_Attribute_Reference
756 The_Package
:= No_Package
;
760 Name_Of
(The_Current_Term
, From_Project_Node_Tree
);
762 if Current_Term_Kind
= N_Attribute_Reference
then
764 Associative_Array_Index_Of
765 (The_Current_Term
, From_Project_Node_Tree
);
768 -- If it is not an associative array attribute
770 if Index
= No_Name
then
772 -- It is not an associative array attribute
774 if The_Package
/= No_Package
then
776 -- First, if there is a package, look into the package
778 if Current_Term_Kind
= N_Variable_Reference
then
780 Shared
.Packages
.Table
781 (The_Package
).Decl
.Variables
;
784 Shared
.Packages
.Table
785 (The_Package
).Decl
.Attributes
;
788 while The_Variable_Id
/= No_Variable
789 and then Shared
.Variable_Elements
.Table
790 (The_Variable_Id
).Name
/= The_Name
793 Shared
.Variable_Elements
.Table
794 (The_Variable_Id
).Next
;
799 if The_Variable_Id
= No_Variable
then
801 -- If we have not found it, look into the project
803 if Current_Term_Kind
= N_Variable_Reference
then
804 The_Variable_Id
:= The_Project
.Decl
.Variables
;
806 The_Variable_Id
:= The_Project
.Decl
.Attributes
;
809 while The_Variable_Id
/= No_Variable
810 and then Shared
.Variable_Elements
.Table
811 (The_Variable_Id
).Name
/= The_Name
814 Shared
.Variable_Elements
.Table
815 (The_Variable_Id
).Next
;
820 if From_Project_Node_Tree
.Incomplete_With
then
821 if The_Variable_Id
= No_Variable
then
822 The_Variable
:= Nil_Variable_Value
;
825 Shared
.Variable_Elements
.Table
826 (The_Variable_Id
).Value
;
830 pragma Assert
(The_Variable_Id
/= No_Variable
,
831 "variable or attribute not found");
834 Shared
.Variable_Elements
.Table
835 (The_Variable_Id
).Value
;
840 -- It is an associative array attribute
843 The_Array
: Array_Id
:= No_Array
;
844 The_Element
: Array_Element_Id
:= No_Array_Element
;
845 Array_Index
: Name_Id
:= No_Name
;
848 if The_Package
/= No_Package
then
850 Shared
.Packages
.Table
(The_Package
).Decl
.Arrays
;
852 The_Array
:= The_Project
.Decl
.Arrays
;
855 while The_Array
/= No_Array
856 and then Shared
.Arrays
.Table
(The_Array
).Name
/=
859 The_Array
:= Shared
.Arrays
.Table
(The_Array
).Next
;
862 if The_Array
/= No_Array
then
864 Shared
.Arrays
.Table
(The_Array
).Value
;
867 (From_Project_Node_Tree
,
871 while The_Element
/= No_Array_Element
872 and then Shared
.Array_Elements
.Table
873 (The_Element
).Index
/= Array_Index
876 Shared
.Array_Elements
.Table
(The_Element
).Next
;
881 if The_Element
/= No_Array_Element
then
883 Shared
.Array_Elements
.Table
(The_Element
).Value
;
886 if Expression_Kind_Of
887 (The_Current_Term
, From_Project_Node_Tree
) =
893 Location
=> No_Location
,
895 Values
=> Nil_String
);
900 Location
=> No_Location
,
902 Value
=> Empty_String
,
909 -- Check the defaults
911 if Current_Term_Kind
= N_Attribute_Reference
then
913 The_Default
: constant Attribute_Default_Value
:=
915 (The_Current_Term
, From_Project_Node_Tree
);
918 -- Check the special value for 'Target when specified
920 if The_Default
= Target_Value
921 and then Opt
.Target_Origin
= Specified
924 Add_Str_To_Name_Buffer
(Opt
.Target_Value
.all);
925 The_Variable
.Value
:= Name_Find
;
927 -- Check the defaults
929 elsif The_Variable
.Default
then
930 case The_Variable
.Kind
is
937 when Read_Only_Value
=>
941 The_Variable
.Value
:= Empty_String
;
944 The_Variable
.Value
:= Dot_String
;
946 when Object_Dir_Value
=>
947 From_Project_Node_Tree
.Project_Nodes
.Table
948 (The_Current_Term
).Name
:=
949 Snames
.Name_Object_Dir
;
950 From_Project_Node_Tree
.Project_Nodes
.Table
951 (The_Current_Term
).Default
:=
953 goto Object_Dir_Restart
;
956 if Opt
.Target_Value
= null then
957 The_Variable
.Value
:= Empty_String
;
961 Add_Str_To_Name_Buffer
962 (Opt
.Target_Value
.all);
963 The_Variable
.Value
:= Name_Find
;
966 when Runtime_Value
=>
967 Get_Name_String
(Index
);
968 To_Lower
(Name_Buffer
(1 .. Name_Len
));
969 The_Variable
.Value
:=
970 Runtime_Defaults
.Get
(Name_Find
);
971 if The_Variable
.Value
= No_Name
then
972 The_Variable
.Value
:= Empty_String
;
979 when Read_Only_Value
=>
983 The_Variable
.Values
:= Nil_String
;
986 The_Variable
.Values
:=
987 Shared
.Dot_String_List
;
989 when Object_Dir_Value |
1002 -- Should never happen
1004 pragma Assert
(False, "undefined expression kind");
1008 case The_Variable
.Kind
is
1014 Add
(Result
.Value
, The_Variable
.Value
);
1018 -- Should never happen
1022 "list cannot appear in single " &
1023 "string expression");
1028 case The_Variable
.Kind
is
1034 String_Element_Table
.Increment_Last
1035 (Shared
.String_Elements
);
1037 if Last
= Nil_String
then
1039 -- This can happen in an expression such as
1043 String_Element_Table
.Last
1044 (Shared
.String_Elements
);
1047 Shared
.String_Elements
.Table
(Last
).Next
:=
1048 String_Element_Table
.Last
1049 (Shared
.String_Elements
);
1053 String_Element_Table
.Last
1054 (Shared
.String_Elements
);
1056 Shared
.String_Elements
.Table
(Last
) :=
1057 (Value
=> The_Variable
.Value
,
1058 Display_Value
=> No_Name
,
1059 Location
=> Location_Of
1061 From_Project_Node_Tree
),
1069 The_List
: String_List_Id
:=
1070 The_Variable
.Values
;
1073 while The_List
/= Nil_String
loop
1074 String_Element_Table
.Increment_Last
1075 (Shared
.String_Elements
);
1077 if Last
= Nil_String
then
1079 String_Element_Table
.Last
1080 (Shared
.String_Elements
);
1084 String_Elements
.Table
(Last
).Next
:=
1085 String_Element_Table
.Last
1086 (Shared
.String_Elements
);
1091 String_Element_Table
.Last
1092 (Shared
.String_Elements
);
1094 Shared
.String_Elements
.Table
1097 Shared
.String_Elements
.Table
1099 Display_Value
=> No_Name
,
1103 From_Project_Node_Tree
),
1108 The_List
:= Shared
.String_Elements
.Table
1116 when N_External_Value
=>
1119 (External_Reference_Of
1120 (The_Current_Term
, From_Project_Node_Tree
),
1121 From_Project_Node_Tree
));
1124 Name
: constant Name_Id
:= Name_Find
;
1125 Default
: Name_Id
:= No_Name
;
1126 Value
: Name_Id
:= No_Name
;
1127 Ext_List
: Boolean := False;
1128 Str_List
: String_List_Access
:= null;
1129 Def_Var
: Variable_Value
;
1131 Default_Node
: constant Project_Node_Id
:=
1134 From_Project_Node_Tree
);
1137 -- If there is a default value for the external reference,
1140 if Present
(Default_Node
) then
1141 Def_Var
:= Expression
1142 (Project
=> Project
,
1144 From_Project_Node
=> From_Project_Node
,
1145 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1150 (Default_Node
, From_Project_Node_Tree
),
1153 if Def_Var
/= Nil_Variable_Value
then
1154 Default
:= Def_Var
.Value
;
1158 Ext_List
:= Expression_Kind_Of
1160 From_Project_Node_Tree
) = List
;
1163 Value
:= Prj
.Ext
.Value_Of
(Env
.External
, Name
, No_Name
);
1165 if Value
/= No_Name
then
1167 Sep
: constant String :=
1168 Get_Name_String
(Default
);
1169 First
: Positive := 1;
1171 Done
: Boolean := False;
1175 Get_Name_String
(Value
);
1178 or else Sep
'Length = 0
1179 or else Name_Buffer
(1 .. Name_Len
) = Sep
1184 if not Done
and then Name_Len
< Sep
'Length then
1188 (Name_Buffer
(1 .. Name_Len
)));
1193 if Name_Buffer
(1 .. Sep
'Length) = Sep
then
1194 First
:= Sep
'Length + 1;
1197 if Name_Len
- First
+ 1 >= Sep
'Length
1199 Name_Buffer
(Name_Len
- Sep
'Length + 1 ..
1202 Name_Len
:= Name_Len
- Sep
'Length;
1205 if Name_Len
= 0 then
1207 new String_List
'(1 => new String'(""));
1214 -- Count the number of strings
1217 Saved
: constant Positive := First
;
1225 Name_Buffer
(First
.. Name_Len
),
1229 First
:= Lst
+ Sep
'Length;
1235 Str_List
:= new String_List
(1 .. Nmb
);
1237 -- Populate the string list
1244 Name_Buffer
(First
.. Name_Len
),
1250 (Name_Buffer (First .. Name_Len));
1256 (Name_Buffer
(First
.. Lst
- 1));
1258 First
:= Lst
+ Sep
'Length;
1268 Value
:= Prj
.Ext
.Value_Of
(Env
.External
, Name
, Default
);
1270 if Value
= No_Name
then
1271 if not Quiet_Output
then
1273 (Env
.Flags
, "?undefined external reference",
1275 (The_Current_Term
, From_Project_Node_Tree
),
1279 Value
:= Empty_String
;
1293 Add
(Result
.Value
, Value
);
1297 if not Ext_List
or else Str_List
/= null then
1298 String_Element_Table
.Increment_Last
1299 (Shared
.String_Elements
);
1301 if Last
= Nil_String
then
1303 String_Element_Table
.Last
1304 (Shared
.String_Elements
);
1307 Shared
.String_Elements
.Table
(Last
).Next
1308 := String_Element_Table
.Last
1309 (Shared
.String_Elements
);
1312 Last
:= String_Element_Table
.Last
1313 (Shared
.String_Elements
);
1316 for Ind
in Str_List
'Range loop
1318 Add_Str_To_Name_Buffer
(Str_List
(Ind
).all);
1320 Shared
.String_Elements
.Table
(Last
) :=
1322 Display_Value
=> No_Name
,
1326 From_Project_Node_Tree
),
1331 if Ind
/= Str_List
'Last then
1332 String_Element_Table
.Increment_Last
1333 (Shared
.String_Elements
);
1334 Shared
.String_Elements
.Table
(Last
).Next
:=
1335 String_Element_Table
.Last
1336 (Shared
.String_Elements
);
1337 Last
:= String_Element_Table
.Last
1338 (Shared
.String_Elements
);
1343 Shared
.String_Elements
.Table
(Last
) :=
1345 Display_Value
=> No_Name
,
1349 From_Project_Node_Tree
),
1360 -- Should never happen
1364 "illegal node kind in an expression");
1365 raise Program_Error
;
1370 The_Term
:= Next_Term
(The_Term
, From_Project_Node_Tree
);
1376 ---------------------------------------
1377 -- Imported_Or_Extended_Project_From --
1378 ---------------------------------------
1380 function Imported_Or_Extended_Project_From
1381 (Project
: Project_Id
;
1382 With_Name
: Name_Id
;
1383 No_Extending
: Boolean := False) return Project_Id
1385 List
: Project_List
;
1386 Result
: Project_Id
;
1387 Temp_Result
: Project_Id
;
1390 -- First check if it is the name of an extended project
1392 Result
:= Project
.Extends
;
1393 while Result
/= No_Project
loop
1394 if Result
.Name
= With_Name
then
1397 Result
:= Result
.Extends
;
1401 -- Then check the name of each imported project
1403 Temp_Result
:= No_Project
;
1404 List
:= Project
.Imported_Projects
;
1405 while List
/= null loop
1406 Result
:= List
.Project
;
1408 -- If the project is directly imported, then returns its ID
1410 if Result
.Name
= With_Name
then
1414 -- If a project extending the project is imported, then keep this
1415 -- extending project as a possibility. It will be the returned ID
1416 -- if the project is not imported directly.
1422 Proj
:= Result
.Extends
;
1423 while Proj
/= No_Project
loop
1424 if Proj
.Name
= With_Name
then
1425 if No_Extending
then
1426 Temp_Result
:= Proj
;
1428 Temp_Result
:= Result
;
1434 Proj
:= Proj
.Extends
;
1441 pragma Assert
(Temp_Result
/= No_Project
, "project not found");
1443 end Imported_Or_Extended_Project_From
;
1449 function Package_From
1450 (Project
: Project_Id
;
1451 Shared
: Shared_Project_Tree_Data_Access
;
1452 With_Name
: Name_Id
) return Package_Id
1454 Result
: Package_Id
:= Project
.Decl
.Packages
;
1457 -- Check the name of each existing package of Project
1459 while Result
/= No_Package
1460 and then Shared
.Packages
.Table
(Result
).Name
/= With_Name
1462 Result
:= Shared
.Packages
.Table
(Result
).Next
;
1465 if Result
= No_Package
then
1467 -- Should never happen
1470 ("package """ & Get_Name_String
(With_Name
) & """ not found");
1471 raise Program_Error
;
1483 (In_Tree
: Project_Tree_Ref
;
1484 Project
: out Project_Id
;
1485 Packages_To_Check
: String_List_Access
;
1486 Success
: out Boolean;
1487 From_Project_Node
: Project_Node_Id
;
1488 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
1489 Env
: in out Prj
.Tree
.Environment
;
1490 Reset_Tree
: Boolean := True;
1491 On_New_Tree_Loaded
: Tree_Loaded_Callback
:= null)
1494 Process_Project_Tree_Phase_1
1495 (In_Tree
=> In_Tree
,
1498 From_Project_Node
=> From_Project_Node
,
1499 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1501 Packages_To_Check
=> Packages_To_Check
,
1502 Reset_Tree
=> Reset_Tree
,
1503 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
1505 if Project_Qualifier_Of
1506 (From_Project_Node
, From_Project_Node_Tree
) /= Configuration
1508 Process_Project_Tree_Phase_2
1509 (In_Tree
=> In_Tree
,
1512 From_Project_Node
=> From_Project_Node
,
1513 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1518 -------------------------------
1519 -- Process_Declarative_Items --
1520 -------------------------------
1522 procedure Process_Declarative_Items
1523 (Project
: Project_Id
;
1524 In_Tree
: Project_Tree_Ref
;
1525 From_Project_Node
: Project_Node_Id
;
1526 Node_Tree
: Project_Node_Tree_Ref
;
1527 Env
: Prj
.Tree
.Environment
;
1529 Item
: Project_Node_Id
;
1530 Child_Env
: in out Prj
.Tree
.Environment
)
1532 Shared
: constant Shared_Project_Tree_Data_Access
:= In_Tree
.Shared
;
1534 procedure Check_Or_Set_Typed_Variable
1535 (Value
: in out Variable_Value
;
1536 Declaration
: Project_Node_Id
);
1537 -- Check whether Value is valid for this typed variable declaration. If
1538 -- it is an error, the behavior depends on the flags: either an error is
1539 -- reported, or a warning, or nothing. In the last two cases, the value
1540 -- of the variable is set to a valid value, replacing Value.
1542 procedure Process_Package_Declaration
1543 (Current_Item
: Project_Node_Id
);
1544 procedure Process_Attribute_Declaration
1545 (Current
: Project_Node_Id
);
1546 procedure Process_Case_Construction
1547 (Current_Item
: Project_Node_Id
);
1548 procedure Process_Associative_Array
1549 (Current_Item
: Project_Node_Id
);
1550 procedure Process_Expression
1551 (Current
: Project_Node_Id
);
1552 procedure Process_Expression_For_Associative_Array
1553 (Current
: Project_Node_Id
;
1554 New_Value
: Variable_Value
);
1555 procedure Process_Expression_Variable_Decl
1556 (Current_Item
: Project_Node_Id
;
1557 New_Value
: Variable_Value
);
1558 -- Process the various declarative items
1560 ---------------------------------
1561 -- Check_Or_Set_Typed_Variable --
1562 ---------------------------------
1564 procedure Check_Or_Set_Typed_Variable
1565 (Value
: in out Variable_Value
;
1566 Declaration
: Project_Node_Id
)
1568 Loc
: constant Source_Ptr
:= Location_Of
(Declaration
, Node_Tree
);
1570 Reset_Value
: Boolean := False;
1571 Current_String
: Project_Node_Id
;
1574 -- Report an error for an empty string
1576 if Value
.Value
= Empty_String
then
1577 Error_Msg_Name_1
:= Name_Of
(Declaration
, Node_Tree
);
1579 case Env
.Flags
.Allow_Invalid_External
is
1582 (Env
.Flags
, "no value defined for %%", Loc
, Project
);
1584 Reset_Value
:= True;
1586 (Env
.Flags
, "?no value defined for %%", Loc
, Project
);
1588 Reset_Value
:= True;
1592 -- Loop through all the valid strings for the
1593 -- string type and compare to the string value.
1596 First_Literal_String
1597 (String_Type_Of
(Declaration
, Node_Tree
), Node_Tree
);
1599 while Present
(Current_String
)
1601 String_Value_Of
(Current_String
, Node_Tree
) /= Value
.Value
1604 Next_Literal_String
(Current_String
, Node_Tree
);
1607 -- Report error if string value is not one for the string type
1609 if No
(Current_String
) then
1610 Error_Msg_Name_1
:= Value
.Value
;
1611 Error_Msg_Name_2
:= Name_Of
(Declaration
, Node_Tree
);
1613 case Env
.Flags
.Allow_Invalid_External
is
1616 (Env
.Flags
, "value %% is illegal for typed string %%",
1621 (Env
.Flags
, "?value %% is illegal for typed string %%",
1623 Reset_Value
:= True;
1626 Reset_Value
:= True;
1633 First_Literal_String
1634 (String_Type_Of
(Declaration
, Node_Tree
), Node_Tree
);
1635 Value
.Value
:= String_Value_Of
(Current_String
, Node_Tree
);
1637 end Check_Or_Set_Typed_Variable
;
1639 ---------------------------------
1640 -- Process_Package_Declaration --
1641 ---------------------------------
1643 procedure Process_Package_Declaration
1644 (Current_Item
: Project_Node_Id
)
1647 -- Do not process a package declaration that should be ignored
1649 if Expression_Kind_Of
(Current_Item
, Node_Tree
) /= Ignored
then
1651 -- Create the new package
1653 Package_Table
.Increment_Last
(Shared
.Packages
);
1656 New_Pkg
: constant Package_Id
:=
1657 Package_Table
.Last
(Shared
.Packages
);
1658 The_New_Package
: Package_Element
;
1660 Project_Of_Renamed_Package
: constant Project_Node_Id
:=
1661 Project_Of_Renamed_Package_Of
1662 (Current_Item
, Node_Tree
);
1665 -- Set the name of the new package
1667 The_New_Package
.Name
:= Name_Of
(Current_Item
, Node_Tree
);
1669 -- Insert the new package in the appropriate list
1671 if Pkg
/= No_Package
then
1672 The_New_Package
.Next
:=
1673 Shared
.Packages
.Table
(Pkg
).Decl
.Packages
;
1674 Shared
.Packages
.Table
(Pkg
).Decl
.Packages
:= New_Pkg
;
1677 The_New_Package
.Next
:= Project
.Decl
.Packages
;
1678 Project
.Decl
.Packages
:= New_Pkg
;
1681 Shared
.Packages
.Table
(New_Pkg
) := The_New_Package
;
1683 if Present
(Project_Of_Renamed_Package
) then
1685 -- Renamed or extending package
1688 Project_Name
: constant Name_Id
:=
1689 Name_Of
(Project_Of_Renamed_Package
,
1692 Renamed_Project
: constant Project_Id
:=
1693 Imported_Or_Extended_Project_From
1694 (Project
, Project_Name
);
1696 Renamed_Package
: constant Package_Id
:=
1698 (Renamed_Project
, Shared
,
1699 Name_Of
(Current_Item
, Node_Tree
));
1702 -- For a renamed package, copy the declarations of the
1703 -- renamed package, but set all the locations to the
1704 -- location of the package name in the renaming
1707 Copy_Package_Declarations
1708 (From
=> Shared
.Packages
.Table
1709 (Renamed_Package
).Decl
,
1710 To
=> Shared
.Packages
.Table
(New_Pkg
).Decl
,
1711 New_Loc
=> Location_Of
(Current_Item
, Node_Tree
),
1712 Restricted
=> False,
1717 -- Set the default values of the attributes
1722 Name_Id
(Project
.Directory
.Display_Name
),
1724 Shared
.Packages
.Table
(New_Pkg
).Decl
,
1726 (Package_Id_Of
(Current_Item
, Node_Tree
)),
1727 Project_Level
=> False);
1730 -- Process declarative items (nothing to do when the package is
1731 -- renaming, as the first declarative item is null).
1733 Process_Declarative_Items
1734 (Project
=> Project
,
1736 From_Project_Node
=> From_Project_Node
,
1737 Node_Tree
=> Node_Tree
,
1741 First_Declarative_Item_Of
(Current_Item
, Node_Tree
),
1742 Child_Env
=> Child_Env
);
1745 end Process_Package_Declaration
;
1747 -------------------------------
1748 -- Process_Associative_Array --
1749 -------------------------------
1751 procedure Process_Associative_Array
1752 (Current_Item
: Project_Node_Id
)
1754 Current_Item_Name
: constant Name_Id
:=
1755 Name_Of
(Current_Item
, Node_Tree
);
1756 -- The name of the attribute
1758 Current_Location
: constant Source_Ptr
:=
1759 Location_Of
(Current_Item
, Node_Tree
);
1761 New_Array
: Array_Id
;
1762 -- The new associative array created
1764 Orig_Array
: Array_Id
;
1765 -- The associative array value
1767 Orig_Project_Name
: Name_Id
:= No_Name
;
1768 -- The name of the project where the associative array
1771 Orig_Project
: Project_Id
:= No_Project
;
1772 -- The id of the project where the associative array
1775 Orig_Package_Name
: Name_Id
:= No_Name
;
1776 -- The name of the package, if any, where the associative array value
1779 Orig_Package
: Package_Id
:= No_Package
;
1780 -- The id of the package, if any, where the associative array value
1783 New_Element
: Array_Element_Id
:= No_Array_Element
;
1784 -- Id of a new array element created
1786 Prev_Element
: Array_Element_Id
:= No_Array_Element
;
1787 -- Last new element id created
1789 Orig_Element
: Array_Element_Id
:= No_Array_Element
;
1790 -- Current array element in original associative array
1792 Next_Element
: Array_Element_Id
:= No_Array_Element
;
1793 -- Id of the array element that follows the new element. This is not
1794 -- always nil, because values for the associative array attribute may
1795 -- already have been declared, and the array elements declared are
1801 -- First find if the associative array attribute already has elements
1804 if Pkg
/= No_Package
then
1805 New_Array
:= Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
;
1807 New_Array
:= Project
.Decl
.Arrays
;
1810 while New_Array
/= No_Array
1811 and then Shared
.Arrays
.Table
(New_Array
).Name
/= Current_Item_Name
1813 New_Array
:= Shared
.Arrays
.Table
(New_Array
).Next
;
1816 -- If the attribute has never been declared add new entry in the
1817 -- arrays of the project/package and link it.
1819 if New_Array
= No_Array
then
1820 Array_Table
.Increment_Last
(Shared
.Arrays
);
1821 New_Array
:= Array_Table
.Last
(Shared
.Arrays
);
1823 if Pkg
/= No_Package
then
1824 Shared
.Arrays
.Table
(New_Array
) :=
1825 (Name
=> Current_Item_Name
,
1826 Location
=> Current_Location
,
1827 Value
=> No_Array_Element
,
1828 Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
);
1830 Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
:= New_Array
;
1833 Shared
.Arrays
.Table
(New_Array
) :=
1834 (Name
=> Current_Item_Name
,
1835 Location
=> Current_Location
,
1836 Value
=> No_Array_Element
,
1837 Next
=> Project
.Decl
.Arrays
);
1839 Project
.Decl
.Arrays
:= New_Array
;
1843 -- Find the project where the value is declared
1845 Orig_Project_Name
:=
1847 (Associative_Project_Of
(Current_Item
, Node_Tree
), Node_Tree
);
1849 Prj
:= In_Tree
.Projects
;
1850 while Prj
/= null loop
1851 if Prj
.Project
.Name
= Orig_Project_Name
then
1852 Orig_Project
:= Prj
.Project
;
1858 pragma Assert
(Orig_Project
/= No_Project
,
1859 "original project not found");
1861 if No
(Associative_Package_Of
(Current_Item
, Node_Tree
)) then
1862 Orig_Array
:= Orig_Project
.Decl
.Arrays
;
1865 -- If in a package, find the package where the value is declared
1867 Orig_Package_Name
:=
1869 (Associative_Package_Of
(Current_Item
, Node_Tree
), Node_Tree
);
1871 Orig_Package
:= Orig_Project
.Decl
.Packages
;
1872 pragma Assert
(Orig_Package
/= No_Package
,
1873 "original package not found");
1875 while Shared
.Packages
.Table
1876 (Orig_Package
).Name
/= Orig_Package_Name
1878 Orig_Package
:= Shared
.Packages
.Table
(Orig_Package
).Next
;
1879 pragma Assert
(Orig_Package
/= No_Package
,
1880 "original package not found");
1883 Orig_Array
:= Shared
.Packages
.Table
(Orig_Package
).Decl
.Arrays
;
1886 -- Now look for the array
1888 while Orig_Array
/= No_Array
1889 and then Shared
.Arrays
.Table
(Orig_Array
).Name
/= Current_Item_Name
1891 Orig_Array
:= Shared
.Arrays
.Table
(Orig_Array
).Next
;
1894 if Orig_Array
= No_Array
then
1897 "associative array value not found",
1898 Location_Of
(Current_Item
, Node_Tree
),
1902 Orig_Element
:= Shared
.Arrays
.Table
(Orig_Array
).Value
;
1904 -- Copy each array element
1906 while Orig_Element
/= No_Array_Element
loop
1908 -- Case of first element
1910 if Prev_Element
= No_Array_Element
then
1912 -- And there is no array element declared yet, create a new
1913 -- first array element.
1915 if Shared
.Arrays
.Table
(New_Array
).Value
=
1918 Array_Element_Table
.Increment_Last
1919 (Shared
.Array_Elements
);
1920 New_Element
:= Array_Element_Table
.Last
1921 (Shared
.Array_Elements
);
1922 Shared
.Arrays
.Table
(New_Array
).Value
:= New_Element
;
1923 Next_Element
:= No_Array_Element
;
1925 -- Otherwise, the new element is the first
1928 New_Element
:= Shared
.Arrays
.Table
(New_Array
).Value
;
1930 Shared
.Array_Elements
.Table
(New_Element
).Next
;
1933 -- Otherwise, reuse an existing element, or create
1934 -- one if necessary.
1938 Shared
.Array_Elements
.Table
(Prev_Element
).Next
;
1940 if Next_Element
= No_Array_Element
then
1941 Array_Element_Table
.Increment_Last
1942 (Shared
.Array_Elements
);
1943 New_Element
:= Array_Element_Table
.Last
1944 (Shared
.Array_Elements
);
1945 Shared
.Array_Elements
.Table
(Prev_Element
).Next
:=
1949 New_Element
:= Next_Element
;
1951 Shared
.Array_Elements
.Table
(New_Element
).Next
;
1955 -- Copy the value of the element
1957 Shared
.Array_Elements
.Table
(New_Element
) :=
1958 Shared
.Array_Elements
.Table
(Orig_Element
);
1959 Shared
.Array_Elements
.Table
(New_Element
).Value
.Project
1962 -- Adjust the Next link
1964 Shared
.Array_Elements
.Table
(New_Element
).Next
:= Next_Element
;
1966 -- Adjust the previous id for the next element
1968 Prev_Element
:= New_Element
;
1970 -- Go to the next element in the original array
1972 Orig_Element
:= Shared
.Array_Elements
.Table
(Orig_Element
).Next
;
1975 -- Make sure that the array ends here, in case there previously a
1976 -- greater number of elements.
1978 Shared
.Array_Elements
.Table
(New_Element
).Next
:= No_Array_Element
;
1980 end Process_Associative_Array
;
1982 ----------------------------------------------
1983 -- Process_Expression_For_Associative_Array --
1984 ----------------------------------------------
1986 procedure Process_Expression_For_Associative_Array
1987 (Current
: Project_Node_Id
;
1988 New_Value
: Variable_Value
)
1990 Name
: constant Name_Id
:= Name_Of
(Current
, Node_Tree
);
1991 Current_Location
: constant Source_Ptr
:=
1992 Location_Of
(Current
, Node_Tree
);
1994 Index_Name
: Name_Id
:=
1995 Associative_Array_Index_Of
(Current
, Node_Tree
);
1997 Source_Index
: constant Int
:=
1998 Source_Index_Of
(Current
, Node_Tree
);
2000 The_Array
: Array_Id
;
2001 Elem
: Array_Element_Id
:= No_Array_Element
;
2004 if Index_Name
/= All_Other_Names
then
2005 Index_Name
:= Get_Attribute_Index
(Node_Tree
, Current
, Index_Name
);
2008 -- Look for the array in the appropriate list
2010 if Pkg
/= No_Package
then
2011 The_Array
:= Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
;
2013 The_Array
:= Project
.Decl
.Arrays
;
2016 while The_Array
/= No_Array
2017 and then Shared
.Arrays
.Table
(The_Array
).Name
/= Name
2019 The_Array
:= Shared
.Arrays
.Table
(The_Array
).Next
;
2022 -- If the array cannot be found, create a new entry in the list.
2023 -- As The_Array_Element is initialized to No_Array_Element, a new
2024 -- element will be created automatically later
2026 if The_Array
= No_Array
then
2027 Array_Table
.Increment_Last
(Shared
.Arrays
);
2028 The_Array
:= Array_Table
.Last
(Shared
.Arrays
);
2030 if Pkg
/= No_Package
then
2031 Shared
.Arrays
.Table
(The_Array
) :=
2033 Location
=> Current_Location
,
2034 Value
=> No_Array_Element
,
2035 Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
);
2037 Shared
.Packages
.Table
(Pkg
).Decl
.Arrays
:= The_Array
;
2040 Shared
.Arrays
.Table
(The_Array
) :=
2042 Location
=> Current_Location
,
2043 Value
=> No_Array_Element
,
2044 Next
=> Project
.Decl
.Arrays
);
2046 Project
.Decl
.Arrays
:= The_Array
;
2050 Elem
:= Shared
.Arrays
.Table
(The_Array
).Value
;
2053 -- Look in the list, if any, to find an element with the same index
2054 -- and same source index.
2056 while Elem
/= No_Array_Element
2058 (Shared
.Array_Elements
.Table
(Elem
).Index
/= Index_Name
2060 Shared
.Array_Elements
.Table
(Elem
).Src_Index
/= Source_Index
)
2062 Elem
:= Shared
.Array_Elements
.Table
(Elem
).Next
;
2065 -- If no such element were found, create a new one
2066 -- and insert it in the element list, with the
2069 if Elem
= No_Array_Element
then
2070 Array_Element_Table
.Increment_Last
(Shared
.Array_Elements
);
2071 Elem
:= Array_Element_Table
.Last
(Shared
.Array_Elements
);
2073 Shared
.Array_Elements
.Table
2075 (Index
=> Index_Name
,
2076 Restricted
=> False,
2077 Src_Index
=> Source_Index
,
2078 Index_Case_Sensitive
=>
2079 not Case_Insensitive
(Current
, Node_Tree
),
2081 Next
=> Shared
.Arrays
.Table
(The_Array
).Value
);
2083 Shared
.Arrays
.Table
(The_Array
).Value
:= Elem
;
2086 -- An element with the same index already exists, just replace its
2087 -- value with the new one.
2089 Shared
.Array_Elements
.Table
(Elem
).Value
:= New_Value
;
2092 if Name
= Snames
.Name_External
then
2093 if In_Tree
.Is_Root_Tree
then
2094 Add
(Child_Env
.External
,
2095 External_Name
=> Get_Name_String
(Index_Name
),
2096 Value
=> Get_Name_String
(New_Value
.Value
),
2097 Source
=> From_External_Attribute
);
2099 External_Name
=> Get_Name_String
(Index_Name
),
2100 Value
=> Get_Name_String
(New_Value
.Value
),
2101 Source
=> From_External_Attribute
,
2104 if Current_Verbosity
= High
then
2106 ("'for External' has no effect except in root aggregate ("
2107 & Get_Name_String
(Index_Name
) & ")", New_Value
.Value
);
2111 end Process_Expression_For_Associative_Array
;
2113 --------------------------------------
2114 -- Process_Expression_Variable_Decl --
2115 --------------------------------------
2117 procedure Process_Expression_Variable_Decl
2118 (Current_Item
: Project_Node_Id
;
2119 New_Value
: Variable_Value
)
2121 Name
: constant Name_Id
:= Name_Of
(Current_Item
, Node_Tree
);
2123 Is_Attribute
: constant Boolean :=
2124 Kind_Of
(Current_Item
, Node_Tree
) =
2125 N_Attribute_Declaration
;
2127 Var
: Variable_Id
:= No_Variable
;
2130 -- First, find the list where to find the variable or attribute
2132 if Is_Attribute
then
2133 if Pkg
/= No_Package
then
2134 Var
:= Shared
.Packages
.Table
(Pkg
).Decl
.Attributes
;
2136 Var
:= Project
.Decl
.Attributes
;
2140 if Pkg
/= No_Package
then
2141 Var
:= Shared
.Packages
.Table
(Pkg
).Decl
.Variables
;
2143 Var
:= Project
.Decl
.Variables
;
2147 -- Loop through the list, to find if it has already been declared
2149 while Var
/= No_Variable
2150 and then Shared
.Variable_Elements
.Table
(Var
).Name
/= Name
2152 Var
:= Shared
.Variable_Elements
.Table
(Var
).Next
;
2155 -- If it has not been declared, create a new entry in the list
2157 if Var
= No_Variable
then
2159 -- All single string attribute should already have been declared
2160 -- with a default empty string value.
2164 "illegal attribute declaration for " & Get_Name_String
(Name
));
2166 Variable_Element_Table
.Increment_Last
(Shared
.Variable_Elements
);
2167 Var
:= Variable_Element_Table
.Last
(Shared
.Variable_Elements
);
2169 -- Put the new variable in the appropriate list
2171 if Pkg
/= No_Package
then
2172 Shared
.Variable_Elements
.Table
(Var
) :=
2173 (Next
=> Shared
.Packages
.Table
(Pkg
).Decl
.Variables
,
2175 Value
=> New_Value
);
2176 Shared
.Packages
.Table
(Pkg
).Decl
.Variables
:= Var
;
2179 Shared
.Variable_Elements
.Table
(Var
) :=
2180 (Next
=> Project
.Decl
.Variables
,
2182 Value
=> New_Value
);
2183 Project
.Decl
.Variables
:= Var
;
2186 -- If the variable/attribute has already been declared, just
2187 -- change the value.
2190 Shared
.Variable_Elements
.Table
(Var
).Value
:= New_Value
;
2193 if Is_Attribute
and then Name
= Snames
.Name_Project_Path
then
2194 if In_Tree
.Is_Root_Tree
then
2197 new Ada
.Containers
.Vectors
(Positive, Name_Id
);
2198 Val
: String_List_Id
:= New_Value
.Values
;
2199 List
: Name_Ids
.Vector
;
2203 while Val
/= Nil_String
loop
2205 (Shared
.String_Elements
.Table
(Val
).Value
);
2206 Val
:= Shared
.String_Elements
.Table
(Val
).Next
;
2209 -- Prepend them in the order found in the attribute
2211 for K
in Positive range 1 .. Positive (List
.Length
) loop
2212 Prj
.Env
.Add_Directories
2213 (Child_Env
.Project_Path
,
2215 (Name
=> Get_Name_String
2217 Directory
=> Get_Name_String
2218 (Project
.Directory
.Display_Name
)),
2224 if Current_Verbosity
= High
then
2226 ("'for Project_Path' has no effect except in"
2227 & " root aggregate");
2231 end Process_Expression_Variable_Decl
;
2233 ------------------------
2234 -- Process_Expression --
2235 ------------------------
2237 procedure Process_Expression
(Current
: Project_Node_Id
) is
2238 New_Value
: Variable_Value
:=
2240 (Project
=> Project
,
2242 From_Project_Node
=> From_Project_Node
,
2243 From_Project_Node_Tree
=> Node_Tree
,
2248 (Expression_Of
(Current
, Node_Tree
), Node_Tree
),
2250 Expression_Kind_Of
(Current
, Node_Tree
));
2253 -- Process a typed variable declaration
2255 if Kind_Of
(Current
, Node_Tree
) = N_Typed_Variable_Declaration
then
2256 Check_Or_Set_Typed_Variable
(New_Value
, Current
);
2259 if Kind_Of
(Current
, Node_Tree
) /= N_Attribute_Declaration
2260 or else Associative_Array_Index_Of
(Current
, Node_Tree
) = No_Name
2262 Process_Expression_Variable_Decl
(Current
, New_Value
);
2264 Process_Expression_For_Associative_Array
(Current
, New_Value
);
2266 end Process_Expression
;
2268 -----------------------------------
2269 -- Process_Attribute_Declaration --
2270 -----------------------------------
2272 procedure Process_Attribute_Declaration
(Current
: Project_Node_Id
) is
2274 if Expression_Of
(Current
, Node_Tree
) = Empty_Node
then
2275 Process_Associative_Array
(Current
);
2277 Process_Expression
(Current
);
2279 end Process_Attribute_Declaration
;
2281 -------------------------------
2282 -- Process_Case_Construction --
2283 -------------------------------
2285 procedure Process_Case_Construction
2286 (Current_Item
: Project_Node_Id
)
2288 The_Project
: Project_Id
:= Project
;
2289 -- The id of the project of the case variable
2291 The_Package
: Package_Id
:= Pkg
;
2292 -- The id of the package, if any, of the case variable
2294 The_Variable
: Variable_Value
:= Nil_Variable_Value
;
2295 -- The case variable
2297 Case_Value
: Name_Id
:= No_Name
;
2298 -- The case variable value
2300 Case_Item
: Project_Node_Id
:= Empty_Node
;
2301 Choice_String
: Project_Node_Id
:= Empty_Node
;
2302 Decl_Item
: Project_Node_Id
:= Empty_Node
;
2306 Variable_Node
: constant Project_Node_Id
:=
2307 Case_Variable_Reference_Of
2311 Var_Id
: Variable_Id
:= No_Variable
;
2312 Name
: Name_Id
:= No_Name
;
2315 -- If a project was specified for the case variable, get its id
2317 if Present
(Project_Node_Of
(Variable_Node
, Node_Tree
)) then
2320 (Project_Node_Of
(Variable_Node
, Node_Tree
), Node_Tree
);
2322 Imported_Or_Extended_Project_From
2323 (Project
, Name
, No_Extending
=> True);
2324 The_Package
:= No_Package
;
2327 -- If a package was specified for the case variable, get its id
2329 if Present
(Package_Node_Of
(Variable_Node
, Node_Tree
)) then
2332 (Package_Node_Of
(Variable_Node
, Node_Tree
), Node_Tree
);
2333 The_Package
:= Package_From
(The_Project
, Shared
, Name
);
2336 Name
:= Name_Of
(Variable_Node
, Node_Tree
);
2338 -- First, look for the case variable into the package, if any
2340 if The_Package
/= No_Package
then
2341 Name
:= Name_Of
(Variable_Node
, Node_Tree
);
2343 Var_Id
:= Shared
.Packages
.Table
(The_Package
).Decl
.Variables
;
2344 while Var_Id
/= No_Variable
2345 and then Shared
.Variable_Elements
.Table
(Var_Id
).Name
/= Name
2347 Var_Id
:= Shared
.Variable_Elements
.Table
(Var_Id
).Next
;
2351 -- If not found in the package, or if there is no package, look at
2352 -- the project level.
2354 if Var_Id
= No_Variable
2355 and then No
(Package_Node_Of
(Variable_Node
, Node_Tree
))
2357 Var_Id
:= The_Project
.Decl
.Variables
;
2358 while Var_Id
/= No_Variable
2359 and then Shared
.Variable_Elements
.Table
(Var_Id
).Name
/= Name
2361 Var_Id
:= Shared
.Variable_Elements
.Table
(Var_Id
).Next
;
2365 if Var_Id
= No_Variable
then
2366 if Node_Tree
.Incomplete_With
then
2369 -- Should never happen, because this has already been checked
2374 ("variable """ & Get_Name_String
(Name
) & """ not found");
2375 raise Program_Error
;
2379 -- Get the case variable
2381 The_Variable
:= Shared
.Variable_Elements
. Table
(Var_Id
).Value
;
2383 if The_Variable
.Kind
/= Single
then
2385 -- Should never happen, because this has already been checked
2388 Write_Line
("variable""" & Get_Name_String
(Name
) &
2389 """ is not a single string variable");
2390 raise Program_Error
;
2393 -- Get the case variable value
2395 Case_Value
:= The_Variable
.Value
;
2398 -- Now look into all the case items of the case construction
2400 Case_Item
:= First_Case_Item_Of
(Current_Item
, Node_Tree
);
2403 while Present
(Case_Item
) loop
2404 Choice_String
:= First_Choice_Of
(Case_Item
, Node_Tree
);
2406 -- When Choice_String is nil, it means that it is the
2407 -- "when others =>" alternative.
2409 if No
(Choice_String
) then
2410 Decl_Item
:= First_Declarative_Item_Of
(Case_Item
, Node_Tree
);
2411 exit Case_Item_Loop
;
2414 -- Look into all the alternative of this case item
2417 while Present
(Choice_String
) loop
2418 if Case_Value
= String_Value_Of
(Choice_String
, Node_Tree
) then
2420 First_Declarative_Item_Of
(Case_Item
, Node_Tree
);
2421 exit Case_Item_Loop
;
2424 Choice_String
:= Next_Literal_String
(Choice_String
, Node_Tree
);
2425 end loop Choice_Loop
;
2427 Case_Item
:= Next_Case_Item
(Case_Item
, Node_Tree
);
2428 end loop Case_Item_Loop
;
2430 -- If there is an alternative, then we process it
2432 if Present
(Decl_Item
) then
2433 Process_Declarative_Items
2434 (Project
=> Project
,
2436 From_Project_Node
=> From_Project_Node
,
2437 Node_Tree
=> Node_Tree
,
2441 Child_Env
=> Child_Env
);
2443 end Process_Case_Construction
;
2447 Current
, Decl
: Project_Node_Id
;
2448 Kind
: Project_Node_Kind
;
2450 -- Start of processing for Process_Declarative_Items
2454 while Present
(Decl
) loop
2455 Current
:= Current_Item_Node
(Decl
, Node_Tree
);
2456 Decl
:= Next_Declarative_Item
(Decl
, Node_Tree
);
2457 Kind
:= Kind_Of
(Current
, Node_Tree
);
2460 when N_Package_Declaration
=>
2461 Process_Package_Declaration
(Current
);
2463 -- Nothing to process for string type declaration
2465 when N_String_Type_Declaration
=>
2468 when N_Attribute_Declaration |
2469 N_Typed_Variable_Declaration |
2470 N_Variable_Declaration
=>
2471 Process_Attribute_Declaration
(Current
);
2473 when N_Case_Construction
=>
2474 Process_Case_Construction
(Current
);
2477 Write_Line
("Illegal declarative item: " & Kind
'Img);
2478 raise Program_Error
;
2481 end Process_Declarative_Items
;
2483 ----------------------------------
2484 -- Process_Project_Tree_Phase_1 --
2485 ----------------------------------
2487 procedure Process_Project_Tree_Phase_1
2488 (In_Tree
: Project_Tree_Ref
;
2489 Project
: out Project_Id
;
2490 Packages_To_Check
: String_List_Access
;
2491 Success
: out Boolean;
2492 From_Project_Node
: Project_Node_Id
;
2493 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2494 Env
: in out Prj
.Tree
.Environment
;
2495 Reset_Tree
: Boolean := True;
2496 On_New_Tree_Loaded
: Tree_Loaded_Callback
:= null)
2501 -- Make sure there are no projects in the data structure
2503 Free_List
(In_Tree
.Projects
, Free_Project
=> True);
2506 Processed_Projects
.Reset
;
2508 -- And process the main project and all of the projects it depends on,
2511 Debug_Increase_Indent
("Process tree, phase 1");
2514 (Project
=> Project
,
2516 Packages_To_Check
=> Packages_To_Check
,
2517 From_Project_Node
=> From_Project_Node
,
2518 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2520 Extended_By
=> No_Project
,
2521 From_Encapsulated_Lib
=> False,
2522 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
2525 Total_Errors_Detected
= 0
2527 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2529 if Current_Verbosity
= High
then
2530 Debug_Decrease_Indent
2531 ("Done Process tree, phase 1, Success=" & Success
'Img);
2533 end Process_Project_Tree_Phase_1
;
2535 ----------------------------------
2536 -- Process_Project_Tree_Phase_2 --
2537 ----------------------------------
2539 procedure Process_Project_Tree_Phase_2
2540 (In_Tree
: Project_Tree_Ref
;
2541 Project
: Project_Id
;
2542 Success
: out Boolean;
2543 From_Project_Node
: Project_Node_Id
;
2544 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2547 Obj_Dir
: Path_Name_Type
;
2548 Extending
: Project_Id
;
2549 Extending2
: Project_Id
;
2552 -- Start of processing for Process_Project_Tree_Phase_2
2557 Debug_Increase_Indent
("Process tree, phase 2", Project
.Name
);
2559 if Project
/= No_Project
then
2560 Check
(In_Tree
, Project
, From_Project_Node_Tree
, Env
.Flags
);
2563 -- If main project is an extending all project, set object directory of
2564 -- all virtual extending projects to object directory of main project.
2566 if Project
/= No_Project
2567 and then Is_Extending_All
(From_Project_Node
, From_Project_Node_Tree
)
2570 Object_Dir
: constant Path_Information
:= Project
.Object_Directory
;
2573 Prj
:= In_Tree
.Projects
;
2574 while Prj
/= null loop
2575 if Prj
.Project
.Virtual
then
2576 Prj
.Project
.Object_Directory
:= Object_Dir
;
2584 -- Check that no extending project shares its object directory with
2585 -- the project(s) it extends.
2587 if Project
/= No_Project
then
2588 Prj
:= In_Tree
.Projects
;
2589 while Prj
/= null loop
2590 Extending
:= Prj
.Project
.Extended_By
;
2592 if Extending
/= No_Project
then
2593 Obj_Dir
:= Prj
.Project
.Object_Directory
.Name
;
2595 -- Check that a project being extended does not share its
2596 -- object directory with any project that extends it, directly
2597 -- or indirectly, including a virtual extending project.
2599 -- Start with the project directly extending it
2601 Extending2
:= Extending
;
2602 while Extending2
/= No_Project
loop
2603 if Has_Ada_Sources
(Extending2
)
2604 and then Extending2
.Object_Directory
.Name
= Obj_Dir
2606 if Extending2
.Virtual
then
2607 Error_Msg_Name_1
:= Prj
.Project
.Display_Name
;
2610 "project %% cannot be extended by a virtual" &
2611 " project with the same object directory",
2612 Prj
.Project
.Location
, Project
);
2615 Error_Msg_Name_1
:= Extending2
.Display_Name
;
2616 Error_Msg_Name_2
:= Prj
.Project
.Display_Name
;
2619 "project %% cannot extend project %%",
2620 Extending2
.Location
, Project
);
2623 "\they share the same object directory",
2624 Extending2
.Location
, Project
);
2628 -- Continue with the next extending project, if any
2630 Extending2
:= Extending2
.Extended_By
;
2638 Debug_Decrease_Indent
("Done Process tree, phase 2");
2640 Success
:= Total_Errors_Detected
= 0
2642 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2643 end Process_Project_Tree_Phase_2
;
2645 -----------------------
2646 -- Recursive_Process --
2647 -----------------------
2649 procedure Recursive_Process
2650 (In_Tree
: Project_Tree_Ref
;
2651 Project
: out Project_Id
;
2652 Packages_To_Check
: String_List_Access
;
2653 From_Project_Node
: Project_Node_Id
;
2654 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2655 Env
: in out Prj
.Tree
.Environment
;
2656 Extended_By
: Project_Id
;
2657 From_Encapsulated_Lib
: Boolean;
2658 On_New_Tree_Loaded
: Tree_Loaded_Callback
:= null)
2660 Shared
: constant Shared_Project_Tree_Data_Access
:= In_Tree
.Shared
;
2662 Child_Env
: Prj
.Tree
.Environment
;
2663 -- Only used for the root aggregate project (if any). This is left
2664 -- uninitialized otherwise.
2666 procedure Process_Imported_Projects
2667 (Imported
: in out Project_List
;
2668 Limited_With
: Boolean);
2669 -- Process imported projects. If Limited_With is True, then only
2670 -- projects processed through a "limited with" are processed, otherwise
2671 -- only projects imported through a standard "with" are processed.
2672 -- Imported is the id of the last imported project.
2674 procedure Process_Aggregated_Projects
;
2675 -- Process all the projects aggregated in List. This does nothing if the
2676 -- project is not an aggregate project.
2678 procedure Process_Extended_Project
;
2679 -- Process the extended project: inherit all packages from the extended
2680 -- project that are not explicitly defined or renamed. Also inherit the
2681 -- languages, if attribute Languages is not explicitly defined.
2683 -------------------------------
2684 -- Process_Imported_Projects --
2685 -------------------------------
2687 procedure Process_Imported_Projects
2688 (Imported
: in out Project_List
;
2689 Limited_With
: Boolean)
2691 With_Clause
: Project_Node_Id
;
2692 New_Project
: Project_Id
;
2693 Proj_Node
: Project_Node_Id
;
2697 First_With_Clause_Of
2698 (From_Project_Node
, From_Project_Node_Tree
);
2700 while Present
(With_Clause
) loop
2702 Non_Limited_Project_Node_Of
2703 (With_Clause
, From_Project_Node_Tree
);
2704 New_Project
:= No_Project
;
2706 if (Limited_With
and then No
(Proj_Node
))
2707 or else (not Limited_With
and then Present
(Proj_Node
))
2710 (In_Tree
=> In_Tree
,
2711 Project
=> New_Project
,
2712 Packages_To_Check
=> Packages_To_Check
,
2713 From_Project_Node
=>
2714 Project_Node_Of
(With_Clause
, From_Project_Node_Tree
),
2715 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2717 Extended_By
=> No_Project
,
2718 From_Encapsulated_Lib
=> From_Encapsulated_Lib
,
2719 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
2721 if Imported
= null then
2722 Project
.Imported_Projects
:= new Project_List_Element
'
2723 (Project => New_Project,
2724 From_Encapsulated_Lib => False,
2726 Imported := Project.Imported_Projects;
2728 Imported.Next := new Project_List_Element'
2729 (Project
=> New_Project
,
2730 From_Encapsulated_Lib
=> False,
2732 Imported
:= Imported
.Next
;
2737 Next_With_Clause_Of
(With_Clause
, From_Project_Node_Tree
);
2739 end Process_Imported_Projects
;
2741 ---------------------------------
2742 -- Process_Aggregated_Projects --
2743 ---------------------------------
2745 procedure Process_Aggregated_Projects
is
2746 List
: Aggregated_Project_List
;
2747 Loaded_Project
: Prj
.Tree
.Project_Node_Id
;
2748 Success
: Boolean := True;
2749 Tree
: Project_Tree_Ref
;
2750 Node_Tree
: Project_Node_Tree_Ref
;
2753 if Project
.Qualifier
not in Aggregate_Project
then
2757 Debug_Increase_Indent
("Process_Aggregated_Projects", Project
.Name
);
2759 Prj
.Nmsc
.Process_Aggregated_Projects
2762 Node_Tree
=> From_Project_Node_Tree
,
2763 Flags
=> Env
.Flags
);
2765 List
:= Project
.Aggregated_Projects
;
2766 while Success
and then List
/= null loop
2767 Node_Tree
:= new Project_Node_Tree_Data
;
2768 Initialize
(Node_Tree
);
2771 (In_Tree
=> Node_Tree
,
2772 Project
=> Loaded_Project
,
2773 Packages_To_Check
=> Packages_To_Check
,
2774 Project_File_Name
=> Get_Name_String
(List
.Path
),
2775 Errout_Handling
=> Prj
.Part
.Never_Finalize
,
2776 Current_Directory
=> Get_Name_String
(Project
.Directory
.Name
),
2777 Is_Config_File
=> False,
2780 Success
:= not Prj
.Tree
.No
(Loaded_Project
);
2783 if Node_Tree
.Incomplete_With
then
2784 From_Project_Node_Tree
.Incomplete_With
:= True;
2787 List
.Tree
:= new Project_Tree_Data
(Is_Root_Tree
=> False);
2788 Prj
.Initialize
(List
.Tree
);
2789 List
.Tree
.Shared
:= In_Tree
.Shared
;
2791 -- In aggregate library, aggregated projects are parsed using
2792 -- the aggregate library tree.
2794 if Project
.Qualifier
= Aggregate_Library
then
2800 -- We can only do the phase 1 of the processing, since we do
2801 -- not have access to the configuration file yet (this is
2802 -- called when doing phase 1 of the processing for the root
2803 -- aggregate project).
2805 if In_Tree
.Is_Root_Tree
then
2806 Process_Project_Tree_Phase_1
2808 Project
=> List
.Project
,
2809 Packages_To_Check
=> Packages_To_Check
,
2811 From_Project_Node
=> Loaded_Project
,
2812 From_Project_Node_Tree
=> Node_Tree
,
2814 Reset_Tree
=> False,
2815 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
2817 -- use the same environment as the rest of the aggregated
2818 -- projects, ie the one that was setup by the root aggregate
2819 Process_Project_Tree_Phase_1
2821 Project
=> List
.Project
,
2822 Packages_To_Check
=> Packages_To_Check
,
2824 From_Project_Node
=> Loaded_Project
,
2825 From_Project_Node_Tree
=> Node_Tree
,
2827 Reset_Tree
=> False,
2828 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
2831 if On_New_Tree_Loaded
/= null then
2833 (Node_Tree
, Tree
, Loaded_Project
, List
.Project
);
2837 Debug_Output
("Failed to parse", Name_Id
(List
.Path
));
2843 Debug_Decrease_Indent
("Done Process_Aggregated_Projects");
2844 end Process_Aggregated_Projects
;
2846 ------------------------------
2847 -- Process_Extended_Project --
2848 ------------------------------
2850 procedure Process_Extended_Project
is
2851 Extended_Pkg
: Package_Id
;
2852 Current_Pkg
: Package_Id
;
2853 Element
: Package_Element
;
2854 First
: constant Package_Id
:= Project
.Decl
.Packages
;
2855 Attribute1
: Variable_Id
;
2856 Attribute2
: Variable_Id
;
2857 Attr_Value1
: Variable
;
2858 Attr_Value2
: Variable
;
2861 Extended_Pkg
:= Project
.Extends
.Decl
.Packages
;
2862 while Extended_Pkg
/= No_Package
loop
2863 Element
:= Shared
.Packages
.Table
(Extended_Pkg
);
2865 Current_Pkg
:= First
;
2866 while Current_Pkg
/= No_Package
2868 Shared
.Packages
.Table
(Current_Pkg
).Name
/= Element
.Name
2870 Current_Pkg
:= Shared
.Packages
.Table
(Current_Pkg
).Next
;
2873 if Current_Pkg
= No_Package
then
2874 Package_Table
.Increment_Last
(Shared
.Packages
);
2875 Current_Pkg
:= Package_Table
.Last
(Shared
.Packages
);
2876 Shared
.Packages
.Table
(Current_Pkg
) :=
2877 (Name
=> Element
.Name
,
2878 Decl
=> No_Declarations
,
2879 Parent
=> No_Package
,
2880 Next
=> Project
.Decl
.Packages
);
2881 Project
.Decl
.Packages
:= Current_Pkg
;
2882 Copy_Package_Declarations
2883 (From
=> Element
.Decl
,
2884 To
=> Shared
.Packages
.Table
(Current_Pkg
).Decl
,
2885 New_Loc
=> No_Location
,
2890 Extended_Pkg
:= Element
.Next
;
2893 -- Check if attribute Languages is declared in the extending project
2895 Attribute1
:= Project
.Decl
.Attributes
;
2896 while Attribute1
/= No_Variable
loop
2897 Attr_Value1
:= Shared
.Variable_Elements
. Table
(Attribute1
);
2898 exit when Attr_Value1
.Name
= Snames
.Name_Languages
;
2899 Attribute1
:= Attr_Value1
.Next
;
2902 if Attribute1
= No_Variable
or else Attr_Value1
.Value
.Default
then
2904 -- Attribute Languages is not declared in the extending project.
2905 -- Check if it is declared in the project being extended.
2907 Attribute2
:= Project
.Extends
.Decl
.Attributes
;
2908 while Attribute2
/= No_Variable
loop
2909 Attr_Value2
:= Shared
.Variable_Elements
.Table
(Attribute2
);
2910 exit when Attr_Value2
.Name
= Snames
.Name_Languages
;
2911 Attribute2
:= Attr_Value2
.Next
;
2914 if Attribute2
/= No_Variable
2915 and then not Attr_Value2
.Value
.Default
2917 -- As attribute Languages is declared in the project being
2918 -- extended, copy its value for the extending project.
2920 if Attribute1
= No_Variable
then
2921 Variable_Element_Table
.Increment_Last
2922 (Shared
.Variable_Elements
);
2923 Attribute1
:= Variable_Element_Table
.Last
2924 (Shared
.Variable_Elements
);
2925 Attr_Value1
.Next
:= Project
.Decl
.Attributes
;
2926 Project
.Decl
.Attributes
:= Attribute1
;
2929 Attr_Value1
.Name
:= Snames
.Name_Languages
;
2930 Attr_Value1
.Value
:= Attr_Value2
.Value
;
2931 Shared
.Variable_Elements
.Table
(Attribute1
) := Attr_Value1
;
2934 end Process_Extended_Project
;
2936 -- Start of processing for Recursive_Process
2939 if No
(From_Project_Node
) then
2940 Project
:= No_Project
;
2944 Imported
, Mark
: Project_List
;
2945 Declaration_Node
: Project_Node_Id
:= Empty_Node
;
2947 Name
: constant Name_Id
:=
2948 Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
2950 Display_Name
: constant Name_Id
:=
2952 (From_Project_Node
, From_Project_Node_Tree
);
2955 Project
:= Processed_Projects
.Get
(Name
);
2957 if Project
/= No_Project
then
2959 -- Make sure that, when a project is extended, the project id
2960 -- of the project extending it is recorded in its data, even
2961 -- when it has already been processed as an imported project.
2962 -- This is for virtually extended projects.
2964 if Extended_By
/= No_Project
then
2965 Project
.Extended_By
:= Extended_By
;
2971 -- Check if the project is already in the tree
2973 Project
:= No_Project
;
2976 List
: Project_List
:= In_Tree
.Projects
;
2977 Path
: constant Path_Name_Type
:=
2978 Path_Name_Of
(From_Project_Node
,
2979 From_Project_Node_Tree
);
2982 while List
/= null loop
2983 if List
.Project
.Path
.Display_Name
= Path
then
2984 Project
:= List
.Project
;
2992 if Project
= No_Project
then
2996 (Project_Qualifier_Of
2997 (From_Project_Node, From_Project_Node_Tree)));
2999 -- Note that at this point we do not know yet if the project
3000 -- has been withed from an encapsulated library or not.
3003 new Project_List_Element'
3004 (Project
=> Project
,
3005 From_Encapsulated_Lib
=> False,
3006 Next
=> In_Tree
.Projects
);
3009 -- Keep track of this point
3011 Mark
:= In_Tree
.Projects
;
3013 Processed_Projects
.Set
(Name
, Project
);
3015 Project
.Name
:= Name
;
3016 Project
.Display_Name
:= Display_Name
;
3018 Get_Name_String
(Name
);
3020 -- If name starts with the virtual prefix, flag the project as
3021 -- being a virtual extending project.
3023 if Name_Len
> Virtual_Prefix
'Length
3025 Name_Buffer
(1 .. Virtual_Prefix
'Length) = Virtual_Prefix
3027 Project
.Virtual
:= True;
3030 Project
.Path
.Display_Name
:=
3031 Path_Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
3032 Get_Name_String
(Project
.Path
.Display_Name
);
3033 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3034 Project
.Path
.Name
:= Name_Find
;
3037 Location_Of
(From_Project_Node
, From_Project_Node_Tree
);
3039 Project
.Directory
.Display_Name
:=
3040 Directory_Of
(From_Project_Node
, From_Project_Node_Tree
);
3041 Get_Name_String
(Project
.Directory
.Display_Name
);
3042 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
3043 Project
.Directory
.Name
:= Name_Find
;
3045 Project
.Extended_By
:= Extended_By
;
3050 Name_Id
(Project
.Directory
.Display_Name
),
3053 Prj
.Attr
.Attribute_First
,
3054 Project_Level
=> True);
3056 Process_Imported_Projects
(Imported
, Limited_With
=> False);
3058 if Project
.Qualifier
= Aggregate
then
3059 Initialize_And_Copy
(Child_Env
, Copy_From
=> Env
);
3061 elsif Project
.Qualifier
= Aggregate_Library
then
3063 -- The child environment is the same as the current one
3068 -- No need to initialize Child_Env, since it will not be
3069 -- used anyway by Process_Declarative_Items (only the root
3070 -- aggregate can modify it, and it is never read anyway).
3076 Project_Declaration_Of
3077 (From_Project_Node
, From_Project_Node_Tree
);
3080 (In_Tree
=> In_Tree
,
3081 Project
=> Project
.Extends
,
3082 Packages_To_Check
=> Packages_To_Check
,
3083 From_Project_Node
=>
3085 (Declaration_Node
, From_Project_Node_Tree
),
3086 From_Project_Node_Tree
=> From_Project_Node_Tree
,
3088 Extended_By
=> Project
,
3089 From_Encapsulated_Lib
=> From_Encapsulated_Lib
,
3090 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
3092 Process_Declarative_Items
3093 (Project
=> Project
,
3095 From_Project_Node
=> From_Project_Node
,
3096 Node_Tree
=> From_Project_Node_Tree
,
3099 Item
=> First_Declarative_Item_Of
3100 (Declaration_Node
, From_Project_Node_Tree
),
3101 Child_Env
=> Child_Env
);
3103 if Project
.Extends
/= No_Project
then
3104 Process_Extended_Project
;
3107 Process_Imported_Projects
(Imported
, Limited_With
=> True);
3109 if Total_Errors_Detected
= 0 then
3110 Process_Aggregated_Projects
;
3113 -- At this point (after Process_Declarative_Items) we have the
3114 -- attribute values set, we can backtrace In_Tree.Project and
3115 -- set the From_Encapsulated_Library status.
3118 Lib_Standalone
: constant Prj
.Variable_Value
:=
3120 (Snames
.Name_Library_Standalone
,
3121 Project
.Decl
.Attributes
,
3123 List
: Project_List
:= In_Tree
.Projects
;
3124 Is_Encapsulated
: Boolean;
3127 Get_Name_String
(Lib_Standalone
.Value
);
3128 To_Lower
(Name_Buffer
(1 .. Name_Len
));
3130 Is_Encapsulated
:= Name_Buffer
(1 .. Name_Len
) = "encapsulated";
3132 if Is_Encapsulated
then
3133 while List
/= null and then List
/= Mark
loop
3134 List
.From_Encapsulated_Lib
:= Is_Encapsulated
;
3139 if Total_Errors_Detected
= 0 then
3141 -- For an aggregate library we add the aggregated projects
3142 -- as imported ones. This is necessary to give visibility
3143 -- to all sources from the aggregates from the aggregated
3144 -- library projects.
3146 if Project
.Qualifier
= Aggregate_Library
then
3148 L
: Aggregated_Project_List
;
3150 L
:= Project
.Aggregated_Projects
;
3151 while L
/= null loop
3152 Project
.Imported_Projects
:=
3153 new Project_List_Element
'
3154 (Project => L.Project,
3155 From_Encapsulated_Lib => Is_Encapsulated,
3157 Project.Imported_Projects);
3165 if Project.Qualifier = Aggregate and then In_Tree.Is_Root_Tree then
3170 end Recursive_Process;
3172 -----------------------------
3173 -- Set_Default_Runtime_For --
3174 -----------------------------
3176 procedure Set_Default_Runtime_For (Language : Name_Id; Value : String) is
3178 Name_Len := Value'Length;
3179 Name_Buffer (1 .. Name_Len) := Value;
3180 Runtime_Defaults.Set (Language, Name_Find);
3181 end Set_Default_Runtime_For;