1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars
; use Err_Vars
;
28 with Osint
; use Osint
;
29 with Output
; use Output
;
30 with Prj
.Attr
; use Prj
.Attr
;
31 with Prj
.Err
; use Prj
.Err
;
32 with Prj
.Ext
; use Prj
.Ext
;
33 with Prj
.Nmsc
; use Prj
.Nmsc
;
36 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
39 package body Prj
.Proc
is
41 package Processed_Projects
is new GNAT
.HTable
.Simple_HTable
42 (Header_Num
=> Header_Num
,
43 Element
=> Project_Id
,
44 No_Element
=> No_Project
,
48 -- This hash table contains all processed projects
50 package Unit_Htable
is new GNAT
.HTable
.Simple_HTable
51 (Header_Num
=> Header_Num
,
53 No_Element
=> No_Source
,
57 -- This hash table contains all processed projects
59 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
);
60 -- Concatenate two strings and returns another string if both
61 -- arguments are not null string.
63 -- In the following procedures, we are expected to guess the meaning of
64 -- the parameters from their names, this is never a good idea, comments
65 -- should be added precisely defining every formal ???
67 procedure Add_Attributes
68 (Project
: Project_Id
;
69 Project_Name
: Name_Id
;
70 Project_Dir
: Name_Id
;
71 In_Tree
: Project_Tree_Ref
;
72 Decl
: in out Declarations
;
73 First
: Attribute_Node_Id
;
74 Project_Level
: Boolean);
75 -- Add all attributes, starting with First, with their default values to
76 -- the package or project with declarations Decl.
79 (In_Tree
: Project_Tree_Ref
;
81 Flags
: Processing_Flags
);
82 -- Set all projects to not checked, then call Recursive_Check for the
83 -- main project Project. Project is set to No_Project if errors occurred.
84 -- Current_Dir is for optimization purposes, avoiding extra system calls.
85 -- If Allow_Duplicate_Basenames, then files with the same base names are
86 -- authorized within a project for source-based languages (never for unit
89 procedure Copy_Package_Declarations
91 To
: in out Declarations
;
94 In_Tree
: Project_Tree_Ref
);
95 -- Copy a package declaration From to To for a renamed package. Change the
96 -- locations of all the attributes to New_Loc. When Restricted is
97 -- True, do not copy attributes Body, Spec, Implementation, Specification
98 -- and Linker_Options.
101 (Project
: Project_Id
;
102 In_Tree
: Project_Tree_Ref
;
103 Flags
: Processing_Flags
;
104 From_Project_Node
: Project_Node_Id
;
105 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
107 First_Term
: Project_Node_Id
;
108 Kind
: Variable_Kind
) return Variable_Value
;
109 -- From N_Expression project node From_Project_Node, compute the value
110 -- of an expression and return it as a Variable_Value.
112 function Imported_Or_Extended_Project_From
113 (Project
: Project_Id
;
114 With_Name
: Name_Id
) return Project_Id
;
115 -- Find an imported or extended project of Project whose name is With_Name
117 function Package_From
118 (Project
: Project_Id
;
119 In_Tree
: Project_Tree_Ref
;
120 With_Name
: Name_Id
) return Package_Id
;
121 -- Find the package of Project whose name is With_Name
123 procedure Process_Declarative_Items
124 (Project
: Project_Id
;
125 In_Tree
: Project_Tree_Ref
;
126 Flags
: Processing_Flags
;
127 From_Project_Node
: Project_Node_Id
;
128 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
130 Item
: Project_Node_Id
);
131 -- Process declarative items starting with From_Project_Node, and put them
132 -- in declarations Decl. This is a recursive procedure; it calls itself for
133 -- a package declaration or a case construction.
135 procedure Recursive_Process
136 (In_Tree
: Project_Tree_Ref
;
137 Project
: out Project_Id
;
138 Flags
: Processing_Flags
;
139 From_Project_Node
: Project_Node_Id
;
140 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
141 Extended_By
: Project_Id
);
142 -- Process project with node From_Project_Node in the tree. Do nothing if
143 -- From_Project_Node is Empty_Node. If project has already been processed,
144 -- simply return its project id. Otherwise create a new project id, mark it
145 -- as processed, call itself recursively for all imported projects and a
146 -- extended project, if any. Then process the declarative items of the
149 function Get_Attribute_Index
150 (Tree
: Project_Node_Tree_Ref
;
151 Attr
: Project_Node_Id
;
152 Index
: Name_Id
) return Name_Id
;
153 -- Copy the index of the attribute into Name_Buffer, converting to lower
154 -- case if the attribute is case-insensitive.
160 procedure Add
(To_Exp
: in out Name_Id
; Str
: Name_Id
) is
162 if To_Exp
= No_Name
or else To_Exp
= Empty_String
then
164 -- To_Exp is nil or empty. The result is Str
168 -- If Str is nil, then do not change To_Ext
170 elsif Str
/= No_Name
and then Str
/= Empty_String
then
172 S
: constant String := Get_Name_String
(Str
);
174 Get_Name_String
(To_Exp
);
175 Add_Str_To_Name_Buffer
(S
);
185 procedure Add_Attributes
186 (Project
: Project_Id
;
187 Project_Name
: Name_Id
;
188 Project_Dir
: Name_Id
;
189 In_Tree
: Project_Tree_Ref
;
190 Decl
: in out Declarations
;
191 First
: Attribute_Node_Id
;
192 Project_Level
: Boolean)
194 The_Attribute
: Attribute_Node_Id
:= First
;
197 while The_Attribute
/= Empty_Attribute
loop
198 if Attribute_Kind_Of
(The_Attribute
) = Single
then
200 New_Attribute
: Variable_Value
;
203 case Variable_Kind_Of
(The_Attribute
) is
205 -- Undefined should not happen
209 (False, "attribute with an undefined kind");
212 -- Single attributes have a default value of empty string
218 Location
=> No_Location
,
220 Value
=> Empty_String
,
223 -- Special cases of <project>'Name and
224 -- <project>'Project_Dir.
226 if Project_Level
then
227 if Attribute_Name_Of
(The_Attribute
) =
230 New_Attribute
.Value
:= Project_Name
;
232 elsif Attribute_Name_Of
(The_Attribute
) =
233 Snames
.Name_Project_Dir
235 New_Attribute
.Value
:= Project_Dir
;
239 -- List attributes have a default value of nil list
245 Location
=> No_Location
,
247 Values
=> Nil_String
);
251 Variable_Element_Table
.Increment_Last
252 (In_Tree
.Variable_Elements
);
253 In_Tree
.Variable_Elements
.Table
254 (Variable_Element_Table
.Last
255 (In_Tree
.Variable_Elements
)) :=
256 (Next
=> Decl
.Attributes
,
257 Name
=> Attribute_Name_Of
(The_Attribute
),
258 Value
=> New_Attribute
);
259 Decl
.Attributes
:= Variable_Element_Table
.Last
260 (In_Tree
.Variable_Elements
);
264 The_Attribute
:= Next_Attribute
(After
=> The_Attribute
);
273 (In_Tree
: Project_Tree_Ref
;
274 Project
: Project_Id
;
275 Flags
: Processing_Flags
)
278 Process_Naming_Scheme
(In_Tree
, Project
, Flags
);
280 -- Set the Other_Part field for the units
286 Iter
: Source_Iterator
;
291 Iter
:= For_Each_Source
(In_Tree
);
293 Source1
:= Prj
.Element
(Iter
);
294 exit when Source1
= No_Source
;
296 if Source1
.Unit
/= No_Unit_Index
then
297 Name
:= Source1
.Unit
.Name
;
298 Source2
:= Unit_Htable
.Get
(Name
);
300 if Source2
= No_Source
then
301 Unit_Htable
.Set
(K
=> Name
, E
=> Source1
);
303 Unit_Htable
.Remove
(Name
);
312 -------------------------------
313 -- Copy_Package_Declarations --
314 -------------------------------
316 procedure Copy_Package_Declarations
317 (From
: Declarations
;
318 To
: in out Declarations
;
319 New_Loc
: Source_Ptr
;
320 Restricted
: Boolean;
321 In_Tree
: Project_Tree_Ref
)
324 V2
: Variable_Id
:= No_Variable
;
327 A2
: Array_Id
:= No_Array
;
329 E1
: Array_Element_Id
;
330 E2
: Array_Element_Id
:= No_Array_Element
;
334 -- To avoid references in error messages to attribute declarations in
335 -- an original package that has been renamed, copy all the attribute
336 -- declarations of the package and change all locations to New_Loc,
337 -- the location of the renamed package.
339 -- First single attributes
341 V1
:= From
.Attributes
;
342 while V1
/= No_Variable
loop
344 -- Copy the attribute
346 Var
:= In_Tree
.Variable_Elements
.Table
(V1
);
349 -- Do not copy the value of attribute Linker_Options if Restricted
351 if Restricted
and then Var
.Name
= Snames
.Name_Linker_Options
then
352 Var
.Value
.Values
:= Nil_String
;
355 -- Remove the Next component
357 Var
.Next
:= No_Variable
;
359 -- Change the location to New_Loc
361 Var
.Value
.Location
:= New_Loc
;
362 Variable_Element_Table
.Increment_Last
(In_Tree
.Variable_Elements
);
364 -- Put in new declaration
366 if To
.Attributes
= No_Variable
then
368 Variable_Element_Table
.Last
(In_Tree
.Variable_Elements
);
370 In_Tree
.Variable_Elements
.Table
(V2
).Next
:=
371 Variable_Element_Table
.Last
(In_Tree
.Variable_Elements
);
374 V2
:= Variable_Element_Table
.Last
(In_Tree
.Variable_Elements
);
375 In_Tree
.Variable_Elements
.Table
(V2
) := Var
;
378 -- Then the associated array attributes
381 while A1
/= No_Array
loop
382 Arr
:= In_Tree
.Arrays
.Table
(A1
);
387 (Arr
.Name
/= Snames
.Name_Body
and then
388 Arr
.Name
/= Snames
.Name_Spec
and then
389 Arr
.Name
/= Snames
.Name_Implementation
and then
390 Arr
.Name
/= Snames
.Name_Specification
)
392 -- Remove the Next component
394 Arr
.Next
:= No_Array
;
395 Array_Table
.Increment_Last
(In_Tree
.Arrays
);
397 -- Create new Array declaration
399 if To
.Arrays
= No_Array
then
400 To
.Arrays
:= Array_Table
.Last
(In_Tree
.Arrays
);
402 In_Tree
.Arrays
.Table
(A2
).Next
:=
403 Array_Table
.Last
(In_Tree
.Arrays
);
406 A2
:= Array_Table
.Last
(In_Tree
.Arrays
);
408 -- Don't store the array as its first element has not been set yet
410 -- Copy the array elements of the array
413 Arr
.Value
:= No_Array_Element
;
414 while E1
/= No_Array_Element
loop
416 -- Copy the array element
418 Elm
:= In_Tree
.Array_Elements
.Table
(E1
);
421 -- Remove the Next component
423 Elm
.Next
:= No_Array_Element
;
425 -- Change the location
427 Elm
.Value
.Location
:= New_Loc
;
428 Array_Element_Table
.Increment_Last
(In_Tree
.Array_Elements
);
430 -- Create new array element
432 if Arr
.Value
= No_Array_Element
then
434 Array_Element_Table
.Last
(In_Tree
.Array_Elements
);
436 In_Tree
.Array_Elements
.Table
(E2
).Next
:=
437 Array_Element_Table
.Last
(In_Tree
.Array_Elements
);
440 E2
:= Array_Element_Table
.Last
(In_Tree
.Array_Elements
);
441 In_Tree
.Array_Elements
.Table
(E2
) := Elm
;
444 -- Finally, store the new array
446 In_Tree
.Arrays
.Table
(A2
) := Arr
;
449 end Copy_Package_Declarations
;
451 -------------------------
452 -- Get_Attribute_Index --
453 -------------------------
455 function Get_Attribute_Index
456 (Tree
: Project_Node_Tree_Ref
;
457 Attr
: Project_Node_Id
;
458 Index
: Name_Id
) return Name_Id
463 if Index
= All_Other_Names
then
467 Get_Name_String
(Index
);
468 Lower
:= Case_Insensitive
(Attr
, Tree
);
470 -- The index is always case insensitive if it does not include any dot.
471 -- ??? Why not use the properties from prj-attr, simply, maybe because
472 -- we don't know whether we have a file as an index?
477 for J
in 1 .. Name_Len
loop
478 if Name_Buffer
(J
) = '.' then
486 To_Lower
(Name_Buffer
(1 .. Name_Len
));
491 end Get_Attribute_Index
;
498 (Project
: Project_Id
;
499 In_Tree
: Project_Tree_Ref
;
500 Flags
: Processing_Flags
;
501 From_Project_Node
: Project_Node_Id
;
502 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
504 First_Term
: Project_Node_Id
;
505 Kind
: Variable_Kind
) return Variable_Value
507 The_Term
: Project_Node_Id
;
508 -- The term in the expression list
510 The_Current_Term
: Project_Node_Id
:= Empty_Node
;
511 -- The current term node id
513 Result
: Variable_Value
(Kind
=> Kind
);
514 -- The returned result
516 Last
: String_List_Id
:= Nil_String
;
517 -- Reference to the last string elements in Result, when Kind is List
520 Result
.Project
:= Project
;
521 Result
.Location
:= Location_Of
(First_Term
, From_Project_Node_Tree
);
523 -- Process each term of the expression, starting with First_Term
525 The_Term
:= First_Term
;
526 while Present
(The_Term
) loop
527 The_Current_Term
:= Current_Term
(The_Term
, From_Project_Node_Tree
);
529 case Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) is
531 when N_Literal_String
=>
537 -- Should never happen
539 pragma Assert
(False, "Undefined expression kind");
545 (The_Current_Term
, From_Project_Node_Tree
));
548 (The_Current_Term
, From_Project_Node_Tree
);
552 String_Element_Table
.Increment_Last
553 (In_Tree
.String_Elements
);
555 if Last
= Nil_String
then
557 -- This can happen in an expression like () & "toto"
559 Result
.Values
:= String_Element_Table
.Last
560 (In_Tree
.String_Elements
);
563 In_Tree
.String_Elements
.Table
564 (Last
).Next
:= String_Element_Table
.Last
565 (In_Tree
.String_Elements
);
568 Last
:= String_Element_Table
.Last
569 (In_Tree
.String_Elements
);
571 In_Tree
.String_Elements
.Table
(Last
) :=
572 (Value
=> String_Value_Of
574 From_Project_Node_Tree
),
575 Index
=> Source_Index_Of
577 From_Project_Node_Tree
),
578 Display_Value
=> No_Name
,
579 Location
=> Location_Of
581 From_Project_Node_Tree
),
586 when N_Literal_String_List
=>
589 String_Node
: Project_Node_Id
:=
590 First_Expression_In_List
592 From_Project_Node_Tree
);
594 Value
: Variable_Value
;
597 if Present
(String_Node
) then
599 -- If String_Node is nil, it is an empty list, there is
606 From_Project_Node
=> From_Project_Node
,
607 From_Project_Node_Tree
=> From_Project_Node_Tree
,
611 (String_Node
, From_Project_Node_Tree
),
613 String_Element_Table
.Increment_Last
614 (In_Tree
.String_Elements
);
616 if Result
.Values
= Nil_String
then
618 -- This literal string list is the first term in a
619 -- string list expression
622 String_Element_Table
.Last
(In_Tree
.String_Elements
);
625 In_Tree
.String_Elements
.Table
627 String_Element_Table
.Last
(In_Tree
.String_Elements
);
631 String_Element_Table
.Last
(In_Tree
.String_Elements
);
633 In_Tree
.String_Elements
.Table
(Last
) :=
634 (Value
=> Value
.Value
,
635 Display_Value
=> No_Name
,
636 Location
=> Value
.Location
,
639 Index
=> Value
.Index
);
642 -- Add the other element of the literal string list
643 -- one after the other
646 Next_Expression_In_List
647 (String_Node
, From_Project_Node_Tree
);
649 exit when No
(String_Node
);
656 From_Project_Node
=> From_Project_Node
,
657 From_Project_Node_Tree
=> From_Project_Node_Tree
,
661 (String_Node
, From_Project_Node_Tree
),
664 String_Element_Table
.Increment_Last
665 (In_Tree
.String_Elements
);
666 In_Tree
.String_Elements
.Table
667 (Last
).Next
:= String_Element_Table
.Last
668 (In_Tree
.String_Elements
);
669 Last
:= String_Element_Table
.Last
670 (In_Tree
.String_Elements
);
671 In_Tree
.String_Elements
.Table
(Last
) :=
672 (Value
=> Value
.Value
,
673 Display_Value
=> No_Name
,
674 Location
=> Value
.Location
,
677 Index
=> Value
.Index
);
682 when N_Variable_Reference | N_Attribute_Reference
=>
685 The_Project
: Project_Id
:= Project
;
686 The_Package
: Package_Id
:= Pkg
;
687 The_Name
: Name_Id
:= No_Name
;
688 The_Variable_Id
: Variable_Id
:= No_Variable
;
689 The_Variable
: Variable_Value
;
690 Term_Project
: constant Project_Node_Id
:=
693 From_Project_Node_Tree
);
694 Term_Package
: constant Project_Node_Id
:=
697 From_Project_Node_Tree
);
698 Index
: Name_Id
:= No_Name
;
701 if Present
(Term_Project
) and then
702 Term_Project
/= From_Project_Node
704 -- This variable or attribute comes from another project
707 Name_Of
(Term_Project
, From_Project_Node_Tree
);
708 The_Project
:= Imported_Or_Extended_Project_From
710 With_Name
=> The_Name
);
713 if Present
(Term_Package
) then
715 -- This is an attribute of a package
718 Name_Of
(Term_Package
, From_Project_Node_Tree
);
719 The_Package
:= The_Project
.Decl
.Packages
;
721 while The_Package
/= No_Package
722 and then In_Tree
.Packages
.Table
723 (The_Package
).Name
/= The_Name
726 In_Tree
.Packages
.Table
731 (The_Package
/= No_Package
,
732 "package not found.");
734 elsif Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) =
735 N_Attribute_Reference
737 The_Package
:= No_Package
;
741 Name_Of
(The_Current_Term
, From_Project_Node_Tree
);
743 if Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) =
744 N_Attribute_Reference
747 Associative_Array_Index_Of
748 (The_Current_Term
, From_Project_Node_Tree
);
751 -- If it is not an associative array attribute
753 if Index
= No_Name
then
755 -- It is not an associative array attribute
757 if The_Package
/= No_Package
then
759 -- First, if there is a package, look into the package
761 if Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) =
765 In_Tree
.Packages
.Table
766 (The_Package
).Decl
.Variables
;
769 In_Tree
.Packages
.Table
770 (The_Package
).Decl
.Attributes
;
773 while The_Variable_Id
/= No_Variable
775 In_Tree
.Variable_Elements
.Table
776 (The_Variable_Id
).Name
/= The_Name
779 In_Tree
.Variable_Elements
.Table
780 (The_Variable_Id
).Next
;
785 if The_Variable_Id
= No_Variable
then
787 -- If we have not found it, look into the project
789 if Kind_Of
(The_Current_Term
, From_Project_Node_Tree
) =
792 The_Variable_Id
:= The_Project
.Decl
.Variables
;
794 The_Variable_Id
:= The_Project
.Decl
.Attributes
;
797 while The_Variable_Id
/= No_Variable
799 In_Tree
.Variable_Elements
.Table
800 (The_Variable_Id
).Name
/= The_Name
803 In_Tree
.Variable_Elements
.Table
804 (The_Variable_Id
).Next
;
809 pragma Assert
(The_Variable_Id
/= No_Variable
,
810 "variable or attribute not found");
813 In_Tree
.Variable_Elements
.Table
814 (The_Variable_Id
).Value
;
818 -- It is an associative array attribute
821 The_Array
: Array_Id
:= No_Array
;
822 The_Element
: Array_Element_Id
:= No_Array_Element
;
823 Array_Index
: Name_Id
:= No_Name
;
826 if The_Package
/= No_Package
then
828 In_Tree
.Packages
.Table
829 (The_Package
).Decl
.Arrays
;
831 The_Array
:= The_Project
.Decl
.Arrays
;
834 while The_Array
/= No_Array
835 and then In_Tree
.Arrays
.Table
836 (The_Array
).Name
/= The_Name
838 The_Array
:= In_Tree
.Arrays
.Table
842 if The_Array
/= No_Array
then
843 The_Element
:= In_Tree
.Arrays
.Table
847 (From_Project_Node_Tree
,
851 while The_Element
/= No_Array_Element
853 In_Tree
.Array_Elements
.Table
854 (The_Element
).Index
/= Array_Index
857 In_Tree
.Array_Elements
.Table
863 if The_Element
/= No_Array_Element
then
865 In_Tree
.Array_Elements
.Table
869 if Expression_Kind_Of
870 (The_Current_Term
, From_Project_Node_Tree
) =
876 Location
=> No_Location
,
878 Values
=> Nil_String
);
883 Location
=> No_Location
,
885 Value
=> Empty_String
,
896 -- Should never happen
898 pragma Assert
(False, "undefined expression kind");
903 case The_Variable
.Kind
is
909 Add
(Result
.Value
, The_Variable
.Value
);
913 -- Should never happen
917 "list cannot appear in single " &
918 "string expression");
923 case The_Variable
.Kind
is
929 String_Element_Table
.Increment_Last
930 (In_Tree
.String_Elements
);
932 if Last
= Nil_String
then
934 -- This can happen in an expression such as
938 String_Element_Table
.Last
939 (In_Tree
.String_Elements
);
942 In_Tree
.String_Elements
.Table
944 String_Element_Table
.Last
945 (In_Tree
.String_Elements
);
949 String_Element_Table
.Last
950 (In_Tree
.String_Elements
);
952 In_Tree
.String_Elements
.Table
(Last
) :=
953 (Value
=> The_Variable
.Value
,
954 Display_Value
=> No_Name
,
955 Location
=> Location_Of
957 From_Project_Node_Tree
),
965 The_List
: String_List_Id
:=
969 while The_List
/= Nil_String
loop
970 String_Element_Table
.Increment_Last
971 (In_Tree
.String_Elements
);
973 if Last
= Nil_String
then
975 String_Element_Table
.Last
981 String_Elements
.Table
(Last
).Next
:=
982 String_Element_Table
.Last
989 String_Element_Table
.Last
990 (In_Tree
.String_Elements
);
992 In_Tree
.String_Elements
.Table
(Last
) :=
994 In_Tree
.String_Elements
.Table
996 Display_Value
=> No_Name
,
1000 From_Project_Node_Tree
),
1006 In_Tree
. String_Elements
.Table
1014 when N_External_Value
=>
1017 (External_Reference_Of
1018 (The_Current_Term
, From_Project_Node_Tree
),
1019 From_Project_Node_Tree
));
1022 Name
: constant Name_Id
:= Name_Find
;
1023 Default
: Name_Id
:= No_Name
;
1024 Value
: Name_Id
:= No_Name
;
1026 Def_Var
: Variable_Value
;
1028 Default_Node
: constant Project_Node_Id
:=
1030 (The_Current_Term
, From_Project_Node_Tree
);
1033 -- If there is a default value for the external reference,
1036 if Present
(Default_Node
) then
1037 Def_Var
:= Expression
1038 (Project
=> Project
,
1041 From_Project_Node
=> From_Project_Node
,
1042 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1046 (Default_Node
, From_Project_Node_Tree
),
1049 if Def_Var
/= Nil_Variable_Value
then
1050 Default
:= Def_Var
.Value
;
1055 Prj
.Ext
.Value_Of
(From_Project_Node_Tree
, Name
, Default
);
1057 if Value
= No_Name
then
1058 if not Quiet_Output
then
1060 (Flags
, "?undefined external reference",
1062 (The_Current_Term
, From_Project_Node_Tree
),
1066 Value
:= Empty_String
;
1075 Add
(Result
.Value
, Value
);
1078 String_Element_Table
.Increment_Last
1079 (In_Tree
.String_Elements
);
1081 if Last
= Nil_String
then
1082 Result
.Values
:= String_Element_Table
.Last
1083 (In_Tree
.String_Elements
);
1086 In_Tree
.String_Elements
.Table
1087 (Last
).Next
:= String_Element_Table
.Last
1088 (In_Tree
.String_Elements
);
1091 Last
:= String_Element_Table
.Last
1092 (In_Tree
.String_Elements
);
1093 In_Tree
.String_Elements
.Table
(Last
) :=
1095 Display_Value
=> No_Name
,
1098 (The_Current_Term
, From_Project_Node_Tree
),
1108 -- Should never happen
1112 "illegal node kind in an expression");
1113 raise Program_Error
;
1117 The_Term
:= Next_Term
(The_Term
, From_Project_Node_Tree
);
1123 ---------------------------------------
1124 -- Imported_Or_Extended_Project_From --
1125 ---------------------------------------
1127 function Imported_Or_Extended_Project_From
1128 (Project
: Project_Id
;
1129 With_Name
: Name_Id
) return Project_Id
1131 List
: Project_List
;
1132 Result
: Project_Id
;
1133 Temp_Result
: Project_Id
;
1136 -- First check if it is the name of an extended project
1138 Result
:= Project
.Extends
;
1139 while Result
/= No_Project
loop
1140 if Result
.Name
= With_Name
then
1143 Result
:= Result
.Extends
;
1147 -- Then check the name of each imported project
1149 Temp_Result
:= No_Project
;
1150 List
:= Project
.Imported_Projects
;
1151 while List
/= null loop
1152 Result
:= List
.Project
;
1154 -- If the project is directly imported, then returns its ID
1156 if Result
.Name
= With_Name
then
1160 -- If a project extending the project is imported, then keep this
1161 -- extending project as a possibility. It will be the returned ID
1162 -- if the project is not imported directly.
1168 Proj
:= Result
.Extends
;
1169 while Proj
/= No_Project
loop
1170 if Proj
.Name
= With_Name
then
1171 Temp_Result
:= Result
;
1175 Proj
:= Proj
.Extends
;
1182 pragma Assert
(Temp_Result
/= No_Project
, "project not found");
1184 end Imported_Or_Extended_Project_From
;
1190 function Package_From
1191 (Project
: Project_Id
;
1192 In_Tree
: Project_Tree_Ref
;
1193 With_Name
: Name_Id
) return Package_Id
1195 Result
: Package_Id
:= Project
.Decl
.Packages
;
1198 -- Check the name of each existing package of Project
1200 while Result
/= No_Package
1201 and then In_Tree
.Packages
.Table
(Result
).Name
/= With_Name
1203 Result
:= In_Tree
.Packages
.Table
(Result
).Next
;
1206 if Result
= No_Package
then
1208 -- Should never happen
1210 Write_Line
("package """ & Get_Name_String
(With_Name
) &
1212 raise Program_Error
;
1224 (In_Tree
: Project_Tree_Ref
;
1225 Project
: out Project_Id
;
1226 Success
: out Boolean;
1227 From_Project_Node
: Project_Node_Id
;
1228 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
1229 Flags
: Processing_Flags
;
1230 Reset_Tree
: Boolean := True)
1233 Process_Project_Tree_Phase_1
1234 (In_Tree
=> In_Tree
,
1237 From_Project_Node
=> From_Project_Node
,
1238 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1240 Reset_Tree
=> Reset_Tree
);
1242 if Project_Qualifier_Of
(From_Project_Node
, From_Project_Node_Tree
) /=
1245 Process_Project_Tree_Phase_2
1246 (In_Tree
=> In_Tree
,
1249 From_Project_Node
=> From_Project_Node
,
1250 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1255 -------------------------------
1256 -- Process_Declarative_Items --
1257 -------------------------------
1259 procedure Process_Declarative_Items
1260 (Project
: Project_Id
;
1261 In_Tree
: Project_Tree_Ref
;
1262 Flags
: Processing_Flags
;
1263 From_Project_Node
: Project_Node_Id
;
1264 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
1266 Item
: Project_Node_Id
)
1268 procedure Check_Or_Set_Typed_Variable
1269 (Value
: in out Variable_Value
;
1270 Declaration
: Project_Node_Id
);
1271 -- Check whether Value is valid for this typed variable declaration. If
1272 -- it is an error, the behavior depends on the flags: either an error is
1273 -- reported, or a warning, or nothing. In the last two cases, the value
1274 -- of the variable is set to a valid value, replacing Value.
1276 ---------------------------------
1277 -- Check_Or_Set_Typed_Variable --
1278 ---------------------------------
1280 procedure Check_Or_Set_Typed_Variable
1281 (Value
: in out Variable_Value
;
1282 Declaration
: Project_Node_Id
)
1284 Loc
: constant Source_Ptr
:=
1285 Location_Of
(Declaration
, From_Project_Node_Tree
);
1287 Reset_Value
: Boolean := False;
1288 Current_String
: Project_Node_Id
;
1291 -- Report an error for an empty string
1293 if Value
.Value
= Empty_String
then
1294 Error_Msg_Name_1
:= Name_Of
(Declaration
, From_Project_Node_Tree
);
1296 case Flags
.Allow_Invalid_External
is
1298 Error_Msg
(Flags
, "no value defined for %%", Loc
, Project
);
1300 Reset_Value
:= True;
1301 Error_Msg
(Flags
, "?no value defined for %%", Loc
, Project
);
1303 Reset_Value
:= True;
1307 -- Loop through all the valid strings for the
1308 -- string type and compare to the string value.
1311 First_Literal_String
1312 (String_Type_Of
(Declaration
, From_Project_Node_Tree
),
1313 From_Project_Node_Tree
);
1314 while Present
(Current_String
)
1315 and then String_Value_Of
1316 (Current_String
, From_Project_Node_Tree
) /= Value
.Value
1319 Next_Literal_String
(Current_String
, From_Project_Node_Tree
);
1322 -- Report error if string value is not one for the string type
1324 if No
(Current_String
) then
1325 Error_Msg_Name_1
:= Value
.Value
;
1327 Name_Of
(Declaration
, From_Project_Node_Tree
);
1329 case Flags
.Allow_Invalid_External
is
1332 (Flags
, "value %% is illegal for typed string %%",
1336 (Flags
, "?value %% is illegal for typed string %%",
1338 Reset_Value
:= True;
1340 Reset_Value
:= True;
1347 First_Literal_String
1348 (String_Type_Of
(Declaration
, From_Project_Node_Tree
),
1349 From_Project_Node_Tree
);
1351 Value
.Value
:= String_Value_Of
1352 (Current_String
, From_Project_Node_Tree
);
1354 end Check_Or_Set_Typed_Variable
;
1358 Current_Declarative_Item
: Project_Node_Id
;
1359 Current_Item
: Project_Node_Id
;
1361 -- Start of processing for Process_Declarative_Items
1364 -- Loop through declarative items
1366 Current_Item
:= Empty_Node
;
1368 Current_Declarative_Item
:= Item
;
1369 while Present
(Current_Declarative_Item
) loop
1375 (Current_Declarative_Item
, From_Project_Node_Tree
);
1377 -- And set Current_Declarative_Item to the next declarative item
1378 -- ready for the next iteration.
1380 Current_Declarative_Item
:=
1381 Next_Declarative_Item
1382 (Current_Declarative_Item
, From_Project_Node_Tree
);
1384 case Kind_Of
(Current_Item
, From_Project_Node_Tree
) is
1386 when N_Package_Declaration
=>
1388 -- Do not process a package declaration that should be ignored
1390 if Expression_Kind_Of
1391 (Current_Item
, From_Project_Node_Tree
) /= Ignored
1393 -- Create the new package
1395 Package_Table
.Increment_Last
(In_Tree
.Packages
);
1398 New_Pkg
: constant Package_Id
:=
1399 Package_Table
.Last
(In_Tree
.Packages
);
1400 The_New_Package
: Package_Element
;
1402 Project_Of_Renamed_Package
:
1403 constant Project_Node_Id
:=
1404 Project_Of_Renamed_Package_Of
1405 (Current_Item
, From_Project_Node_Tree
);
1408 -- Set the name of the new package
1410 The_New_Package
.Name
:=
1411 Name_Of
(Current_Item
, From_Project_Node_Tree
);
1413 -- Insert the new package in the appropriate list
1415 if Pkg
/= No_Package
then
1416 The_New_Package
.Next
:=
1417 In_Tree
.Packages
.Table
(Pkg
).Decl
.Packages
;
1418 In_Tree
.Packages
.Table
(Pkg
).Decl
.Packages
:=
1422 The_New_Package
.Next
:= Project
.Decl
.Packages
;
1423 Project
.Decl
.Packages
:= New_Pkg
;
1426 In_Tree
.Packages
.Table
(New_Pkg
) :=
1429 if Present
(Project_Of_Renamed_Package
) then
1431 -- Renamed or extending package
1434 Project_Name
: constant Name_Id
:=
1436 (Project_Of_Renamed_Package
,
1437 From_Project_Node_Tree
);
1440 constant Project_Id
:=
1441 Imported_Or_Extended_Project_From
1442 (Project
, Project_Name
);
1444 Renamed_Package
: constant Package_Id
:=
1446 (Renamed_Project
, In_Tree
,
1449 From_Project_Node_Tree
));
1452 -- For a renamed package, copy the declarations of
1453 -- the renamed package, but set all the locations
1454 -- to the location of the package name in the
1455 -- renaming declaration.
1457 Copy_Package_Declarations
1459 In_Tree
.Packages
.Table
(Renamed_Package
).Decl
,
1461 In_Tree
.Packages
.Table
(New_Pkg
).Decl
,
1464 (Current_Item
, From_Project_Node_Tree
),
1465 Restricted
=> False,
1466 In_Tree
=> In_Tree
);
1470 -- Set the default values of the attributes
1475 Name_Id
(Project
.Directory
.Name
),
1477 In_Tree
.Packages
.Table
(New_Pkg
).Decl
,
1480 (Current_Item
, From_Project_Node_Tree
)),
1481 Project_Level
=> False);
1485 -- Process declarative items (nothing to do when the
1486 -- package is renaming, as the first declarative item is
1489 Process_Declarative_Items
1490 (Project
=> Project
,
1493 From_Project_Node
=> From_Project_Node
,
1494 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1497 First_Declarative_Item_Of
1498 (Current_Item
, From_Project_Node_Tree
));
1502 when N_String_Type_Declaration
=>
1504 -- There is nothing to process
1508 when N_Attribute_Declaration |
1509 N_Typed_Variable_Declaration |
1510 N_Variable_Declaration
=>
1512 if Expression_Of
(Current_Item
, From_Project_Node_Tree
) =
1516 -- It must be a full associative array attribute declaration
1519 Current_Item_Name
: constant Name_Id
:=
1522 From_Project_Node_Tree
);
1523 -- The name of the attribute
1525 Current_Location
: constant Source_Ptr
:=
1528 From_Project_Node_Tree
);
1530 New_Array
: Array_Id
;
1531 -- The new associative array created
1533 Orig_Array
: Array_Id
;
1534 -- The associative array value
1536 Orig_Project_Name
: Name_Id
:= No_Name
;
1537 -- The name of the project where the associative array
1540 Orig_Project
: Project_Id
:= No_Project
;
1541 -- The id of the project where the associative array
1544 Orig_Package_Name
: Name_Id
:= No_Name
;
1545 -- The name of the package, if any, where the associative
1548 Orig_Package
: Package_Id
:= No_Package
;
1549 -- The id of the package, if any, where the associative
1552 New_Element
: Array_Element_Id
:= No_Array_Element
;
1553 -- Id of a new array element created
1555 Prev_Element
: Array_Element_Id
:= No_Array_Element
;
1556 -- Last new element id created
1558 Orig_Element
: Array_Element_Id
:= No_Array_Element
;
1559 -- Current array element in original associative array
1561 Next_Element
: Array_Element_Id
:= No_Array_Element
;
1562 -- Id of the array element that follows the new element.
1563 -- This is not always nil, because values for the
1564 -- associative array attribute may already have been
1565 -- declared, and the array elements declared are reused.
1570 -- First find if the associative array attribute already
1571 -- has elements declared.
1573 if Pkg
/= No_Package
then
1574 New_Array
:= In_Tree
.Packages
.Table
1578 New_Array
:= Project
.Decl
.Arrays
;
1581 while New_Array
/= No_Array
1582 and then In_Tree
.Arrays
.Table
(New_Array
).Name
/=
1585 New_Array
:= In_Tree
.Arrays
.Table
(New_Array
).Next
;
1588 -- If the attribute has never been declared add new entry
1589 -- in the arrays of the project/package and link it.
1591 if New_Array
= No_Array
then
1592 Array_Table
.Increment_Last
(In_Tree
.Arrays
);
1593 New_Array
:= Array_Table
.Last
(In_Tree
.Arrays
);
1595 if Pkg
/= No_Package
then
1596 In_Tree
.Arrays
.Table
(New_Array
) :=
1597 (Name
=> Current_Item_Name
,
1598 Location
=> Current_Location
,
1599 Value
=> No_Array_Element
,
1600 Next
=> In_Tree
.Packages
.Table
1603 In_Tree
.Packages
.Table
(Pkg
).Decl
.Arrays
:=
1607 In_Tree
.Arrays
.Table
(New_Array
) :=
1608 (Name
=> Current_Item_Name
,
1609 Location
=> Current_Location
,
1610 Value
=> No_Array_Element
,
1611 Next
=> Project
.Decl
.Arrays
);
1613 Project
.Decl
.Arrays
:= New_Array
;
1617 -- Find the project where the value is declared
1619 Orig_Project_Name
:=
1621 (Associative_Project_Of
1622 (Current_Item
, From_Project_Node_Tree
),
1623 From_Project_Node_Tree
);
1625 Prj
:= In_Tree
.Projects
;
1626 while Prj
/= null loop
1627 if Prj
.Project
.Name
= Orig_Project_Name
then
1628 Orig_Project
:= Prj
.Project
;
1634 pragma Assert
(Orig_Project
/= No_Project
,
1635 "original project not found");
1637 if No
(Associative_Package_Of
1638 (Current_Item
, From_Project_Node_Tree
))
1640 Orig_Array
:= Orig_Project
.Decl
.Arrays
;
1643 -- If in a package, find the package where the value
1646 Orig_Package_Name
:=
1648 (Associative_Package_Of
1649 (Current_Item
, From_Project_Node_Tree
),
1650 From_Project_Node_Tree
);
1652 Orig_Package
:= Orig_Project
.Decl
.Packages
;
1653 pragma Assert
(Orig_Package
/= No_Package
,
1654 "original package not found");
1656 while In_Tree
.Packages
.Table
1657 (Orig_Package
).Name
/= Orig_Package_Name
1659 Orig_Package
:= In_Tree
.Packages
.Table
1660 (Orig_Package
).Next
;
1661 pragma Assert
(Orig_Package
/= No_Package
,
1662 "original package not found");
1666 In_Tree
.Packages
.Table
(Orig_Package
).Decl
.Arrays
;
1669 -- Now look for the array
1671 while Orig_Array
/= No_Array
1672 and then In_Tree
.Arrays
.Table
(Orig_Array
).Name
/=
1675 Orig_Array
:= In_Tree
.Arrays
.Table
1679 if Orig_Array
= No_Array
then
1682 "associative array value not found",
1683 Location_Of
(Current_Item
, From_Project_Node_Tree
),
1688 In_Tree
.Arrays
.Table
(Orig_Array
).Value
;
1690 -- Copy each array element
1692 while Orig_Element
/= No_Array_Element
loop
1694 -- Case of first element
1696 if Prev_Element
= No_Array_Element
then
1698 -- And there is no array element declared yet,
1699 -- create a new first array element.
1701 if In_Tree
.Arrays
.Table
(New_Array
).Value
=
1704 Array_Element_Table
.Increment_Last
1705 (In_Tree
.Array_Elements
);
1706 New_Element
:= Array_Element_Table
.Last
1707 (In_Tree
.Array_Elements
);
1708 In_Tree
.Arrays
.Table
1709 (New_Array
).Value
:= New_Element
;
1710 Next_Element
:= No_Array_Element
;
1712 -- Otherwise, the new element is the first
1715 New_Element
:= In_Tree
.Arrays
.
1716 Table
(New_Array
).Value
;
1718 In_Tree
.Array_Elements
.Table
1722 -- Otherwise, reuse an existing element, or create
1723 -- one if necessary.
1727 In_Tree
.Array_Elements
.Table
1728 (Prev_Element
).Next
;
1730 if Next_Element
= No_Array_Element
then
1731 Array_Element_Table
.Increment_Last
1732 (In_Tree
.Array_Elements
);
1734 Array_Element_Table
.Last
1735 (In_Tree
.Array_Elements
);
1736 In_Tree
.Array_Elements
.Table
1737 (Prev_Element
).Next
:= New_Element
;
1740 New_Element
:= Next_Element
;
1742 In_Tree
.Array_Elements
.Table
1747 -- Copy the value of the element
1749 In_Tree
.Array_Elements
.Table
1751 In_Tree
.Array_Elements
.Table
(Orig_Element
);
1752 In_Tree
.Array_Elements
.Table
1753 (New_Element
).Value
.Project
:= Project
;
1755 -- Adjust the Next link
1757 In_Tree
.Array_Elements
.Table
1758 (New_Element
).Next
:= Next_Element
;
1760 -- Adjust the previous id for the next element
1762 Prev_Element
:= New_Element
;
1764 -- Go to the next element in the original array
1767 In_Tree
.Array_Elements
.Table
1768 (Orig_Element
).Next
;
1771 -- Make sure that the array ends here, in case there
1772 -- previously a greater number of elements.
1774 In_Tree
.Array_Elements
.Table
1775 (New_Element
).Next
:= No_Array_Element
;
1779 -- Declarations other that full associative arrays
1783 New_Value
: Variable_Value
:=
1785 (Project
=> Project
,
1788 From_Project_Node
=> From_Project_Node
,
1789 From_Project_Node_Tree
=> From_Project_Node_Tree
,
1794 (Current_Item
, From_Project_Node_Tree
),
1795 From_Project_Node_Tree
),
1798 (Current_Item
, From_Project_Node_Tree
));
1799 -- The expression value
1801 The_Variable
: Variable_Id
:= No_Variable
;
1803 Current_Item_Name
: constant Name_Id
:=
1806 From_Project_Node_Tree
);
1808 Current_Location
: constant Source_Ptr
:=
1811 From_Project_Node_Tree
);
1814 -- Process a typed variable declaration
1816 if Kind_Of
(Current_Item
, From_Project_Node_Tree
) =
1817 N_Typed_Variable_Declaration
1819 Check_Or_Set_Typed_Variable
1820 (Value
=> New_Value
,
1821 Declaration
=> Current_Item
);
1826 if Kind_Of
(Current_Item
, From_Project_Node_Tree
) /=
1827 N_Attribute_Declaration
1829 Associative_Array_Index_Of
1830 (Current_Item
, From_Project_Node_Tree
) = No_Name
1832 -- Case of a variable declaration or of a not
1833 -- associative array attribute.
1835 -- First, find the list where to find the variable
1838 if Kind_Of
(Current_Item
, From_Project_Node_Tree
) =
1839 N_Attribute_Declaration
1841 if Pkg
/= No_Package
then
1843 In_Tree
.Packages
.Table
1844 (Pkg
).Decl
.Attributes
;
1846 The_Variable
:= Project
.Decl
.Attributes
;
1850 if Pkg
/= No_Package
then
1852 In_Tree
.Packages
.Table
1853 (Pkg
).Decl
.Variables
;
1855 The_Variable
:= Project
.Decl
.Variables
;
1860 -- Loop through the list, to find if it has already
1863 while The_Variable
/= No_Variable
1865 In_Tree
.Variable_Elements
.Table
1866 (The_Variable
).Name
/= Current_Item_Name
1869 In_Tree
.Variable_Elements
.Table
1870 (The_Variable
).Next
;
1873 -- If it has not been declared, create a new entry
1876 if The_Variable
= No_Variable
then
1878 -- All single string attribute should already have
1879 -- been declared with a default empty string value.
1882 (Kind_Of
(Current_Item
, From_Project_Node_Tree
) /=
1883 N_Attribute_Declaration
,
1884 "illegal attribute declaration for "
1885 & Get_Name_String
(Current_Item_Name
));
1887 Variable_Element_Table
.Increment_Last
1888 (In_Tree
.Variable_Elements
);
1889 The_Variable
:= Variable_Element_Table
.Last
1890 (In_Tree
.Variable_Elements
);
1892 -- Put the new variable in the appropriate list
1894 if Pkg
/= No_Package
then
1895 In_Tree
.Variable_Elements
.Table
(The_Variable
) :=
1897 In_Tree
.Packages
.Table
1898 (Pkg
).Decl
.Variables
,
1899 Name
=> Current_Item_Name
,
1900 Value
=> New_Value
);
1901 In_Tree
.Packages
.Table
1902 (Pkg
).Decl
.Variables
:= The_Variable
;
1905 In_Tree
.Variable_Elements
.Table
(The_Variable
) :=
1906 (Next
=> Project
.Decl
.Variables
,
1907 Name
=> Current_Item_Name
,
1908 Value
=> New_Value
);
1909 Project
.Decl
.Variables
:= The_Variable
;
1912 -- If the variable/attribute has already been
1913 -- declared, just change the value.
1916 In_Tree
.Variable_Elements
.Table
1917 (The_Variable
).Value
:= New_Value
;
1920 -- Associative array attribute
1924 Index_Name
: Name_Id
:=
1925 Associative_Array_Index_Of
1927 From_Project_Node_Tree
);
1929 Source_Index
: constant Int
:=
1932 From_Project_Node_Tree
);
1934 The_Array
: Array_Id
;
1935 The_Array_Element
: Array_Element_Id
:=
1939 if Index_Name
/= All_Other_Names
then
1940 Index_Name
:= Get_Attribute_Index
1941 (From_Project_Node_Tree
,
1943 Associative_Array_Index_Of
1944 (Current_Item
, From_Project_Node_Tree
));
1947 -- Look for the array in the appropriate list
1949 if Pkg
/= No_Package
then
1951 In_Tree
.Packages
.Table
(Pkg
).Decl
.Arrays
;
1954 Project
.Decl
.Arrays
;
1958 The_Array
/= No_Array
1960 In_Tree
.Arrays
.Table
(The_Array
).Name
/=
1964 In_Tree
.Arrays
.Table
(The_Array
).Next
;
1967 -- If the array cannot be found, create a new entry
1968 -- in the list. As The_Array_Element is initialized
1969 -- to No_Array_Element, a new element will be
1970 -- created automatically later
1972 if The_Array
= No_Array
then
1973 Array_Table
.Increment_Last
(In_Tree
.Arrays
);
1974 The_Array
:= Array_Table
.Last
(In_Tree
.Arrays
);
1976 if Pkg
/= No_Package
then
1977 In_Tree
.Arrays
.Table
(The_Array
) :=
1978 (Name
=> Current_Item_Name
,
1979 Location
=> Current_Location
,
1980 Value
=> No_Array_Element
,
1981 Next
=> In_Tree
.Packages
.Table
1984 In_Tree
.Packages
.Table
(Pkg
).Decl
.Arrays
:=
1988 In_Tree
.Arrays
.Table
(The_Array
) :=
1989 (Name
=> Current_Item_Name
,
1990 Location
=> Current_Location
,
1991 Value
=> No_Array_Element
,
1992 Next
=> Project
.Decl
.Arrays
);
1994 Project
.Decl
.Arrays
:= The_Array
;
1997 -- Otherwise initialize The_Array_Element as the
1998 -- head of the element list.
2001 The_Array_Element
:=
2002 In_Tree
.Arrays
.Table
(The_Array
).Value
;
2005 -- Look in the list, if any, to find an element
2006 -- with the same index and same source index.
2008 while The_Array_Element
/= No_Array_Element
2010 (In_Tree
.Array_Elements
.Table
2011 (The_Array_Element
).Index
/= Index_Name
2013 In_Tree
.Array_Elements
.Table
2014 (The_Array_Element
).Src_Index
/= Source_Index
)
2016 The_Array_Element
:=
2017 In_Tree
.Array_Elements
.Table
2018 (The_Array_Element
).Next
;
2021 -- If no such element were found, create a new one
2022 -- and insert it in the element list, with the
2025 if The_Array_Element
= No_Array_Element
then
2026 Array_Element_Table
.Increment_Last
2027 (In_Tree
.Array_Elements
);
2028 The_Array_Element
:=
2029 Array_Element_Table
.Last
2030 (In_Tree
.Array_Elements
);
2032 In_Tree
.Array_Elements
.Table
2033 (The_Array_Element
) :=
2034 (Index
=> Index_Name
,
2035 Src_Index
=> Source_Index
,
2036 Index_Case_Sensitive
=>
2037 not Case_Insensitive
2038 (Current_Item
, From_Project_Node_Tree
),
2041 In_Tree
.Arrays
.Table
(The_Array
).Value
);
2043 In_Tree
.Arrays
.Table
(The_Array
).Value
:=
2046 -- An element with the same index already exists,
2047 -- just replace its value with the new one.
2050 In_Tree
.Array_Elements
.Table
2051 (The_Array_Element
).Value
:= New_Value
;
2058 when N_Case_Construction
=>
2060 The_Project
: Project_Id
:= Project
;
2061 -- The id of the project of the case variable
2063 The_Package
: Package_Id
:= Pkg
;
2064 -- The id of the package, if any, of the case variable
2066 The_Variable
: Variable_Value
:= Nil_Variable_Value
;
2067 -- The case variable
2069 Case_Value
: Name_Id
:= No_Name
;
2070 -- The case variable value
2072 Case_Item
: Project_Node_Id
:= Empty_Node
;
2073 Choice_String
: Project_Node_Id
:= Empty_Node
;
2074 Decl_Item
: Project_Node_Id
:= Empty_Node
;
2078 Variable_Node
: constant Project_Node_Id
:=
2079 Case_Variable_Reference_Of
2081 From_Project_Node_Tree
);
2083 Var_Id
: Variable_Id
:= No_Variable
;
2084 Name
: Name_Id
:= No_Name
;
2087 -- If a project was specified for the case variable,
2090 if Present
(Project_Node_Of
2091 (Variable_Node
, From_Project_Node_Tree
))
2096 (Variable_Node
, From_Project_Node_Tree
),
2097 From_Project_Node_Tree
);
2099 Imported_Or_Extended_Project_From
(Project
, Name
);
2102 -- If a package were specified for the case variable,
2105 if Present
(Package_Node_Of
2106 (Variable_Node
, From_Project_Node_Tree
))
2111 (Variable_Node
, From_Project_Node_Tree
),
2112 From_Project_Node_Tree
);
2114 Package_From
(The_Project
, In_Tree
, Name
);
2117 Name
:= Name_Of
(Variable_Node
, From_Project_Node_Tree
);
2119 -- First, look for the case variable into the package,
2122 if The_Package
/= No_Package
then
2123 Var_Id
:= In_Tree
.Packages
.Table
2124 (The_Package
).Decl
.Variables
;
2126 Name_Of
(Variable_Node
, From_Project_Node_Tree
);
2127 while Var_Id
/= No_Variable
2129 In_Tree
.Variable_Elements
.Table
2130 (Var_Id
).Name
/= Name
2132 Var_Id
:= In_Tree
.Variable_Elements
.
2133 Table
(Var_Id
).Next
;
2137 -- If not found in the package, or if there is no
2138 -- package, look at the project level.
2140 if Var_Id
= No_Variable
2143 (Variable_Node
, From_Project_Node_Tree
))
2145 Var_Id
:= The_Project
.Decl
.Variables
;
2146 while Var_Id
/= No_Variable
2148 In_Tree
.Variable_Elements
.Table
2149 (Var_Id
).Name
/= Name
2151 Var_Id
:= In_Tree
.Variable_Elements
.
2152 Table
(Var_Id
).Next
;
2156 if Var_Id
= No_Variable
then
2158 -- Should never happen, because this has already been
2159 -- checked during parsing.
2161 Write_Line
("variable """ &
2162 Get_Name_String
(Name
) &
2164 raise Program_Error
;
2167 -- Get the case variable
2169 The_Variable
:= In_Tree
.Variable_Elements
.
2170 Table
(Var_Id
).Value
;
2172 if The_Variable
.Kind
/= Single
then
2174 -- Should never happen, because this has already been
2175 -- checked during parsing.
2177 Write_Line
("variable""" &
2178 Get_Name_String
(Name
) &
2179 """ is not a single string variable");
2180 raise Program_Error
;
2183 -- Get the case variable value
2184 Case_Value
:= The_Variable
.Value
;
2187 -- Now look into all the case items of the case construction
2190 First_Case_Item_Of
(Current_Item
, From_Project_Node_Tree
);
2192 while Present
(Case_Item
) loop
2194 First_Choice_Of
(Case_Item
, From_Project_Node_Tree
);
2196 -- When Choice_String is nil, it means that it is
2197 -- the "when others =>" alternative.
2199 if No
(Choice_String
) then
2201 First_Declarative_Item_Of
2202 (Case_Item
, From_Project_Node_Tree
);
2203 exit Case_Item_Loop
;
2206 -- Look into all the alternative of this case item
2209 while Present
(Choice_String
) loop
2212 (Choice_String
, From_Project_Node_Tree
)
2215 First_Declarative_Item_Of
2216 (Case_Item
, From_Project_Node_Tree
);
2217 exit Case_Item_Loop
;
2222 (Choice_String
, From_Project_Node_Tree
);
2223 end loop Choice_Loop
;
2226 Next_Case_Item
(Case_Item
, From_Project_Node_Tree
);
2227 end loop Case_Item_Loop
;
2229 -- If there is an alternative, then we process it
2231 if Present
(Decl_Item
) then
2232 Process_Declarative_Items
2233 (Project
=> Project
,
2236 From_Project_Node
=> From_Project_Node
,
2237 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2245 -- Should never happen
2247 Write_Line
("Illegal declarative item: " &
2248 Project_Node_Kind
'Image
2250 (Current_Item
, From_Project_Node_Tree
)));
2251 raise Program_Error
;
2254 end Process_Declarative_Items
;
2256 ----------------------------------
2257 -- Process_Project_Tree_Phase_1 --
2258 ----------------------------------
2260 procedure Process_Project_Tree_Phase_1
2261 (In_Tree
: Project_Tree_Ref
;
2262 Project
: out Project_Id
;
2263 Success
: out Boolean;
2264 From_Project_Node
: Project_Node_Id
;
2265 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2266 Flags
: Processing_Flags
;
2267 Reset_Tree
: Boolean := True)
2272 -- Make sure there are no projects in the data structure
2274 Free_List
(In_Tree
.Projects
, Free_Project
=> True);
2277 Processed_Projects
.Reset
;
2279 -- And process the main project and all of the projects it depends on,
2283 (Project
=> Project
,
2286 From_Project_Node
=> From_Project_Node
,
2287 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2288 Extended_By
=> No_Project
);
2291 Total_Errors_Detected
= 0
2293 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2294 end Process_Project_Tree_Phase_1
;
2296 ----------------------------------
2297 -- Process_Project_Tree_Phase_2 --
2298 ----------------------------------
2300 procedure Process_Project_Tree_Phase_2
2301 (In_Tree
: Project_Tree_Ref
;
2302 Project
: Project_Id
;
2303 Success
: out Boolean;
2304 From_Project_Node
: Project_Node_Id
;
2305 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2306 Flags
: Processing_Flags
)
2308 Obj_Dir
: Path_Name_Type
;
2309 Extending
: Project_Id
;
2310 Extending2
: Project_Id
;
2313 -- Start of processing for Process_Project_Tree_Phase_2
2318 if Project
/= No_Project
then
2319 Check
(In_Tree
, Project
, Flags
);
2322 -- If main project is an extending all project, set object directory of
2323 -- all virtual extending projects to object directory of main project.
2325 if Project
/= No_Project
2327 Is_Extending_All
(From_Project_Node
, From_Project_Node_Tree
)
2330 Object_Dir
: constant Path_Information
:=
2331 Project
.Object_Directory
;
2333 Prj
:= In_Tree
.Projects
;
2334 while Prj
/= null loop
2335 if Prj
.Project
.Virtual
then
2336 Prj
.Project
.Object_Directory
:= Object_Dir
;
2343 -- Check that no extending project shares its object directory with
2344 -- the project(s) it extends.
2346 if Project
/= No_Project
then
2347 Prj
:= In_Tree
.Projects
;
2348 while Prj
/= null loop
2349 Extending
:= Prj
.Project
.Extended_By
;
2351 if Extending
/= No_Project
then
2352 Obj_Dir
:= Prj
.Project
.Object_Directory
.Name
;
2354 -- Check that a project being extended does not share its
2355 -- object directory with any project that extends it, directly
2356 -- or indirectly, including a virtual extending project.
2358 -- Start with the project directly extending it
2360 Extending2
:= Extending
;
2361 while Extending2
/= No_Project
loop
2362 if Has_Ada_Sources
(Extending2
)
2363 and then Extending2
.Object_Directory
.Name
= Obj_Dir
2365 if Extending2
.Virtual
then
2366 Error_Msg_Name_1
:= Prj
.Project
.Display_Name
;
2369 "project %% cannot be extended by a virtual" &
2370 " project with the same object directory",
2371 Prj
.Project
.Location
, Project
);
2374 Error_Msg_Name_1
:= Extending2
.Display_Name
;
2375 Error_Msg_Name_2
:= Prj
.Project
.Display_Name
;
2378 "project %% cannot extend project %%",
2379 Extending2
.Location
, Project
);
2382 "\they share the same object directory",
2383 Extending2
.Location
, Project
);
2387 -- Continue with the next extending project, if any
2389 Extending2
:= Extending2
.Extended_By
;
2398 Total_Errors_Detected
= 0
2400 (Warning_Mode
/= Treat_As_Error
or else Warnings_Detected
= 0);
2401 end Process_Project_Tree_Phase_2
;
2403 -----------------------
2404 -- Recursive_Process --
2405 -----------------------
2407 procedure Recursive_Process
2408 (In_Tree
: Project_Tree_Ref
;
2409 Project
: out Project_Id
;
2410 Flags
: Processing_Flags
;
2411 From_Project_Node
: Project_Node_Id
;
2412 From_Project_Node_Tree
: Project_Node_Tree_Ref
;
2413 Extended_By
: Project_Id
)
2415 procedure Process_Imported_Projects
2416 (Imported
: in out Project_List
;
2417 Limited_With
: Boolean);
2418 -- Process imported projects. If Limited_With is True, then only
2419 -- projects processed through a "limited with" are processed, otherwise
2420 -- only projects imported through a standard "with" are processed.
2421 -- Imported is the id of the last imported project.
2423 -------------------------------
2424 -- Process_Imported_Projects --
2425 -------------------------------
2427 procedure Process_Imported_Projects
2428 (Imported
: in out Project_List
;
2429 Limited_With
: Boolean)
2431 With_Clause
: Project_Node_Id
;
2432 New_Project
: Project_Id
;
2433 Proj_Node
: Project_Node_Id
;
2437 First_With_Clause_Of
2438 (From_Project_Node
, From_Project_Node_Tree
);
2439 while Present
(With_Clause
) loop
2441 Non_Limited_Project_Node_Of
2442 (With_Clause
, From_Project_Node_Tree
);
2443 New_Project
:= No_Project
;
2445 if (Limited_With
and then No
(Proj_Node
))
2446 or else (not Limited_With
and then Present
(Proj_Node
))
2449 (In_Tree
=> In_Tree
,
2450 Project
=> New_Project
,
2452 From_Project_Node
=>
2454 (With_Clause
, From_Project_Node_Tree
),
2455 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2456 Extended_By
=> No_Project
);
2458 -- Imported is the id of the last imported project. If
2459 -- it is nil, then this imported project is our first.
2461 if Imported
= null then
2462 Project
.Imported_Projects
:=
2463 new Project_List_Element
'
2464 (Project => New_Project,
2466 Imported := Project.Imported_Projects;
2468 Imported.Next := new Project_List_Element'
2469 (Project
=> New_Project
,
2471 Imported
:= Imported
.Next
;
2476 Next_With_Clause_Of
(With_Clause
, From_Project_Node_Tree
);
2478 end Process_Imported_Projects
;
2480 -- Start of processing for Recursive_Process
2483 if No
(From_Project_Node
) then
2484 Project
:= No_Project
;
2488 Imported
: Project_List
;
2489 Declaration_Node
: Project_Node_Id
:= Empty_Node
;
2491 Name
: constant Name_Id
:=
2492 Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
2494 Name_Node
: constant Tree_Private_Part
.Project_Name_And_Node
:=
2495 Tree_Private_Part
.Projects_Htable
.Get
2496 (From_Project_Node_Tree
.Projects_HT
, Name
);
2499 Project
:= Processed_Projects
.Get
(Name
);
2501 if Project
/= No_Project
then
2503 -- Make sure that, when a project is extended, the project id
2504 -- of the project extending it is recorded in its data, even
2505 -- when it has already been processed as an imported project.
2506 -- This is for virtually extended projects.
2508 if Extended_By
/= No_Project
then
2509 Project
.Extended_By
:= Extended_By
;
2515 Project
:= new Project_Data
'(Empty_Project);
2516 In_Tree.Projects := new Project_List_Element'
2517 (Project
=> Project
,
2518 Next
=> In_Tree
.Projects
);
2520 Processed_Projects
.Set
(Name
, Project
);
2522 Project
.Name
:= Name
;
2523 Project
.Display_Name
:= Name_Node
.Display_Name
;
2524 Project
.Qualifier
:=
2525 Project_Qualifier_Of
(From_Project_Node
, From_Project_Node_Tree
);
2527 Get_Name_String
(Name
);
2529 -- If name starts with the virtual prefix, flag the project as
2530 -- being a virtual extending project.
2532 if Name_Len
> Virtual_Prefix
'Length
2533 and then Name_Buffer
(1 .. Virtual_Prefix
'Length) =
2536 Project
.Virtual
:= True;
2540 Project
.Path
.Display_Name
:=
2541 Path_Name_Of
(From_Project_Node
, From_Project_Node_Tree
);
2542 Get_Name_String
(Project
.Path
.Display_Name
);
2543 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2544 Project
.Path
.Name
:= Name_Find
;
2547 Location_Of
(From_Project_Node
, From_Project_Node_Tree
);
2549 Project
.Directory
.Display_Name
:=
2550 Directory_Of
(From_Project_Node
, From_Project_Node_Tree
);
2551 Get_Name_String
(Project
.Directory
.Display_Name
);
2552 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
2553 Project
.Directory
.Name
:= Name_Find
;
2555 Project
.Extended_By
:= Extended_By
;
2560 Name_Id
(Project
.Directory
.Name
),
2563 Prj
.Attr
.Attribute_First
,
2564 Project_Level
=> True);
2566 Process_Imported_Projects
(Imported
, Limited_With
=> False);
2569 Project_Declaration_Of
2570 (From_Project_Node
, From_Project_Node_Tree
);
2573 (In_Tree
=> In_Tree
,
2574 Project
=> Project
.Extends
,
2576 From_Project_Node
=> Extended_Project_Of
2578 From_Project_Node_Tree
),
2579 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2580 Extended_By
=> Project
);
2582 Process_Declarative_Items
2583 (Project
=> Project
,
2586 From_Project_Node
=> From_Project_Node
,
2587 From_Project_Node_Tree
=> From_Project_Node_Tree
,
2589 Item
=> First_Declarative_Item_Of
2591 From_Project_Node_Tree
));
2593 -- If it is an extending project, inherit all packages
2594 -- from the extended project that are not explicitly defined
2595 -- or renamed. Also inherit the languages, if attribute Languages
2596 -- is not explicitly defined.
2598 if Project
.Extends
/= No_Project
then
2600 Extended_Pkg
: Package_Id
;
2601 Current_Pkg
: Package_Id
;
2602 Element
: Package_Element
;
2603 First
: constant Package_Id
:=
2604 Project
.Decl
.Packages
;
2605 Attribute1
: Variable_Id
;
2606 Attribute2
: Variable_Id
;
2607 Attr_Value1
: Variable
;
2608 Attr_Value2
: Variable
;
2611 Extended_Pkg
:= Project
.Extends
.Decl
.Packages
;
2612 while Extended_Pkg
/= No_Package
loop
2613 Element
:= In_Tree
.Packages
.Table
(Extended_Pkg
);
2615 Current_Pkg
:= First
;
2616 while Current_Pkg
/= No_Package
2617 and then In_Tree
.Packages
.Table
(Current_Pkg
).Name
/=
2621 In_Tree
.Packages
.Table
(Current_Pkg
).Next
;
2624 if Current_Pkg
= No_Package
then
2625 Package_Table
.Increment_Last
2627 Current_Pkg
:= Package_Table
.Last
(In_Tree
.Packages
);
2628 In_Tree
.Packages
.Table
(Current_Pkg
) :=
2629 (Name
=> Element
.Name
,
2630 Decl
=> No_Declarations
,
2631 Parent
=> No_Package
,
2632 Next
=> Project
.Decl
.Packages
);
2633 Project
.Decl
.Packages
:= Current_Pkg
;
2634 Copy_Package_Declarations
2635 (From
=> Element
.Decl
,
2637 In_Tree
.Packages
.Table
(Current_Pkg
).Decl
,
2638 New_Loc
=> No_Location
,
2640 In_Tree
=> In_Tree
);
2643 Extended_Pkg
:= Element
.Next
;
2646 -- Check if attribute Languages is declared in the
2647 -- extending project.
2649 Attribute1
:= Project
.Decl
.Attributes
;
2650 while Attribute1
/= No_Variable
loop
2651 Attr_Value1
:= In_Tree
.Variable_Elements
.
2653 exit when Attr_Value1
.Name
= Snames
.Name_Languages
;
2654 Attribute1
:= Attr_Value1
.Next
;
2657 if Attribute1
= No_Variable
or else
2658 Attr_Value1
.Value
.Default
2660 -- Attribute Languages is not declared in the extending
2661 -- project. Check if it is declared in the project being
2664 Attribute2
:= Project
.Extends
.Decl
.Attributes
;
2665 while Attribute2
/= No_Variable
loop
2666 Attr_Value2
:= In_Tree
.Variable_Elements
.
2668 exit when Attr_Value2
.Name
= Snames
.Name_Languages
;
2669 Attribute2
:= Attr_Value2
.Next
;
2672 if Attribute2
/= No_Variable
and then
2673 not Attr_Value2
.Value
.Default
2675 -- As attribute Languages is declared in the project
2676 -- being extended, copy its value for the extending
2679 if Attribute1
= No_Variable
then
2680 Variable_Element_Table
.Increment_Last
2681 (In_Tree
.Variable_Elements
);
2682 Attribute1
:= Variable_Element_Table
.Last
2683 (In_Tree
.Variable_Elements
);
2684 Attr_Value1
.Next
:= Project
.Decl
.Attributes
;
2685 Project
.Decl
.Attributes
:= Attribute1
;
2688 Attr_Value1
.Name
:= Snames
.Name_Languages
;
2689 Attr_Value1
.Value
:= Attr_Value2
.Value
;
2690 In_Tree
.Variable_Elements
.Table
2691 (Attribute1
) := Attr_Value1
;
2697 Process_Imported_Projects
(Imported
, Limited_With
=> True);
2700 end Recursive_Process
;