1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2009, 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 GNAT.Case_Util; use GNAT.Case_Util;
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
28 with GNAT.Dynamic_HTables;
30 with Err_Vars; use Err_Vars;
32 with Osint; use Osint;
33 with Output; use Output;
34 with Prj.Err; use Prj.Err;
35 with Prj.Util; use Prj.Util;
37 with Snames; use Snames;
38 with Targparm; use Targparm;
40 with Ada.Characters.Handling; use Ada.Characters.Handling;
41 with Ada.Directories; use Ada.Directories;
42 with Ada.Strings; use Ada.Strings;
43 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
44 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
46 package body Prj.Nmsc is
48 No_Continuation_String : aliased String := "";
49 Continuation_String : aliased String := "\";
50 -- Used in Check_Library for continuation error messages at the same
53 type Name_Location is record
54 Name : File_Name_Type; -- ??? duplicates the key
55 Location : Source_Ptr;
56 Source : Source_Id := No_Source;
57 Found : Boolean := False;
59 No_Name_Location : constant Name_Location :=
60 (No_File, No_Location, No_Source, False);
61 package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
62 (Header_Num => Header_Num,
63 Element => Name_Location,
64 No_Element => No_Name_Location,
65 Key => File_Name_Type,
68 -- Information about file names found in string list attribute
69 -- (Source_Files or Source_List_File).
70 -- Except is set to True if source is a naming exception in the project.
71 -- This is used to check that all referenced files were indeed found on the
74 type Unit_Exception is record
75 Name : Name_Id; -- ??? duplicates the key
76 Spec : File_Name_Type;
77 Impl : File_Name_Type;
80 No_Unit_Exception : constant Unit_Exception := (No_Name, No_File, No_File);
82 package Unit_Exceptions_Htable is new GNAT.Dynamic_HTables.Simple_HTable
83 (Header_Num => Header_Num,
84 Element => Unit_Exception,
85 No_Element => No_Unit_Exception,
89 -- Record special naming schemes for Ada units (name of spec file and name
90 -- of implementation file). The elements in this list come from the naming
91 -- exceptions specified in the project files.
93 type File_Found is record
94 File : File_Name_Type := No_File;
95 Found : Boolean := False;
96 Location : Source_Ptr := No_Location;
99 No_File_Found : constant File_Found := (No_File, False, No_Location);
101 package Excluded_Sources_Htable is new GNAT.Dynamic_HTables.Simple_HTable
102 (Header_Num => Header_Num,
103 Element => File_Found,
104 No_Element => No_File_Found,
105 Key => File_Name_Type,
108 -- A hash table to store the base names of excluded files, if any
110 package Object_File_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
111 (Header_Num => Header_Num,
112 Element => Source_Id,
113 No_Element => No_Source,
114 Key => File_Name_Type,
117 -- A hash table to store the object file names for a project, to check that
118 -- two different sources have different object file names.
120 type Project_Processing_Data is record
121 Project : Project_Id;
122 Source_Names : Source_Names_Htable.Instance;
123 Unit_Exceptions : Unit_Exceptions_Htable.Instance;
124 Excluded : Excluded_Sources_Htable.Instance;
126 Source_List_File_Location : Source_Ptr;
127 -- Location of the Source_List_File attribute, for error messages
129 -- This is similar to Tree_Processing_Data, but contains project-specific
130 -- information which is only useful while processing the project, and can
131 -- be discarded as soon as we have finished processing the project
133 package Files_Htable is new GNAT.Dynamic_HTables.Simple_HTable
134 (Header_Num => Header_Num,
135 Element => Source_Id,
136 No_Element => No_Source,
137 Key => File_Name_Type,
140 -- Mapping from base file names to Source_Id (containing full info about
143 type Tree_Processing_Data is record
144 Tree : Project_Tree_Ref;
145 File_To_Source : Files_Htable.Instance;
146 Flags : Prj.Processing_Flags;
148 -- Temporary data which is needed while parsing a project. It does not need
149 -- to be kept in memory once a project has been fully loaded, but is
150 -- necessary while performing consistency checks (duplicate sources,...)
151 -- This data must be initialized before processing any project, and the
152 -- same data is used for processing all projects in the tree.
155 (Data : out Tree_Processing_Data;
156 Tree : Project_Tree_Ref;
157 Flags : Prj.Processing_Flags);
160 procedure Free (Data : in out Tree_Processing_Data);
161 -- Free the memory occupied by Data
164 (Project : Project_Id;
165 Data : in out Tree_Processing_Data);
166 -- Process the naming scheme for a single project
169 (Data : in out Project_Processing_Data;
170 Project : Project_Id);
171 procedure Free (Data : in out Project_Processing_Data);
172 -- Initialize or free memory for a project-specific data
174 procedure Find_Excluded_Sources
175 (Project : in out Project_Processing_Data;
176 Data : in out Tree_Processing_Data);
177 -- Find the list of files that should not be considered as source files
178 -- for this project. Sets the list in the Project.Excluded_Sources_Htable.
180 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
181 -- Override the reference kind for a source file. This properly updates
182 -- the unit data if necessary.
184 procedure Load_Naming_Exceptions
185 (Project : in out Project_Processing_Data;
186 Data : in out Tree_Processing_Data);
187 -- All source files in Data.First_Source are considered as naming
188 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
193 Data : in out Tree_Processing_Data;
194 Project : Project_Id;
195 Lang_Id : Language_Ptr;
197 File_Name : File_Name_Type;
198 Display_File : File_Name_Type;
199 Naming_Exception : Boolean := False;
200 Path : Path_Information := No_Path_Information;
201 Alternate_Languages : Language_List := null;
202 Unit : Name_Id := No_Name;
204 Locally_Removed : Boolean := False;
205 Location : Source_Ptr := No_Location);
206 -- Add a new source to the different lists: list of all sources in the
207 -- project tree, list of source of a project and list of sources of a
210 -- If Path is specified, the file is also added to Source_Paths_HT.
212 -- Location is used for error messages
214 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
215 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
216 -- This alters Name_Buffer
218 function Suffix_Matches
220 Suffix : File_Name_Type) return Boolean;
221 -- True if the file name ends with the given suffix. Always returns False
222 -- if Suffix is No_Name.
224 procedure Replace_Into_Name_Buffer
227 Replacement : Character);
228 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
229 -- converted to lower-case at the same time.
231 procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
232 -- Check that a name is a valid Ada unit name
234 procedure Check_Package_Naming
235 (Project : Project_Id;
236 Data : in out Tree_Processing_Data;
237 Bodies : out Array_Element_Id;
238 Specs : out Array_Element_Id);
239 -- Check the naming scheme part of Data, and initialize the naming scheme
240 -- data in the config of the various languages. This also returns the
241 -- naming scheme exceptions for unit-based languages (Bodies and Specs are
242 -- associative arrays mapping individual unit names to source file names).
244 procedure Check_Configuration
245 (Project : Project_Id;
246 Data : in out Tree_Processing_Data);
247 -- Check the configuration attributes for the project
249 procedure Check_If_Externally_Built
250 (Project : Project_Id;
251 Data : in out Tree_Processing_Data);
252 -- Check attribute Externally_Built of project Project in project tree
253 -- Data.Tree and modify its data Data if it has the value "true".
255 procedure Check_Interfaces
256 (Project : Project_Id;
257 Data : in out Tree_Processing_Data);
258 -- If a list of sources is specified in attribute Interfaces, set
259 -- In_Interfaces only for the sources specified in the list.
261 procedure Check_Library_Attributes
262 (Project : Project_Id;
263 Data : in out Tree_Processing_Data);
264 -- Check the library attributes of project Project in project tree
265 -- and modify its data Data accordingly.
267 procedure Check_Programming_Languages
268 (Project : Project_Id;
269 Data : in out Tree_Processing_Data);
270 -- Check attribute Languages for the project with data Data in project
271 -- tree Data.Tree and set the components of Data for all the programming
272 -- languages indicated in attribute Languages, if any.
274 procedure Check_Stand_Alone_Library
275 (Project : Project_Id;
276 Data : in out Tree_Processing_Data);
277 -- Check if project Project in project tree Data.Tree is a Stand-Alone
278 -- Library project, and modify its data Data accordingly if it is one.
280 function Compute_Directory_Last (Dir : String) return Natural;
281 -- Return the index of the last significant character in Dir. This is used
282 -- to avoid duplicate '/' (slash) characters at the end of directory names.
284 procedure Search_Directories
285 (Project : in out Project_Processing_Data;
286 Data : in out Tree_Processing_Data;
287 For_All_Sources : Boolean);
288 -- Search the source directories to find the sources. If For_All_Sources is
289 -- True, check each regular file name against the naming schemes of the
290 -- various languages. Otherwise consider only the file names in hash table
291 -- Source_Names. If Allow_Duplicate_Basenames then files with identical
292 -- base names are permitted within a project for source-based languages
293 -- (never for unit based languages).
296 (Project : in out Project_Processing_Data;
297 Data : in out Tree_Processing_Data;
298 Path : Path_Name_Type;
299 File_Name : File_Name_Type;
300 Display_File_Name : File_Name_Type;
301 Locally_Removed : Boolean;
302 For_All_Sources : Boolean);
303 -- Check if file File_Name is a valid source of the project. This is used
304 -- in multi-language mode only. When the file matches one of the naming
305 -- schemes, it is added to various htables through Add_Source and to
306 -- Source_Paths_Htable.
308 -- Name is the name of the candidate file. It hasn't been normalized yet
309 -- and is the direct result of readdir().
311 -- File_Name is the same as Name, but has been normalized.
312 -- Display_File_Name, however, has not been normalized.
314 -- Source_Directory is the directory in which the file was found. It is
315 -- neither normalized nor has had links resolved, and must not end with a
316 -- a directory separator, to avoid duplicates later on.
318 -- If For_All_Sources is True, then all possible file names are analyzed
319 -- otherwise only those currently set in the Source_Names hash table.
321 procedure Check_File_Naming_Schemes
322 (In_Tree : Project_Tree_Ref;
323 Project : Project_Processing_Data;
324 File_Name : File_Name_Type;
325 Alternate_Languages : out Language_List;
326 Language : out Language_Ptr;
327 Display_Language_Name : out Name_Id;
329 Lang_Kind : out Language_Kind;
330 Kind : out Source_Kind);
331 -- Check if the file name File_Name conforms to one of the naming schemes
332 -- of the project. If the file does not match one of the naming schemes,
333 -- set Language to No_Language_Index. Filename is the name of the file
334 -- being investigated. It has been normalized (case-folded). File_Name is
337 procedure Get_Directories
338 (Project : Project_Id;
339 Data : in out Tree_Processing_Data);
340 -- Get the object directory, the exec directory and the source directories
344 (Project : Project_Id;
345 Data : in out Tree_Processing_Data);
346 -- Get the mains of a project from attribute Main, if it exists, and put
347 -- them in the project data.
349 procedure Get_Sources_From_File
351 Location : Source_Ptr;
352 Project : in out Project_Processing_Data;
353 Data : in out Tree_Processing_Data);
354 -- Get the list of sources from a text file and put them in hash table
357 procedure Find_Sources
358 (Project : in out Project_Processing_Data;
359 Data : in out Tree_Processing_Data);
360 -- Process the Source_Files and Source_List_File attributes, and store the
361 -- list of source files into the Source_Names htable. When these attributes
362 -- are not defined, find all files matching the naming schemes in the
363 -- source directories. If Allow_Duplicate_Basenames, then files with the
364 -- same base names are authorized within a project for source-based
365 -- languages (never for unit based languages)
367 procedure Compute_Unit_Name
368 (File_Name : File_Name_Type;
369 Naming : Lang_Naming_Data;
370 Kind : out Source_Kind;
372 Project : Project_Processing_Data;
373 In_Tree : Project_Tree_Ref);
374 -- Check whether the file matches the naming scheme. If it does,
375 -- compute its unit name. If Unit is set to No_Name on exit, none of the
376 -- other out parameters are relevant.
378 procedure Check_Illegal_Suffix
379 (Project : Project_Id;
380 Suffix : File_Name_Type;
381 Dot_Replacement : File_Name_Type;
382 Attribute_Name : String;
383 Location : Source_Ptr;
384 Data : in out Tree_Processing_Data);
385 -- Display an error message if the given suffix is illegal for some reason.
386 -- The name of the attribute we are testing is specified in Attribute_Name,
387 -- which is used in the error message. Location is the location where the
388 -- suffix is defined.
390 procedure Locate_Directory
391 (Project : Project_Id;
392 Name : File_Name_Type;
393 Path : out Path_Information;
394 Dir_Exists : out Boolean;
395 Data : in out Tree_Processing_Data;
396 Create : String := "";
397 Location : Source_Ptr := No_Location;
398 Must_Exist : Boolean := True;
399 Externally_Built : Boolean := False);
400 -- Locate a directory. Name is the directory name. Relative paths are
401 -- resolved relative to the project's directory. If the directory does not
402 -- exist and Setup_Projects is True and Create is a non null string, an
403 -- attempt is made to create the directory. If the directory does not
404 -- exist, it is either created if Setup_Projects is False (and then
405 -- returned), or simply returned without checking for its existence (if
406 -- Must_Exist is False) or No_Path_Information is returned. In all cases,
407 -- Dir_Exists indicates whether the directory now exists. Create is also
408 -- used for debugging traces to show which path we are computing.
410 procedure Look_For_Sources
411 (Project : in out Project_Processing_Data;
412 Data : in out Tree_Processing_Data);
413 -- Find all the sources of project Project in project tree Data.Tree and
414 -- update its Data accordingly. This assumes that Data.First_Source has
415 -- been initialized with the list of excluded sources and special naming
418 function Path_Name_Of
419 (File_Name : File_Name_Type;
420 Directory : Path_Name_Type) return String;
421 -- Returns the path name of a (non project) file. Returns an empty string
422 -- if file cannot be found.
424 procedure Remove_Source
426 Replaced_By : Source_Id);
427 -- Remove a file from the list of sources of a project. This might be
428 -- because the file is replaced by another one in an extending project,
429 -- or because a file was added as a naming exception but was not found
432 procedure Report_No_Sources
433 (Project : Project_Id;
435 Data : Tree_Processing_Data;
436 Location : Source_Ptr;
437 Continuation : Boolean := False);
438 -- Report an error or a warning depending on the value of When_No_Sources
439 -- when there are no sources for language Lang_Name.
441 procedure Show_Source_Dirs
442 (Project : Project_Id; In_Tree : Project_Tree_Ref);
443 -- List all the source directories of a project
445 procedure Write_Attr (Name, Value : String);
446 -- Debug print a value for a specific property. Does nothing when not in
449 ------------------------------
450 -- Replace_Into_Name_Buffer --
451 ------------------------------
453 procedure Replace_Into_Name_Buffer
456 Replacement : Character)
458 Max : constant Integer := Str'Last - Pattern'Length + 1;
465 while J <= Str'Last loop
466 Name_Len := Name_Len + 1;
469 and then Str (J .. J + Pattern'Length - 1) = Pattern
471 Name_Buffer (Name_Len) := Replacement;
472 J := J + Pattern'Length;
475 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
479 end Replace_Into_Name_Buffer;
485 function Suffix_Matches
487 Suffix : File_Name_Type) return Boolean
489 Min_Prefix_Length : Natural := 0;
492 if Suffix = No_File or else Suffix = Empty_File then
497 Suf : String := Get_Name_String (Suffix);
500 -- On non case-sensitive systems, use proper suffix casing
502 Canonical_Case_File_Name (Suf);
504 -- The file name must end with the suffix (which is not an extension)
505 -- For instance a suffix "configure.in" must match a file with the
506 -- same name. To avoid dummy cases, though, a suffix starting with
507 -- '.' requires a file that is at least one character longer ('.cpp'
508 -- should not match a file with the same name)
510 if Suf (Suf'First) = '.' then
511 Min_Prefix_Length := 1;
514 return Filename'Length >= Suf'Length + Min_Prefix_Length
516 (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
524 procedure Write_Attr (Name, Value : String) is
526 if Current_Verbosity = High then
527 Write_Str (" " & Name & " = """);
540 Data : in out Tree_Processing_Data;
541 Project : Project_Id;
542 Lang_Id : Language_Ptr;
544 File_Name : File_Name_Type;
545 Display_File : File_Name_Type;
546 Naming_Exception : Boolean := False;
547 Path : Path_Information := No_Path_Information;
548 Alternate_Languages : Language_List := null;
549 Unit : Name_Id := No_Name;
551 Locally_Removed : Boolean := False;
552 Location : Source_Ptr := No_Location)
554 Config : constant Language_Config := Lang_Id.Config;
558 Prev_Unit : Unit_Index := No_Unit_Index;
560 Source_To_Replace : Source_Id := No_Source;
563 -- Check if the same file name or unit is used in the prj tree
567 if Unit /= No_Name then
568 Prev_Unit := Units_Htable.Get (Data.Tree.Units_HT, Unit);
571 if Prev_Unit /= No_Unit_Index
572 and then (Kind = Impl or else Kind = Spec)
573 and then Prev_Unit.File_Names (Kind) /= null
575 -- Suspicious, we need to check later whether this is authorized
578 Source := Prev_Unit.File_Names (Kind);
581 Source := Files_Htable.Get (Data.File_To_Source, File_Name);
583 if Source /= No_Source
584 and then Source.Index = Index
590 -- Duplication of file/unit in same project is allowed if order of
591 -- source directories is known.
593 if Add_Src = False then
596 if Project = Source.Project then
597 if Prev_Unit = No_Unit_Index then
598 if Data.Flags.Allow_Duplicate_Basenames then
601 elsif Project.Known_Order_Of_Source_Dirs then
605 Error_Msg_File_1 := File_Name;
607 (Data.Flags, "duplicate source file name {",
613 if Project.Known_Order_Of_Source_Dirs then
616 -- We might be seeing the same file through a different path
617 -- (for instance because of symbolic links).
619 elsif Source.Path.Name /= Path.Name then
620 Error_Msg_Name_1 := Unit;
622 (Data.Flags, "duplicate unit %%", Location, Project);
627 -- Do not allow the same unit name in different projects, except
628 -- if one is extending the other.
630 -- For a file based language, the same file name replaces a file
631 -- in a project being extended, but it is allowed to have the same
632 -- file name in unrelated projects.
634 elsif Is_Extending (Project, Source.Project) then
635 if not Locally_Removed then
636 Source_To_Replace := Source;
639 elsif Prev_Unit /= No_Unit_Index
640 and then not Source.Locally_Removed
642 -- Path is set if this is a source we found on the disk, in which
643 -- case we can provide more explicit error message. Path is unset
644 -- when the source is added from one of the naming exceptions in
647 if Path /= No_Path_Information then
648 Error_Msg_Name_1 := Unit;
651 "unit %% cannot belong to several projects",
654 Error_Msg_Name_1 := Project.Name;
655 Error_Msg_Name_2 := Name_Id (Path.Name);
657 (Data.Flags, "\ project %%, %%", Location, Project);
659 Error_Msg_Name_1 := Source.Project.Name;
660 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
662 (Data.Flags, "\ project %%, %%", Location, Project);
665 Error_Msg_Name_1 := Unit;
666 Error_Msg_Name_2 := Source.Project.Name;
668 (Data.Flags, "unit %% already belongs to project %%",
674 elsif not Source.Locally_Removed
675 and then not Data.Flags.Allow_Duplicate_Basenames
676 and then Lang_Id.Config.Kind = Unit_Based
678 Error_Msg_File_1 := File_Name;
679 Error_Msg_File_2 := File_Name_Type (Source.Project.Name);
682 "{ is already a source of project {", Location, Project);
684 -- Add the file anyway, to avoid further warnings like "language
697 Id := new Source_Data;
699 if Current_Verbosity = High then
700 Write_Str ("Adding source File: ");
701 Write_Str (Get_Name_String (File_Name));
704 Write_Str (" at" & Index'Img);
707 if Lang_Id.Config.Kind = Unit_Based then
708 Write_Str (" Unit: ");
710 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
711 -- (see test extended_projects).
713 if Unit /= No_Name then
714 Write_Str (Get_Name_String (Unit));
717 Write_Str (" Kind: ");
718 Write_Str (Source_Kind'Image (Kind));
724 Id.Project := Project;
725 Id.Language := Lang_Id;
727 Id.Alternate_Languages := Alternate_Languages;
728 Id.Locally_Removed := Locally_Removed;
730 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
733 if Unit /= No_Name then
734 UData := Units_Htable.Get (Data.Tree.Units_HT, Unit);
736 if UData = No_Unit_Index then
737 UData := new Unit_Data;
739 Units_Htable.Set (Data.Tree.Units_HT, Unit, UData);
744 -- Note that this updates Unit information as well
746 Override_Kind (Id, Kind);
750 Id.File := File_Name;
751 Id.Display_File := Display_File;
752 Id.Dep_Name := Dependency_Name
753 (File_Name, Lang_Id.Config.Dependency_Kind);
754 Id.Naming_Exception := Naming_Exception;
756 if Is_Compilable (Id) and then Config.Object_Generated then
757 Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
758 Id.Switches := Switches_Name (File_Name);
761 if Path /= No_Path_Information then
763 Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id);
766 -- Add the source to the language list
768 Id.Next_In_Lang := Lang_Id.First_Source;
769 Lang_Id.First_Source := Id;
771 if Source_To_Replace /= No_Source then
772 Remove_Source (Source_To_Replace, Id);
775 Files_Htable.Set (Data.File_To_Source, File_Name, Id);
778 ------------------------------
779 -- Canonical_Case_File_Name --
780 ------------------------------
782 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
784 if Osint.File_Names_Case_Sensitive then
785 return File_Name_Type (Name);
787 Get_Name_String (Name);
788 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
791 end Canonical_Case_File_Name;
798 (Project : Project_Id;
799 Data : in out Tree_Processing_Data)
801 Specs : Array_Element_Id;
802 Bodies : Array_Element_Id;
803 Extending : Boolean := False;
804 Prj_Data : Project_Processing_Data;
807 Initialize (Prj_Data, Project);
809 Check_If_Externally_Built (Project, Data);
811 -- Object, exec and source directories
813 Get_Directories (Project, Data);
815 -- Get the programming languages
817 Check_Programming_Languages (Project, Data);
819 if Project.Qualifier = Dry
820 and then Project.Source_Dirs /= Nil_String
823 Source_Dirs : constant Variable_Value :=
826 Project.Decl.Attributes, Data.Tree);
827 Source_Files : constant Variable_Value :=
830 Project.Decl.Attributes, Data.Tree);
831 Source_List_File : constant Variable_Value :=
833 (Name_Source_List_File,
834 Project.Decl.Attributes, Data.Tree);
835 Languages : constant Variable_Value :=
838 Project.Decl.Attributes, Data.Tree);
841 if Source_Dirs.Values = Nil_String
842 and then Source_Files.Values = Nil_String
843 and then Languages.Values = Nil_String
844 and then Source_List_File.Default
846 Project.Source_Dirs := Nil_String;
851 "at least one of Source_Files, Source_Dirs or Languages "
852 & "must be declared empty for an abstract project",
853 Project.Location, Project);
858 -- Check configuration. This must be done even for gnatmake (even though
859 -- no user configuration file was provided) since the default config we
860 -- generate indicates whether libraries are supported for instance.
862 Check_Configuration (Project, Data);
864 -- Library attributes
866 Check_Library_Attributes (Project, Data);
868 if Current_Verbosity = High then
869 Show_Source_Dirs (Project, Data.Tree);
872 Extending := Project.Extends /= No_Project;
874 Check_Package_Naming (Project, Data, Bodies => Bodies, Specs => Specs);
878 if Project.Source_Dirs /= Nil_String then
879 Look_For_Sources (Prj_Data, Data);
881 if not Project.Externally_Built
882 and then not Extending
885 Language : Language_Ptr;
887 Alt_Lang : Language_List;
888 Continuation : Boolean := False;
889 Iter : Source_Iterator;
892 Language := Project.Languages;
893 while Language /= No_Language_Index loop
895 -- If there are no sources for this language, check if there
896 -- are sources for which this is an alternate language.
898 if Language.First_Source = No_Source
899 and then (Data.Flags.Require_Sources_Other_Lang
900 or else Language.Name = Name_Ada)
902 Iter := For_Each_Source (In_Tree => Data.Tree,
905 Source := Element (Iter);
906 exit Source_Loop when Source = No_Source
907 or else Source.Language = Language;
909 Alt_Lang := Source.Alternate_Languages;
910 while Alt_Lang /= null loop
911 exit Source_Loop when Alt_Lang.Language = Language;
912 Alt_Lang := Alt_Lang.Next;
916 end loop Source_Loop;
918 if Source = No_Source then
922 Get_Name_String (Language.Display_Name),
924 Prj_Data.Source_List_File_Location,
926 Continuation := True;
930 Language := Language.Next;
936 -- If a list of sources is specified in attribute Interfaces, set
937 -- In_Interfaces only for the sources specified in the list.
939 Check_Interfaces (Project, Data);
941 -- If it is a library project file, check if it is a standalone library
943 if Project.Library then
944 Check_Stand_Alone_Library (Project, Data);
947 -- Put the list of Mains, if any, in the project data
949 Get_Mains (Project, Data);
958 procedure Check_Ada_Name (Name : String; Unit : out Name_Id) is
959 The_Name : String := Name;
961 Need_Letter : Boolean := True;
962 Last_Underscore : Boolean := False;
963 OK : Boolean := The_Name'Length > 0;
966 function Is_Reserved (Name : Name_Id) return Boolean;
967 function Is_Reserved (S : String) return Boolean;
968 -- Check that the given name is not an Ada 95 reserved word. The reason
969 -- for the Ada 95 here is that we do not want to exclude the case of an
970 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
971 -- name would be rejected anyway by the compiler. That means there is no
972 -- requirement that the project file parser reject this.
978 function Is_Reserved (S : String) return Boolean is
981 Add_Str_To_Name_Buffer (S);
982 return Is_Reserved (Name_Find);
989 function Is_Reserved (Name : Name_Id) return Boolean is
991 if Get_Name_Table_Byte (Name) /= 0
992 and then Name /= Name_Project
993 and then Name /= Name_Extends
994 and then Name /= Name_External
995 and then Name not in Ada_2005_Reserved_Words
999 if Current_Verbosity = High then
1000 Write_Str (The_Name);
1001 Write_Line (" is an Ada reserved word.");
1011 -- Start of processing for Check_Ada_Name
1014 To_Lower (The_Name);
1016 Name_Len := The_Name'Length;
1017 Name_Buffer (1 .. Name_Len) := The_Name;
1019 -- Special cases of children of packages A, G, I and S on VMS
1021 if OpenVMS_On_Target
1022 and then Name_Len > 3
1023 and then Name_Buffer (2 .. 3) = "__"
1025 ((Name_Buffer (1) = 'a') or else
1026 (Name_Buffer (1) = 'g') or else
1027 (Name_Buffer (1) = 'i') or else
1028 (Name_Buffer (1) = 's'))
1030 Name_Buffer (2) := '.';
1031 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1032 Name_Len := Name_Len - 1;
1035 Real_Name := Name_Find;
1037 if Is_Reserved (Real_Name) then
1041 First := The_Name'First;
1043 for Index in The_Name'Range loop
1046 -- We need a letter (at the beginning, and following a dot),
1047 -- but we don't have one.
1049 if Is_Letter (The_Name (Index)) then
1050 Need_Letter := False;
1055 if Current_Verbosity = High then
1056 Write_Int (Types.Int (Index));
1058 Write_Char (The_Name (Index));
1059 Write_Line ("' is not a letter.");
1065 elsif Last_Underscore
1066 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1068 -- Two underscores are illegal, and a dot cannot follow
1073 if Current_Verbosity = High then
1074 Write_Int (Types.Int (Index));
1076 Write_Char (The_Name (Index));
1077 Write_Line ("' is illegal here.");
1082 elsif The_Name (Index) = '.' then
1084 -- First, check if the name before the dot is not a reserved word
1086 if Is_Reserved (The_Name (First .. Index - 1)) then
1092 -- We need a letter after a dot
1094 Need_Letter := True;
1096 elsif The_Name (Index) = '_' then
1097 Last_Underscore := True;
1100 -- We need an letter or a digit
1102 Last_Underscore := False;
1104 if not Is_Alphanumeric (The_Name (Index)) then
1107 if Current_Verbosity = High then
1108 Write_Int (Types.Int (Index));
1110 Write_Char (The_Name (Index));
1111 Write_Line ("' is not alphanumeric.");
1119 -- Cannot end with an underscore or a dot
1121 OK := OK and then not Need_Letter and then not Last_Underscore;
1124 if First /= Name'First and then
1125 Is_Reserved (The_Name (First .. The_Name'Last))
1133 -- Signal a problem with No_Name
1139 -------------------------
1140 -- Check_Configuration --
1141 -------------------------
1143 procedure Check_Configuration
1144 (Project : Project_Id;
1145 Data : in out Tree_Processing_Data)
1147 Dot_Replacement : File_Name_Type := No_File;
1148 Casing : Casing_Type := All_Lower_Case;
1149 Separate_Suffix : File_Name_Type := No_File;
1151 Lang_Index : Language_Ptr := No_Language_Index;
1152 -- The index of the language data being checked
1154 Prev_Index : Language_Ptr := No_Language_Index;
1155 -- The index of the previous language
1157 procedure Process_Project_Level_Simple_Attributes;
1158 -- Process the simple attributes at the project level
1160 procedure Process_Project_Level_Array_Attributes;
1161 -- Process the associate array attributes at the project level
1163 procedure Process_Packages;
1164 -- Read the packages of the project
1166 ----------------------
1167 -- Process_Packages --
1168 ----------------------
1170 procedure Process_Packages is
1171 Packages : Package_Id;
1172 Element : Package_Element;
1174 procedure Process_Binder (Arrays : Array_Id);
1175 -- Process the associate array attributes of package Binder
1177 procedure Process_Builder (Attributes : Variable_Id);
1178 -- Process the simple attributes of package Builder
1180 procedure Process_Compiler (Arrays : Array_Id);
1181 -- Process the associate array attributes of package Compiler
1183 procedure Process_Naming (Attributes : Variable_Id);
1184 -- Process the simple attributes of package Naming
1186 procedure Process_Naming (Arrays : Array_Id);
1187 -- Process the associate array attributes of package Naming
1189 procedure Process_Linker (Attributes : Variable_Id);
1190 -- Process the simple attributes of package Linker of a
1191 -- configuration project.
1193 --------------------
1194 -- Process_Binder --
1195 --------------------
1197 procedure Process_Binder (Arrays : Array_Id) is
1198 Current_Array_Id : Array_Id;
1199 Current_Array : Array_Data;
1200 Element_Id : Array_Element_Id;
1201 Element : Array_Element;
1204 -- Process the associative array attribute of package Binder
1206 Current_Array_Id := Arrays;
1207 while Current_Array_Id /= No_Array loop
1208 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1210 Element_Id := Current_Array.Value;
1211 while Element_Id /= No_Array_Element loop
1212 Element := Data.Tree.Array_Elements.Table (Element_Id);
1214 if Element.Index /= All_Other_Names then
1216 -- Get the name of the language
1219 Get_Language_From_Name
1220 (Project, Get_Name_String (Element.Index));
1222 if Lang_Index /= No_Language_Index then
1223 case Current_Array.Name is
1226 -- Attribute Driver (<language>)
1228 Lang_Index.Config.Binder_Driver :=
1229 File_Name_Type (Element.Value.Value);
1231 when Name_Required_Switches =>
1234 Lang_Index.Config.Binder_Required_Switches,
1235 From_List => Element.Value.Values,
1236 In_Tree => Data.Tree);
1240 -- Attribute Prefix (<language>)
1242 Lang_Index.Config.Binder_Prefix :=
1243 Element.Value.Value;
1245 when Name_Objects_Path =>
1247 -- Attribute Objects_Path (<language>)
1249 Lang_Index.Config.Objects_Path :=
1250 Element.Value.Value;
1252 when Name_Objects_Path_File =>
1254 -- Attribute Objects_Path (<language>)
1256 Lang_Index.Config.Objects_Path_File :=
1257 Element.Value.Value;
1265 Element_Id := Element.Next;
1268 Current_Array_Id := Current_Array.Next;
1272 ---------------------
1273 -- Process_Builder --
1274 ---------------------
1276 procedure Process_Builder (Attributes : Variable_Id) is
1277 Attribute_Id : Variable_Id;
1278 Attribute : Variable;
1281 -- Process non associated array attribute from package Builder
1283 Attribute_Id := Attributes;
1284 while Attribute_Id /= No_Variable loop
1286 Data.Tree.Variable_Elements.Table (Attribute_Id);
1288 if not Attribute.Value.Default then
1289 if Attribute.Name = Name_Executable_Suffix then
1291 -- Attribute Executable_Suffix: the suffix of the
1294 Project.Config.Executable_Suffix :=
1295 Attribute.Value.Value;
1299 Attribute_Id := Attribute.Next;
1301 end Process_Builder;
1303 ----------------------
1304 -- Process_Compiler --
1305 ----------------------
1307 procedure Process_Compiler (Arrays : Array_Id) is
1308 Current_Array_Id : Array_Id;
1309 Current_Array : Array_Data;
1310 Element_Id : Array_Element_Id;
1311 Element : Array_Element;
1312 List : String_List_Id;
1315 -- Process the associative array attribute of package Compiler
1317 Current_Array_Id := Arrays;
1318 while Current_Array_Id /= No_Array loop
1319 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1321 Element_Id := Current_Array.Value;
1322 while Element_Id /= No_Array_Element loop
1323 Element := Data.Tree.Array_Elements.Table (Element_Id);
1325 if Element.Index /= All_Other_Names then
1327 -- Get the name of the language
1329 Lang_Index := Get_Language_From_Name
1330 (Project, Get_Name_String (Element.Index));
1332 if Lang_Index /= No_Language_Index then
1333 case Current_Array.Name is
1334 when Name_Dependency_Switches =>
1336 -- Attribute Dependency_Switches (<language>)
1338 if Lang_Index.Config.Dependency_Kind = None then
1339 Lang_Index.Config.Dependency_Kind := Makefile;
1342 List := Element.Value.Values;
1344 if List /= Nil_String then
1346 Lang_Index.Config.Dependency_Option,
1348 In_Tree => Data.Tree);
1351 when Name_Dependency_Driver =>
1353 -- Attribute Dependency_Driver (<language>)
1355 if Lang_Index.Config.Dependency_Kind = None then
1356 Lang_Index.Config.Dependency_Kind := Makefile;
1359 List := Element.Value.Values;
1361 if List /= Nil_String then
1363 Lang_Index.Config.Compute_Dependency,
1365 In_Tree => Data.Tree);
1368 when Name_Include_Switches =>
1370 -- Attribute Include_Switches (<language>)
1372 List := Element.Value.Values;
1374 if List = Nil_String then
1376 (Data.Flags, "include option cannot be null",
1377 Element.Value.Location, Project);
1380 Put (Into_List => Lang_Index.Config.Include_Option,
1382 In_Tree => Data.Tree);
1384 when Name_Include_Path =>
1386 -- Attribute Include_Path (<language>)
1388 Lang_Index.Config.Include_Path :=
1389 Element.Value.Value;
1391 when Name_Include_Path_File =>
1393 -- Attribute Include_Path_File (<language>)
1395 Lang_Index.Config.Include_Path_File :=
1396 Element.Value.Value;
1400 -- Attribute Driver (<language>)
1402 Lang_Index.Config.Compiler_Driver :=
1403 File_Name_Type (Element.Value.Value);
1405 when Name_Required_Switches |
1406 Name_Leading_Required_Switches =>
1409 Compiler_Leading_Required_Switches,
1410 From_List => Element.Value.Values,
1411 In_Tree => Data.Tree);
1413 when Name_Trailing_Required_Switches =>
1416 Compiler_Trailing_Required_Switches,
1417 From_List => Element.Value.Values,
1418 In_Tree => Data.Tree);
1420 when Name_Path_Syntax =>
1422 Lang_Index.Config.Path_Syntax :=
1423 Path_Syntax_Kind'Value
1424 (Get_Name_String (Element.Value.Value));
1427 when Constraint_Error =>
1430 "invalid value for Path_Syntax",
1431 Element.Value.Location, Project);
1434 when Name_Object_File_Suffix =>
1435 if Get_Name_String (Element.Value.Value) = "" then
1438 "object file suffix cannot be empty",
1439 Element.Value.Location, Project);
1442 Lang_Index.Config.Object_File_Suffix :=
1443 Element.Value.Value;
1446 when Name_Object_File_Switches =>
1448 Lang_Index.Config.Object_File_Switches,
1449 From_List => Element.Value.Values,
1450 In_Tree => Data.Tree);
1452 when Name_Pic_Option =>
1454 -- Attribute Compiler_Pic_Option (<language>)
1456 List := Element.Value.Values;
1458 if List = Nil_String then
1461 "compiler PIC option cannot be null",
1462 Element.Value.Location, Project);
1466 Lang_Index.Config.Compilation_PIC_Option,
1468 In_Tree => Data.Tree);
1470 when Name_Mapping_File_Switches =>
1472 -- Attribute Mapping_File_Switches (<language>)
1474 List := Element.Value.Values;
1476 if List = Nil_String then
1479 "mapping file switches cannot be null",
1480 Element.Value.Location, Project);
1484 Lang_Index.Config.Mapping_File_Switches,
1486 In_Tree => Data.Tree);
1488 when Name_Mapping_Spec_Suffix =>
1490 -- Attribute Mapping_Spec_Suffix (<language>)
1492 Lang_Index.Config.Mapping_Spec_Suffix :=
1493 File_Name_Type (Element.Value.Value);
1495 when Name_Mapping_Body_Suffix =>
1497 -- Attribute Mapping_Body_Suffix (<language>)
1499 Lang_Index.Config.Mapping_Body_Suffix :=
1500 File_Name_Type (Element.Value.Value);
1502 when Name_Config_File_Switches =>
1504 -- Attribute Config_File_Switches (<language>)
1506 List := Element.Value.Values;
1508 if List = Nil_String then
1511 "config file switches cannot be null",
1512 Element.Value.Location, Project);
1516 Lang_Index.Config.Config_File_Switches,
1518 In_Tree => Data.Tree);
1520 when Name_Objects_Path =>
1522 -- Attribute Objects_Path (<language>)
1524 Lang_Index.Config.Objects_Path :=
1525 Element.Value.Value;
1527 when Name_Objects_Path_File =>
1529 -- Attribute Objects_Path_File (<language>)
1531 Lang_Index.Config.Objects_Path_File :=
1532 Element.Value.Value;
1534 when Name_Config_Body_File_Name =>
1536 -- Attribute Config_Body_File_Name (<language>)
1538 Lang_Index.Config.Config_Body :=
1539 Element.Value.Value;
1541 when Name_Config_Body_File_Name_Pattern =>
1543 -- Attribute Config_Body_File_Name_Pattern
1546 Lang_Index.Config.Config_Body_Pattern :=
1547 Element.Value.Value;
1549 when Name_Config_Spec_File_Name =>
1551 -- Attribute Config_Spec_File_Name (<language>)
1553 Lang_Index.Config.Config_Spec :=
1554 Element.Value.Value;
1556 when Name_Config_Spec_File_Name_Pattern =>
1558 -- Attribute Config_Spec_File_Name_Pattern
1561 Lang_Index.Config.Config_Spec_Pattern :=
1562 Element.Value.Value;
1564 when Name_Config_File_Unique =>
1566 -- Attribute Config_File_Unique (<language>)
1569 Lang_Index.Config.Config_File_Unique :=
1571 (Get_Name_String (Element.Value.Value));
1573 when Constraint_Error =>
1576 "illegal value for Config_File_Unique",
1577 Element.Value.Location, Project);
1586 Element_Id := Element.Next;
1589 Current_Array_Id := Current_Array.Next;
1591 end Process_Compiler;
1593 --------------------
1594 -- Process_Naming --
1595 --------------------
1597 procedure Process_Naming (Attributes : Variable_Id) is
1598 Attribute_Id : Variable_Id;
1599 Attribute : Variable;
1602 -- Process non associated array attribute from package Naming
1604 Attribute_Id := Attributes;
1605 while Attribute_Id /= No_Variable loop
1606 Attribute := Data.Tree.Variable_Elements.Table (Attribute_Id);
1608 if not Attribute.Value.Default then
1609 if Attribute.Name = Name_Separate_Suffix then
1611 -- Attribute Separate_Suffix
1613 Get_Name_String (Attribute.Value.Value);
1614 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1615 Separate_Suffix := Name_Find;
1617 elsif Attribute.Name = Name_Casing then
1623 Value (Get_Name_String (Attribute.Value.Value));
1626 when Constraint_Error =>
1629 "invalid value for Casing",
1630 Attribute.Value.Location, Project);
1633 elsif Attribute.Name = Name_Dot_Replacement then
1635 -- Attribute Dot_Replacement
1637 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1642 Attribute_Id := Attribute.Next;
1646 procedure Process_Naming (Arrays : Array_Id) is
1647 Current_Array_Id : Array_Id;
1648 Current_Array : Array_Data;
1649 Element_Id : Array_Element_Id;
1650 Element : Array_Element;
1653 -- Process the associative array attribute of package Naming
1655 Current_Array_Id := Arrays;
1656 while Current_Array_Id /= No_Array loop
1657 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
1659 Element_Id := Current_Array.Value;
1660 while Element_Id /= No_Array_Element loop
1661 Element := Data.Tree.Array_Elements.Table (Element_Id);
1663 -- Get the name of the language
1665 Lang_Index := Get_Language_From_Name
1666 (Project, Get_Name_String (Element.Index));
1668 if Lang_Index /= No_Language_Index then
1669 case Current_Array.Name is
1670 when Name_Spec_Suffix | Name_Specification_Suffix =>
1672 -- Attribute Spec_Suffix (<language>)
1674 Get_Name_String (Element.Value.Value);
1675 Canonical_Case_File_Name
1676 (Name_Buffer (1 .. Name_Len));
1677 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1680 when Name_Implementation_Suffix | Name_Body_Suffix =>
1682 Get_Name_String (Element.Value.Value);
1683 Canonical_Case_File_Name
1684 (Name_Buffer (1 .. Name_Len));
1686 -- Attribute Body_Suffix (<language>)
1688 Lang_Index.Config.Naming_Data.Body_Suffix :=
1690 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1691 Lang_Index.Config.Naming_Data.Body_Suffix;
1698 Element_Id := Element.Next;
1701 Current_Array_Id := Current_Array.Next;
1705 --------------------
1706 -- Process_Linker --
1707 --------------------
1709 procedure Process_Linker (Attributes : Variable_Id) is
1710 Attribute_Id : Variable_Id;
1711 Attribute : Variable;
1714 -- Process non associated array attribute from package Linker
1716 Attribute_Id := Attributes;
1717 while Attribute_Id /= No_Variable loop
1719 Data.Tree.Variable_Elements.Table (Attribute_Id);
1721 if not Attribute.Value.Default then
1722 if Attribute.Name = Name_Driver then
1724 -- Attribute Linker'Driver: the default linker to use
1726 Project.Config.Linker :=
1727 Path_Name_Type (Attribute.Value.Value);
1729 -- Linker'Driver is also used to link shared libraries
1730 -- if the obsolescent attribute Library_GCC has not been
1733 if Project.Config.Shared_Lib_Driver = No_File then
1734 Project.Config.Shared_Lib_Driver :=
1735 File_Name_Type (Attribute.Value.Value);
1738 elsif Attribute.Name = Name_Required_Switches then
1740 -- Attribute Required_Switches: the minimum
1741 -- options to use when invoking the linker
1743 Put (Into_List => Project.Config.Minimum_Linker_Options,
1744 From_List => Attribute.Value.Values,
1745 In_Tree => Data.Tree);
1747 elsif Attribute.Name = Name_Map_File_Option then
1748 Project.Config.Map_File_Option := Attribute.Value.Value;
1750 elsif Attribute.Name = Name_Max_Command_Line_Length then
1752 Project.Config.Max_Command_Line_Length :=
1753 Natural'Value (Get_Name_String
1754 (Attribute.Value.Value));
1757 when Constraint_Error =>
1760 "value must be positive or equal to 0",
1761 Attribute.Value.Location, Project);
1764 elsif Attribute.Name = Name_Response_File_Format then
1769 Get_Name_String (Attribute.Value.Value);
1770 To_Lower (Name_Buffer (1 .. Name_Len));
1773 if Name = Name_None then
1774 Project.Config.Resp_File_Format := None;
1776 elsif Name = Name_Gnu then
1777 Project.Config.Resp_File_Format := GNU;
1779 elsif Name = Name_Object_List then
1780 Project.Config.Resp_File_Format := Object_List;
1782 elsif Name = Name_Option_List then
1783 Project.Config.Resp_File_Format := Option_List;
1788 "illegal response file format",
1789 Attribute.Value.Location, Project);
1793 elsif Attribute.Name = Name_Response_File_Switches then
1794 Put (Into_List => Project.Config.Resp_File_Options,
1795 From_List => Attribute.Value.Values,
1796 In_Tree => Data.Tree);
1800 Attribute_Id := Attribute.Next;
1804 -- Start of processing for Process_Packages
1807 Packages := Project.Decl.Packages;
1808 while Packages /= No_Package loop
1809 Element := Data.Tree.Packages.Table (Packages);
1811 case Element.Name is
1814 -- Process attributes of package Binder
1816 Process_Binder (Element.Decl.Arrays);
1818 when Name_Builder =>
1820 -- Process attributes of package Builder
1822 Process_Builder (Element.Decl.Attributes);
1824 when Name_Compiler =>
1826 -- Process attributes of package Compiler
1828 Process_Compiler (Element.Decl.Arrays);
1832 -- Process attributes of package Linker
1834 Process_Linker (Element.Decl.Attributes);
1838 -- Process attributes of package Naming
1840 Process_Naming (Element.Decl.Attributes);
1841 Process_Naming (Element.Decl.Arrays);
1847 Packages := Element.Next;
1849 end Process_Packages;
1851 ---------------------------------------------
1852 -- Process_Project_Level_Simple_Attributes --
1853 ---------------------------------------------
1855 procedure Process_Project_Level_Simple_Attributes is
1856 Attribute_Id : Variable_Id;
1857 Attribute : Variable;
1858 List : String_List_Id;
1861 -- Process non associated array attribute at project level
1863 Attribute_Id := Project.Decl.Attributes;
1864 while Attribute_Id /= No_Variable loop
1866 Data.Tree.Variable_Elements.Table (Attribute_Id);
1868 if not Attribute.Value.Default then
1869 if Attribute.Name = Name_Target then
1871 -- Attribute Target: the target specified
1873 Project.Config.Target := Attribute.Value.Value;
1875 elsif Attribute.Name = Name_Library_Builder then
1877 -- Attribute Library_Builder: the application to invoke
1878 -- to build libraries.
1880 Project.Config.Library_Builder :=
1881 Path_Name_Type (Attribute.Value.Value);
1883 elsif Attribute.Name = Name_Archive_Builder then
1885 -- Attribute Archive_Builder: the archive builder
1886 -- (usually "ar") and its minimum options (usually "cr").
1888 List := Attribute.Value.Values;
1890 if List = Nil_String then
1893 "archive builder cannot be null",
1894 Attribute.Value.Location, Project);
1897 Put (Into_List => Project.Config.Archive_Builder,
1899 In_Tree => Data.Tree);
1901 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
1903 -- Attribute Archive_Builder: the archive builder
1904 -- (usually "ar") and its minimum options (usually "cr").
1906 List := Attribute.Value.Values;
1908 if List /= Nil_String then
1911 Project.Config.Archive_Builder_Append_Option,
1913 In_Tree => Data.Tree);
1916 elsif Attribute.Name = Name_Archive_Indexer then
1918 -- Attribute Archive_Indexer: the optional archive
1919 -- indexer (usually "ranlib") with its minimum options
1922 List := Attribute.Value.Values;
1924 if List = Nil_String then
1927 "archive indexer cannot be null",
1928 Attribute.Value.Location, Project);
1931 Put (Into_List => Project.Config.Archive_Indexer,
1933 In_Tree => Data.Tree);
1935 elsif Attribute.Name = Name_Library_Partial_Linker then
1937 -- Attribute Library_Partial_Linker: the optional linker
1938 -- driver with its minimum options, to partially link
1941 List := Attribute.Value.Values;
1943 if List = Nil_String then
1946 "partial linker cannot be null",
1947 Attribute.Value.Location, Project);
1950 Put (Into_List => Project.Config.Lib_Partial_Linker,
1952 In_Tree => Data.Tree);
1954 elsif Attribute.Name = Name_Library_GCC then
1955 Project.Config.Shared_Lib_Driver :=
1956 File_Name_Type (Attribute.Value.Value);
1959 "?Library_'G'C'C is an obsolescent attribute, " &
1960 "use Linker''Driver instead",
1961 Attribute.Value.Location, Project);
1963 elsif Attribute.Name = Name_Archive_Suffix then
1964 Project.Config.Archive_Suffix :=
1965 File_Name_Type (Attribute.Value.Value);
1967 elsif Attribute.Name = Name_Linker_Executable_Option then
1969 -- Attribute Linker_Executable_Option: optional options
1970 -- to specify an executable name. Defaults to "-o".
1972 List := Attribute.Value.Values;
1974 if List = Nil_String then
1977 "linker executable option cannot be null",
1978 Attribute.Value.Location, Project);
1981 Put (Into_List => Project.Config.Linker_Executable_Option,
1983 In_Tree => Data.Tree);
1985 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
1987 -- Attribute Linker_Lib_Dir_Option: optional options
1988 -- to specify a library search directory. Defaults to
1991 Get_Name_String (Attribute.Value.Value);
1993 if Name_Len = 0 then
1996 "linker library directory option cannot be empty",
1997 Attribute.Value.Location, Project);
2000 Project.Config.Linker_Lib_Dir_Option :=
2001 Attribute.Value.Value;
2003 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2005 -- Attribute Linker_Lib_Name_Option: optional options
2006 -- to specify the name of a library to be linked in.
2007 -- Defaults to "-l".
2009 Get_Name_String (Attribute.Value.Value);
2011 if Name_Len = 0 then
2014 "linker library name option cannot be empty",
2015 Attribute.Value.Location, Project);
2018 Project.Config.Linker_Lib_Name_Option :=
2019 Attribute.Value.Value;
2021 elsif Attribute.Name = Name_Run_Path_Option then
2023 -- Attribute Run_Path_Option: optional options to
2024 -- specify a path for libraries.
2026 List := Attribute.Value.Values;
2028 if List /= Nil_String then
2029 Put (Into_List => Project.Config.Run_Path_Option,
2031 In_Tree => Data.Tree);
2034 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2036 pragma Unsuppress (All_Checks);
2038 Project.Config.Separate_Run_Path_Options :=
2039 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2041 when Constraint_Error =>
2044 "invalid value """ &
2045 Get_Name_String (Attribute.Value.Value) &
2046 """ for Separate_Run_Path_Options",
2047 Attribute.Value.Location, Project);
2050 elsif Attribute.Name = Name_Library_Support then
2052 pragma Unsuppress (All_Checks);
2054 Project.Config.Lib_Support :=
2055 Library_Support'Value (Get_Name_String
2056 (Attribute.Value.Value));
2058 when Constraint_Error =>
2061 "invalid value """ &
2062 Get_Name_String (Attribute.Value.Value) &
2063 """ for Library_Support",
2064 Attribute.Value.Location, Project);
2067 elsif Attribute.Name = Name_Shared_Library_Prefix then
2068 Project.Config.Shared_Lib_Prefix :=
2069 File_Name_Type (Attribute.Value.Value);
2071 elsif Attribute.Name = Name_Shared_Library_Suffix then
2072 Project.Config.Shared_Lib_Suffix :=
2073 File_Name_Type (Attribute.Value.Value);
2075 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2077 pragma Unsuppress (All_Checks);
2079 Project.Config.Symbolic_Link_Supported :=
2080 Boolean'Value (Get_Name_String
2081 (Attribute.Value.Value));
2083 when Constraint_Error =>
2087 & Get_Name_String (Attribute.Value.Value)
2088 & """ for Symbolic_Link_Supported",
2089 Attribute.Value.Location, Project);
2093 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2096 pragma Unsuppress (All_Checks);
2098 Project.Config.Lib_Maj_Min_Id_Supported :=
2099 Boolean'Value (Get_Name_String
2100 (Attribute.Value.Value));
2102 when Constraint_Error =>
2105 "invalid value """ &
2106 Get_Name_String (Attribute.Value.Value) &
2107 """ for Library_Major_Minor_Id_Supported",
2108 Attribute.Value.Location, Project);
2111 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2113 pragma Unsuppress (All_Checks);
2115 Project.Config.Auto_Init_Supported :=
2116 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2118 when Constraint_Error =>
2122 & Get_Name_String (Attribute.Value.Value)
2123 & """ for Library_Auto_Init_Supported",
2124 Attribute.Value.Location, Project);
2127 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2128 List := Attribute.Value.Values;
2130 if List /= Nil_String then
2131 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2133 In_Tree => Data.Tree);
2136 elsif Attribute.Name = Name_Library_Version_Switches then
2137 List := Attribute.Value.Values;
2139 if List /= Nil_String then
2140 Put (Into_List => Project.Config.Lib_Version_Options,
2142 In_Tree => Data.Tree);
2147 Attribute_Id := Attribute.Next;
2149 end Process_Project_Level_Simple_Attributes;
2151 --------------------------------------------
2152 -- Process_Project_Level_Array_Attributes --
2153 --------------------------------------------
2155 procedure Process_Project_Level_Array_Attributes is
2156 Current_Array_Id : Array_Id;
2157 Current_Array : Array_Data;
2158 Element_Id : Array_Element_Id;
2159 Element : Array_Element;
2160 List : String_List_Id;
2163 -- Process the associative array attributes at project level
2165 Current_Array_Id := Project.Decl.Arrays;
2166 while Current_Array_Id /= No_Array loop
2167 Current_Array := Data.Tree.Arrays.Table (Current_Array_Id);
2169 Element_Id := Current_Array.Value;
2170 while Element_Id /= No_Array_Element loop
2171 Element := Data.Tree.Array_Elements.Table (Element_Id);
2173 -- Get the name of the language
2176 Get_Language_From_Name
2177 (Project, Get_Name_String (Element.Index));
2179 if Lang_Index /= No_Language_Index then
2180 case Current_Array.Name is
2181 when Name_Inherit_Source_Path =>
2182 List := Element.Value.Values;
2184 if List /= Nil_String then
2187 Lang_Index.Config.Include_Compatible_Languages,
2189 In_Tree => Data.Tree,
2190 Lower_Case => True);
2193 when Name_Toolchain_Description =>
2195 -- Attribute Toolchain_Description (<language>)
2197 Lang_Index.Config.Toolchain_Description :=
2198 Element.Value.Value;
2200 when Name_Toolchain_Version =>
2202 -- Attribute Toolchain_Version (<language>)
2204 Lang_Index.Config.Toolchain_Version :=
2205 Element.Value.Value;
2207 when Name_Runtime_Library_Dir =>
2209 -- Attribute Runtime_Library_Dir (<language>)
2211 Lang_Index.Config.Runtime_Library_Dir :=
2212 Element.Value.Value;
2214 when Name_Runtime_Source_Dir =>
2216 -- Attribute Runtime_Library_Dir (<language>)
2218 Lang_Index.Config.Runtime_Source_Dir :=
2219 Element.Value.Value;
2221 when Name_Object_Generated =>
2223 pragma Unsuppress (All_Checks);
2229 (Get_Name_String (Element.Value.Value));
2231 Lang_Index.Config.Object_Generated := Value;
2233 -- If no object is generated, no object may be
2237 Lang_Index.Config.Objects_Linked := False;
2241 when Constraint_Error =>
2245 & Get_Name_String (Element.Value.Value)
2246 & """ for Object_Generated",
2247 Element.Value.Location, Project);
2250 when Name_Objects_Linked =>
2252 pragma Unsuppress (All_Checks);
2258 (Get_Name_String (Element.Value.Value));
2260 -- No change if Object_Generated is False, as this
2261 -- forces Objects_Linked to be False too.
2263 if Lang_Index.Config.Object_Generated then
2264 Lang_Index.Config.Objects_Linked := Value;
2268 when Constraint_Error =>
2272 & Get_Name_String (Element.Value.Value)
2273 & """ for Objects_Linked",
2274 Element.Value.Location, Project);
2281 Element_Id := Element.Next;
2284 Current_Array_Id := Current_Array.Next;
2286 end Process_Project_Level_Array_Attributes;
2288 -- Start of processing for Check_Configuration
2291 Process_Project_Level_Simple_Attributes;
2292 Process_Project_Level_Array_Attributes;
2295 -- For unit based languages, set Casing, Dot_Replacement and
2296 -- Separate_Suffix in Naming_Data.
2298 Lang_Index := Project.Languages;
2299 while Lang_Index /= No_Language_Index loop
2300 if Lang_Index.Name = Name_Ada then
2301 Lang_Index.Config.Naming_Data.Casing := Casing;
2302 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2304 if Separate_Suffix /= No_File then
2305 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2312 Lang_Index := Lang_Index.Next;
2315 -- Give empty names to various prefixes/suffixes, if they have not
2316 -- been specified in the configuration.
2318 if Project.Config.Archive_Suffix = No_File then
2319 Project.Config.Archive_Suffix := Empty_File;
2322 if Project.Config.Shared_Lib_Prefix = No_File then
2323 Project.Config.Shared_Lib_Prefix := Empty_File;
2326 if Project.Config.Shared_Lib_Suffix = No_File then
2327 Project.Config.Shared_Lib_Suffix := Empty_File;
2330 Lang_Index := Project.Languages;
2331 while Lang_Index /= No_Language_Index loop
2333 -- For all languages, Compiler_Driver needs to be specified. This is
2334 -- only needed if we do intend to compile (not in GPS for instance).
2336 if Data.Flags.Compiler_Driver_Mandatory
2337 and then Lang_Index.Config.Compiler_Driver = No_File
2339 Error_Msg_Name_1 := Lang_Index.Display_Name;
2342 "?no compiler specified for language %%" &
2343 ", ignoring all its sources",
2344 No_Location, Project);
2346 if Lang_Index = Project.Languages then
2347 Project.Languages := Lang_Index.Next;
2349 Prev_Index.Next := Lang_Index.Next;
2352 elsif Lang_Index.Name = Name_Ada then
2353 Prev_Index := Lang_Index;
2355 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2356 -- Body_Suffix need to be specified.
2358 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2361 "Dot_Replacement not specified for Ada",
2362 No_Location, Project);
2365 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2368 "Spec_Suffix not specified for Ada",
2369 No_Location, Project);
2372 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2375 "Body_Suffix not specified for Ada",
2376 No_Location, Project);
2380 Prev_Index := Lang_Index;
2382 -- For file based languages, either Spec_Suffix or Body_Suffix
2383 -- need to be specified.
2385 if Data.Flags.Require_Sources_Other_Lang
2386 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2387 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2389 Error_Msg_Name_1 := Lang_Index.Display_Name;
2392 "no suffixes specified for %%",
2393 No_Location, Project);
2397 Lang_Index := Lang_Index.Next;
2399 end Check_Configuration;
2401 -------------------------------
2402 -- Check_If_Externally_Built --
2403 -------------------------------
2405 procedure Check_If_Externally_Built
2406 (Project : Project_Id;
2407 Data : in out Tree_Processing_Data)
2409 Externally_Built : constant Variable_Value :=
2411 (Name_Externally_Built,
2412 Project.Decl.Attributes, Data.Tree);
2415 if not Externally_Built.Default then
2416 Get_Name_String (Externally_Built.Value);
2417 To_Lower (Name_Buffer (1 .. Name_Len));
2419 if Name_Buffer (1 .. Name_Len) = "true" then
2420 Project.Externally_Built := True;
2422 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2423 Error_Msg (Data.Flags,
2424 "Externally_Built may only be true or false",
2425 Externally_Built.Location, Project);
2429 -- A virtual project extending an externally built project is itself
2430 -- externally built.
2432 if Project.Virtual and then Project.Extends /= No_Project then
2433 Project.Externally_Built := Project.Extends.Externally_Built;
2436 if Current_Verbosity = High then
2437 Write_Str ("Project is ");
2439 if not Project.Externally_Built then
2443 Write_Line ("externally built.");
2445 end Check_If_Externally_Built;
2447 ----------------------
2448 -- Check_Interfaces --
2449 ----------------------
2451 procedure Check_Interfaces
2452 (Project : Project_Id;
2453 Data : in out Tree_Processing_Data)
2455 Interfaces : constant Prj.Variable_Value :=
2457 (Snames.Name_Interfaces,
2458 Project.Decl.Attributes,
2461 List : String_List_Id;
2462 Element : String_Element;
2463 Name : File_Name_Type;
2464 Iter : Source_Iterator;
2466 Project_2 : Project_Id;
2470 if not Interfaces.Default then
2472 -- Set In_Interfaces to False for all sources. It will be set to True
2473 -- later for the sources in the Interfaces list.
2475 Project_2 := Project;
2476 while Project_2 /= No_Project loop
2477 Iter := For_Each_Source (Data.Tree, Project_2);
2479 Source := Prj.Element (Iter);
2480 exit when Source = No_Source;
2481 Source.In_Interfaces := False;
2485 Project_2 := Project_2.Extends;
2488 List := Interfaces.Values;
2489 while List /= Nil_String loop
2490 Element := Data.Tree.String_Elements.Table (List);
2491 Name := Canonical_Case_File_Name (Element.Value);
2493 Project_2 := Project;
2495 while Project_2 /= No_Project loop
2496 Iter := For_Each_Source (Data.Tree, Project_2);
2499 Source := Prj.Element (Iter);
2500 exit when Source = No_Source;
2502 if Source.File = Name then
2503 if not Source.Locally_Removed then
2504 Source.In_Interfaces := True;
2505 Source.Declared_In_Interfaces := True;
2507 Other := Other_Part (Source);
2509 if Other /= No_Source then
2510 Other.In_Interfaces := True;
2511 Other.Declared_In_Interfaces := True;
2514 if Current_Verbosity = High then
2515 Write_Str (" interface: ");
2516 Write_Line (Get_Name_String (Source.Path.Name));
2526 Project_2 := Project_2.Extends;
2529 if Source = No_Source then
2530 Error_Msg_File_1 := File_Name_Type (Element.Value);
2531 Error_Msg_Name_1 := Project.Name;
2535 "{ cannot be an interface of project %% "
2536 & "as it is not one of its sources",
2537 Element.Location, Project);
2540 List := Element.Next;
2543 Project.Interfaces_Defined := True;
2545 elsif Project.Extends /= No_Project then
2546 Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
2548 if Project.Interfaces_Defined then
2549 Iter := For_Each_Source (Data.Tree, Project);
2551 Source := Prj.Element (Iter);
2552 exit when Source = No_Source;
2554 if not Source.Declared_In_Interfaces then
2555 Source.In_Interfaces := False;
2562 end Check_Interfaces;
2564 --------------------------
2565 -- Check_Package_Naming --
2566 --------------------------
2568 procedure Check_Package_Naming
2569 (Project : Project_Id;
2570 Data : in out Tree_Processing_Data;
2571 Bodies : out Array_Element_Id;
2572 Specs : out Array_Element_Id)
2574 Naming_Id : constant Package_Id :=
2576 (Name_Naming, Project.Decl.Packages, Data.Tree);
2577 Naming : Package_Element;
2579 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2581 procedure Check_Naming;
2582 -- Check the validity of the Naming package (suffixes valid, ...)
2584 procedure Check_Common
2585 (Dot_Replacement : in out File_Name_Type;
2586 Casing : in out Casing_Type;
2587 Casing_Defined : out Boolean;
2588 Separate_Suffix : in out File_Name_Type;
2589 Sep_Suffix_Loc : out Source_Ptr);
2590 -- Check attributes common
2592 procedure Process_Exceptions_File_Based
2593 (Lang_Id : Language_Ptr;
2594 Kind : Source_Kind);
2595 procedure Process_Exceptions_Unit_Based
2596 (Lang_Id : Language_Ptr;
2597 Kind : Source_Kind);
2598 -- Process the naming exceptions for the two types of languages
2600 procedure Initialize_Naming_Data;
2601 -- Initialize internal naming data for the various languages
2607 procedure Check_Common
2608 (Dot_Replacement : in out File_Name_Type;
2609 Casing : in out Casing_Type;
2610 Casing_Defined : out Boolean;
2611 Separate_Suffix : in out File_Name_Type;
2612 Sep_Suffix_Loc : out Source_Ptr)
2614 Dot_Repl : constant Variable_Value :=
2616 (Name_Dot_Replacement,
2617 Naming.Decl.Attributes,
2619 Casing_String : constant Variable_Value :=
2622 Naming.Decl.Attributes,
2624 Sep_Suffix : constant Variable_Value :=
2626 (Name_Separate_Suffix,
2627 Naming.Decl.Attributes,
2629 Dot_Repl_Loc : Source_Ptr;
2632 Sep_Suffix_Loc := No_Location;
2634 if not Dot_Repl.Default then
2636 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2638 if Length_Of_Name (Dot_Repl.Value) = 0 then
2640 (Data.Flags, "Dot_Replacement cannot be empty",
2641 Dot_Repl.Location, Project);
2644 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2645 Dot_Repl_Loc := Dot_Repl.Location;
2648 Repl : constant String := Get_Name_String (Dot_Replacement);
2651 -- Dot_Replacement cannot
2653 -- - start or end with an alphanumeric
2654 -- - be a single '_'
2655 -- - start with an '_' followed by an alphanumeric
2656 -- - contain a '.' except if it is "."
2659 or else Is_Alphanumeric (Repl (Repl'First))
2660 or else Is_Alphanumeric (Repl (Repl'Last))
2661 or else (Repl (Repl'First) = '_'
2665 Is_Alphanumeric (Repl (Repl'First + 1))))
2666 or else (Repl'Length > 1
2668 Index (Source => Repl, Pattern => ".") /= 0)
2673 """ is illegal for Dot_Replacement.",
2674 Dot_Repl_Loc, Project);
2679 if Dot_Replacement /= No_File then
2681 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
2684 Casing_Defined := False;
2686 if not Casing_String.Default then
2688 (Casing_String.Kind = Single, "Casing is not a string");
2691 Casing_Image : constant String :=
2692 Get_Name_String (Casing_String.Value);
2695 if Casing_Image'Length = 0 then
2698 "Casing cannot be an empty string",
2699 Casing_String.Location, Project);
2702 Casing := Value (Casing_Image);
2703 Casing_Defined := True;
2706 when Constraint_Error =>
2707 Name_Len := Casing_Image'Length;
2708 Name_Buffer (1 .. Name_Len) := Casing_Image;
2709 Err_Vars.Error_Msg_Name_1 := Name_Find;
2712 "%% is not a correct Casing",
2713 Casing_String.Location, Project);
2717 Write_Attr ("Casing", Image (Casing));
2719 if not Sep_Suffix.Default then
2720 if Length_Of_Name (Sep_Suffix.Value) = 0 then
2723 "Separate_Suffix cannot be empty",
2724 Sep_Suffix.Location, Project);
2727 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
2728 Sep_Suffix_Loc := Sep_Suffix.Location;
2730 Check_Illegal_Suffix
2731 (Project, Separate_Suffix,
2732 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
2737 if Separate_Suffix /= No_File then
2739 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
2743 -----------------------------------
2744 -- Process_Exceptions_File_Based --
2745 -----------------------------------
2747 procedure Process_Exceptions_File_Based
2748 (Lang_Id : Language_Ptr;
2751 Lang : constant Name_Id := Lang_Id.Name;
2752 Exceptions : Array_Element_Id;
2753 Exception_List : Variable_Value;
2754 Element_Id : String_List_Id;
2755 Element : String_Element;
2756 File_Name : File_Name_Type;
2758 Iter : Source_Iterator;
2765 (Name_Implementation_Exceptions,
2766 In_Arrays => Naming.Decl.Arrays,
2767 In_Tree => Data.Tree);
2772 (Name_Specification_Exceptions,
2773 In_Arrays => Naming.Decl.Arrays,
2774 In_Tree => Data.Tree);
2777 Exception_List := Value_Of
2779 In_Array => Exceptions,
2780 In_Tree => Data.Tree);
2782 if Exception_List /= Nil_Variable_Value then
2783 Element_Id := Exception_List.Values;
2784 while Element_Id /= Nil_String loop
2785 Element := Data.Tree.String_Elements.Table (Element_Id);
2786 File_Name := Canonical_Case_File_Name (Element.Value);
2788 Iter := For_Each_Source (Data.Tree, Project);
2790 Source := Prj.Element (Iter);
2791 exit when Source = No_Source or else Source.File = File_Name;
2795 if Source = No_Source then
2802 File_Name => File_Name,
2803 Display_File => File_Name_Type (Element.Value),
2804 Naming_Exception => True);
2807 -- Check if the file name is already recorded for another
2808 -- language or another kind.
2810 if Source.Language /= Lang_Id then
2813 "the same file cannot be a source of two languages",
2814 Element.Location, Project);
2816 elsif Source.Kind /= Kind then
2819 "the same file cannot be a source and a template",
2820 Element.Location, Project);
2823 -- If the file is already recorded for the same
2824 -- language and the same kind, it means that the file
2825 -- name appears several times in the *_Exceptions
2826 -- attribute; so there is nothing to do.
2829 Element_Id := Element.Next;
2832 end Process_Exceptions_File_Based;
2834 -----------------------------------
2835 -- Process_Exceptions_Unit_Based --
2836 -----------------------------------
2838 procedure Process_Exceptions_Unit_Based
2839 (Lang_Id : Language_Ptr;
2842 Lang : constant Name_Id := Lang_Id.Name;
2843 Exceptions : Array_Element_Id;
2844 Element : Array_Element;
2847 File_Name : File_Name_Type;
2856 In_Arrays => Naming.Decl.Arrays,
2857 In_Tree => Data.Tree);
2859 if Exceptions = No_Array_Element then
2862 (Name_Implementation,
2863 In_Arrays => Naming.Decl.Arrays,
2864 In_Tree => Data.Tree);
2871 In_Arrays => Naming.Decl.Arrays,
2872 In_Tree => Data.Tree);
2874 if Exceptions = No_Array_Element then
2878 In_Arrays => Naming.Decl.Arrays,
2879 In_Tree => Data.Tree);
2883 while Exceptions /= No_Array_Element loop
2884 Element := Data.Tree.Array_Elements.Table (Exceptions);
2885 File_Name := Canonical_Case_File_Name (Element.Value.Value);
2887 Get_Name_String (Element.Index);
2888 To_Lower (Name_Buffer (1 .. Name_Len));
2890 Index := Element.Value.Index;
2892 -- For Ada, check if it is a valid unit name
2894 if Lang = Name_Ada then
2895 Get_Name_String (Element.Index);
2896 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
2898 if Unit = No_Name then
2899 Err_Vars.Error_Msg_Name_1 := Element.Index;
2902 "%% is not a valid unit name.",
2903 Element.Value.Location, Project);
2907 if Unit /= No_Name then
2914 File_Name => File_Name,
2915 Display_File => File_Name_Type (Element.Value.Value),
2918 Location => Element.Value.Location,
2919 Naming_Exception => True);
2922 Exceptions := Element.Next;
2924 end Process_Exceptions_Unit_Based;
2930 procedure Check_Naming is
2931 Dot_Replacement : File_Name_Type :=
2933 (First_Name_Id + Character'Pos ('-'));
2934 Separate_Suffix : File_Name_Type := No_File;
2935 Casing : Casing_Type := All_Lower_Case;
2936 Casing_Defined : Boolean;
2937 Lang_Id : Language_Ptr;
2938 Sep_Suffix_Loc : Source_Ptr;
2939 Suffix : Variable_Value;
2944 (Dot_Replacement => Dot_Replacement,
2946 Casing_Defined => Casing_Defined,
2947 Separate_Suffix => Separate_Suffix,
2948 Sep_Suffix_Loc => Sep_Suffix_Loc);
2950 -- For all unit based languages, if any, set the specified value
2951 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
2952 -- systematically overwrite, since the defaults come from the
2953 -- configuration file.
2955 if Dot_Replacement /= No_File
2956 or else Casing_Defined
2957 or else Separate_Suffix /= No_File
2959 Lang_Id := Project.Languages;
2960 while Lang_Id /= No_Language_Index loop
2961 if Lang_Id.Config.Kind = Unit_Based then
2962 if Dot_Replacement /= No_File then
2963 Lang_Id.Config.Naming_Data.Dot_Replacement :=
2967 if Casing_Defined then
2968 Lang_Id.Config.Naming_Data.Casing := Casing;
2972 Lang_Id := Lang_Id.Next;
2976 -- Next, get the spec and body suffixes
2978 Lang_Id := Project.Languages;
2979 while Lang_Id /= No_Language_Index loop
2980 Lang := Lang_Id.Name;
2986 Attribute_Or_Array_Name => Name_Spec_Suffix,
2987 In_Package => Naming_Id,
2988 In_Tree => Data.Tree);
2990 if Suffix = Nil_Variable_Value then
2993 Attribute_Or_Array_Name => Name_Specification_Suffix,
2994 In_Package => Naming_Id,
2995 In_Tree => Data.Tree);
2998 if Suffix /= Nil_Variable_Value then
2999 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3000 File_Name_Type (Suffix.Value);
3002 Check_Illegal_Suffix
3004 Lang_Id.Config.Naming_Data.Spec_Suffix,
3005 Lang_Id.Config.Naming_Data.Dot_Replacement,
3006 "Spec_Suffix", Suffix.Location, Data);
3010 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3018 Attribute_Or_Array_Name => Name_Body_Suffix,
3019 In_Package => Naming_Id,
3020 In_Tree => Data.Tree);
3022 if Suffix = Nil_Variable_Value then
3026 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3027 In_Package => Naming_Id,
3028 In_Tree => Data.Tree);
3031 if Suffix /= Nil_Variable_Value then
3032 Lang_Id.Config.Naming_Data.Body_Suffix :=
3033 File_Name_Type (Suffix.Value);
3035 -- The default value of separate suffix should be the same as
3036 -- the body suffix, so we need to compute that first.
3038 if Separate_Suffix = No_File then
3039 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3040 Lang_Id.Config.Naming_Data.Body_Suffix;
3044 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3046 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3050 Check_Illegal_Suffix
3052 Lang_Id.Config.Naming_Data.Body_Suffix,
3053 Lang_Id.Config.Naming_Data.Dot_Replacement,
3054 "Body_Suffix", Suffix.Location, Data);
3058 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3060 elsif Separate_Suffix /= No_File then
3061 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3064 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3065 -- since that would cause a clear ambiguity. Note that we do allow
3066 -- a Spec_Suffix to have the same termination as one of these,
3067 -- which causes a potential ambiguity, but we resolve that my
3068 -- matching the longest possible suffix.
3070 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3071 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3072 Lang_Id.Config.Naming_Data.Body_Suffix
3077 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3078 & """) cannot be the same as Spec_Suffix.",
3079 Ada_Body_Suffix_Loc, Project);
3082 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3083 Lang_Id.Config.Naming_Data.Separate_Suffix
3084 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3085 Lang_Id.Config.Naming_Data.Separate_Suffix
3089 "Separate_Suffix ("""
3091 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3092 & """) cannot be the same as Spec_Suffix.",
3093 Sep_Suffix_Loc, Project);
3096 Lang_Id := Lang_Id.Next;
3099 -- Get the naming exceptions for all languages
3101 for Kind in Spec .. Impl loop
3102 Lang_Id := Project.Languages;
3103 while Lang_Id /= No_Language_Index loop
3104 case Lang_Id.Config.Kind is
3106 Process_Exceptions_File_Based (Lang_Id, Kind);
3109 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3112 Lang_Id := Lang_Id.Next;
3117 ----------------------------
3118 -- Initialize_Naming_Data --
3119 ----------------------------
3121 procedure Initialize_Naming_Data is
3122 Specs : Array_Element_Id :=
3128 Impls : Array_Element_Id :=
3134 Lang : Language_Ptr;
3135 Lang_Name : Name_Id;
3136 Value : Variable_Value;
3137 Extended : Project_Id;
3140 -- At this stage, the project already contains the default extensions
3141 -- for the various languages. We now merge those suffixes read in the
3142 -- user project, and they override the default.
3144 while Specs /= No_Array_Element loop
3145 Lang_Name := Data.Tree.Array_Elements.Table (Specs).Index;
3147 Get_Language_From_Name
3148 (Project, Name => Get_Name_String (Lang_Name));
3150 -- An extending project inherits its parent projects' languages
3151 -- so if needed we should create entries for those languages
3154 Extended := Project.Extends;
3155 while Extended /= null loop
3156 Lang := Get_Language_From_Name
3157 (Extended, Name => Get_Name_String (Lang_Name));
3158 exit when Lang /= null;
3160 Extended := Extended.Extends;
3163 if Lang /= null then
3164 Lang := new Language_Data'(Lang.all);
3165 Lang.First_Source := null;
3166 Lang.Next := Project.Languages;
3167 Project.Languages := Lang;
3171 -- If language was not found in project or the projects it extends
3174 if Current_Verbosity = High then
3176 ("Ignoring spec naming data for "
3177 & Get_Name_String (Lang_Name)
3178 & " since language is not defined for this project");
3182 Value := Data.Tree.Array_Elements.Table (Specs).Value;
3184 if Value.Kind = Single then
3185 Lang.Config.Naming_Data.Spec_Suffix :=
3186 Canonical_Case_File_Name (Value.Value);
3190 Specs := Data.Tree.Array_Elements.Table (Specs).Next;
3193 while Impls /= No_Array_Element loop
3194 Lang_Name := Data.Tree.Array_Elements.Table (Impls).Index;
3196 Get_Language_From_Name
3197 (Project, Name => Get_Name_String (Lang_Name));
3200 if Current_Verbosity = High then
3202 ("Ignoring impl naming data for "
3203 & Get_Name_String (Lang_Name)
3204 & " since language is not defined for this project");
3207 Value := Data.Tree.Array_Elements.Table (Impls).Value;
3209 if Lang.Name = Name_Ada then
3210 Ada_Body_Suffix_Loc := Value.Location;
3213 if Value.Kind = Single then
3214 Lang.Config.Naming_Data.Body_Suffix :=
3215 Canonical_Case_File_Name (Value.Value);
3219 Impls := Data.Tree.Array_Elements.Table (Impls).Next;
3221 end Initialize_Naming_Data;
3223 -- Start of processing for Check_Naming_Schemes
3226 Specs := No_Array_Element;
3227 Bodies := No_Array_Element;
3229 -- No Naming package or parsing a configuration file? nothing to do
3231 if Naming_Id /= No_Package
3232 and then Project.Qualifier /= Configuration
3234 Naming := Data.Tree.Packages.Table (Naming_Id);
3236 if Current_Verbosity = High then
3237 Write_Line ("Checking package Naming for project "
3238 & Get_Name_String (Project.Name));
3241 Initialize_Naming_Data;
3244 end Check_Package_Naming;
3246 ------------------------------
3247 -- Check_Library_Attributes --
3248 ------------------------------
3250 procedure Check_Library_Attributes
3251 (Project : Project_Id;
3252 Data : in out Tree_Processing_Data)
3254 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3256 Lib_Dir : constant Prj.Variable_Value :=
3258 (Snames.Name_Library_Dir, Attributes, Data.Tree);
3260 Lib_Name : constant Prj.Variable_Value :=
3262 (Snames.Name_Library_Name, Attributes, Data.Tree);
3264 Lib_Version : constant Prj.Variable_Value :=
3266 (Snames.Name_Library_Version, Attributes, Data.Tree);
3268 Lib_ALI_Dir : constant Prj.Variable_Value :=
3270 (Snames.Name_Library_Ali_Dir, Attributes, Data.Tree);
3272 Lib_GCC : constant Prj.Variable_Value :=
3274 (Snames.Name_Library_GCC, Attributes, Data.Tree);
3276 The_Lib_Kind : constant Prj.Variable_Value :=
3278 (Snames.Name_Library_Kind, Attributes, Data.Tree);
3280 Imported_Project_List : Project_List;
3282 Continuation : String_Access := No_Continuation_String'Access;
3284 Support_For_Libraries : Library_Support;
3286 Library_Directory_Present : Boolean;
3288 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3289 -- Check if an imported or extended project if also a library project
3295 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3297 Iter : Source_Iterator;
3300 if Proj /= No_Project then
3301 if not Proj.Library then
3303 -- The only not library projects that are OK are those that
3304 -- have no sources. However, header files from non-Ada
3305 -- languages are OK, as there is nothing to compile.
3307 Iter := For_Each_Source (Data.Tree, Proj);
3309 Src_Id := Prj.Element (Iter);
3310 exit when Src_Id = No_Source
3311 or else Src_Id.Language.Config.Kind /= File_Based
3312 or else Src_Id.Kind /= Spec;
3316 if Src_Id /= No_Source then
3317 Error_Msg_Name_1 := Project.Name;
3318 Error_Msg_Name_2 := Proj.Name;
3321 if Project.Library_Kind /= Static then
3325 "shared library project %% cannot extend " &
3326 "project %% that is not a library project",
3327 Project.Location, Project);
3328 Continuation := Continuation_String'Access;
3331 elsif (not Unchecked_Shared_Lib_Imports)
3332 and then Project.Library_Kind /= Static
3337 "shared library project %% cannot import project %% " &
3338 "that is not a shared library project",
3339 Project.Location, Project);
3340 Continuation := Continuation_String'Access;
3344 elsif Project.Library_Kind /= Static and then
3345 Proj.Library_Kind = Static
3347 Error_Msg_Name_1 := Project.Name;
3348 Error_Msg_Name_2 := Proj.Name;
3354 "shared library project %% cannot extend static " &
3355 "library project %%",
3356 Project.Location, Project);
3357 Continuation := Continuation_String'Access;
3359 elsif not Unchecked_Shared_Lib_Imports then
3363 "shared library project %% cannot import static " &
3364 "library project %%",
3365 Project.Location, Project);
3366 Continuation := Continuation_String'Access;
3373 Dir_Exists : Boolean;
3375 -- Start of processing for Check_Library_Attributes
3378 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3380 -- Special case of extending project
3382 if Project.Extends /= No_Project then
3384 -- If the project extended is a library project, we inherit the
3385 -- library name, if it is not redefined; we check that the library
3386 -- directory is specified.
3388 if Project.Extends.Library then
3389 if Project.Qualifier = Standard then
3392 "a standard project cannot extend a library project",
3393 Project.Location, Project);
3396 if Lib_Name.Default then
3397 Project.Library_Name := Project.Extends.Library_Name;
3400 if Lib_Dir.Default then
3401 if not Project.Virtual then
3404 "a project extending a library project must " &
3405 "specify an attribute Library_Dir",
3406 Project.Location, Project);
3409 -- For a virtual project extending a library project,
3410 -- inherit library directory.
3412 Project.Library_Dir := Project.Extends.Library_Dir;
3413 Library_Directory_Present := True;
3420 pragma Assert (Lib_Name.Kind = Single);
3422 if Lib_Name.Value = Empty_String then
3423 if Current_Verbosity = High
3424 and then Project.Library_Name = No_Name
3426 Write_Line ("No library name");
3430 -- There is no restriction on the syntax of library names
3432 Project.Library_Name := Lib_Name.Value;
3435 if Project.Library_Name /= No_Name then
3436 if Current_Verbosity = High then
3438 ("Library name", Get_Name_String (Project.Library_Name));
3441 pragma Assert (Lib_Dir.Kind = Single);
3443 if not Library_Directory_Present then
3444 if Current_Verbosity = High then
3445 Write_Line ("No library directory");
3449 -- Find path name (unless inherited), check that it is a directory
3451 if Project.Library_Dir = No_Path_Information then
3454 File_Name_Type (Lib_Dir.Value),
3455 Path => Project.Library_Dir,
3456 Dir_Exists => Dir_Exists,
3458 Create => "library",
3459 Must_Exist => False,
3460 Location => Lib_Dir.Location,
3461 Externally_Built => Project.Externally_Built);
3467 (Project.Library_Dir.Display_Name));
3470 if not Dir_Exists then
3472 -- Get the absolute name of the library directory that
3473 -- does not exist, to report an error.
3475 Err_Vars.Error_Msg_File_1 :=
3476 File_Name_Type (Project.Library_Dir.Display_Name);
3479 "library directory { does not exist",
3480 Lib_Dir.Location, Project);
3482 -- The library directory cannot be the same as the Object
3485 elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
3488 "library directory cannot be the same " &
3489 "as object directory",
3490 Lib_Dir.Location, Project);
3491 Project.Library_Dir := No_Path_Information;
3495 OK : Boolean := True;
3496 Dirs_Id : String_List_Id;
3497 Dir_Elem : String_Element;
3501 -- The library directory cannot be the same as a source
3502 -- directory of the current project.
3504 Dirs_Id := Project.Source_Dirs;
3505 while Dirs_Id /= Nil_String loop
3506 Dir_Elem := Data.Tree.String_Elements.Table (Dirs_Id);
3507 Dirs_Id := Dir_Elem.Next;
3509 if Project.Library_Dir.Name =
3510 Path_Name_Type (Dir_Elem.Value)
3512 Err_Vars.Error_Msg_File_1 :=
3513 File_Name_Type (Dir_Elem.Value);
3516 "library directory cannot be the same " &
3517 "as source directory {",
3518 Lib_Dir.Location, Project);
3526 -- The library directory cannot be the same as a source
3527 -- directory of another project either.
3529 Pid := Data.Tree.Projects;
3531 exit Project_Loop when Pid = null;
3533 if Pid.Project /= Project then
3534 Dirs_Id := Pid.Project.Source_Dirs;
3536 Dir_Loop : while Dirs_Id /= Nil_String loop
3538 Data.Tree.String_Elements.Table (Dirs_Id);
3539 Dirs_Id := Dir_Elem.Next;
3541 if Project.Library_Dir.Name =
3542 Path_Name_Type (Dir_Elem.Value)
3544 Err_Vars.Error_Msg_File_1 :=
3545 File_Name_Type (Dir_Elem.Value);
3546 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
3550 "library directory cannot be the same " &
3551 "as source directory { of project %%",
3552 Lib_Dir.Location, Project);
3560 end loop Project_Loop;
3564 Project.Library_Dir := No_Path_Information;
3566 elsif Current_Verbosity = High then
3568 -- Display the Library directory in high verbosity
3571 ("Library directory",
3572 Get_Name_String (Project.Library_Dir.Display_Name));
3581 Project.Library_Dir /= No_Path_Information
3582 and then Project.Library_Name /= No_Name;
3584 if Project.Extends = No_Project then
3585 case Project.Qualifier is
3587 if Project.Library then
3590 "a standard project cannot be a library project",
3591 Lib_Name.Location, Project);
3595 if not Project.Library then
3596 if Project.Library_Dir = No_Path_Information then
3599 "\attribute Library_Dir not declared",
3600 Project.Location, Project);
3603 if Project.Library_Name = No_Name then
3606 "\attribute Library_Name not declared",
3607 Project.Location, Project);
3617 if Project.Library then
3618 Support_For_Libraries := Project.Config.Lib_Support;
3620 if Support_For_Libraries = Prj.None then
3623 "?libraries are not supported on this platform",
3624 Lib_Name.Location, Project);
3625 Project.Library := False;
3628 if Lib_ALI_Dir.Value = Empty_String then
3629 if Current_Verbosity = High then
3630 Write_Line ("No library ALI directory specified");
3633 Project.Library_ALI_Dir := Project.Library_Dir;
3636 -- Find path name, check that it is a directory
3640 File_Name_Type (Lib_ALI_Dir.Value),
3641 Path => Project.Library_ALI_Dir,
3642 Create => "library ALI",
3643 Dir_Exists => Dir_Exists,
3645 Must_Exist => False,
3646 Location => Lib_ALI_Dir.Location,
3647 Externally_Built => Project.Externally_Built);
3649 if not Dir_Exists then
3651 -- Get the absolute name of the library ALI directory that
3652 -- does not exist, to report an error.
3654 Err_Vars.Error_Msg_File_1 :=
3655 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
3658 "library 'A'L'I directory { does not exist",
3659 Lib_ALI_Dir.Location, Project);
3662 if Project.Library_ALI_Dir /= Project.Library_Dir then
3664 -- The library ALI directory cannot be the same as the
3665 -- Object directory.
3667 if Project.Library_ALI_Dir = Project.Object_Directory then
3670 "library 'A'L'I directory cannot be the same " &
3671 "as object directory",
3672 Lib_ALI_Dir.Location, Project);
3673 Project.Library_ALI_Dir := No_Path_Information;
3677 OK : Boolean := True;
3678 Dirs_Id : String_List_Id;
3679 Dir_Elem : String_Element;
3683 -- The library ALI directory cannot be the same as
3684 -- a source directory of the current project.
3686 Dirs_Id := Project.Source_Dirs;
3687 while Dirs_Id /= Nil_String loop
3689 Data.Tree.String_Elements.Table (Dirs_Id);
3690 Dirs_Id := Dir_Elem.Next;
3692 if Project.Library_ALI_Dir.Name =
3693 Path_Name_Type (Dir_Elem.Value)
3695 Err_Vars.Error_Msg_File_1 :=
3696 File_Name_Type (Dir_Elem.Value);
3699 "library 'A'L'I directory cannot be " &
3700 "the same as source directory {",
3701 Lib_ALI_Dir.Location, Project);
3709 -- The library ALI directory cannot be the same as
3710 -- a source directory of another project either.
3712 Pid := Data.Tree.Projects;
3713 ALI_Project_Loop : loop
3714 exit ALI_Project_Loop when Pid = null;
3716 if Pid.Project /= Project then
3717 Dirs_Id := Pid.Project.Source_Dirs;
3720 while Dirs_Id /= Nil_String loop
3722 Data.Tree.String_Elements.Table
3724 Dirs_Id := Dir_Elem.Next;
3726 if Project.Library_ALI_Dir.Name =
3727 Path_Name_Type (Dir_Elem.Value)
3729 Err_Vars.Error_Msg_File_1 :=
3730 File_Name_Type (Dir_Elem.Value);
3731 Err_Vars.Error_Msg_Name_1 :=
3736 "library 'A'L'I directory cannot " &
3737 "be the same as source directory " &
3739 Lib_ALI_Dir.Location, Project);
3741 exit ALI_Project_Loop;
3743 end loop ALI_Dir_Loop;
3746 end loop ALI_Project_Loop;
3750 Project.Library_ALI_Dir := No_Path_Information;
3752 elsif Current_Verbosity = High then
3754 -- Display Library ALI directory in high verbosity
3759 (Project.Library_ALI_Dir.Display_Name));
3766 pragma Assert (Lib_Version.Kind = Single);
3768 if Lib_Version.Value = Empty_String then
3769 if Current_Verbosity = High then
3770 Write_Line ("No library version specified");
3774 Project.Lib_Internal_Name := Lib_Version.Value;
3777 pragma Assert (The_Lib_Kind.Kind = Single);
3779 if The_Lib_Kind.Value = Empty_String then
3780 if Current_Verbosity = High then
3781 Write_Line ("No library kind specified");
3785 Get_Name_String (The_Lib_Kind.Value);
3788 Kind_Name : constant String :=
3789 To_Lower (Name_Buffer (1 .. Name_Len));
3791 OK : Boolean := True;
3794 if Kind_Name = "static" then
3795 Project.Library_Kind := Static;
3797 elsif Kind_Name = "dynamic" then
3798 Project.Library_Kind := Dynamic;
3800 elsif Kind_Name = "relocatable" then
3801 Project.Library_Kind := Relocatable;
3806 "illegal value for Library_Kind",
3807 The_Lib_Kind.Location, Project);
3811 if Current_Verbosity = High and then OK then
3812 Write_Attr ("Library kind", Kind_Name);
3815 if Project.Library_Kind /= Static then
3816 if Support_For_Libraries = Prj.Static_Only then
3819 "only static libraries are supported " &
3821 The_Lib_Kind.Location, Project);
3822 Project.Library := False;
3825 -- Check if (obsolescent) attribute Library_GCC or
3826 -- Linker'Driver is declared.
3828 if Lib_GCC.Value /= Empty_String then
3831 "?Library_'G'C'C is an obsolescent attribute, " &
3832 "use Linker''Driver instead",
3833 Lib_GCC.Location, Project);
3834 Project.Config.Shared_Lib_Driver :=
3835 File_Name_Type (Lib_GCC.Value);
3839 Linker : constant Package_Id :=
3842 Project.Decl.Packages,
3844 Driver : constant Variable_Value :=
3847 Attribute_Or_Array_Name =>
3849 In_Package => Linker,
3850 In_Tree => Data.Tree);
3853 if Driver /= Nil_Variable_Value
3854 and then Driver.Value /= Empty_String
3856 Project.Config.Shared_Lib_Driver :=
3857 File_Name_Type (Driver.Value);
3866 if Project.Library then
3867 if Current_Verbosity = High then
3868 Write_Line ("This is a library project file");
3871 Check_Library (Project.Extends, Extends => True);
3873 Imported_Project_List := Project.Imported_Projects;
3874 while Imported_Project_List /= null loop
3876 (Imported_Project_List.Project,
3878 Imported_Project_List := Imported_Project_List.Next;
3885 -- Check if Linker'Switches or Linker'Default_Switches are declared.
3886 -- Warn if they are declared, as it is a common error to think that
3887 -- library are "linked" with Linker switches.
3889 if Project.Library then
3891 Linker_Package_Id : constant Package_Id :=
3894 Project.Decl.Packages, Data.Tree);
3895 Linker_Package : Package_Element;
3896 Switches : Array_Element_Id := No_Array_Element;
3899 if Linker_Package_Id /= No_Package then
3900 Linker_Package := Data.Tree.Packages.Table (Linker_Package_Id);
3904 (Name => Name_Switches,
3905 In_Arrays => Linker_Package.Decl.Arrays,
3906 In_Tree => Data.Tree);
3908 if Switches = No_Array_Element then
3911 (Name => Name_Default_Switches,
3912 In_Arrays => Linker_Package.Decl.Arrays,
3913 In_Tree => Data.Tree);
3916 if Switches /= No_Array_Element then
3919 "?Linker switches not taken into account in library " &
3921 No_Location, Project);
3927 if Project.Extends /= No_Project then
3928 Project.Extends.Library := False;
3930 end Check_Library_Attributes;
3932 ---------------------------------
3933 -- Check_Programming_Languages --
3934 ---------------------------------
3936 procedure Check_Programming_Languages
3937 (Project : Project_Id;
3938 Data : in out Tree_Processing_Data)
3940 Languages : Variable_Value := Nil_Variable_Value;
3941 Def_Lang : Variable_Value := Nil_Variable_Value;
3942 Def_Lang_Id : Name_Id;
3944 procedure Add_Language (Name, Display_Name : Name_Id);
3945 -- Add a new language to the list of languages for the project.
3946 -- Nothing is done if the language has already been defined
3952 procedure Add_Language (Name, Display_Name : Name_Id) is
3953 Lang : Language_Ptr;
3956 Lang := Project.Languages;
3957 while Lang /= No_Language_Index loop
3958 if Name = Lang.Name then
3965 Lang := new Language_Data'(No_Language_Data);
3966 Lang.Next := Project.Languages;
3967 Project.Languages := Lang;
3969 Lang.Display_Name := Display_Name;
3971 if Name = Name_Ada then
3972 Lang.Config.Kind := Unit_Based;
3973 Lang.Config.Dependency_Kind := ALI_File;
3975 Lang.Config.Kind := File_Based;
3979 -- Start of processing for Check_Programming_Languages
3982 Project.Languages := null;
3984 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Data.Tree);
3987 (Name_Default_Language, Project.Decl.Attributes, Data.Tree);
3989 if Project.Source_Dirs /= Nil_String then
3991 -- Check if languages are specified in this project
3993 if Languages.Default then
3995 -- Fail if there is no default language defined
3997 if Def_Lang.Default then
4000 "no languages defined for this project",
4001 Project.Location, Project);
4002 Def_Lang_Id := No_Name;
4005 Get_Name_String (Def_Lang.Value);
4006 To_Lower (Name_Buffer (1 .. Name_Len));
4007 Def_Lang_Id := Name_Find;
4010 if Def_Lang_Id /= No_Name then
4011 Get_Name_String (Def_Lang_Id);
4012 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4014 (Name => Def_Lang_Id,
4015 Display_Name => Name_Find);
4020 Current : String_List_Id := Languages.Values;
4021 Element : String_Element;
4024 -- If there are no languages declared, there are no sources
4026 if Current = Nil_String then
4027 Project.Source_Dirs := Nil_String;
4029 if Project.Qualifier = Standard then
4032 "a standard project must have at least one language",
4033 Languages.Location, Project);
4037 -- Look through all the languages specified in attribute
4040 while Current /= Nil_String loop
4041 Element := Data.Tree.String_Elements.Table (Current);
4042 Get_Name_String (Element.Value);
4043 To_Lower (Name_Buffer (1 .. Name_Len));
4047 Display_Name => Element.Value);
4049 Current := Element.Next;
4055 end Check_Programming_Languages;
4057 -------------------------------
4058 -- Check_Stand_Alone_Library --
4059 -------------------------------
4061 procedure Check_Stand_Alone_Library
4062 (Project : Project_Id;
4063 Data : in out Tree_Processing_Data)
4065 Lib_Interfaces : constant Prj.Variable_Value :=
4067 (Snames.Name_Library_Interface,
4068 Project.Decl.Attributes,
4071 Lib_Auto_Init : constant Prj.Variable_Value :=
4073 (Snames.Name_Library_Auto_Init,
4074 Project.Decl.Attributes,
4077 Lib_Src_Dir : constant Prj.Variable_Value :=
4079 (Snames.Name_Library_Src_Dir,
4080 Project.Decl.Attributes,
4083 Lib_Symbol_File : constant Prj.Variable_Value :=
4085 (Snames.Name_Library_Symbol_File,
4086 Project.Decl.Attributes,
4089 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4091 (Snames.Name_Library_Symbol_Policy,
4092 Project.Decl.Attributes,
4095 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4097 (Snames.Name_Library_Reference_Symbol_File,
4098 Project.Decl.Attributes,
4101 Auto_Init_Supported : Boolean;
4102 OK : Boolean := True;
4104 Next_Proj : Project_Id;
4105 Iter : Source_Iterator;
4108 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4110 pragma Assert (Lib_Interfaces.Kind = List);
4112 -- It is a stand-alone library project file if attribute
4113 -- Library_Interface is defined.
4115 if not Lib_Interfaces.Default then
4117 Interfaces : String_List_Id := Lib_Interfaces.Values;
4118 Interface_ALIs : String_List_Id := Nil_String;
4122 Project.Standalone_Library := True;
4124 -- Library_Interface cannot be an empty list
4126 if Interfaces = Nil_String then
4129 "Library_Interface cannot be an empty list",
4130 Lib_Interfaces.Location, Project);
4133 -- Process each unit name specified in the attribute
4134 -- Library_Interface.
4136 while Interfaces /= Nil_String loop
4138 (Data.Tree.String_Elements.Table (Interfaces).Value);
4139 To_Lower (Name_Buffer (1 .. Name_Len));
4141 if Name_Len = 0 then
4144 "an interface cannot be an empty string",
4145 Data.Tree.String_Elements.Table (Interfaces).Location,
4150 Error_Msg_Name_1 := Unit;
4152 Next_Proj := Project.Extends;
4153 Iter := For_Each_Source (Data.Tree, Project);
4155 while Prj.Element (Iter) /= No_Source
4157 (Prj.Element (Iter).Unit = null
4158 or else Prj.Element (Iter).Unit.Name /= Unit)
4163 Source := Prj.Element (Iter);
4164 exit when Source /= No_Source
4165 or else Next_Proj = No_Project;
4167 Iter := For_Each_Source (Data.Tree, Next_Proj);
4168 Next_Proj := Next_Proj.Extends;
4171 if Source /= No_Source then
4172 if Source.Kind = Sep then
4173 Source := No_Source;
4175 elsif Source.Kind = Spec
4176 and then Other_Part (Source) /= No_Source
4178 Source := Other_Part (Source);
4182 if Source /= No_Source then
4183 if Source.Project /= Project
4184 and then not Is_Extending (Project, Source.Project)
4186 Source := No_Source;
4190 if Source = No_Source then
4193 "%% is not a unit of this project",
4194 Data.Tree.String_Elements.Table
4195 (Interfaces).Location, Project);
4198 if Source.Kind = Spec
4199 and then Other_Part (Source) /= No_Source
4201 Source := Other_Part (Source);
4204 String_Element_Table.Increment_Last
4205 (Data.Tree.String_Elements);
4207 Data.Tree.String_Elements.Table
4208 (String_Element_Table.Last
4209 (Data.Tree.String_Elements)) :=
4210 (Value => Name_Id (Source.Dep_Name),
4212 Display_Value => Name_Id (Source.Dep_Name),
4214 Data.Tree.String_Elements.Table
4215 (Interfaces).Location,
4217 Next => Interface_ALIs);
4220 String_Element_Table.Last
4221 (Data.Tree.String_Elements);
4225 Interfaces := Data.Tree.String_Elements.Table (Interfaces).Next;
4228 -- Put the list of Interface ALIs in the project data
4230 Project.Lib_Interface_ALIs := Interface_ALIs;
4232 -- Check value of attribute Library_Auto_Init and set
4233 -- Lib_Auto_Init accordingly.
4235 if Lib_Auto_Init.Default then
4237 -- If no attribute Library_Auto_Init is declared, then set auto
4238 -- init only if it is supported.
4240 Project.Lib_Auto_Init := Auto_Init_Supported;
4243 Get_Name_String (Lib_Auto_Init.Value);
4244 To_Lower (Name_Buffer (1 .. Name_Len));
4246 if Name_Buffer (1 .. Name_Len) = "false" then
4247 Project.Lib_Auto_Init := False;
4249 elsif Name_Buffer (1 .. Name_Len) = "true" then
4250 if Auto_Init_Supported then
4251 Project.Lib_Auto_Init := True;
4254 -- Library_Auto_Init cannot be "true" if auto init is not
4259 "library auto init not supported " &
4261 Lib_Auto_Init.Location, Project);
4267 "invalid value for attribute Library_Auto_Init",
4268 Lib_Auto_Init.Location, Project);
4273 -- If attribute Library_Src_Dir is defined and not the empty string,
4274 -- check if the directory exist and is not the object directory or
4275 -- one of the source directories. This is the directory where copies
4276 -- of the interface sources will be copied. Note that this directory
4277 -- may be the library directory.
4279 if Lib_Src_Dir.Value /= Empty_String then
4281 Dir_Id : constant File_Name_Type :=
4282 File_Name_Type (Lib_Src_Dir.Value);
4283 Dir_Exists : Boolean;
4289 Path => Project.Library_Src_Dir,
4290 Dir_Exists => Dir_Exists,
4292 Must_Exist => False,
4293 Create => "library source copy",
4294 Location => Lib_Src_Dir.Location,
4295 Externally_Built => Project.Externally_Built);
4297 -- If directory does not exist, report an error
4299 if not Dir_Exists then
4301 -- Get the absolute name of the library directory that does
4302 -- not exist, to report an error.
4304 Err_Vars.Error_Msg_File_1 :=
4305 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4308 "Directory { does not exist",
4309 Lib_Src_Dir.Location, Project);
4311 -- Report error if it is the same as the object directory
4313 elsif Project.Library_Src_Dir = Project.Object_Directory then
4316 "directory to copy interfaces cannot be " &
4317 "the object directory",
4318 Lib_Src_Dir.Location, Project);
4319 Project.Library_Src_Dir := No_Path_Information;
4323 Src_Dirs : String_List_Id;
4324 Src_Dir : String_Element;
4328 -- Interface copy directory cannot be one of the source
4329 -- directory of the current project.
4331 Src_Dirs := Project.Source_Dirs;
4332 while Src_Dirs /= Nil_String loop
4333 Src_Dir := Data.Tree.String_Elements.Table (Src_Dirs);
4335 -- Report error if it is one of the source directories
4337 if Project.Library_Src_Dir.Name =
4338 Path_Name_Type (Src_Dir.Value)
4342 "directory to copy interfaces cannot " &
4343 "be one of the source directories",
4344 Lib_Src_Dir.Location, Project);
4345 Project.Library_Src_Dir := No_Path_Information;
4349 Src_Dirs := Src_Dir.Next;
4352 if Project.Library_Src_Dir /= No_Path_Information then
4354 -- It cannot be a source directory of any other
4357 Pid := Data.Tree.Projects;
4359 exit Project_Loop when Pid = null;
4361 Src_Dirs := Pid.Project.Source_Dirs;
4362 Dir_Loop : while Src_Dirs /= Nil_String loop
4364 Data.Tree.String_Elements.Table (Src_Dirs);
4366 -- Report error if it is one of the source
4369 if Project.Library_Src_Dir.Name =
4370 Path_Name_Type (Src_Dir.Value)
4373 File_Name_Type (Src_Dir.Value);
4374 Error_Msg_Name_1 := Pid.Project.Name;
4377 "directory to copy interfaces cannot " &
4378 "be the same as source directory { of " &
4380 Lib_Src_Dir.Location, Project);
4381 Project.Library_Src_Dir :=
4382 No_Path_Information;
4386 Src_Dirs := Src_Dir.Next;
4390 end loop Project_Loop;
4394 -- In high verbosity, if there is a valid Library_Src_Dir,
4395 -- display its path name.
4397 if Project.Library_Src_Dir /= No_Path_Information
4398 and then Current_Verbosity = High
4401 ("Directory to copy interfaces",
4402 Get_Name_String (Project.Library_Src_Dir.Name));
4408 -- Check the symbol related attributes
4410 -- First, the symbol policy
4412 if not Lib_Symbol_Policy.Default then
4414 Value : constant String :=
4416 (Get_Name_String (Lib_Symbol_Policy.Value));
4419 -- Symbol policy must hove one of a limited number of values
4421 if Value = "autonomous" or else Value = "default" then
4422 Project.Symbol_Data.Symbol_Policy := Autonomous;
4424 elsif Value = "compliant" then
4425 Project.Symbol_Data.Symbol_Policy := Compliant;
4427 elsif Value = "controlled" then
4428 Project.Symbol_Data.Symbol_Policy := Controlled;
4430 elsif Value = "restricted" then
4431 Project.Symbol_Data.Symbol_Policy := Restricted;
4433 elsif Value = "direct" then
4434 Project.Symbol_Data.Symbol_Policy := Direct;
4439 "illegal value for Library_Symbol_Policy",
4440 Lib_Symbol_Policy.Location, Project);
4445 -- If attribute Library_Symbol_File is not specified, symbol policy
4446 -- cannot be Restricted.
4448 if Lib_Symbol_File.Default then
4449 if Project.Symbol_Data.Symbol_Policy = Restricted then
4452 "Library_Symbol_File needs to be defined when " &
4453 "symbol policy is Restricted",
4454 Lib_Symbol_Policy.Location, Project);
4458 -- Library_Symbol_File is defined
4460 Project.Symbol_Data.Symbol_File :=
4461 Path_Name_Type (Lib_Symbol_File.Value);
4463 Get_Name_String (Lib_Symbol_File.Value);
4465 if Name_Len = 0 then
4468 "symbol file name cannot be an empty string",
4469 Lib_Symbol_File.Location, Project);
4472 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4475 for J in 1 .. Name_Len loop
4476 if Name_Buffer (J) = '/'
4477 or else Name_Buffer (J) = Directory_Separator
4486 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4489 "symbol file name { is illegal. " &
4490 "Name cannot include directory info.",
4491 Lib_Symbol_File.Location, Project);
4496 -- If attribute Library_Reference_Symbol_File is not defined,
4497 -- symbol policy cannot be Compliant or Controlled.
4499 if Lib_Ref_Symbol_File.Default then
4500 if Project.Symbol_Data.Symbol_Policy = Compliant
4501 or else Project.Symbol_Data.Symbol_Policy = Controlled
4505 "a reference symbol file needs to be defined",
4506 Lib_Symbol_Policy.Location, Project);
4510 -- Library_Reference_Symbol_File is defined, check file exists
4512 Project.Symbol_Data.Reference :=
4513 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4515 Get_Name_String (Lib_Ref_Symbol_File.Value);
4517 if Name_Len = 0 then
4520 "reference symbol file name cannot be an empty string",
4521 Lib_Symbol_File.Location, Project);
4524 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4526 Add_Str_To_Name_Buffer
4527 (Get_Name_String (Project.Directory.Name));
4528 Add_Str_To_Name_Buffer
4529 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4530 Project.Symbol_Data.Reference := Name_Find;
4533 if not Is_Regular_File
4534 (Get_Name_String (Project.Symbol_Data.Reference))
4537 File_Name_Type (Lib_Ref_Symbol_File.Value);
4539 -- For controlled and direct symbol policies, it is an error
4540 -- if the reference symbol file does not exist. For other
4541 -- symbol policies, this is just a warning
4544 Project.Symbol_Data.Symbol_Policy /= Controlled
4545 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4549 "<library reference symbol file { does not exist",
4550 Lib_Ref_Symbol_File.Location, Project);
4552 -- In addition in the non-controlled case, if symbol policy
4553 -- is Compliant, it is changed to Autonomous, because there
4554 -- is no reference to check against, and we don't want to
4555 -- fail in this case.
4557 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4558 if Project.Symbol_Data.Symbol_Policy = Compliant then
4559 Project.Symbol_Data.Symbol_Policy := Autonomous;
4564 -- If both the reference symbol file and the symbol file are
4565 -- defined, then check that they are not the same file.
4567 if Project.Symbol_Data.Symbol_File /= No_Path then
4568 Get_Name_String (Project.Symbol_Data.Symbol_File);
4570 if Name_Len > 0 then
4572 -- We do not need to pass a Directory to
4573 -- Normalize_Pathname, since the path_information
4574 -- already contains absolute information.
4576 Symb_Path : constant String :=
4579 (Project.Object_Directory.Name) &
4580 Name_Buffer (1 .. Name_Len),
4583 Opt.Follow_Links_For_Files);
4584 Ref_Path : constant String :=
4587 (Project.Symbol_Data.Reference),
4590 Opt.Follow_Links_For_Files);
4592 if Symb_Path = Ref_Path then
4595 "library reference symbol file and library" &
4596 " symbol file cannot be the same file",
4597 Lib_Ref_Symbol_File.Location, Project);
4605 end Check_Stand_Alone_Library;
4607 ----------------------------
4608 -- Compute_Directory_Last --
4609 ----------------------------
4611 function Compute_Directory_Last (Dir : String) return Natural is
4614 and then (Dir (Dir'Last - 1) = Directory_Separator
4616 Dir (Dir'Last - 1) = '/')
4618 return Dir'Last - 1;
4622 end Compute_Directory_Last;
4624 ---------------------
4625 -- Get_Directories --
4626 ---------------------
4628 procedure Get_Directories
4629 (Project : Project_Id;
4630 Data : in out Tree_Processing_Data)
4632 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
4633 (Header_Num => Header_Num,
4635 No_Element => False,
4639 -- Hash table stores recursive source directories, to avoid looking
4640 -- several times, and to avoid cycles that may be introduced by symbolic
4643 Visited : Recursive_Dirs.Instance;
4645 Object_Dir : constant Variable_Value :=
4647 (Name_Object_Dir, Project.Decl.Attributes, Data.Tree);
4649 Exec_Dir : constant Variable_Value :=
4651 (Name_Exec_Dir, Project.Decl.Attributes, Data.Tree);
4653 Source_Dirs : constant Variable_Value :=
4655 (Name_Source_Dirs, Project.Decl.Attributes, Data.Tree);
4657 Excluded_Source_Dirs : constant Variable_Value :=
4659 (Name_Excluded_Source_Dirs,
4660 Project.Decl.Attributes,
4663 Source_Files : constant Variable_Value :=
4666 Project.Decl.Attributes, Data.Tree);
4668 Last_Source_Dir : String_List_Id := Nil_String;
4670 Languages : constant Variable_Value :=
4672 (Name_Languages, Project.Decl.Attributes, Data.Tree);
4674 procedure Find_Source_Dirs
4675 (From : File_Name_Type;
4676 Location : Source_Ptr;
4677 Removed : Boolean := False);
4678 -- Find one or several source directories, and add (or remove, if
4679 -- Removed is True) them to list of source directories of the project.
4681 ----------------------
4682 -- Find_Source_Dirs --
4683 ----------------------
4685 procedure Find_Source_Dirs
4686 (From : File_Name_Type;
4687 Location : Source_Ptr;
4688 Removed : Boolean := False)
4690 Directory : constant String := Get_Name_String (From);
4691 Element : String_Element;
4693 procedure Recursive_Find_Dirs (Path : Name_Id);
4694 -- Find all the subdirectories (recursively) of Path and add them
4695 -- to the list of source directories of the project.
4697 -------------------------
4698 -- Recursive_Find_Dirs --
4699 -------------------------
4701 procedure Recursive_Find_Dirs (Path : Name_Id) is
4703 Name : String (1 .. 250);
4705 List : String_List_Id;
4706 Prev : String_List_Id;
4707 Element : String_Element;
4708 Found : Boolean := False;
4710 Non_Canonical_Path : Name_Id := No_Name;
4711 Canonical_Path : Name_Id := No_Name;
4713 The_Path : constant String :=
4715 (Get_Name_String (Path),
4717 Get_Name_String (Project.Directory.Display_Name),
4718 Resolve_Links => Opt.Follow_Links_For_Dirs) &
4719 Directory_Separator;
4721 The_Path_Last : constant Natural :=
4722 Compute_Directory_Last (The_Path);
4725 Name_Len := The_Path_Last - The_Path'First + 1;
4726 Name_Buffer (1 .. Name_Len) :=
4727 The_Path (The_Path'First .. The_Path_Last);
4728 Non_Canonical_Path := Name_Find;
4730 Name_Id (Canonical_Case_File_Name (Non_Canonical_Path));
4732 -- To avoid processing the same directory several times, check
4733 -- if the directory is already in Recursive_Dirs. If it is, then
4734 -- there is nothing to do, just return. If it is not, put it there
4735 -- and continue recursive processing.
4738 if Recursive_Dirs.Get (Visited, Canonical_Path) then
4741 Recursive_Dirs.Set (Visited, Canonical_Path, True);
4745 -- Check if directory is already in list
4747 List := Project.Source_Dirs;
4749 while List /= Nil_String loop
4750 Element := Data.Tree.String_Elements.Table (List);
4752 if Element.Value /= No_Name then
4753 Found := Element.Value = Canonical_Path;
4758 List := Element.Next;
4761 -- If directory is not already in list, put it there
4763 if (not Removed) and (not Found) then
4764 if Current_Verbosity = High then
4766 Write_Line (The_Path (The_Path'First .. The_Path_Last));
4769 String_Element_Table.Increment_Last (Data.Tree.String_Elements);
4771 (Value => Canonical_Path,
4772 Display_Value => Non_Canonical_Path,
4773 Location => No_Location,
4778 -- Case of first source directory
4780 if Last_Source_Dir = Nil_String then
4781 Project.Source_Dirs :=
4782 String_Element_Table.Last (Data.Tree.String_Elements);
4784 -- Here we already have source directories
4787 -- Link the previous last to the new one
4789 Data.Tree.String_Elements.Table
4790 (Last_Source_Dir).Next :=
4791 String_Element_Table.Last (Data.Tree.String_Elements);
4794 -- And register this source directory as the new last
4797 String_Element_Table.Last (Data.Tree.String_Elements);
4798 Data.Tree.String_Elements.Table (Last_Source_Dir) := Element;
4800 elsif Removed and Found then
4801 if Prev = Nil_String then
4802 Project.Source_Dirs :=
4803 Data.Tree.String_Elements.Table (List).Next;
4805 Data.Tree.String_Elements.Table (Prev).Next :=
4806 Data.Tree.String_Elements.Table (List).Next;
4810 -- Now look for subdirectories. We do that even when this
4811 -- directory is already in the list, because some of its
4812 -- subdirectories may not be in the list yet.
4814 Open (Dir, The_Path (The_Path'First .. The_Path_Last));
4817 Read (Dir, Name, Last);
4820 if Name (1 .. Last) /= "."
4821 and then Name (1 .. Last) /= ".."
4823 -- Avoid . and .. directories
4825 if Current_Verbosity = High then
4826 Write_Str (" Checking ");
4827 Write_Line (Name (1 .. Last));
4831 Path_Name : constant String :=
4833 (Name => Name (1 .. Last),
4835 The_Path (The_Path'First .. The_Path_Last),
4836 Resolve_Links => Opt.Follow_Links_For_Dirs,
4837 Case_Sensitive => True);
4840 if Is_Directory (Path_Name) then
4842 -- We have found a new subdirectory, call self
4844 Name_Len := Path_Name'Length;
4845 Name_Buffer (1 .. Name_Len) := Path_Name;
4846 Recursive_Find_Dirs (Name_Find);
4855 when Directory_Error =>
4857 end Recursive_Find_Dirs;
4859 -- Start of processing for Find_Source_Dirs
4862 if Current_Verbosity = High and then not Removed then
4863 Write_Str ("Find_Source_Dirs (""");
4864 Write_Str (Directory);
4868 -- First, check if we are looking for a directory tree, indicated
4869 -- by "/**" at the end.
4871 if Directory'Length >= 3
4872 and then Directory (Directory'Last - 1 .. Directory'Last) = "**"
4873 and then (Directory (Directory'Last - 2) = '/'
4875 Directory (Directory'Last - 2) = Directory_Separator)
4878 Project.Known_Order_Of_Source_Dirs := False;
4881 Name_Len := Directory'Length - 3;
4883 if Name_Len = 0 then
4885 -- Case of "/**": all directories in file system
4888 Name_Buffer (1) := Directory (Directory'First);
4891 Name_Buffer (1 .. Name_Len) :=
4892 Directory (Directory'First .. Directory'Last - 3);
4895 if Current_Verbosity = High then
4896 Write_Str ("Looking for all subdirectories of """);
4897 Write_Str (Name_Buffer (1 .. Name_Len));
4902 Base_Dir : constant File_Name_Type := Name_Find;
4903 Root_Dir : constant String :=
4905 (Name => Get_Name_String (Base_Dir),
4908 (Project.Directory.Display_Name),
4909 Resolve_Links => False,
4910 Case_Sensitive => True);
4913 if Root_Dir'Length = 0 then
4914 Err_Vars.Error_Msg_File_1 := Base_Dir;
4916 if Location = No_Location then
4919 "{ is not a valid directory.",
4920 Project.Location, Project);
4924 "{ is not a valid directory.",
4929 -- We have an existing directory, we register it and all of
4930 -- its subdirectories.
4932 if Current_Verbosity = High then
4933 Write_Line ("Looking for source directories:");
4936 Name_Len := Root_Dir'Length;
4937 Name_Buffer (1 .. Name_Len) := Root_Dir;
4938 Recursive_Find_Dirs (Name_Find);
4940 if Current_Verbosity = High then
4941 Write_Line ("End of looking for source directories.");
4946 -- We have a single directory
4950 Path_Name : Path_Information;
4951 List : String_List_Id;
4952 Prev : String_List_Id;
4953 Dir_Exists : Boolean;
4957 (Project => Project,
4960 Dir_Exists => Dir_Exists,
4962 Must_Exist => False);
4964 if not Dir_Exists then
4965 Err_Vars.Error_Msg_File_1 := From;
4967 if Location = No_Location then
4970 "{ is not a valid directory",
4971 Project.Location, Project);
4975 "{ is not a valid directory",
4981 Path : constant String :=
4982 Get_Name_String (Path_Name.Name);
4983 Last_Path : constant Natural :=
4984 Compute_Directory_Last (Path);
4986 Display_Path : constant String :=
4988 (Path_Name.Display_Name);
4989 Last_Display_Path : constant Natural :=
4990 Compute_Directory_Last
4992 Display_Path_Id : Name_Id;
4996 Add_Str_To_Name_Buffer (Path (Path'First .. Last_Path));
4997 Path_Id := Name_Find;
4999 Add_Str_To_Name_Buffer
5001 (Display_Path'First .. Last_Display_Path));
5002 Display_Path_Id := Name_Find;
5006 -- As it is an existing directory, we add it to the
5007 -- list of directories.
5009 String_Element_Table.Increment_Last
5010 (Data.Tree.String_Elements);
5014 Display_Value => Display_Path_Id,
5015 Location => No_Location,
5017 Next => Nil_String);
5019 if Last_Source_Dir = Nil_String then
5021 -- This is the first source directory
5023 Project.Source_Dirs := String_Element_Table.Last
5024 (Data.Tree.String_Elements);
5027 -- We already have source directories, link the
5028 -- previous last to the new one.
5030 Data.Tree.String_Elements.Table
5031 (Last_Source_Dir).Next :=
5032 String_Element_Table.Last
5033 (Data.Tree.String_Elements);
5036 -- And register this source directory as the new last
5038 Last_Source_Dir := String_Element_Table.Last
5039 (Data.Tree.String_Elements);
5040 Data.Tree.String_Elements.Table
5041 (Last_Source_Dir) := Element;
5044 -- Remove source dir, if present
5048 -- Look for source dir in current list
5050 List := Project.Source_Dirs;
5051 while List /= Nil_String loop
5052 Element := Data.Tree.String_Elements.Table (List);
5053 exit when Element.Value = Path_Id;
5055 List := Element.Next;
5058 if List /= Nil_String then
5059 -- Source dir was found, remove it from the list
5061 if Prev = Nil_String then
5062 Project.Source_Dirs :=
5063 Data.Tree.String_Elements.Table (List).Next;
5066 Data.Tree.String_Elements.Table (Prev).Next :=
5067 Data.Tree.String_Elements.Table (List).Next;
5076 Recursive_Dirs.Reset (Visited);
5077 end Find_Source_Dirs;
5079 -- Start of processing for Get_Directories
5081 Dir_Exists : Boolean;
5084 if Current_Verbosity = High then
5085 Write_Line ("Starting to look for directories");
5088 -- Set the object directory to its default which may be nil, if there
5089 -- is no sources in the project.
5091 if (((not Source_Files.Default)
5092 and then Source_Files.Values = Nil_String)
5094 ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
5096 ((not Languages.Default) and then Languages.Values = Nil_String))
5097 and then Project.Extends = No_Project
5099 Project.Object_Directory := No_Path_Information;
5101 Project.Object_Directory := Project.Directory;
5104 -- Check the object directory
5106 if Object_Dir.Value /= Empty_String then
5107 Get_Name_String (Object_Dir.Value);
5109 if Name_Len = 0 then
5112 "Object_Dir cannot be empty",
5113 Object_Dir.Location, Project);
5116 -- We check that the specified object directory does exist.
5117 -- However, even when it doesn't exist, we set it to a default
5118 -- value. This is for the benefit of tools that recover from
5119 -- errors; for example, these tools could create the non existent
5120 -- directory. We always return an absolute directory name though.
5124 File_Name_Type (Object_Dir.Value),
5125 Path => Project.Object_Directory,
5127 Dir_Exists => Dir_Exists,
5129 Location => Object_Dir.Location,
5130 Must_Exist => False,
5131 Externally_Built => Project.Externally_Built);
5134 and then not Project.Externally_Built
5136 -- The object directory does not exist, report an error if
5137 -- the project is not externally built.
5139 Err_Vars.Error_Msg_File_1 :=
5140 File_Name_Type (Object_Dir.Value);
5143 "object directory { not found",
5144 Project.Location, Project);
5148 elsif Project.Object_Directory /= No_Path_Information
5149 and then Subdirs /= null
5152 Name_Buffer (1) := '.';
5156 Path => Project.Object_Directory,
5158 Dir_Exists => Dir_Exists,
5160 Location => Object_Dir.Location,
5161 Externally_Built => Project.Externally_Built);
5164 if Current_Verbosity = High then
5165 if Project.Object_Directory = No_Path_Information then
5166 Write_Line ("No object directory");
5169 ("Object directory",
5170 Get_Name_String (Project.Object_Directory.Display_Name));
5174 -- Check the exec directory
5176 -- We set the object directory to its default
5178 Project.Exec_Directory := Project.Object_Directory;
5180 if Exec_Dir.Value /= Empty_String then
5181 Get_Name_String (Exec_Dir.Value);
5183 if Name_Len = 0 then
5186 "Exec_Dir cannot be empty",
5187 Exec_Dir.Location, Project);
5190 -- We check that the specified exec directory does exist
5194 File_Name_Type (Exec_Dir.Value),
5195 Path => Project.Exec_Directory,
5196 Dir_Exists => Dir_Exists,
5199 Location => Exec_Dir.Location,
5200 Externally_Built => Project.Externally_Built);
5202 if not Dir_Exists then
5203 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5206 "exec directory { not found",
5207 Project.Location, Project);
5212 if Current_Verbosity = High then
5213 if Project.Exec_Directory = No_Path_Information then
5214 Write_Line ("No exec directory");
5216 Write_Str ("Exec directory: """);
5217 Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
5222 -- Look for the source directories
5224 if Current_Verbosity = High then
5225 Write_Line ("Starting to look for source directories");
5228 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5230 if (not Source_Files.Default)
5231 and then Source_Files.Values = Nil_String
5233 Project.Source_Dirs := Nil_String;
5235 if Project.Qualifier = Standard then
5238 "a standard project cannot have no sources",
5239 Source_Files.Location, Project);
5242 elsif Source_Dirs.Default then
5244 -- No Source_Dirs specified: the single source directory is the one
5245 -- containing the project file.
5247 String_Element_Table.Append (Data.Tree.String_Elements,
5248 (Value => Name_Id (Project.Directory.Name),
5249 Display_Value => Name_Id (Project.Directory.Display_Name),
5250 Location => No_Location,
5255 Project.Source_Dirs :=
5256 String_Element_Table.Last (Data.Tree.String_Elements);
5258 if Current_Verbosity = High then
5260 ("Default source directory",
5261 Get_Name_String (Project.Directory.Display_Name));
5264 elsif Source_Dirs.Values = Nil_String then
5265 if Project.Qualifier = Standard then
5268 "a standard project cannot have no source directories",
5269 Source_Dirs.Location, Project);
5272 Project.Source_Dirs := Nil_String;
5276 Source_Dir : String_List_Id;
5277 Element : String_Element;
5280 -- Process the source directories for each element of the list
5282 Source_Dir := Source_Dirs.Values;
5283 while Source_Dir /= Nil_String loop
5284 Element := Data.Tree.String_Elements.Table (Source_Dir);
5286 (File_Name_Type (Element.Value), Element.Location);
5287 Source_Dir := Element.Next;
5292 if not Excluded_Source_Dirs.Default
5293 and then Excluded_Source_Dirs.Values /= Nil_String
5296 Source_Dir : String_List_Id;
5297 Element : String_Element;
5300 -- Process the source directories for each element of the list
5302 Source_Dir := Excluded_Source_Dirs.Values;
5303 while Source_Dir /= Nil_String loop
5304 Element := Data.Tree.String_Elements.Table (Source_Dir);
5306 (File_Name_Type (Element.Value),
5309 Source_Dir := Element.Next;
5314 if Current_Verbosity = High then
5315 Write_Line ("Putting source directories in canonical cases");
5319 Current : String_List_Id := Project.Source_Dirs;
5320 Element : String_Element;
5323 while Current /= Nil_String loop
5324 Element := Data.Tree.String_Elements.Table (Current);
5325 if Element.Value /= No_Name then
5327 Name_Id (Canonical_Case_File_Name (Name_Id (Element.Value)));
5328 Data.Tree.String_Elements.Table (Current) := Element;
5331 Current := Element.Next;
5334 end Get_Directories;
5341 (Project : Project_Id;
5342 Data : in out Tree_Processing_Data)
5344 Mains : constant Variable_Value :=
5346 (Name_Main, Project.Decl.Attributes, Data.Tree);
5347 List : String_List_Id;
5348 Elem : String_Element;
5351 Project.Mains := Mains.Values;
5353 -- If no Mains were specified, and if we are an extending project,
5354 -- inherit the Mains from the project we are extending.
5356 if Mains.Default then
5357 if not Project.Library and then Project.Extends /= No_Project then
5358 Project.Mains := Project.Extends.Mains;
5361 -- In a library project file, Main cannot be specified
5363 elsif Project.Library then
5366 "a library project file cannot have Main specified",
5367 Mains.Location, Project);
5370 List := Mains.Values;
5371 while List /= Nil_String loop
5372 Elem := Data.Tree.String_Elements.Table (List);
5374 if Length_Of_Name (Elem.Value) = 0 then
5377 "?a main cannot have an empty name",
5378 Elem.Location, Project);
5387 ---------------------------
5388 -- Get_Sources_From_File --
5389 ---------------------------
5391 procedure Get_Sources_From_File
5393 Location : Source_Ptr;
5394 Project : in out Project_Processing_Data;
5395 Data : in out Tree_Processing_Data)
5397 File : Prj.Util.Text_File;
5398 Line : String (1 .. 250);
5400 Source_Name : File_Name_Type;
5401 Name_Loc : Name_Location;
5404 if Current_Verbosity = High then
5405 Write_Str ("Opening """);
5412 Prj.Util.Open (File, Path);
5414 if not Prj.Util.Is_Valid (File) then
5416 (Data.Flags, "file does not exist", Location, Project.Project);
5419 -- Read the lines one by one
5421 while not Prj.Util.End_Of_File (File) loop
5422 Prj.Util.Get_Line (File, Line, Last);
5424 -- A non empty, non comment line should contain a file name
5427 and then (Last = 1 or else Line (1 .. 2) /= "--")
5430 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5431 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5432 Source_Name := Name_Find;
5434 -- Check that there is no directory information
5436 for J in 1 .. Last loop
5437 if Line (J) = '/' or else Line (J) = Directory_Separator then
5438 Error_Msg_File_1 := Source_Name;
5441 "file name cannot include directory information ({)",
5442 Location, Project.Project);
5447 Name_Loc := Source_Names_Htable.Get
5448 (Project.Source_Names, Source_Name);
5450 if Name_Loc = No_Name_Location then
5452 (Name => Source_Name,
5453 Location => Location,
5454 Source => No_Source,
5458 Source_Names_Htable.Set
5459 (Project.Source_Names, Source_Name, Name_Loc);
5463 Prj.Util.Close (File);
5466 end Get_Sources_From_File;
5468 -----------------------
5469 -- Compute_Unit_Name --
5470 -----------------------
5472 procedure Compute_Unit_Name
5473 (File_Name : File_Name_Type;
5474 Naming : Lang_Naming_Data;
5475 Kind : out Source_Kind;
5477 Project : Project_Processing_Data;
5478 In_Tree : Project_Tree_Ref)
5480 Filename : constant String := Get_Name_String (File_Name);
5481 Last : Integer := Filename'Last;
5486 Unit_Except : Unit_Exception;
5487 Masked : Boolean := False;
5493 if Naming.Separate_Suffix = No_File
5494 or else Naming.Body_Suffix = No_File
5495 or else Naming.Spec_Suffix = No_File
5500 if Naming.Dot_Replacement = No_File then
5501 if Current_Verbosity = High then
5502 Write_Line (" No dot_replacement specified");
5508 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5509 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5510 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5512 -- Choose the longest suffix that matches. If there are several matches,
5513 -- give priority to specs, then bodies, then separates.
5515 if Naming.Separate_Suffix /= Naming.Body_Suffix
5516 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5518 Last := Filename'Last - Sep_Len;
5522 if Filename'Last - Body_Len <= Last
5523 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5525 Last := Natural'Min (Last, Filename'Last - Body_Len);
5529 if Filename'Last - Spec_Len <= Last
5530 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5532 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5536 if Last = Filename'Last then
5537 if Current_Verbosity = High then
5538 Write_Line (" no matching suffix");
5544 -- Check that the casing matches
5546 if File_Names_Case_Sensitive then
5547 case Naming.Casing is
5548 when All_Lower_Case =>
5549 for J in Filename'First .. Last loop
5550 if Is_Letter (Filename (J))
5551 and then not Is_Lower (Filename (J))
5553 if Current_Verbosity = High then
5554 Write_Line (" Invalid casing");
5561 when All_Upper_Case =>
5562 for J in Filename'First .. Last loop
5563 if Is_Letter (Filename (J))
5564 and then not Is_Upper (Filename (J))
5566 if Current_Verbosity = High then
5567 Write_Line (" Invalid casing");
5574 when Mixed_Case | Unknown =>
5579 -- If Dot_Replacement is not a single dot, then there should not
5580 -- be any dot in the name.
5583 Dot_Repl : constant String :=
5584 Get_Name_String (Naming.Dot_Replacement);
5587 if Dot_Repl /= "." then
5588 for Index in Filename'First .. Last loop
5589 if Filename (Index) = '.' then
5590 if Current_Verbosity = High then
5591 Write_Line (" Invalid name, contains dot");
5598 Replace_Into_Name_Buffer
5599 (Filename (Filename'First .. Last), Dot_Repl, '.');
5602 Name_Len := Last - Filename'First + 1;
5603 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5605 (Source => Name_Buffer (1 .. Name_Len),
5606 Mapping => Lower_Case_Map);
5610 -- In the standard GNAT naming scheme, check for special cases: children
5611 -- or separates of A, G, I or S, and run time sources.
5613 if Is_Standard_GNAT_Naming (Naming)
5614 and then Name_Len >= 3
5617 S1 : constant Character := Name_Buffer (1);
5618 S2 : constant Character := Name_Buffer (2);
5619 S3 : constant Character := Name_Buffer (3);
5627 -- Children or separates of packages A, G, I or S. These names
5628 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5629 -- versions (x__... and x~...) are allowed in all platforms,
5630 -- because it is not possible to know the platform before
5631 -- processing of the project files.
5633 if S2 = '_' and then S3 = '_' then
5634 Name_Buffer (2) := '.';
5635 Name_Buffer (3 .. Name_Len - 1) :=
5636 Name_Buffer (4 .. Name_Len);
5637 Name_Len := Name_Len - 1;
5640 Name_Buffer (2) := '.';
5644 -- If it is potentially a run time source
5652 -- Name_Buffer contains the name of the the unit in lower-cases. Check
5653 -- that this is a valid unit name
5655 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5657 -- If there is a naming exception for the same unit, the file is not
5658 -- a source for the unit.
5660 if Unit /= No_Name then
5662 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5665 Masked := Unit_Except.Spec /= No_File
5667 Unit_Except.Spec /= File_Name;
5669 Masked := Unit_Except.Impl /= No_File
5671 Unit_Except.Impl /= File_Name;
5675 if Current_Verbosity = High then
5676 Write_Str (" """ & Filename & """ contains the ");
5679 Write_Str ("spec of a unit found in """);
5680 Write_Str (Get_Name_String (Unit_Except.Spec));
5682 Write_Str ("body of a unit found in """);
5683 Write_Str (Get_Name_String (Unit_Except.Impl));
5686 Write_Line (""" (ignored)");
5694 and then Current_Verbosity = High
5697 when Spec => Write_Str (" spec of ");
5698 when Impl => Write_Str (" body of ");
5699 when Sep => Write_Str (" sep of ");
5702 Write_Line (Get_Name_String (Unit));
5704 end Compute_Unit_Name;
5706 --------------------------
5707 -- Check_Illegal_Suffix --
5708 --------------------------
5710 procedure Check_Illegal_Suffix
5711 (Project : Project_Id;
5712 Suffix : File_Name_Type;
5713 Dot_Replacement : File_Name_Type;
5714 Attribute_Name : String;
5715 Location : Source_Ptr;
5716 Data : in out Tree_Processing_Data)
5718 Suffix_Str : constant String := Get_Name_String (Suffix);
5721 if Suffix_Str'Length = 0 then
5727 elsif Index (Suffix_Str, ".") = 0 then
5728 Err_Vars.Error_Msg_File_1 := Suffix;
5731 "{ is illegal for " & Attribute_Name & ": must have a dot",
5736 -- Case of dot replacement is a single dot, and first character of
5737 -- suffix is also a dot.
5739 if Dot_Replacement /= No_File
5740 and then Get_Name_String (Dot_Replacement) = "."
5741 and then Suffix_Str (Suffix_Str'First) = '.'
5743 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5745 -- If there are multiple dots in the name
5747 if Suffix_Str (Index) = '.' then
5749 -- It is illegal to have a letter following the initial dot
5751 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5752 Err_Vars.Error_Msg_File_1 := Suffix;
5755 "{ is illegal for " & Attribute_Name
5756 & ": ambiguous prefix when Dot_Replacement is a dot",
5763 end Check_Illegal_Suffix;
5765 ----------------------
5766 -- Locate_Directory --
5767 ----------------------
5769 procedure Locate_Directory
5770 (Project : Project_Id;
5771 Name : File_Name_Type;
5772 Path : out Path_Information;
5773 Dir_Exists : out Boolean;
5774 Data : in out Tree_Processing_Data;
5775 Create : String := "";
5776 Location : Source_Ptr := No_Location;
5777 Must_Exist : Boolean := True;
5778 Externally_Built : Boolean := False)
5780 Parent : constant Path_Name_Type :=
5781 Project.Directory.Display_Name;
5782 The_Parent : constant String :=
5783 Get_Name_String (Parent);
5784 The_Parent_Last : constant Natural :=
5785 Compute_Directory_Last (The_Parent);
5786 Full_Name : File_Name_Type;
5787 The_Name : File_Name_Type;
5790 Get_Name_String (Name);
5792 -- Add Subdirs.all if it is a directory that may be created and
5793 -- Subdirs is not null;
5795 if Create /= "" and then Subdirs /= null then
5796 if Name_Buffer (Name_Len) /= Directory_Separator then
5797 Add_Char_To_Name_Buffer (Directory_Separator);
5800 Add_Str_To_Name_Buffer (Subdirs.all);
5803 -- Convert '/' to directory separator (for Windows)
5805 for J in 1 .. Name_Len loop
5806 if Name_Buffer (J) = '/' then
5807 Name_Buffer (J) := Directory_Separator;
5811 The_Name := Name_Find;
5813 if Current_Verbosity = High then
5814 Write_Str ("Locate_Directory (""");
5815 Write_Str (Get_Name_String (The_Name));
5816 Write_Str (""", """);
5817 Write_Str (The_Parent);
5821 Path := No_Path_Information;
5822 Dir_Exists := False;
5824 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5825 Full_Name := The_Name;
5829 Add_Str_To_Name_Buffer
5830 (The_Parent (The_Parent'First .. The_Parent_Last));
5831 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5832 Full_Name := Name_Find;
5836 Full_Path_Name : String_Access :=
5837 new String'(Get_Name_String (Full_Name));
5840 if (Setup_Projects or else Subdirs /= null)
5841 and then Create'Length > 0
5843 if not Is_Directory (Full_Path_Name.all) then
5845 -- If project is externally built, do not create a subdir,
5846 -- use the specified directory, without the subdir.
5848 if Externally_Built then
5849 if Is_Absolute_Path (Get_Name_String (Name)) then
5850 Get_Name_String (Name);
5854 Add_Str_To_Name_Buffer
5855 (The_Parent (The_Parent'First .. The_Parent_Last));
5856 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5859 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5863 Create_Path (Full_Path_Name.all);
5865 if not Quiet_Output then
5867 Write_Str (" directory """);
5868 Write_Str (Full_Path_Name.all);
5869 Write_Str (""" created for project ");
5870 Write_Line (Get_Name_String (Project.Name));
5877 "could not create " & Create &
5878 " directory " & Full_Path_Name.all,
5885 Dir_Exists := Is_Directory (Full_Path_Name.all);
5887 if not Must_Exist or else Dir_Exists then
5889 Normed : constant String :=
5891 (Full_Path_Name.all,
5893 The_Parent (The_Parent'First .. The_Parent_Last),
5894 Resolve_Links => False,
5895 Case_Sensitive => True);
5897 Canonical_Path : constant String :=
5902 (The_Parent'First .. The_Parent_Last),
5904 Opt.Follow_Links_For_Dirs,
5905 Case_Sensitive => False);
5908 Name_Len := Normed'Length;
5909 Name_Buffer (1 .. Name_Len) := Normed;
5911 -- Directories should always end with a directory separator
5913 if Name_Buffer (Name_Len) /= Directory_Separator then
5914 Add_Char_To_Name_Buffer (Directory_Separator);
5917 Path.Display_Name := Name_Find;
5919 Name_Len := Canonical_Path'Length;
5920 Name_Buffer (1 .. Name_Len) := Canonical_Path;
5922 if Name_Buffer (Name_Len) /= Directory_Separator then
5923 Add_Char_To_Name_Buffer (Directory_Separator);
5926 Path.Name := Name_Find;
5930 Free (Full_Path_Name);
5932 end Locate_Directory;
5934 ---------------------------
5935 -- Find_Excluded_Sources --
5936 ---------------------------
5938 procedure Find_Excluded_Sources
5939 (Project : in out Project_Processing_Data;
5940 Data : in out Tree_Processing_Data)
5942 Excluded_Source_List_File : constant Variable_Value :=
5944 (Name_Excluded_Source_List_File,
5945 Project.Project.Decl.Attributes,
5947 Excluded_Sources : Variable_Value := Util.Value_Of
5948 (Name_Excluded_Source_Files,
5949 Project.Project.Decl.Attributes,
5952 Current : String_List_Id;
5953 Element : String_Element;
5954 Location : Source_Ptr;
5955 Name : File_Name_Type;
5956 File : Prj.Util.Text_File;
5957 Line : String (1 .. 300);
5959 Locally_Removed : Boolean := False;
5962 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
5964 if Excluded_Sources.Default then
5965 Locally_Removed := True;
5968 (Name_Locally_Removed_Files,
5969 Project.Project.Decl.Attributes, Data.Tree);
5972 -- If there are excluded sources, put them in the table
5974 if not Excluded_Sources.Default then
5975 if not Excluded_Source_List_File.Default then
5976 if Locally_Removed then
5979 "?both attributes Locally_Removed_Files and " &
5980 "Excluded_Source_List_File are present",
5981 Excluded_Source_List_File.Location, Project.Project);
5985 "?both attributes Excluded_Source_Files and " &
5986 "Excluded_Source_List_File are present",
5987 Excluded_Source_List_File.Location, Project.Project);
5991 Current := Excluded_Sources.Values;
5992 while Current /= Nil_String loop
5993 Element := Data.Tree.String_Elements.Table (Current);
5994 Name := Canonical_Case_File_Name (Element.Value);
5996 -- If the element has no location, then use the location of
5997 -- Excluded_Sources to report possible errors.
5999 if Element.Location = No_Location then
6000 Location := Excluded_Sources.Location;
6002 Location := Element.Location;
6005 Excluded_Sources_Htable.Set
6006 (Project.Excluded, Name, (Name, False, Location));
6007 Current := Element.Next;
6010 elsif not Excluded_Source_List_File.Default then
6011 Location := Excluded_Source_List_File.Location;
6014 Source_File_Path_Name : constant String :=
6017 (Excluded_Source_List_File.Value),
6018 Project.Project.Directory.Name);
6021 if Source_File_Path_Name'Length = 0 then
6022 Err_Vars.Error_Msg_File_1 :=
6023 File_Name_Type (Excluded_Source_List_File.Value);
6026 "file with excluded sources { does not exist",
6027 Excluded_Source_List_File.Location, Project.Project);
6032 Prj.Util.Open (File, Source_File_Path_Name);
6034 if not Prj.Util.Is_Valid (File) then
6036 (Data.Flags, "file does not exist",
6037 Location, Project.Project);
6039 -- Read the lines one by one
6041 while not Prj.Util.End_Of_File (File) loop
6042 Prj.Util.Get_Line (File, Line, Last);
6044 -- Non empty, non comment line should contain a file name
6047 and then (Last = 1 or else Line (1 .. 2) /= "--")
6050 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6051 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6054 -- Check that there is no directory information
6056 for J in 1 .. Last loop
6058 or else Line (J) = Directory_Separator
6060 Error_Msg_File_1 := Name;
6063 "file name cannot include " &
6064 "directory information ({)",
6065 Location, Project.Project);
6070 Excluded_Sources_Htable.Set
6071 (Project.Excluded, Name, (Name, False, Location));
6075 Prj.Util.Close (File);
6080 end Find_Excluded_Sources;
6086 procedure Find_Sources
6087 (Project : in out Project_Processing_Data;
6088 Data : in out Tree_Processing_Data)
6090 Sources : constant Variable_Value :=
6093 Project.Project.Decl.Attributes,
6096 Source_List_File : constant Variable_Value :=
6098 (Name_Source_List_File,
6099 Project.Project.Decl.Attributes,
6102 Name_Loc : Name_Location;
6103 Has_Explicit_Sources : Boolean;
6106 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6108 (Source_List_File.Kind = Single,
6109 "Source_List_File is not a single string");
6111 Project.Source_List_File_Location := Source_List_File.Location;
6113 -- If the user has specified a Source_Files attribute
6115 if not Sources.Default then
6116 if not Source_List_File.Default then
6119 "?both attributes source_files and " &
6120 "source_list_file are present",
6121 Source_List_File.Location, Project.Project);
6124 -- Sources is a list of file names
6127 Current : String_List_Id := Sources.Values;
6128 Element : String_Element;
6129 Location : Source_Ptr;
6130 Name : File_Name_Type;
6133 if Current = Nil_String then
6134 Project.Project.Languages := No_Language_Index;
6136 -- This project contains no source. For projects that don't
6137 -- extend other projects, this also means that there is no
6138 -- need for an object directory, if not specified.
6140 if Project.Project.Extends = No_Project
6141 and then Project.Project.Object_Directory =
6142 Project.Project.Directory
6144 Project.Project.Object_Directory := No_Path_Information;
6148 while Current /= Nil_String loop
6149 Element := Data.Tree.String_Elements.Table (Current);
6150 Name := Canonical_Case_File_Name (Element.Value);
6151 Get_Name_String (Element.Value);
6153 -- If the element has no location, then use the location of
6154 -- Sources to report possible errors.
6156 if Element.Location = No_Location then
6157 Location := Sources.Location;
6159 Location := Element.Location;
6162 -- Check that there is no directory information
6164 for J in 1 .. Name_Len loop
6165 if Name_Buffer (J) = '/'
6166 or else Name_Buffer (J) = Directory_Separator
6168 Error_Msg_File_1 := Name;
6171 "file name cannot include directory " &
6173 Location, Project.Project);
6178 -- Check whether the file is already there: the same file name
6179 -- may be in the list. If the source is missing, the error will
6180 -- be on the first mention of the source file name.
6182 Name_Loc := Source_Names_Htable.Get
6183 (Project.Source_Names, Name);
6185 if Name_Loc = No_Name_Location then
6188 Location => Location,
6189 Source => No_Source,
6191 Source_Names_Htable.Set
6192 (Project.Source_Names, Name, Name_Loc);
6195 Current := Element.Next;
6198 Has_Explicit_Sources := True;
6201 -- If we have no Source_Files attribute, check the Source_List_File
6204 elsif not Source_List_File.Default then
6206 -- Source_List_File is the name of the file that contains the source
6210 Source_File_Path_Name : constant String :=
6212 (File_Name_Type (Source_List_File.Value),
6213 Project.Project.Directory.Name);
6216 Has_Explicit_Sources := True;
6218 if Source_File_Path_Name'Length = 0 then
6219 Err_Vars.Error_Msg_File_1 :=
6220 File_Name_Type (Source_List_File.Value);
6223 "file with sources { does not exist",
6224 Source_List_File.Location, Project.Project);
6227 Get_Sources_From_File
6228 (Source_File_Path_Name, Source_List_File.Location,
6234 -- Neither Source_Files nor Source_List_File has been specified. Find
6235 -- all the files that satisfy the naming scheme in all the source
6238 Has_Explicit_Sources := False;
6244 For_All_Sources => Sources.Default and then Source_List_File.Default);
6246 -- Check if all exceptions have been found
6250 Iter : Source_Iterator;
6253 Iter := For_Each_Source (Data.Tree, Project.Project);
6255 Source := Prj.Element (Iter);
6256 exit when Source = No_Source;
6258 if Source.Naming_Exception
6259 and then Source.Path = No_Path_Information
6261 if Source.Unit /= No_Unit_Index then
6263 -- For multi-unit source files, source_id gets duplicated
6264 -- once for every unit. Only the first source_id got its
6265 -- full path set. So if it isn't set for that first one,
6266 -- the file wasn't found. Otherwise we need to update for
6267 -- units after the first one.
6270 or else Source.Index = 1
6272 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6273 Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
6276 "source file %% for unit %% not found",
6277 No_Location, Project.Project);
6280 Source.Path := Files_Htable.Get
6281 (Data.File_To_Source, Source.File).Path;
6283 if Current_Verbosity = High then
6284 if Source.Path /= No_Path_Information then
6285 Write_Line ("Setting full path for "
6286 & Get_Name_String (Source.File)
6287 & " at" & Source.Index'Img
6289 & Get_Name_String (Source.Path.Name));
6295 if Source.Path = No_Path_Information then
6296 Remove_Source (Source, No_Source);
6304 -- It is an error if a source file name in a source list or in a source
6305 -- list file is not found.
6307 if Has_Explicit_Sources then
6310 First_Error : Boolean;
6313 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6314 First_Error := True;
6315 while NL /= No_Name_Location loop
6316 if not NL.Found then
6317 Err_Vars.Error_Msg_File_1 := NL.Name;
6322 "source file { not found",
6323 NL.Location, Project.Project);
6324 First_Error := False;
6329 "\source file { not found",
6330 NL.Location, Project.Project);
6334 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6344 procedure Initialize
6345 (Data : out Tree_Processing_Data;
6346 Tree : Project_Tree_Ref;
6347 Flags : Prj.Processing_Flags)
6350 Files_Htable.Reset (Data.File_To_Source);
6352 Data.Flags := Flags;
6359 procedure Free (Data : in out Tree_Processing_Data) is
6361 Files_Htable.Reset (Data.File_To_Source);
6368 procedure Initialize
6369 (Data : in out Project_Processing_Data;
6370 Project : Project_Id)
6373 Data.Project := Project;
6380 procedure Free (Data : in out Project_Processing_Data) is
6382 Source_Names_Htable.Reset (Data.Source_Names);
6383 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6384 Excluded_Sources_Htable.Reset (Data.Excluded);
6387 -------------------------------
6388 -- Check_File_Naming_Schemes --
6389 -------------------------------
6391 procedure Check_File_Naming_Schemes
6392 (In_Tree : Project_Tree_Ref;
6393 Project : Project_Processing_Data;
6394 File_Name : File_Name_Type;
6395 Alternate_Languages : out Language_List;
6396 Language : out Language_Ptr;
6397 Display_Language_Name : out Name_Id;
6399 Lang_Kind : out Language_Kind;
6400 Kind : out Source_Kind)
6402 Filename : constant String := Get_Name_String (File_Name);
6403 Config : Language_Config;
6404 Tmp_Lang : Language_Ptr;
6406 Header_File : Boolean := False;
6407 -- True if we found at least one language for which the file is a header
6408 -- In such a case, we search for all possible languages where this is
6409 -- also a header (C and C++ for instance), since the file might be used
6410 -- for several such languages.
6412 procedure Check_File_Based_Lang;
6413 -- Does the naming scheme test for file-based languages. For those,
6414 -- there is no Unit. Just check if the file name has the implementation
6415 -- or, if it is specified, the template suffix of the language.
6417 -- Returns True if the file belongs to the current language and we
6418 -- should stop searching for matching languages. Not that a given header
6419 -- file could belong to several languages (C and C++ for instance). Thus
6420 -- if we found a header we'll check whether it matches other languages.
6422 ---------------------------
6423 -- Check_File_Based_Lang --
6424 ---------------------------
6426 procedure Check_File_Based_Lang is
6429 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6433 Language := Tmp_Lang;
6435 if Current_Verbosity = High then
6436 Write_Str (" implementation of language ");
6437 Write_Line (Get_Name_String (Display_Language_Name));
6440 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6441 if Current_Verbosity = High then
6442 Write_Str (" header of language ");
6443 Write_Line (Get_Name_String (Display_Language_Name));
6447 Alternate_Languages := new Language_List_Element'
6448 (Language => Language,
6449 Next => Alternate_Languages);
6452 Header_File := True;
6455 Language := Tmp_Lang;
6458 end Check_File_Based_Lang;
6460 -- Start of processing for Check_File_Naming_Schemes
6463 Language := No_Language_Index;
6464 Alternate_Languages := null;
6465 Display_Language_Name := No_Name;
6467 Lang_Kind := File_Based;
6470 Tmp_Lang := Project.Project.Languages;
6471 while Tmp_Lang /= No_Language_Index loop
6472 if Current_Verbosity = High then
6474 (" Testing language "
6475 & Get_Name_String (Tmp_Lang.Name)
6476 & " Header_File=" & Header_File'Img);
6479 Display_Language_Name := Tmp_Lang.Display_Name;
6480 Config := Tmp_Lang.Config;
6481 Lang_Kind := Config.Kind;
6485 Check_File_Based_Lang;
6486 exit when Kind = Impl;
6490 -- We know it belongs to a least a file_based language, no
6491 -- need to check unit-based ones.
6493 if not Header_File then
6495 (File_Name => File_Name,
6496 Naming => Config.Naming_Data,
6500 In_Tree => In_Tree);
6502 if Unit /= No_Name then
6503 Language := Tmp_Lang;
6509 Tmp_Lang := Tmp_Lang.Next;
6512 if Language = No_Language_Index
6513 and then Current_Verbosity = High
6515 Write_Line (" not a source of any language");
6517 end Check_File_Naming_Schemes;
6523 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6525 -- If the file was previously already associated with a unit, change it
6527 if Source.Unit /= null
6528 and then Source.Kind in Spec_Or_Body
6529 and then Source.Unit.File_Names (Source.Kind) /= null
6531 -- If we had another file referencing the same unit (for instance it
6532 -- was in an extended project), that source file is in fact invisible
6533 -- from now on, and in particular doesn't belong to the same unit.
6535 if Source.Unit.File_Names (Source.Kind) /= Source then
6536 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6539 Source.Unit.File_Names (Source.Kind) := null;
6542 Source.Kind := Kind;
6544 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6545 Source.Unit.File_Names (Source.Kind) := Source;
6553 procedure Check_File
6554 (Project : in out Project_Processing_Data;
6555 Data : in out Tree_Processing_Data;
6556 Path : Path_Name_Type;
6557 File_Name : File_Name_Type;
6558 Display_File_Name : File_Name_Type;
6559 Locally_Removed : Boolean;
6560 For_All_Sources : Boolean)
6562 Canonical_Path : constant Path_Name_Type :=
6564 (Canonical_Case_File_Name (Name_Id (Path)));
6566 Name_Loc : Name_Location :=
6567 Source_Names_Htable.Get
6568 (Project.Source_Names, File_Name);
6569 Check_Name : Boolean := False;
6570 Alternate_Languages : Language_List;
6571 Language : Language_Ptr;
6573 Src_Ind : Source_File_Index;
6575 Display_Language_Name : Name_Id;
6576 Lang_Kind : Language_Kind;
6577 Kind : Source_Kind := Spec;
6580 if Name_Loc = No_Name_Location then
6581 Check_Name := For_All_Sources;
6584 if Name_Loc.Found then
6586 -- Check if it is OK to have the same file name in several
6587 -- source directories.
6589 if not Project.Project.Known_Order_Of_Source_Dirs then
6590 Error_Msg_File_1 := File_Name;
6593 "{ is found in several source directories",
6594 Name_Loc.Location, Project.Project);
6598 Name_Loc.Found := True;
6600 Source_Names_Htable.Set
6601 (Project.Source_Names, File_Name, Name_Loc);
6603 if Name_Loc.Source = No_Source then
6607 Name_Loc.Source.Path := (Canonical_Path, Path);
6609 Source_Paths_Htable.Set
6610 (Data.Tree.Source_Paths_HT,
6614 -- Check if this is a subunit
6616 if Name_Loc.Source.Unit /= No_Unit_Index
6617 and then Name_Loc.Source.Kind = Impl
6619 Src_Ind := Sinput.P.Load_Project_File
6620 (Get_Name_String (Canonical_Path));
6622 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6623 Override_Kind (Name_Loc.Source, Sep);
6628 (Data.File_To_Source, File_Name, Name_Loc.Source);
6634 Check_File_Naming_Schemes
6635 (In_Tree => Data.Tree,
6637 File_Name => File_Name,
6638 Alternate_Languages => Alternate_Languages,
6639 Language => Language,
6640 Display_Language_Name => Display_Language_Name,
6642 Lang_Kind => Lang_Kind,
6645 if Language = No_Language_Index then
6647 -- A file name in a list must be a source of a language
6649 if Data.Flags.Error_On_Unknown_Language
6650 and then Name_Loc.Found
6652 Error_Msg_File_1 := File_Name;
6655 "language unknown for {",
6656 Name_Loc.Location, Project.Project);
6662 Project => Project.Project,
6663 Lang_Id => Language,
6666 Alternate_Languages => Alternate_Languages,
6667 File_Name => File_Name,
6668 Display_File => Display_File_Name,
6670 Locally_Removed => Locally_Removed,
6671 Path => (Canonical_Path, Path));
6676 ------------------------
6677 -- Search_Directories --
6678 ------------------------
6680 procedure Search_Directories
6681 (Project : in out Project_Processing_Data;
6682 Data : in out Tree_Processing_Data;
6683 For_All_Sources : Boolean)
6685 Source_Dir : String_List_Id;
6686 Element : String_Element;
6688 Name : String (1 .. 1_000);
6690 File_Name : File_Name_Type;
6691 Display_File_Name : File_Name_Type;
6694 if Current_Verbosity = High then
6695 Write_Line ("Looking for sources:");
6698 -- Loop through subdirectories
6700 Source_Dir := Project.Project.Source_Dirs;
6701 while Source_Dir /= Nil_String loop
6703 Element := Data.Tree.String_Elements.Table (Source_Dir);
6704 if Element.Value /= No_Name then
6705 Get_Name_String (Element.Display_Value);
6708 Source_Directory : constant String :=
6709 Name_Buffer (1 .. Name_Len) &
6710 Directory_Separator;
6712 Dir_Last : constant Natural :=
6713 Compute_Directory_Last
6717 if Current_Verbosity = High then
6718 Write_Attr ("Source_Dir", Source_Directory);
6721 -- We look to every entry in the source directory
6723 Open (Dir, Source_Directory);
6726 Read (Dir, Name, Last);
6730 -- ??? Duplicate system call here, we just did a a
6731 -- similar one. Maybe Ada.Directories would be more
6732 -- appropriate here.
6735 (Source_Directory & Name (1 .. Last))
6737 if Current_Verbosity = High then
6738 Write_Str (" Checking ");
6739 Write_Line (Name (1 .. Last));
6743 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6744 Display_File_Name := Name_Find;
6746 if Osint.File_Names_Case_Sensitive then
6747 File_Name := Display_File_Name;
6749 Canonical_Case_File_Name
6750 (Name_Buffer (1 .. Name_Len));
6751 File_Name := Name_Find;
6755 Path_Name : constant String :=
6760 (Source_Directory'First ..
6763 Opt.Follow_Links_For_Files,
6764 Case_Sensitive => True);
6765 -- Case_Sensitive set True (no folding)
6767 Path : Path_Name_Type;
6768 FF : File_Found := Excluded_Sources_Htable.Get
6769 (Project.Excluded, File_Name);
6770 To_Remove : Boolean := False;
6773 Name_Len := Path_Name'Length;
6774 Name_Buffer (1 .. Name_Len) := Path_Name;
6777 if FF /= No_File_Found then
6778 if not FF.Found then
6780 Excluded_Sources_Htable.Set
6781 (Project.Excluded, File_Name, FF);
6783 if Current_Verbosity = High then
6784 Write_Str (" excluded source """);
6785 Write_Str (Get_Name_String (File_Name));
6789 -- Will mark the file as removed, but we
6790 -- still need to add it to the list: if we
6791 -- don't, the file will not appear in the
6792 -- mapping file and will cause the compiler
6800 (Project => Project,
6803 File_Name => File_Name,
6804 Locally_Removed => To_Remove,
6805 Display_File_Name => Display_File_Name,
6806 For_All_Sources => For_All_Sources);
6816 when Directory_Error =>
6820 Source_Dir := Element.Next;
6823 if Current_Verbosity = High then
6824 Write_Line ("end Looking for sources.");
6826 end Search_Directories;
6828 ----------------------------
6829 -- Load_Naming_Exceptions --
6830 ----------------------------
6832 procedure Load_Naming_Exceptions
6833 (Project : in out Project_Processing_Data;
6834 Data : in out Tree_Processing_Data)
6837 Iter : Source_Iterator;
6840 Iter := For_Each_Source (Data.Tree, Project.Project);
6842 Source := Prj.Element (Iter);
6843 exit when Source = No_Source;
6845 -- An excluded file cannot also be an exception file name
6847 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
6850 Error_Msg_File_1 := Source.File;
6853 "{ cannot be both excluded and an exception file name",
6854 No_Location, Project.Project);
6857 if Current_Verbosity = High then
6858 Write_Str ("Naming exception: Putting source file ");
6859 Write_Str (Get_Name_String (Source.File));
6860 Write_Line (" in Source_Names");
6863 Source_Names_Htable.Set
6864 (Project.Source_Names,
6867 (Name => Source.File,
6868 Location => No_Location,
6872 -- If this is an Ada exception, record in table Unit_Exceptions
6874 if Source.Unit /= No_Unit_Index then
6876 Unit_Except : Unit_Exception :=
6877 Unit_Exceptions_Htable.Get
6878 (Project.Unit_Exceptions, Source.Unit.Name);
6881 Unit_Except.Name := Source.Unit.Name;
6883 if Source.Kind = Spec then
6884 Unit_Except.Spec := Source.File;
6886 Unit_Except.Impl := Source.File;
6889 Unit_Exceptions_Htable.Set
6890 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
6896 end Load_Naming_Exceptions;
6898 ----------------------
6899 -- Look_For_Sources --
6900 ----------------------
6902 procedure Look_For_Sources
6903 (Project : in out Project_Processing_Data;
6904 Data : in out Tree_Processing_Data)
6906 Object_Files : Object_File_Names_Htable.Instance;
6907 Iter : Source_Iterator;
6910 procedure Check_Object (Src : Source_Id);
6911 -- Check if object file name of Src is already used in the project tree,
6912 -- and report an error if so.
6914 procedure Check_Object_Files;
6915 -- Check that no two sources of this project have the same object file
6917 procedure Mark_Excluded_Sources;
6918 -- Mark as such the sources that are declared as excluded
6924 procedure Check_Object (Src : Source_Id) is
6928 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
6930 -- We cannot just check on "Source /= Src", since we might have
6931 -- two different entries for the same file (and since that's
6932 -- the same file it is expected that it has the same object)
6934 if Source /= No_Source
6935 and then Source.Path /= Src.Path
6937 Error_Msg_File_1 := Src.File;
6938 Error_Msg_File_2 := Source.File;
6941 "{ and { have the same object file name",
6942 No_Location, Project.Project);
6945 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
6949 ---------------------------
6950 -- Mark_Excluded_Sources --
6951 ---------------------------
6953 procedure Mark_Excluded_Sources is
6954 Source : Source_Id := No_Source;
6955 Excluded : File_Found;
6959 -- Minor optimization: if there are no excluded files, no need to
6960 -- traverse the list of sources. We cannot however also check whether
6961 -- the existing exceptions have ".Found" set to True (indicating we
6962 -- found them before) because we need to do some final processing on
6963 -- them in any case.
6965 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
6968 Proj := Project.Project;
6969 while Proj /= No_Project loop
6970 Iter := For_Each_Source (Data.Tree, Proj);
6971 while Prj.Element (Iter) /= No_Source loop
6972 Source := Prj.Element (Iter);
6973 Excluded := Excluded_Sources_Htable.Get
6974 (Project.Excluded, Source.File);
6976 if Excluded /= No_File_Found then
6977 Source.Locally_Removed := True;
6978 Source.In_Interfaces := False;
6980 if Current_Verbosity = High then
6981 Write_Str ("Removing file ");
6983 (Get_Name_String (Excluded.File)
6984 & " " & Get_Name_String (Source.Project.Name));
6987 Excluded_Sources_Htable.Remove
6988 (Project.Excluded, Source.File);
6994 Proj := Proj.Extends;
6998 -- If we have any excluded element left, that means we did not find
7001 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7002 while Excluded /= No_File_Found loop
7003 if not Excluded.Found then
7005 -- Check if the file belongs to another imported project to
7006 -- provide a better error message.
7009 (In_Tree => Data.Tree,
7010 Project => Project.Project,
7011 In_Imported_Only => True,
7012 Base_Name => Excluded.File);
7014 Err_Vars.Error_Msg_File_1 := Excluded.File;
7016 if Src = No_Source then
7019 "unknown file {", Excluded.Location, Project.Project);
7023 "cannot remove a source from an imported project: {",
7024 Excluded.Location, Project.Project);
7028 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7030 end Mark_Excluded_Sources;
7032 ------------------------
7033 -- Check_Object_Files --
7034 ------------------------
7036 procedure Check_Object_Files is
7037 Iter : Source_Iterator;
7039 Src_Ind : Source_File_Index;
7042 Iter := For_Each_Source (Data.Tree);
7044 Src_Id := Prj.Element (Iter);
7045 exit when Src_Id = No_Source;
7047 if Is_Compilable (Src_Id)
7048 and then Src_Id.Language.Config.Object_Generated
7049 and then Is_Extending (Project.Project, Src_Id.Project)
7051 if Src_Id.Unit = No_Unit_Index then
7052 if Src_Id.Kind = Impl then
7053 Check_Object (Src_Id);
7059 if Other_Part (Src_Id) = No_Source then
7060 Check_Object (Src_Id);
7067 if Other_Part (Src_Id) /= No_Source then
7068 Check_Object (Src_Id);
7071 -- Check if it is a subunit
7074 Sinput.P.Load_Project_File
7075 (Get_Name_String (Src_Id.Path.Name));
7077 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7078 Override_Kind (Src_Id, Sep);
7080 Check_Object (Src_Id);
7089 end Check_Object_Files;
7091 -- Start of processing for Look_For_Sources
7094 Find_Excluded_Sources (Project, Data);
7096 if Project.Project.Languages /= No_Language_Index then
7097 Load_Naming_Exceptions (Project, Data);
7098 Find_Sources (Project, Data);
7099 Mark_Excluded_Sources;
7103 Object_File_Names_Htable.Reset (Object_Files);
7104 end Look_For_Sources;
7110 function Path_Name_Of
7111 (File_Name : File_Name_Type;
7112 Directory : Path_Name_Type) return String
7114 Result : String_Access;
7115 The_Directory : constant String := Get_Name_String (Directory);
7118 Get_Name_String (File_Name);
7121 (File_Name => Name_Buffer (1 .. Name_Len),
7122 Path => The_Directory);
7124 if Result = null then
7128 R : String := Result.all;
7131 Canonical_Case_File_Name (R);
7141 procedure Remove_Source
7143 Replaced_By : Source_Id)
7148 if Current_Verbosity = High then
7149 Write_Str ("Removing source ");
7150 Write_Line (Get_Name_String (Id.File) & " at" & Id.Index'Img);
7153 if Replaced_By /= No_Source then
7154 Id.Replaced_By := Replaced_By;
7155 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7158 Id.In_Interfaces := False;
7159 Id.Locally_Removed := True;
7161 -- ??? Should we remove the source from the unit ? The file is not used,
7162 -- so probably should not be referenced from the unit. On the other hand
7163 -- it might give useful additional info
7164 -- if Id.Unit /= null then
7165 -- Id.Unit.File_Names (Id.Kind) := null;
7168 Source := Id.Language.First_Source;
7171 Id.Language.First_Source := Id.Next_In_Lang;
7174 while Source.Next_In_Lang /= Id loop
7175 Source := Source.Next_In_Lang;
7178 Source.Next_In_Lang := Id.Next_In_Lang;
7182 -----------------------
7183 -- Report_No_Sources --
7184 -----------------------
7186 procedure Report_No_Sources
7187 (Project : Project_Id;
7189 Data : Tree_Processing_Data;
7190 Location : Source_Ptr;
7191 Continuation : Boolean := False)
7194 case Data.Flags.When_No_Sources is
7198 when Warning | Error =>
7200 Msg : constant String :=
7203 " sources in this project";
7206 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7208 if Continuation then
7209 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7211 Error_Msg (Data.Flags, Msg, Location, Project);
7215 end Report_No_Sources;
7217 ----------------------
7218 -- Show_Source_Dirs --
7219 ----------------------
7221 procedure Show_Source_Dirs
7222 (Project : Project_Id;
7223 In_Tree : Project_Tree_Ref)
7225 Current : String_List_Id;
7226 Element : String_Element;
7229 Write_Line ("Source_Dirs:");
7231 Current := Project.Source_Dirs;
7232 while Current /= Nil_String loop
7233 Element := In_Tree.String_Elements.Table (Current);
7235 Write_Line (Get_Name_String (Element.Value));
7236 Current := Element.Next;
7239 Write_Line ("end Source_Dirs.");
7240 end Show_Source_Dirs;
7242 ---------------------------
7243 -- Process_Naming_Scheme --
7244 ---------------------------
7246 procedure Process_Naming_Scheme
7247 (Tree : Project_Tree_Ref;
7248 Root_Project : Project_Id;
7249 Flags : Processing_Flags)
7251 procedure Recursive_Check
7252 (Project : Project_Id;
7253 Data : in out Tree_Processing_Data);
7254 -- Check_Naming_Scheme for the project
7256 ---------------------
7257 -- Recursive_Check --
7258 ---------------------
7260 procedure Recursive_Check
7261 (Project : Project_Id;
7262 Data : in out Tree_Processing_Data)
7265 if Verbose_Mode then
7266 Write_Str ("Processing_Naming_Scheme for project """);
7267 Write_Str (Get_Name_String (Project.Name));
7271 Prj.Nmsc.Check (Project, Data);
7272 end Recursive_Check;
7274 procedure Check_All_Projects is new
7275 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
7277 Data : Tree_Processing_Data;
7279 -- Start of processing for Process_Naming_Scheme
7281 Initialize (Data, Tree => Tree, Flags => Flags);
7282 Check_All_Projects (Root_Project, Data, Imported_First => True);
7284 end Process_Naming_Scheme;