[AArch64] Remove simd_type
[official-gcc.git] / gcc / ada / prj.adb
blobb98f711c5e7a580e37e8ff66b1e2d20de3320047
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2013, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Debug;
27 with Opt;
28 with Osint; use Osint;
29 with Output; use Output;
30 with Prj.Attr;
31 with Prj.Com;
32 with Prj.Err; use Prj.Err;
33 with Snames; use Snames;
34 with Uintp; use Uintp;
36 with Ada.Characters.Handling; use Ada.Characters.Handling;
37 with Ada.Containers.Ordered_Sets;
38 with Ada.Unchecked_Deallocation;
40 with GNAT.Case_Util; use GNAT.Case_Util;
41 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
42 with GNAT.HTable;
44 package body Prj is
46 type Restricted_Lang;
47 type Restricted_Lang_Access is access Restricted_Lang;
48 type Restricted_Lang is record
49 Name : Name_Id;
50 Next : Restricted_Lang_Access;
51 end record;
53 Restricted_Languages : Restricted_Lang_Access := null;
54 -- When null, all languages are allowed, otherwise only the languages in
55 -- the list are allowed.
57 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
58 -- File suffix for object files
60 Initial_Buffer_Size : constant := 100;
61 -- Initial size for extensible buffer used in Add_To_Buffer
63 The_Empty_String : Name_Id := No_Name;
65 Debug_Level : Integer := 0;
66 -- Current indentation level for debug traces
68 type Cst_String_Access is access constant String;
70 All_Lower_Case_Image : aliased constant String := "lowercase";
71 All_Upper_Case_Image : aliased constant String := "UPPERCASE";
72 Mixed_Case_Image : aliased constant String := "MixedCase";
74 The_Casing_Images : constant array (Known_Casing) of Cst_String_Access :=
75 (All_Lower_Case => All_Lower_Case_Image'Access,
76 All_Upper_Case => All_Upper_Case_Image'Access,
77 Mixed_Case => Mixed_Case_Image'Access);
79 procedure Free (Project : in out Project_Id);
80 -- Free memory allocated for Project
82 procedure Free_List (Languages : in out Language_Ptr);
83 procedure Free_List (Source : in out Source_Id);
84 procedure Free_List (Languages : in out Language_List);
85 -- Free memory allocated for the list of languages or sources
87 procedure Reset_Units_In_Table (Table : in out Units_Htable.Instance);
88 -- Resets all Units to No_Unit_Index Unit.File_Names (Spec).Unit &
89 -- Unit.File_Names (Impl).Unit in the given table.
91 procedure Free_Units (Table : in out Units_Htable.Instance);
92 -- Free memory allocated for unit information in the project
94 procedure Language_Changed (Iter : in out Source_Iterator);
95 procedure Project_Changed (Iter : in out Source_Iterator);
96 -- Called when a new project or language was selected for this iterator
98 function Contains_ALI_Files (Dir : Path_Name_Type) return Boolean;
99 -- Return True if there is at least one ALI file in the directory Dir
101 -----------------------------
102 -- Add_Restricted_Language --
103 -----------------------------
105 procedure Add_Restricted_Language (Name : String) is
106 N : String (1 .. Name'Length) := Name;
107 begin
108 To_Lower (N);
109 Name_Len := 0;
110 Add_Str_To_Name_Buffer (N);
111 Restricted_Languages :=
112 new Restricted_Lang'(Name => Name_Find, Next => Restricted_Languages);
113 end Add_Restricted_Language;
115 -------------------------------------
116 -- Remove_All_Restricted_Languages --
117 -------------------------------------
119 procedure Remove_All_Restricted_Languages is
120 begin
121 Restricted_Languages := null;
122 end Remove_All_Restricted_Languages;
124 -------------------
125 -- Add_To_Buffer --
126 -------------------
128 procedure Add_To_Buffer
129 (S : String;
130 To : in out String_Access;
131 Last : in out Natural)
133 begin
134 if To = null then
135 To := new String (1 .. Initial_Buffer_Size);
136 Last := 0;
137 end if;
139 -- If Buffer is too small, double its size
141 while Last + S'Length > To'Last loop
142 declare
143 New_Buffer : constant String_Access :=
144 new String (1 .. 2 * Last);
146 begin
147 New_Buffer (1 .. Last) := To (1 .. Last);
148 Free (To);
149 To := New_Buffer;
150 end;
151 end loop;
153 To (Last + 1 .. Last + S'Length) := S;
154 Last := Last + S'Length;
155 end Add_To_Buffer;
157 ---------------------------------
158 -- Current_Object_Path_File_Of --
159 ---------------------------------
161 function Current_Object_Path_File_Of
162 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type
164 begin
165 return Shared.Private_Part.Current_Object_Path_File;
166 end Current_Object_Path_File_Of;
168 ---------------------------------
169 -- Current_Source_Path_File_Of --
170 ---------------------------------
172 function Current_Source_Path_File_Of
173 (Shared : Shared_Project_Tree_Data_Access)
174 return Path_Name_Type is
175 begin
176 return Shared.Private_Part.Current_Source_Path_File;
177 end Current_Source_Path_File_Of;
179 ---------------------------
180 -- Delete_Temporary_File --
181 ---------------------------
183 procedure Delete_Temporary_File
184 (Shared : Shared_Project_Tree_Data_Access := null;
185 Path : Path_Name_Type)
187 Dont_Care : Boolean;
188 pragma Warnings (Off, Dont_Care);
190 begin
191 if not Debug.Debug_Flag_N then
192 if Current_Verbosity = High then
193 Write_Line ("Removing temp file: " & Get_Name_String (Path));
194 end if;
196 Delete_File (Get_Name_String (Path), Dont_Care);
198 if Shared /= null then
199 for Index in
200 1 .. Temp_Files_Table.Last (Shared.Private_Part.Temp_Files)
201 loop
202 if Shared.Private_Part.Temp_Files.Table (Index) = Path then
203 Shared.Private_Part.Temp_Files.Table (Index) := No_Path;
204 end if;
205 end loop;
206 end if;
207 end if;
208 end Delete_Temporary_File;
210 ------------------------------
211 -- Delete_Temp_Config_Files --
212 ------------------------------
214 procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref) is
215 Success : Boolean;
216 pragma Warnings (Off, Success);
218 Proj : Project_List;
220 begin
221 if not Debug.Debug_Flag_N then
222 if Project_Tree /= null then
223 Proj := Project_Tree.Projects;
224 while Proj /= null loop
225 if Proj.Project.Config_File_Temp then
226 Delete_Temporary_File
227 (Project_Tree.Shared, Proj.Project.Config_File_Name);
229 -- Make sure that we don't have a config file for this
230 -- project, in case there are several mains. In this case,
231 -- we will recreate another config file: we cannot reuse the
232 -- one that we just deleted!
234 Proj.Project.Config_Checked := False;
235 Proj.Project.Config_File_Name := No_Path;
236 Proj.Project.Config_File_Temp := False;
237 end if;
239 Proj := Proj.Next;
240 end loop;
241 end if;
242 end if;
243 end Delete_Temp_Config_Files;
245 ---------------------------
246 -- Delete_All_Temp_Files --
247 ---------------------------
249 procedure Delete_All_Temp_Files
250 (Shared : Shared_Project_Tree_Data_Access)
252 Dont_Care : Boolean;
253 pragma Warnings (Off, Dont_Care);
255 Path : Path_Name_Type;
257 begin
258 if not Debug.Debug_Flag_N then
259 for Index in
260 1 .. Temp_Files_Table.Last (Shared.Private_Part.Temp_Files)
261 loop
262 Path := Shared.Private_Part.Temp_Files.Table (Index);
264 if Path /= No_Path then
265 if Current_Verbosity = High then
266 Write_Line ("Removing temp file: "
267 & Get_Name_String (Path));
268 end if;
270 Delete_File (Get_Name_String (Path), Dont_Care);
271 end if;
272 end loop;
274 Temp_Files_Table.Free (Shared.Private_Part.Temp_Files);
275 Temp_Files_Table.Init (Shared.Private_Part.Temp_Files);
276 end if;
278 -- If any of the environment variables ADA_PRJ_INCLUDE_FILE or
279 -- ADA_PRJ_OBJECTS_FILE has been set, then reset their value to
280 -- the empty string. On VMS, this has the effect of deassigning
281 -- the logical names.
283 if Shared.Private_Part.Current_Source_Path_File /= No_Path then
284 Setenv (Project_Include_Path_File, "");
285 end if;
287 if Shared.Private_Part.Current_Object_Path_File /= No_Path then
288 Setenv (Project_Objects_Path_File, "");
289 end if;
290 end Delete_All_Temp_Files;
292 ---------------------
293 -- Dependency_Name --
294 ---------------------
296 function Dependency_Name
297 (Source_File_Name : File_Name_Type;
298 Dependency : Dependency_File_Kind) return File_Name_Type
300 begin
301 case Dependency is
302 when None =>
303 return No_File;
305 when Makefile =>
306 return Extend_Name (Source_File_Name, Makefile_Dependency_Suffix);
308 when ALI_File | ALI_Closure =>
309 return Extend_Name (Source_File_Name, ALI_Dependency_Suffix);
310 end case;
311 end Dependency_Name;
313 ----------------
314 -- Empty_File --
315 ----------------
317 function Empty_File return File_Name_Type is
318 begin
319 return File_Name_Type (The_Empty_String);
320 end Empty_File;
322 -------------------
323 -- Empty_Project --
324 -------------------
326 function Empty_Project
327 (Qualifier : Project_Qualifier) return Project_Data
329 begin
330 Prj.Initialize (Tree => No_Project_Tree);
332 declare
333 Data : Project_Data (Qualifier => Qualifier);
335 begin
336 -- Only the fields for which no default value could be provided in
337 -- prj.ads are initialized below.
339 Data.Config := Default_Project_Config;
340 return Data;
341 end;
342 end Empty_Project;
344 ------------------
345 -- Empty_String --
346 ------------------
348 function Empty_String return Name_Id is
349 begin
350 return The_Empty_String;
351 end Empty_String;
353 ------------
354 -- Expect --
355 ------------
357 procedure Expect (The_Token : Token_Type; Token_Image : String) is
358 begin
359 if Token /= The_Token then
361 -- ??? Should pass user flags here instead
363 Error_Msg (Gnatmake_Flags, Token_Image & " expected", Token_Ptr);
364 end if;
365 end Expect;
367 -----------------
368 -- Extend_Name --
369 -----------------
371 function Extend_Name
372 (File : File_Name_Type;
373 With_Suffix : String) return File_Name_Type
375 Last : Positive;
377 begin
378 Get_Name_String (File);
379 Last := Name_Len + 1;
381 while Name_Len /= 0 and then Name_Buffer (Name_Len) /= '.' loop
382 Name_Len := Name_Len - 1;
383 end loop;
385 if Name_Len <= 1 then
386 Name_Len := Last;
387 end if;
389 for J in With_Suffix'Range loop
390 Name_Buffer (Name_Len) := With_Suffix (J);
391 Name_Len := Name_Len + 1;
392 end loop;
394 Name_Len := Name_Len - 1;
395 return Name_Find;
396 end Extend_Name;
398 -------------------------
399 -- Is_Allowed_Language --
400 -------------------------
402 function Is_Allowed_Language (Name : Name_Id) return Boolean is
403 R : Restricted_Lang_Access := Restricted_Languages;
404 Lang : constant String := Get_Name_String (Name);
406 begin
407 if R = null then
408 return True;
410 else
411 while R /= null loop
412 if Get_Name_String (R.Name) = Lang then
413 return True;
414 end if;
416 R := R.Next;
417 end loop;
419 return False;
420 end if;
421 end Is_Allowed_Language;
423 ---------------------
424 -- Project_Changed --
425 ---------------------
427 procedure Project_Changed (Iter : in out Source_Iterator) is
428 begin
429 if Iter.Project /= null then
430 Iter.Language := Iter.Project.Project.Languages;
431 Language_Changed (Iter);
432 end if;
433 end Project_Changed;
435 ----------------------
436 -- Language_Changed --
437 ----------------------
439 procedure Language_Changed (Iter : in out Source_Iterator) is
440 begin
441 Iter.Current := No_Source;
443 if Iter.Language_Name /= No_Name then
444 while Iter.Language /= null
445 and then Iter.Language.Name /= Iter.Language_Name
446 loop
447 Iter.Language := Iter.Language.Next;
448 end loop;
449 end if;
451 -- If there is no matching language in this project, move to next
453 if Iter.Language = No_Language_Index then
454 if Iter.All_Projects then
455 loop
456 Iter.Project := Iter.Project.Next;
457 exit when Iter.Project = null
458 or else Iter.Encapsulated_Libs
459 or else not Iter.Project.From_Encapsulated_Lib;
460 end loop;
462 Project_Changed (Iter);
463 else
464 Iter.Project := null;
465 end if;
467 else
468 Iter.Current := Iter.Language.First_Source;
470 if Iter.Current = No_Source then
471 Iter.Language := Iter.Language.Next;
472 Language_Changed (Iter);
474 elsif not Iter.Locally_Removed
475 and then Iter.Current.Locally_Removed
476 then
477 Next (Iter);
478 end if;
479 end if;
480 end Language_Changed;
482 ---------------------
483 -- For_Each_Source --
484 ---------------------
486 function For_Each_Source
487 (In_Tree : Project_Tree_Ref;
488 Project : Project_Id := No_Project;
489 Language : Name_Id := No_Name;
490 Encapsulated_Libs : Boolean := True;
491 Locally_Removed : Boolean := True) return Source_Iterator
493 Iter : Source_Iterator;
494 begin
495 Iter := Source_Iterator'
496 (In_Tree => In_Tree,
497 Project => In_Tree.Projects,
498 All_Projects => Project = No_Project,
499 Language_Name => Language,
500 Language => No_Language_Index,
501 Current => No_Source,
502 Encapsulated_Libs => Encapsulated_Libs,
503 Locally_Removed => Locally_Removed);
505 if Project /= null then
506 while Iter.Project /= null
507 and then Iter.Project.Project /= Project
508 loop
509 Iter.Project := Iter.Project.Next;
510 end loop;
512 else
513 while not Iter.Encapsulated_Libs
514 and then Iter.Project.From_Encapsulated_Lib
515 loop
516 Iter.Project := Iter.Project.Next;
517 end loop;
518 end if;
520 Project_Changed (Iter);
522 return Iter;
523 end For_Each_Source;
525 -------------
526 -- Element --
527 -------------
529 function Element (Iter : Source_Iterator) return Source_Id is
530 begin
531 return Iter.Current;
532 end Element;
534 ----------
535 -- Next --
536 ----------
538 procedure Next (Iter : in out Source_Iterator) is
539 begin
540 loop
541 Iter.Current := Iter.Current.Next_In_Lang;
543 exit when Iter.Locally_Removed
544 or else Iter.Current = No_Source
545 or else not Iter.Current.Locally_Removed;
546 end loop;
548 if Iter.Current = No_Source then
549 Iter.Language := Iter.Language.Next;
550 Language_Changed (Iter);
551 end if;
552 end Next;
554 --------------------------------
555 -- For_Every_Project_Imported --
556 --------------------------------
558 procedure For_Every_Project_Imported_Context
559 (By : Project_Id;
560 Tree : Project_Tree_Ref;
561 With_State : in out State;
562 Include_Aggregated : Boolean := True;
563 Imported_First : Boolean := False)
565 use Project_Boolean_Htable;
567 procedure Recursive_Check_Context
568 (Project : Project_Id;
569 Tree : Project_Tree_Ref;
570 In_Aggregate_Lib : Boolean;
571 From_Encapsulated_Lib : Boolean);
572 -- Recursively handle the project tree creating a new context for
573 -- keeping track about already handled projects.
575 -----------------------------
576 -- Recursive_Check_Context --
577 -----------------------------
579 procedure Recursive_Check_Context
580 (Project : Project_Id;
581 Tree : Project_Tree_Ref;
582 In_Aggregate_Lib : Boolean;
583 From_Encapsulated_Lib : Boolean)
585 package Name_Id_Set is
586 new Ada.Containers.Ordered_Sets (Element_Type => Name_Id);
588 Seen_Name : Name_Id_Set.Set;
589 -- This set is needed to ensure that we do not handle the same
590 -- project twice in the context of aggregate libraries.
592 procedure Recursive_Check
593 (Project : Project_Id;
594 Tree : Project_Tree_Ref;
595 In_Aggregate_Lib : Boolean;
596 From_Encapsulated_Lib : Boolean);
597 -- Check if project has already been seen. If not, mark it as Seen,
598 -- Call Action, and check all its imported and aggregated projects.
600 ---------------------
601 -- Recursive_Check --
602 ---------------------
604 procedure Recursive_Check
605 (Project : Project_Id;
606 Tree : Project_Tree_Ref;
607 In_Aggregate_Lib : Boolean;
608 From_Encapsulated_Lib : Boolean)
611 function Has_Sources (P : Project_Id) return Boolean;
612 -- Returns True if P has sources
614 function Get_From_Tree (P : Project_Id) return Project_Id;
615 -- Get project P from Tree. If P has no sources get another
616 -- instance of this project with sources. If P has sources,
617 -- returns it.
619 -----------------
620 -- Has_Sources --
621 -----------------
623 function Has_Sources (P : Project_Id) return Boolean is
624 Lang : Language_Ptr;
626 begin
627 Lang := P.Languages;
628 while Lang /= No_Language_Index loop
629 if Lang.First_Source /= No_Source then
630 return True;
631 end if;
633 Lang := Lang.Next;
634 end loop;
636 return False;
637 end Has_Sources;
639 -------------------
640 -- Get_From_Tree --
641 -------------------
643 function Get_From_Tree (P : Project_Id) return Project_Id is
644 List : Project_List := Tree.Projects;
646 begin
647 if not Has_Sources (P) then
648 while List /= null loop
649 if List.Project.Name = P.Name
650 and then Has_Sources (List.Project)
651 then
652 return List.Project;
653 end if;
655 List := List.Next;
656 end loop;
657 end if;
659 return P;
660 end Get_From_Tree;
662 -- Local variables
664 List : Project_List;
666 -- Start of processing for Recursive_Check
668 begin
669 if not Seen_Name.Contains (Project.Name) then
671 -- Even if a project is aggregated multiple times in an
672 -- aggregated library, we will only return it once.
674 Seen_Name.Include (Project.Name);
676 if not Imported_First then
677 Action
678 (Get_From_Tree (Project),
679 Tree,
680 Project_Context'(In_Aggregate_Lib, From_Encapsulated_Lib),
681 With_State);
682 end if;
684 -- Visit all extended projects
686 if Project.Extends /= No_Project then
687 Recursive_Check
688 (Project.Extends, Tree,
689 In_Aggregate_Lib, From_Encapsulated_Lib);
690 end if;
692 -- Visit all imported projects
694 List := Project.Imported_Projects;
695 while List /= null loop
696 Recursive_Check
697 (List.Project, Tree,
698 In_Aggregate_Lib,
699 From_Encapsulated_Lib
700 or else Project.Standalone_Library = Encapsulated);
701 List := List.Next;
702 end loop;
704 -- Visit all aggregated projects
706 if Include_Aggregated
707 and then Project.Qualifier in Aggregate_Project
708 then
709 declare
710 Agg : Aggregated_Project_List;
712 begin
713 Agg := Project.Aggregated_Projects;
714 while Agg /= null loop
715 pragma Assert (Agg.Project /= No_Project);
717 -- For aggregated libraries, the tree must be the one
718 -- of the aggregate library.
720 if Project.Qualifier = Aggregate_Library then
721 Recursive_Check
722 (Agg.Project, Tree,
723 True,
724 From_Encapsulated_Lib
725 or else
726 Project.Standalone_Library = Encapsulated);
728 else
729 -- Use a new context as we want to returns the same
730 -- project in different project tree for aggregated
731 -- projects.
733 Recursive_Check_Context
734 (Agg.Project, Agg.Tree, False, False);
735 end if;
737 Agg := Agg.Next;
738 end loop;
739 end;
740 end if;
742 if Imported_First then
743 Action
744 (Get_From_Tree (Project),
745 Tree,
746 Project_Context'(In_Aggregate_Lib, From_Encapsulated_Lib),
747 With_State);
748 end if;
749 end if;
750 end Recursive_Check;
752 -- Start of processing for Recursive_Check_Context
754 begin
755 Recursive_Check
756 (Project, Tree, In_Aggregate_Lib, From_Encapsulated_Lib);
757 end Recursive_Check_Context;
759 -- Start of processing for For_Every_Project_Imported
761 begin
762 Recursive_Check_Context
763 (Project => By,
764 Tree => Tree,
765 In_Aggregate_Lib => False,
766 From_Encapsulated_Lib => False);
767 end For_Every_Project_Imported_Context;
769 procedure For_Every_Project_Imported
770 (By : Project_Id;
771 Tree : Project_Tree_Ref;
772 With_State : in out State;
773 Include_Aggregated : Boolean := True;
774 Imported_First : Boolean := False)
776 procedure Internal
777 (Project : Project_Id;
778 Tree : Project_Tree_Ref;
779 Context : Project_Context;
780 With_State : in out State);
781 -- Action wrapper for handling the context
783 --------------
784 -- Internal --
785 --------------
787 procedure Internal
788 (Project : Project_Id;
789 Tree : Project_Tree_Ref;
790 Context : Project_Context;
791 With_State : in out State)
793 pragma Unreferenced (Context);
794 begin
795 Action (Project, Tree, With_State);
796 end Internal;
798 procedure For_Projects is
799 new For_Every_Project_Imported_Context (State, Internal);
801 begin
802 For_Projects (By, Tree, With_State, Include_Aggregated, Imported_First);
803 end For_Every_Project_Imported;
805 -----------------
806 -- Find_Source --
807 -----------------
809 function Find_Source
810 (In_Tree : Project_Tree_Ref;
811 Project : Project_Id;
812 In_Imported_Only : Boolean := False;
813 In_Extended_Only : Boolean := False;
814 Base_Name : File_Name_Type;
815 Index : Int := 0) return Source_Id
817 Result : Source_Id := No_Source;
819 procedure Look_For_Sources
820 (Proj : Project_Id;
821 Tree : Project_Tree_Ref;
822 Src : in out Source_Id);
823 -- Look for Base_Name in the sources of Proj
825 ----------------------
826 -- Look_For_Sources --
827 ----------------------
829 procedure Look_For_Sources
830 (Proj : Project_Id;
831 Tree : Project_Tree_Ref;
832 Src : in out Source_Id)
834 Iterator : Source_Iterator;
836 begin
837 Iterator := For_Each_Source (In_Tree => Tree, Project => Proj);
838 while Element (Iterator) /= No_Source loop
839 if Element (Iterator).File = Base_Name
840 and then (Index = 0 or else Element (Iterator).Index = Index)
841 then
842 Src := Element (Iterator);
844 -- If the source has been excluded, continue looking. We will
845 -- get the excluded source only if there is no other source
846 -- with the same base name that is not locally removed.
848 if not Element (Iterator).Locally_Removed then
849 return;
850 end if;
851 end if;
853 Next (Iterator);
854 end loop;
855 end Look_For_Sources;
857 procedure For_Imported_Projects is new For_Every_Project_Imported
858 (State => Source_Id, Action => Look_For_Sources);
860 Proj : Project_Id;
862 -- Start of processing for Find_Source
864 begin
865 if In_Extended_Only then
866 Proj := Project;
867 while Proj /= No_Project loop
868 Look_For_Sources (Proj, In_Tree, Result);
869 exit when Result /= No_Source;
871 Proj := Proj.Extends;
872 end loop;
874 elsif In_Imported_Only then
875 Look_For_Sources (Project, In_Tree, Result);
877 if Result = No_Source then
878 For_Imported_Projects
879 (By => Project,
880 Tree => In_Tree,
881 Include_Aggregated => False,
882 With_State => Result);
883 end if;
885 else
886 Look_For_Sources (No_Project, In_Tree, Result);
887 end if;
889 return Result;
890 end Find_Source;
892 ----------
893 -- Hash --
894 ----------
896 function Hash is new GNAT.HTable.Hash (Header_Num => Header_Num);
897 -- Used in implementation of other functions Hash below
899 function Hash (Name : File_Name_Type) return Header_Num is
900 begin
901 return Hash (Get_Name_String (Name));
902 end Hash;
904 function Hash (Name : Name_Id) return Header_Num is
905 begin
906 return Hash (Get_Name_String (Name));
907 end Hash;
909 function Hash (Name : Path_Name_Type) return Header_Num is
910 begin
911 return Hash (Get_Name_String (Name));
912 end Hash;
914 function Hash (Project : Project_Id) return Header_Num is
915 begin
916 if Project = No_Project then
917 return Header_Num'First;
918 else
919 return Hash (Get_Name_String (Project.Name));
920 end if;
921 end Hash;
923 -----------
924 -- Image --
925 -----------
927 function Image (The_Casing : Casing_Type) return String is
928 begin
929 return The_Casing_Images (The_Casing).all;
930 end Image;
932 -----------------------------
933 -- Is_Standard_GNAT_Naming --
934 -----------------------------
936 function Is_Standard_GNAT_Naming
937 (Naming : Lang_Naming_Data) return Boolean
939 begin
940 return Get_Name_String (Naming.Spec_Suffix) = ".ads"
941 and then Get_Name_String (Naming.Body_Suffix) = ".adb"
942 and then Get_Name_String (Naming.Dot_Replacement) = "-";
943 end Is_Standard_GNAT_Naming;
945 ----------------
946 -- Initialize --
947 ----------------
949 procedure Initialize (Tree : Project_Tree_Ref) is
950 begin
951 if The_Empty_String = No_Name then
952 Uintp.Initialize;
953 Name_Len := 0;
954 The_Empty_String := Name_Find;
956 Prj.Attr.Initialize;
958 -- Make sure that new reserved words after Ada 95 may be used as
959 -- identifiers.
961 Opt.Ada_Version := Opt.Ada_95;
962 Opt.Ada_Version_Pragma := Empty;
964 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
965 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
966 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
967 Set_Name_Table_Byte
968 (Name_External_As_List, Token_Type'Pos (Tok_External_As_List));
969 end if;
971 if Tree /= No_Project_Tree then
972 Reset (Tree);
973 end if;
974 end Initialize;
976 ------------------
977 -- Is_Extending --
978 ------------------
980 function Is_Extending
981 (Extending : Project_Id;
982 Extended : Project_Id) return Boolean
984 Proj : Project_Id;
986 begin
987 Proj := Extending;
988 while Proj /= No_Project loop
989 if Proj = Extended then
990 return True;
991 end if;
993 Proj := Proj.Extends;
994 end loop;
996 return False;
997 end Is_Extending;
999 -----------------
1000 -- Object_Name --
1001 -----------------
1003 function Object_Name
1004 (Source_File_Name : File_Name_Type;
1005 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type
1007 begin
1008 if Object_File_Suffix = No_Name then
1009 return Extend_Name
1010 (Source_File_Name, Object_Suffix);
1011 else
1012 return Extend_Name
1013 (Source_File_Name, Get_Name_String (Object_File_Suffix));
1014 end if;
1015 end Object_Name;
1017 function Object_Name
1018 (Source_File_Name : File_Name_Type;
1019 Source_Index : Int;
1020 Index_Separator : Character;
1021 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type
1023 Index_Img : constant String := Source_Index'Img;
1024 Last : Natural;
1026 begin
1027 Get_Name_String (Source_File_Name);
1029 Last := Name_Len;
1030 while Last > 1 and then Name_Buffer (Last) /= '.' loop
1031 Last := Last - 1;
1032 end loop;
1034 if Last > 1 then
1035 Name_Len := Last - 1;
1036 end if;
1038 Add_Char_To_Name_Buffer (Index_Separator);
1039 Add_Str_To_Name_Buffer (Index_Img (2 .. Index_Img'Last));
1041 if Object_File_Suffix = No_Name then
1042 Add_Str_To_Name_Buffer (Object_Suffix);
1043 else
1044 Add_Str_To_Name_Buffer (Get_Name_String (Object_File_Suffix));
1045 end if;
1047 return Name_Find;
1048 end Object_Name;
1050 ----------------------
1051 -- Record_Temp_File --
1052 ----------------------
1054 procedure Record_Temp_File
1055 (Shared : Shared_Project_Tree_Data_Access;
1056 Path : Path_Name_Type)
1058 begin
1059 Temp_Files_Table.Append (Shared.Private_Part.Temp_Files, Path);
1060 end Record_Temp_File;
1062 ----------
1063 -- Free --
1064 ----------
1066 procedure Free (List : in out Aggregated_Project_List) is
1067 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
1068 (Aggregated_Project, Aggregated_Project_List);
1069 Tmp : Aggregated_Project_List;
1070 begin
1071 while List /= null loop
1072 Tmp := List.Next;
1074 Free (List.Tree);
1076 Unchecked_Free (List);
1077 List := Tmp;
1078 end loop;
1079 end Free;
1081 ----------------------------
1082 -- Add_Aggregated_Project --
1083 ----------------------------
1085 procedure Add_Aggregated_Project
1086 (Project : Project_Id; Path : Path_Name_Type) is
1087 begin
1088 Project.Aggregated_Projects := new Aggregated_Project'
1089 (Path => Path,
1090 Project => No_Project,
1091 Tree => null,
1092 Next => Project.Aggregated_Projects);
1093 end Add_Aggregated_Project;
1095 ----------
1096 -- Free --
1097 ----------
1099 procedure Free (Project : in out Project_Id) is
1100 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
1101 (Project_Data, Project_Id);
1103 begin
1104 if Project /= null then
1105 Free (Project.Ada_Include_Path);
1106 Free (Project.Objects_Path);
1107 Free (Project.Ada_Objects_Path);
1108 Free_List (Project.Imported_Projects, Free_Project => False);
1109 Free_List (Project.All_Imported_Projects, Free_Project => False);
1110 Free_List (Project.Languages);
1112 case Project.Qualifier is
1113 when Aggregate | Aggregate_Library =>
1114 Free (Project.Aggregated_Projects);
1116 when others =>
1117 null;
1118 end case;
1120 Unchecked_Free (Project);
1121 end if;
1122 end Free;
1124 ---------------
1125 -- Free_List --
1126 ---------------
1128 procedure Free_List (Languages : in out Language_List) is
1129 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
1130 (Language_List_Element, Language_List);
1131 Tmp : Language_List;
1132 begin
1133 while Languages /= null loop
1134 Tmp := Languages.Next;
1135 Unchecked_Free (Languages);
1136 Languages := Tmp;
1137 end loop;
1138 end Free_List;
1140 ---------------
1141 -- Free_List --
1142 ---------------
1144 procedure Free_List (Source : in out Source_Id) is
1145 procedure Unchecked_Free is new
1146 Ada.Unchecked_Deallocation (Source_Data, Source_Id);
1148 Tmp : Source_Id;
1150 begin
1151 while Source /= No_Source loop
1152 Tmp := Source.Next_In_Lang;
1153 Free_List (Source.Alternate_Languages);
1155 if Source.Unit /= null
1156 and then Source.Kind in Spec_Or_Body
1157 then
1158 Source.Unit.File_Names (Source.Kind) := null;
1159 end if;
1161 Unchecked_Free (Source);
1162 Source := Tmp;
1163 end loop;
1164 end Free_List;
1166 ---------------
1167 -- Free_List --
1168 ---------------
1170 procedure Free_List
1171 (List : in out Project_List;
1172 Free_Project : Boolean)
1174 procedure Unchecked_Free is new
1175 Ada.Unchecked_Deallocation (Project_List_Element, Project_List);
1177 Tmp : Project_List;
1179 begin
1180 while List /= null loop
1181 Tmp := List.Next;
1183 if Free_Project then
1184 Free (List.Project);
1185 end if;
1187 Unchecked_Free (List);
1188 List := Tmp;
1189 end loop;
1190 end Free_List;
1192 ---------------
1193 -- Free_List --
1194 ---------------
1196 procedure Free_List (Languages : in out Language_Ptr) is
1197 procedure Unchecked_Free is new
1198 Ada.Unchecked_Deallocation (Language_Data, Language_Ptr);
1200 Tmp : Language_Ptr;
1202 begin
1203 while Languages /= null loop
1204 Tmp := Languages.Next;
1205 Free_List (Languages.First_Source);
1206 Unchecked_Free (Languages);
1207 Languages := Tmp;
1208 end loop;
1209 end Free_List;
1211 --------------------------
1212 -- Reset_Units_In_Table --
1213 --------------------------
1215 procedure Reset_Units_In_Table (Table : in out Units_Htable.Instance) is
1216 Unit : Unit_Index;
1218 begin
1219 Unit := Units_Htable.Get_First (Table);
1220 while Unit /= No_Unit_Index loop
1221 if Unit.File_Names (Spec) /= null then
1222 Unit.File_Names (Spec).Unit := No_Unit_Index;
1223 end if;
1225 if Unit.File_Names (Impl) /= null then
1226 Unit.File_Names (Impl).Unit := No_Unit_Index;
1227 end if;
1229 Unit := Units_Htable.Get_Next (Table);
1230 end loop;
1231 end Reset_Units_In_Table;
1233 ----------------
1234 -- Free_Units --
1235 ----------------
1237 procedure Free_Units (Table : in out Units_Htable.Instance) is
1238 procedure Unchecked_Free is new
1239 Ada.Unchecked_Deallocation (Unit_Data, Unit_Index);
1241 Unit : Unit_Index;
1243 begin
1244 Unit := Units_Htable.Get_First (Table);
1245 while Unit /= No_Unit_Index loop
1247 -- We cannot reset Unit.File_Names (Impl or Spec).Unit here as
1248 -- Source_Data buffer is freed by the following instruction
1249 -- Free_List (Tree.Projects, Free_Project => True);
1251 Unchecked_Free (Unit);
1252 Unit := Units_Htable.Get_Next (Table);
1253 end loop;
1255 Units_Htable.Reset (Table);
1256 end Free_Units;
1258 ----------
1259 -- Free --
1260 ----------
1262 procedure Free (Tree : in out Project_Tree_Ref) is
1263 procedure Unchecked_Free is new
1264 Ada.Unchecked_Deallocation
1265 (Project_Tree_Data, Project_Tree_Ref);
1267 procedure Unchecked_Free is new
1268 Ada.Unchecked_Deallocation
1269 (Project_Tree_Appdata'Class, Project_Tree_Appdata_Access);
1271 begin
1272 if Tree /= null then
1273 if Tree.Is_Root_Tree then
1274 Name_List_Table.Free (Tree.Shared.Name_Lists);
1275 Number_List_Table.Free (Tree.Shared.Number_Lists);
1276 String_Element_Table.Free (Tree.Shared.String_Elements);
1277 Variable_Element_Table.Free (Tree.Shared.Variable_Elements);
1278 Array_Element_Table.Free (Tree.Shared.Array_Elements);
1279 Array_Table.Free (Tree.Shared.Arrays);
1280 Package_Table.Free (Tree.Shared.Packages);
1281 Temp_Files_Table.Free (Tree.Shared.Private_Part.Temp_Files);
1282 end if;
1284 if Tree.Appdata /= null then
1285 Free (Tree.Appdata.all);
1286 Unchecked_Free (Tree.Appdata);
1287 end if;
1289 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
1290 Source_Files_Htable.Reset (Tree.Source_Files_HT);
1292 Reset_Units_In_Table (Tree.Units_HT);
1293 Free_List (Tree.Projects, Free_Project => True);
1294 Free_Units (Tree.Units_HT);
1296 Unchecked_Free (Tree);
1297 end if;
1298 end Free;
1300 -----------
1301 -- Reset --
1302 -----------
1304 procedure Reset (Tree : Project_Tree_Ref) is
1305 begin
1306 -- Visible tables
1308 if Tree.Is_Root_Tree then
1310 -- We cannot use 'Access here:
1311 -- "illegal attribute for discriminant-dependent component"
1312 -- However, we know this is valid since Shared and Shared_Data have
1313 -- the same lifetime and will always exist concurrently.
1315 Tree.Shared := Tree.Shared_Data'Unrestricted_Access;
1316 Name_List_Table.Init (Tree.Shared.Name_Lists);
1317 Number_List_Table.Init (Tree.Shared.Number_Lists);
1318 String_Element_Table.Init (Tree.Shared.String_Elements);
1319 Variable_Element_Table.Init (Tree.Shared.Variable_Elements);
1320 Array_Element_Table.Init (Tree.Shared.Array_Elements);
1321 Array_Table.Init (Tree.Shared.Arrays);
1322 Package_Table.Init (Tree.Shared.Packages);
1324 -- Private part table
1326 Temp_Files_Table.Init (Tree.Shared.Private_Part.Temp_Files);
1328 Tree.Shared.Private_Part.Current_Source_Path_File := No_Path;
1329 Tree.Shared.Private_Part.Current_Object_Path_File := No_Path;
1330 end if;
1332 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
1333 Source_Files_Htable.Reset (Tree.Source_Files_HT);
1334 Replaced_Source_HTable.Reset (Tree.Replaced_Sources);
1336 Tree.Replaced_Source_Number := 0;
1338 Reset_Units_In_Table (Tree.Units_HT);
1339 Free_List (Tree.Projects, Free_Project => True);
1340 Free_Units (Tree.Units_HT);
1341 end Reset;
1343 -------------------------------------
1344 -- Set_Current_Object_Path_File_Of --
1345 -------------------------------------
1347 procedure Set_Current_Object_Path_File_Of
1348 (Shared : Shared_Project_Tree_Data_Access;
1349 To : Path_Name_Type)
1351 begin
1352 Shared.Private_Part.Current_Object_Path_File := To;
1353 end Set_Current_Object_Path_File_Of;
1355 -------------------------------------
1356 -- Set_Current_Source_Path_File_Of --
1357 -------------------------------------
1359 procedure Set_Current_Source_Path_File_Of
1360 (Shared : Shared_Project_Tree_Data_Access;
1361 To : Path_Name_Type)
1363 begin
1364 Shared.Private_Part.Current_Source_Path_File := To;
1365 end Set_Current_Source_Path_File_Of;
1367 -----------------------
1368 -- Set_Path_File_Var --
1369 -----------------------
1371 procedure Set_Path_File_Var (Name : String; Value : String) is
1372 Host_Spec : String_Access := To_Host_File_Spec (Value);
1373 begin
1374 if Host_Spec = null then
1375 Prj.Com.Fail
1376 ("could not convert file name """ & Value & """ to host spec");
1377 else
1378 Setenv (Name, Host_Spec.all);
1379 Free (Host_Spec);
1380 end if;
1381 end Set_Path_File_Var;
1383 -------------------
1384 -- Switches_Name --
1385 -------------------
1387 function Switches_Name
1388 (Source_File_Name : File_Name_Type) return File_Name_Type
1390 begin
1391 return Extend_Name (Source_File_Name, Switches_Dependency_Suffix);
1392 end Switches_Name;
1394 -----------
1395 -- Value --
1396 -----------
1398 function Value (Image : String) return Casing_Type is
1399 begin
1400 for Casing in The_Casing_Images'Range loop
1401 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
1402 return Casing;
1403 end if;
1404 end loop;
1406 raise Constraint_Error;
1407 end Value;
1409 ---------------------
1410 -- Has_Ada_Sources --
1411 ---------------------
1413 function Has_Ada_Sources (Data : Project_Id) return Boolean is
1414 Lang : Language_Ptr;
1416 begin
1417 Lang := Data.Languages;
1418 while Lang /= No_Language_Index loop
1419 if Lang.Name = Name_Ada then
1420 return Lang.First_Source /= No_Source;
1421 end if;
1422 Lang := Lang.Next;
1423 end loop;
1425 return False;
1426 end Has_Ada_Sources;
1428 ------------------------
1429 -- Contains_ALI_Files --
1430 ------------------------
1432 function Contains_ALI_Files (Dir : Path_Name_Type) return Boolean is
1433 Dir_Name : constant String := Get_Name_String (Dir);
1434 Direct : Dir_Type;
1435 Name : String (1 .. 1_000);
1436 Last : Natural;
1437 Result : Boolean := False;
1439 begin
1440 Open (Direct, Dir_Name);
1442 -- For each file in the directory, check if it is an ALI file
1444 loop
1445 Read (Direct, Name, Last);
1446 exit when Last = 0;
1447 Canonical_Case_File_Name (Name (1 .. Last));
1448 Result := Last >= 5 and then Name (Last - 3 .. Last) = ".ali";
1449 exit when Result;
1450 end loop;
1452 Close (Direct);
1453 return Result;
1455 exception
1456 -- If there is any problem, close the directory if open and return True.
1457 -- The library directory will be added to the path.
1459 when others =>
1460 if Is_Open (Direct) then
1461 Close (Direct);
1462 end if;
1464 return True;
1465 end Contains_ALI_Files;
1467 --------------------------
1468 -- Get_Object_Directory --
1469 --------------------------
1471 function Get_Object_Directory
1472 (Project : Project_Id;
1473 Including_Libraries : Boolean;
1474 Only_If_Ada : Boolean := False) return Path_Name_Type
1476 begin
1477 if (Project.Library and then Including_Libraries)
1478 or else
1479 (Project.Object_Directory /= No_Path_Information
1480 and then (not Including_Libraries or else not Project.Library))
1481 then
1482 -- For a library project, add the library ALI directory if there is
1483 -- no object directory or if the library ALI directory contains ALI
1484 -- files; otherwise add the object directory.
1486 if Project.Library then
1487 if Project.Object_Directory = No_Path_Information
1488 or else Contains_ALI_Files (Project.Library_ALI_Dir.Display_Name)
1489 then
1490 return Project.Library_ALI_Dir.Display_Name;
1491 else
1492 return Project.Object_Directory.Display_Name;
1493 end if;
1495 -- For a non-library project, add object directory if it is not a
1496 -- virtual project, and if there are Ada sources in the project or
1497 -- one of the projects it extends. If there are no Ada sources,
1498 -- adding the object directory could disrupt the order of the
1499 -- object dirs in the path.
1501 elsif not Project.Virtual then
1502 declare
1503 Add_Object_Dir : Boolean;
1504 Prj : Project_Id;
1506 begin
1507 Add_Object_Dir := not Only_If_Ada;
1508 Prj := Project;
1509 while not Add_Object_Dir and then Prj /= No_Project loop
1510 if Has_Ada_Sources (Prj) then
1511 Add_Object_Dir := True;
1512 else
1513 Prj := Prj.Extends;
1514 end if;
1515 end loop;
1517 if Add_Object_Dir then
1518 return Project.Object_Directory.Display_Name;
1519 end if;
1520 end;
1521 end if;
1522 end if;
1524 return No_Path;
1525 end Get_Object_Directory;
1527 -----------------------------------
1528 -- Ultimate_Extending_Project_Of --
1529 -----------------------------------
1531 function Ultimate_Extending_Project_Of
1532 (Proj : Project_Id) return Project_Id
1534 Prj : Project_Id;
1536 begin
1537 Prj := Proj;
1538 while Prj /= null and then Prj.Extended_By /= No_Project loop
1539 Prj := Prj.Extended_By;
1540 end loop;
1542 return Prj;
1543 end Ultimate_Extending_Project_Of;
1545 -----------------------------------
1546 -- Compute_All_Imported_Projects --
1547 -----------------------------------
1549 procedure Compute_All_Imported_Projects
1550 (Root_Project : Project_Id;
1551 Tree : Project_Tree_Ref)
1553 procedure Analyze_Tree
1554 (Local_Root : Project_Id;
1555 Local_Tree : Project_Tree_Ref;
1556 Context : Project_Context);
1557 -- Process Project and all its aggregated project to analyze their own
1558 -- imported projects.
1560 ------------------
1561 -- Analyze_Tree --
1562 ------------------
1564 procedure Analyze_Tree
1565 (Local_Root : Project_Id;
1566 Local_Tree : Project_Tree_Ref;
1567 Context : Project_Context)
1569 pragma Unreferenced (Local_Root);
1571 Project : Project_Id;
1573 procedure Recursive_Add
1574 (Prj : Project_Id;
1575 Tree : Project_Tree_Ref;
1576 Context : Project_Context;
1577 Dummy : in out Boolean);
1578 -- Recursively add the projects imported by project Project, but not
1579 -- those that are extended.
1581 -------------------
1582 -- Recursive_Add --
1583 -------------------
1585 procedure Recursive_Add
1586 (Prj : Project_Id;
1587 Tree : Project_Tree_Ref;
1588 Context : Project_Context;
1589 Dummy : in out Boolean)
1591 pragma Unreferenced (Dummy, Tree);
1593 List : Project_List;
1594 Prj2 : Project_Id;
1596 begin
1597 -- A project is not importing itself
1599 Prj2 := Ultimate_Extending_Project_Of (Prj);
1601 if Project /= Prj2 then
1603 -- Check that the project is not already in the list. We know
1604 -- the one passed to Recursive_Add have never been visited
1605 -- before, but the one passed it are the extended projects.
1607 List := Project.All_Imported_Projects;
1608 while List /= null loop
1609 if List.Project = Prj2 then
1610 return;
1611 end if;
1613 List := List.Next;
1614 end loop;
1616 -- Add it to the list
1618 Project.All_Imported_Projects :=
1619 new Project_List_Element'
1620 (Project => Prj2,
1621 From_Encapsulated_Lib =>
1622 Context.From_Encapsulated_Lib
1623 or else Analyze_Tree.Context.From_Encapsulated_Lib,
1624 Next => Project.All_Imported_Projects);
1625 end if;
1626 end Recursive_Add;
1628 procedure For_All_Projects is
1629 new For_Every_Project_Imported_Context (Boolean, Recursive_Add);
1631 Dummy : Boolean := False;
1632 List : Project_List;
1634 begin
1635 List := Local_Tree.Projects;
1636 while List /= null loop
1637 Project := List.Project;
1638 Free_List
1639 (Project.All_Imported_Projects, Free_Project => False);
1640 For_All_Projects
1641 (Project, Local_Tree, Dummy, Include_Aggregated => False);
1642 List := List.Next;
1643 end loop;
1644 end Analyze_Tree;
1646 procedure For_Aggregates is
1647 new For_Project_And_Aggregated_Context (Analyze_Tree);
1649 -- Start of processing for Compute_All_Imported_Projects
1651 begin
1652 For_Aggregates (Root_Project, Tree);
1653 end Compute_All_Imported_Projects;
1655 -------------------
1656 -- Is_Compilable --
1657 -------------------
1659 function Is_Compilable (Source : Source_Id) return Boolean is
1660 begin
1661 case Source.Compilable is
1662 when Unknown =>
1663 if Source.Language.Config.Compiler_Driver /= No_File
1664 and then
1665 Length_Of_Name (Source.Language.Config.Compiler_Driver) /= 0
1666 and then not Source.Locally_Removed
1667 and then (Source.Language.Config.Kind /= File_Based
1668 or else Source.Kind /= Spec)
1669 then
1670 -- Do not modify Source.Compilable before the source record
1671 -- has been initialized.
1673 if Source.Source_TS /= Empty_Time_Stamp then
1674 Source.Compilable := Yes;
1675 end if;
1677 return True;
1679 else
1680 if Source.Source_TS /= Empty_Time_Stamp then
1681 Source.Compilable := No;
1682 end if;
1684 return False;
1685 end if;
1687 when Yes =>
1688 return True;
1690 when No =>
1691 return False;
1692 end case;
1693 end Is_Compilable;
1695 ------------------------------
1696 -- Object_To_Global_Archive --
1697 ------------------------------
1699 function Object_To_Global_Archive (Source : Source_Id) return Boolean is
1700 begin
1701 return Source.Language.Config.Kind = File_Based
1702 and then Source.Kind = Impl
1703 and then Source.Language.Config.Objects_Linked
1704 and then Is_Compilable (Source)
1705 and then Source.Language.Config.Object_Generated;
1706 end Object_To_Global_Archive;
1708 ----------------------------
1709 -- Get_Language_From_Name --
1710 ----------------------------
1712 function Get_Language_From_Name
1713 (Project : Project_Id;
1714 Name : String) return Language_Ptr
1716 N : Name_Id;
1717 Result : Language_Ptr;
1719 begin
1720 Name_Len := Name'Length;
1721 Name_Buffer (1 .. Name_Len) := Name;
1722 To_Lower (Name_Buffer (1 .. Name_Len));
1723 N := Name_Find;
1725 Result := Project.Languages;
1726 while Result /= No_Language_Index loop
1727 if Result.Name = N then
1728 return Result;
1729 end if;
1731 Result := Result.Next;
1732 end loop;
1734 return No_Language_Index;
1735 end Get_Language_From_Name;
1737 ----------------
1738 -- Other_Part --
1739 ----------------
1741 function Other_Part (Source : Source_Id) return Source_Id is
1742 begin
1743 if Source.Unit /= No_Unit_Index then
1744 case Source.Kind is
1745 when Impl =>
1746 return Source.Unit.File_Names (Spec);
1747 when Spec =>
1748 return Source.Unit.File_Names (Impl);
1749 when Sep =>
1750 return No_Source;
1751 end case;
1752 else
1753 return No_Source;
1754 end if;
1755 end Other_Part;
1757 ------------------
1758 -- Create_Flags --
1759 ------------------
1761 function Create_Flags
1762 (Report_Error : Error_Handler;
1763 When_No_Sources : Error_Warning;
1764 Require_Sources_Other_Lang : Boolean := True;
1765 Allow_Duplicate_Basenames : Boolean := True;
1766 Compiler_Driver_Mandatory : Boolean := False;
1767 Error_On_Unknown_Language : Boolean := True;
1768 Require_Obj_Dirs : Error_Warning := Error;
1769 Allow_Invalid_External : Error_Warning := Error;
1770 Missing_Source_Files : Error_Warning := Error;
1771 Ignore_Missing_With : Boolean := False)
1772 return Processing_Flags
1774 begin
1775 return Processing_Flags'
1776 (Report_Error => Report_Error,
1777 When_No_Sources => When_No_Sources,
1778 Require_Sources_Other_Lang => Require_Sources_Other_Lang,
1779 Allow_Duplicate_Basenames => Allow_Duplicate_Basenames,
1780 Error_On_Unknown_Language => Error_On_Unknown_Language,
1781 Compiler_Driver_Mandatory => Compiler_Driver_Mandatory,
1782 Require_Obj_Dirs => Require_Obj_Dirs,
1783 Allow_Invalid_External => Allow_Invalid_External,
1784 Missing_Source_Files => Missing_Source_Files,
1785 Ignore_Missing_With => Ignore_Missing_With);
1786 end Create_Flags;
1788 ------------
1789 -- Length --
1790 ------------
1792 function Length
1793 (Table : Name_List_Table.Instance;
1794 List : Name_List_Index) return Natural
1796 Count : Natural := 0;
1797 Tmp : Name_List_Index;
1799 begin
1800 Tmp := List;
1801 while Tmp /= No_Name_List loop
1802 Count := Count + 1;
1803 Tmp := Table.Table (Tmp).Next;
1804 end loop;
1806 return Count;
1807 end Length;
1809 ------------------
1810 -- Debug_Output --
1811 ------------------
1813 procedure Debug_Output (Str : String) is
1814 begin
1815 if Current_Verbosity > Default then
1816 Set_Standard_Error;
1817 Write_Line ((1 .. Debug_Level * 2 => ' ') & Str);
1818 Set_Standard_Output;
1819 end if;
1820 end Debug_Output;
1822 ------------------
1823 -- Debug_Indent --
1824 ------------------
1826 procedure Debug_Indent is
1827 begin
1828 if Current_Verbosity = High then
1829 Set_Standard_Error;
1830 Write_Str ((1 .. Debug_Level * 2 => ' '));
1831 Set_Standard_Output;
1832 end if;
1833 end Debug_Indent;
1835 ------------------
1836 -- Debug_Output --
1837 ------------------
1839 procedure Debug_Output (Str : String; Str2 : Name_Id) is
1840 begin
1841 if Current_Verbosity = High then
1842 Debug_Indent;
1843 Set_Standard_Error;
1844 Write_Str (Str);
1846 if Str2 = No_Name then
1847 Write_Line (" <no_name>");
1848 else
1849 Write_Line (" """ & Get_Name_String (Str2) & '"');
1850 end if;
1852 Set_Standard_Output;
1853 end if;
1854 end Debug_Output;
1856 ---------------------------
1857 -- Debug_Increase_Indent --
1858 ---------------------------
1860 procedure Debug_Increase_Indent
1861 (Str : String := ""; Str2 : Name_Id := No_Name)
1863 begin
1864 if Str2 /= No_Name then
1865 Debug_Output (Str, Str2);
1866 else
1867 Debug_Output (Str);
1868 end if;
1869 Debug_Level := Debug_Level + 1;
1870 end Debug_Increase_Indent;
1872 ---------------------------
1873 -- Debug_Decrease_Indent --
1874 ---------------------------
1876 procedure Debug_Decrease_Indent (Str : String := "") is
1877 begin
1878 if Debug_Level > 0 then
1879 Debug_Level := Debug_Level - 1;
1880 end if;
1882 if Str /= "" then
1883 Debug_Output (Str);
1884 end if;
1885 end Debug_Decrease_Indent;
1887 ----------------
1888 -- Debug_Name --
1889 ----------------
1891 function Debug_Name (Tree : Project_Tree_Ref) return Name_Id is
1892 P : Project_List;
1894 begin
1895 Name_Len := 0;
1896 Add_Str_To_Name_Buffer ("Tree [");
1898 P := Tree.Projects;
1899 while P /= null loop
1900 if P /= Tree.Projects then
1901 Add_Char_To_Name_Buffer (',');
1902 end if;
1904 Add_Str_To_Name_Buffer (Get_Name_String (P.Project.Name));
1906 P := P.Next;
1907 end loop;
1909 Add_Char_To_Name_Buffer (']');
1911 return Name_Find;
1912 end Debug_Name;
1914 ----------
1915 -- Free --
1916 ----------
1918 procedure Free (Tree : in out Project_Tree_Appdata) is
1919 pragma Unreferenced (Tree);
1920 begin
1921 null;
1922 end Free;
1924 --------------------------------
1925 -- For_Project_And_Aggregated --
1926 --------------------------------
1928 procedure For_Project_And_Aggregated
1929 (Root_Project : Project_Id;
1930 Root_Tree : Project_Tree_Ref)
1932 Agg : Aggregated_Project_List;
1934 begin
1935 Action (Root_Project, Root_Tree);
1937 if Root_Project.Qualifier in Aggregate_Project then
1938 Agg := Root_Project.Aggregated_Projects;
1939 while Agg /= null loop
1940 For_Project_And_Aggregated (Agg.Project, Agg.Tree);
1941 Agg := Agg.Next;
1942 end loop;
1943 end if;
1944 end For_Project_And_Aggregated;
1946 ----------------------------------------
1947 -- For_Project_And_Aggregated_Context --
1948 ----------------------------------------
1950 procedure For_Project_And_Aggregated_Context
1951 (Root_Project : Project_Id;
1952 Root_Tree : Project_Tree_Ref)
1955 procedure Recursive_Process
1956 (Project : Project_Id;
1957 Tree : Project_Tree_Ref;
1958 Context : Project_Context);
1959 -- Process Project and all aggregated projects recursively
1961 -----------------------
1962 -- Recursive_Process --
1963 -----------------------
1965 procedure Recursive_Process
1966 (Project : Project_Id;
1967 Tree : Project_Tree_Ref;
1968 Context : Project_Context)
1970 Agg : Aggregated_Project_List;
1971 Ctx : Project_Context;
1973 begin
1974 Action (Project, Tree, Context);
1976 if Project.Qualifier in Aggregate_Project then
1977 Ctx :=
1978 (In_Aggregate_Lib => True,
1979 From_Encapsulated_Lib =>
1980 Context.From_Encapsulated_Lib
1981 or else Project.Standalone_Library = Encapsulated);
1983 Agg := Project.Aggregated_Projects;
1984 while Agg /= null loop
1985 Recursive_Process (Agg.Project, Agg.Tree, Ctx);
1986 Agg := Agg.Next;
1987 end loop;
1988 end if;
1989 end Recursive_Process;
1991 -- Start of processing for For_Project_And_Aggregated_Context
1993 begin
1994 Recursive_Process
1995 (Root_Project, Root_Tree, Project_Context'(False, False));
1996 end For_Project_And_Aggregated_Context;
1998 -- Package initialization for Prj
2000 begin
2001 -- Make sure that the standard config and user project file extensions are
2002 -- compatible with canonical case file naming.
2004 Canonical_Case_File_Name (Config_Project_File_Extension);
2005 Canonical_Case_File_Name (Project_File_Extension);
2006 end Prj;