1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2000-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars; use Err_Vars;
28 with Osint; use Osint;
29 with Output; use Output;
31 with Prj.Env; use Prj.Env;
32 with Prj.Err; use Prj.Err;
33 with Prj.Tree; use Prj.Tree;
34 with Prj.Util; use Prj.Util;
36 with Snames; use Snames;
37 with Targparm; use Targparm;
39 with Ada.Characters.Handling; use Ada.Characters.Handling;
40 with Ada.Directories; use Ada.Directories;
41 with Ada.Strings; use Ada.Strings;
42 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
43 with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
45 with GNAT.Case_Util; use GNAT.Case_Util;
46 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
47 with GNAT.Dynamic_HTables;
48 with GNAT.Regexp; use GNAT.Regexp;
51 package body Prj.Nmsc is
53 No_Continuation_String : aliased String := "";
54 Continuation_String : aliased String := "\";
55 -- Used in Check_Library for continuation error messages at the same
58 type Name_Location is record
59 Name : File_Name_Type;
60 -- Key is duplicated, so that it is known when using functions Get_First
61 -- and Get_Next, as these functions only return an Element.
63 Location : Source_Ptr;
64 Source : Source_Id := No_Source;
65 Listed : Boolean := False;
66 Found : Boolean := False;
69 No_Name_Location : constant Name_Location :=
71 Location => No_Location,
76 package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
77 (Header_Num => Header_Num,
78 Element => Name_Location,
79 No_Element => No_Name_Location,
80 Key => File_Name_Type,
83 -- File name information found in string list attribute (Source_Files or
84 -- Source_List_File). Except is set to True if source is a naming exception
85 -- in the project. Used to check that all referenced files were indeed
88 type Unit_Exception is record
90 -- Key is duplicated, so that it is known when using functions Get_First
91 -- and Get_Next, as these functions only return an Element.
93 Spec : File_Name_Type;
94 Impl : File_Name_Type;
97 No_Unit_Exception : constant Unit_Exception := (No_Name, No_File, No_File);
99 package Unit_Exceptions_Htable is new GNAT.Dynamic_HTables.Simple_HTable
100 (Header_Num => Header_Num,
101 Element => Unit_Exception,
102 No_Element => No_Unit_Exception,
106 -- Record special naming schemes for Ada units (name of spec file and name
107 -- of implementation file). The elements in this list come from the naming
108 -- exceptions specified in the project files.
110 type File_Found is record
111 File : File_Name_Type := No_File;
112 Excl_File : File_Name_Type := No_File;
113 Excl_Line : Natural := 0;
114 Found : Boolean := False;
115 Location : Source_Ptr := No_Location;
118 No_File_Found : constant File_Found :=
119 (No_File, No_File, 0, False, No_Location);
121 package Excluded_Sources_Htable is new GNAT.Dynamic_HTables.Simple_HTable
122 (Header_Num => Header_Num,
123 Element => File_Found,
124 No_Element => No_File_Found,
125 Key => File_Name_Type,
128 -- A hash table to store the base names of excluded files, if any
130 package Object_File_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
131 (Header_Num => Header_Num,
132 Element => Source_Id,
133 No_Element => No_Source,
134 Key => File_Name_Type,
137 -- A hash table to store the object file names for a project, to check that
138 -- two different sources have different object file names.
140 type Project_Processing_Data is record
141 Project : Project_Id;
142 Source_Names : Source_Names_Htable.Instance;
143 Unit_Exceptions : Unit_Exceptions_Htable.Instance;
144 Excluded : Excluded_Sources_Htable.Instance;
146 Source_List_File_Location : Source_Ptr;
147 -- Location of the Source_List_File attribute, for error messages
149 -- This is similar to Tree_Processing_Data, but contains project-specific
150 -- information which is only useful while processing the project, and can
151 -- be discarded as soon as we have finished processing the project
153 type Tree_Processing_Data is record
154 Tree : Project_Tree_Ref;
155 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
156 Flags : Prj.Processing_Flags;
158 -- Temporary data which is needed while parsing a project. It does not need
159 -- to be kept in memory once a project has been fully loaded, but is
160 -- necessary while performing consistency checks (duplicate sources,...)
161 -- This data must be initialized before processing any project, and the
162 -- same data is used for processing all projects in the tree.
164 type Lib_Data is record
169 package Lib_Data_Table is new GNAT.Table
170 (Table_Component_Type => Lib_Data,
171 Table_Index_Type => Natural,
172 Table_Low_Bound => 1,
174 Table_Increment => 100);
175 -- A table to record library names in order to check that two library
176 -- projects do not have the same library names.
179 (Data : out Tree_Processing_Data;
180 Tree : Project_Tree_Ref;
181 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
182 Flags : Prj.Processing_Flags);
185 procedure Free (Data : in out Tree_Processing_Data);
186 -- Free the memory occupied by Data
189 (Project : Project_Id;
190 Data : in out Tree_Processing_Data);
191 -- Process the naming scheme for a single project
194 (Data : in out Project_Processing_Data;
195 Project : Project_Id);
196 procedure Free (Data : in out Project_Processing_Data);
197 -- Initialize or free memory for a project-specific data
199 procedure Find_Excluded_Sources
200 (Project : in out Project_Processing_Data;
201 Data : in out Tree_Processing_Data);
202 -- Find the list of files that should not be considered as source files
203 -- for this project. Sets the list in the Project.Excluded_Sources_Htable.
205 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
206 -- Override the reference kind for a source file. This properly updates
207 -- the unit data if necessary.
209 procedure Load_Naming_Exceptions
210 (Project : in out Project_Processing_Data;
211 Data : in out Tree_Processing_Data);
212 -- All source files in Data.First_Source are considered as naming
213 -- exceptions, and copied into the Source_Names and Unit_Exceptions tables
216 type Search_Type is (Search_Files, Search_Directories);
219 with procedure Callback
220 (Path : Path_Information;
221 Pattern_Index : Natural);
222 procedure Expand_Subdirectory_Pattern
223 (Project : Project_Id;
224 Data : in out Tree_Processing_Data;
225 Patterns : String_List_Id;
226 Ignore : String_List_Id;
227 Search_For : Search_Type;
228 Resolve_Links : Boolean);
229 -- Search the subdirectories of Project's directory for files or
230 -- directories that match the globbing patterns found in Patterns (for
231 -- instance "**/*.adb"). Typically, Patterns will be the value of the
232 -- Source_Dirs or Excluded_Source_Dirs attributes.
234 -- Every time such a file or directory is found, the callback is called.
235 -- Resolve_Links indicates whether we should resolve links while
236 -- normalizing names.
238 -- In the callback, Pattern_Index is the index within Patterns where the
239 -- expanded pattern was found (1 for the first element of Patterns and
240 -- all its matching directories, then 2,...).
242 -- We use a generic and not an access-to-subprogram because in some cases
243 -- this code is compiled with the restriction No_Implicit_Dynamic_Code.
244 -- An error message is raised if a pattern does not match any file.
248 Data : in out Tree_Processing_Data;
249 Project : Project_Id;
250 Source_Dir_Rank : Natural;
251 Lang_Id : Language_Ptr;
253 File_Name : File_Name_Type;
254 Display_File : File_Name_Type;
255 Naming_Exception : Boolean := False;
256 Path : Path_Information := No_Path_Information;
257 Alternate_Languages : Language_List := null;
258 Unit : Name_Id := No_Name;
260 Locally_Removed : Boolean := False;
261 Location : Source_Ptr := No_Location);
262 -- Add a new source to the different lists: list of all sources in the
263 -- project tree, list of source of a project and list of sources of a
264 -- language. If Path is specified, the file is also added to
265 -- Source_Paths_HT. Location is used for error messages
267 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type;
268 -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id.
269 -- This alters Name_Buffer.
271 function Suffix_Matches
273 Suffix : File_Name_Type) return Boolean;
274 -- True if the file name ends with the given suffix. Always returns False
275 -- if Suffix is No_Name.
277 procedure Replace_Into_Name_Buffer
280 Replacement : Character);
281 -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is
282 -- converted to lower-case at the same time.
284 procedure Check_Unit_Name (Name : String; Unit : out Name_Id);
285 -- Check that a name is a valid unit name
287 procedure Check_Package_Naming
288 (Project : Project_Id;
289 Data : in out Tree_Processing_Data);
290 -- Check the naming scheme part of Data, and initialize the naming scheme
291 -- data in the config of the various languages.
293 procedure Check_Configuration
294 (Project : Project_Id;
295 Data : in out Tree_Processing_Data);
296 -- Check the configuration attributes for the project
298 procedure Check_If_Externally_Built
299 (Project : Project_Id;
300 Data : in out Tree_Processing_Data);
301 -- Check attribute Externally_Built of project Project in project tree
302 -- Data.Tree and modify its data Data if it has the value "true".
304 procedure Check_Interfaces
305 (Project : Project_Id;
306 Data : in out Tree_Processing_Data);
307 -- If a list of sources is specified in attribute Interfaces, set
308 -- In_Interfaces only for the sources specified in the list.
310 procedure Check_Library_Attributes
311 (Project : Project_Id;
312 Data : in out Tree_Processing_Data);
313 -- Check the library attributes of project Project in project tree
314 -- and modify its data Data accordingly.
316 procedure Check_Abstract_Project
317 (Project : Project_Id;
318 Data : in out Tree_Processing_Data);
319 -- Check abstract projects attributes
321 procedure Check_Programming_Languages
322 (Project : Project_Id;
323 Data : in out Tree_Processing_Data);
324 -- Check attribute Languages for the project with data Data in project
325 -- tree Data.Tree and set the components of Data for all the programming
326 -- languages indicated in attribute Languages, if any.
328 procedure Check_Stand_Alone_Library
329 (Project : Project_Id;
330 Data : in out Tree_Processing_Data);
331 -- Check if project Project in project tree Data.Tree is a Stand-Alone
332 -- Library project, and modify its data Data accordingly if it is one.
334 function Compute_Directory_Last (Dir : String) return Natural;
335 -- Return the index of the last significant character in Dir. This is used
336 -- to avoid duplicate '/' (slash) characters at the end of directory names.
338 procedure Search_Directories
339 (Project : in out Project_Processing_Data;
340 Data : in out Tree_Processing_Data;
341 For_All_Sources : Boolean);
342 -- Search the source directories to find the sources. If For_All_Sources is
343 -- True, check each regular file name against the naming schemes of the
344 -- various languages. Otherwise consider only the file names in hash table
345 -- Source_Names. If Allow_Duplicate_Basenames then files with identical
346 -- base names are permitted within a project for source-based languages
347 -- (never for unit based languages).
350 (Project : in out Project_Processing_Data;
351 Data : in out Tree_Processing_Data;
352 Source_Dir_Rank : Natural;
353 Path : Path_Name_Type;
354 Display_Path : Path_Name_Type;
355 File_Name : File_Name_Type;
356 Display_File_Name : File_Name_Type;
357 Locally_Removed : Boolean;
358 For_All_Sources : Boolean);
359 -- Check if file File_Name is a valid source of the project. This is used
360 -- in multi-language mode only. When the file matches one of the naming
361 -- schemes, it is added to various htables through Add_Source and to
362 -- Source_Paths_Htable.
364 -- File_Name is the same as Display_File_Name, but has been normalized.
365 -- They do not include the directory information.
367 -- Path and Display_Path on the other hand are the full path to the file.
368 -- Path must have been normalized (canonical casing and possibly links
371 -- Source_Directory is the directory in which the file was found. It is
372 -- neither normalized nor has had links resolved, and must not end with a
373 -- a directory separator, to avoid duplicates later on.
375 -- If For_All_Sources is True, then all possible file names are analyzed
376 -- otherwise only those currently set in the Source_Names hash table.
378 procedure Check_File_Naming_Schemes
379 (In_Tree : Project_Tree_Ref;
380 Project : Project_Processing_Data;
381 File_Name : File_Name_Type;
382 Alternate_Languages : out Language_List;
383 Language : out Language_Ptr;
384 Display_Language_Name : out Name_Id;
386 Lang_Kind : out Language_Kind;
387 Kind : out Source_Kind);
388 -- Check if the file name File_Name conforms to one of the naming schemes
389 -- of the project. If the file does not match one of the naming schemes,
390 -- set Language to No_Language_Index. Filename is the name of the file
391 -- being investigated. It has been normalized (case-folded). File_Name is
394 procedure Get_Directories
395 (Project : Project_Id;
396 Data : in out Tree_Processing_Data);
397 -- Get the object directory, the exec directory and the source directories
401 (Project : Project_Id;
402 Data : in out Tree_Processing_Data);
403 -- Get the mains of a project from attribute Main, if it exists, and put
404 -- them in the project data.
406 procedure Get_Sources_From_File
408 Location : Source_Ptr;
409 Project : in out Project_Processing_Data;
410 Data : in out Tree_Processing_Data);
411 -- Get the list of sources from a text file and put them in hash table
414 procedure Find_Sources
415 (Project : in out Project_Processing_Data;
416 Data : in out Tree_Processing_Data);
417 -- Process the Source_Files and Source_List_File attributes, and store the
418 -- list of source files into the Source_Names htable. When these attributes
419 -- are not defined, find all files matching the naming schemes in the
420 -- source directories. If Allow_Duplicate_Basenames, then files with the
421 -- same base names are authorized within a project for source-based
422 -- languages (never for unit based languages)
424 procedure Compute_Unit_Name
425 (File_Name : File_Name_Type;
426 Naming : Lang_Naming_Data;
427 Kind : out Source_Kind;
429 Project : Project_Processing_Data;
430 In_Tree : Project_Tree_Ref);
431 -- Check whether the file matches the naming scheme. If it does,
432 -- compute its unit name. If Unit is set to No_Name on exit, none of the
433 -- other out parameters are relevant.
435 procedure Check_Illegal_Suffix
436 (Project : Project_Id;
437 Suffix : File_Name_Type;
438 Dot_Replacement : File_Name_Type;
439 Attribute_Name : String;
440 Location : Source_Ptr;
441 Data : in out Tree_Processing_Data);
442 -- Display an error message if the given suffix is illegal for some reason.
443 -- The name of the attribute we are testing is specified in Attribute_Name,
444 -- which is used in the error message. Location is the location where the
445 -- suffix is defined.
447 procedure Locate_Directory
448 (Project : Project_Id;
449 Name : File_Name_Type;
450 Path : out Path_Information;
451 Dir_Exists : out Boolean;
452 Data : in out Tree_Processing_Data;
453 Create : String := "";
454 Location : Source_Ptr := No_Location;
455 Must_Exist : Boolean := True;
456 Externally_Built : Boolean := False);
457 -- Locate a directory. Name is the directory name. Relative paths are
458 -- resolved relative to the project's directory. If the directory does not
459 -- exist and Setup_Projects is True and Create is a non null string, an
460 -- attempt is made to create the directory. If the directory does not
461 -- exist, it is either created if Setup_Projects is False (and then
462 -- returned), or simply returned without checking for its existence (if
463 -- Must_Exist is False) or No_Path_Information is returned. In all cases,
464 -- Dir_Exists indicates whether the directory now exists. Create is also
465 -- used for debugging traces to show which path we are computing.
467 procedure Look_For_Sources
468 (Project : in out Project_Processing_Data;
469 Data : in out Tree_Processing_Data);
470 -- Find all the sources of project Project in project tree Data.Tree and
471 -- update its Data accordingly. This assumes that the special naming
472 -- exceptions have already been processed.
474 function Path_Name_Of
475 (File_Name : File_Name_Type;
476 Directory : Path_Name_Type) return String;
477 -- Returns the path name of a (non project) file. Returns an empty string
478 -- if file cannot be found.
480 procedure Remove_Source
481 (Tree : Project_Tree_Ref;
483 Replaced_By : Source_Id);
484 -- Remove a file from the list of sources of a project. This might be
485 -- because the file is replaced by another one in an extending project,
486 -- or because a file was added as a naming exception but was not found
489 procedure Report_No_Sources
490 (Project : Project_Id;
492 Data : Tree_Processing_Data;
493 Location : Source_Ptr;
494 Continuation : Boolean := False);
495 -- Report an error or a warning depending on the value of When_No_Sources
496 -- when there are no sources for language Lang_Name.
498 procedure Show_Source_Dirs
499 (Project : Project_Id;
500 Shared : Shared_Project_Tree_Data_Access);
501 -- List all the source directories of a project
503 procedure Write_Attr (Name, Value : String);
504 -- Debug print a value for a specific property. Does nothing when not in
507 procedure Error_Or_Warning
508 (Flags : Processing_Flags;
509 Kind : Error_Warning;
511 Location : Source_Ptr;
512 Project : Project_Id);
513 -- Emits either an error or warning message (or nothing), depending on Kind
515 function No_Space_Img (N : Natural) return String;
516 -- Image of a Natural without the initial space
518 ----------------------
519 -- Error_Or_Warning --
520 ----------------------
522 procedure Error_Or_Warning
523 (Flags : Processing_Flags;
524 Kind : Error_Warning;
526 Location : Source_Ptr;
527 Project : Project_Id) is
530 when Error => Error_Msg (Flags, Msg, Location, Project);
531 when Warning => Error_Msg (Flags, "?" & Msg, Location, Project);
534 end Error_Or_Warning;
536 ------------------------------
537 -- Replace_Into_Name_Buffer --
538 ------------------------------
540 procedure Replace_Into_Name_Buffer
543 Replacement : Character)
545 Max : constant Integer := Str'Last - Pattern'Length + 1;
552 while J <= Str'Last loop
553 Name_Len := Name_Len + 1;
556 and then Str (J .. J + Pattern'Length - 1) = Pattern
558 Name_Buffer (Name_Len) := Replacement;
559 J := J + Pattern'Length;
562 Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J));
566 end Replace_Into_Name_Buffer;
572 function Suffix_Matches
574 Suffix : File_Name_Type) return Boolean
576 Min_Prefix_Length : Natural := 0;
579 if Suffix = No_File or else Suffix = Empty_File then
584 Suf : String := Get_Name_String (Suffix);
587 -- On non case-sensitive systems, use proper suffix casing
589 Canonical_Case_File_Name (Suf);
591 -- The file name must end with the suffix (which is not an extension)
592 -- For instance a suffix "configure.in" must match a file with the
593 -- same name. To avoid dummy cases, though, a suffix starting with
594 -- '.' requires a file that is at least one character longer ('.cpp'
595 -- should not match a file with the same name).
597 if Suf (Suf'First) = '.' then
598 Min_Prefix_Length := 1;
601 return Filename'Length >= Suf'Length + Min_Prefix_Length
603 Filename (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
611 procedure Write_Attr (Name, Value : String) is
613 if Current_Verbosity = High then
614 Debug_Output (Name & " = """ & Value & '"');
624 Data : in out Tree_Processing_Data;
625 Project : Project_Id;
626 Source_Dir_Rank : Natural;
627 Lang_Id : Language_Ptr;
629 File_Name : File_Name_Type;
630 Display_File : File_Name_Type;
631 Naming_Exception : Boolean := False;
632 Path : Path_Information := No_Path_Information;
633 Alternate_Languages : Language_List := null;
634 Unit : Name_Id := No_Name;
636 Locally_Removed : Boolean := False;
637 Location : Source_Ptr := No_Location)
639 Config : constant Language_Config := Lang_Id.Config;
643 Prev_Unit : Unit_Index := No_Unit_Index;
644 Source_To_Replace : Source_Id := No_Source;
647 -- Check if the same file name or unit is used in the prj tree
651 if Unit /= No_Name then
652 Prev_Unit := Units_Htable.Get (Data.Tree.Units_HT, Unit);
655 if Prev_Unit /= No_Unit_Index
656 and then (Kind = Impl or else Kind = Spec)
657 and then Prev_Unit.File_Names (Kind) /= null
659 -- Suspicious, we need to check later whether this is authorized
662 Source := Prev_Unit.File_Names (Kind);
665 Source := Source_Files_Htable.Get
666 (Data.Tree.Source_Files_HT, File_Name);
668 if Source /= No_Source
669 and then Source.Index = Index
675 -- Duplication of file/unit in same project is allowed if order of
676 -- source directories is known, or if there is no compiler for the
679 if Add_Src = False then
682 if Project = Source.Project then
683 if Prev_Unit = No_Unit_Index then
684 if Data.Flags.Allow_Duplicate_Basenames then
687 elsif Lang_Id.Config.Compiler_Driver = Empty_File then
690 elsif Source_Dir_Rank /= Source.Source_Dir_Rank then
694 Error_Msg_File_1 := File_Name;
696 (Data.Flags, "duplicate source file name {",
702 if Source_Dir_Rank /= Source.Source_Dir_Rank then
705 -- We might be seeing the same file through a different path
706 -- (for instance because of symbolic links).
708 elsif Source.Path.Name /= Path.Name then
709 if not Source.Duplicate_Unit then
710 Error_Msg_Name_1 := Unit;
712 (Data.Flags, "\duplicate unit %%", Location, Project);
713 Source.Duplicate_Unit := True;
720 -- Do not allow the same unit name in different projects, except
721 -- if one is extending the other.
723 -- For a file based language, the same file name replaces a file
724 -- in a project being extended, but it is allowed to have the same
725 -- file name in unrelated projects.
727 elsif Is_Extending (Project, Source.Project) then
728 if not Locally_Removed then
729 Source_To_Replace := Source;
732 elsif Prev_Unit /= No_Unit_Index
733 and then Prev_Unit.File_Names (Kind) /= null
734 and then not Source.Locally_Removed
736 -- Path is set if this is a source we found on the disk, in which
737 -- case we can provide more explicit error message. Path is unset
738 -- when the source is added from one of the naming exceptions in
741 if Path /= No_Path_Information then
742 Error_Msg_Name_1 := Unit;
745 "unit %% cannot belong to several projects",
748 Error_Msg_Name_1 := Project.Name;
749 Error_Msg_Name_2 := Name_Id (Path.Display_Name);
751 (Data.Flags, "\ project %%, %%", Location, Project);
753 Error_Msg_Name_1 := Source.Project.Name;
754 Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
756 (Data.Flags, "\ project %%, %%", Location, Project);
759 Error_Msg_Name_1 := Unit;
760 Error_Msg_Name_2 := Source.Project.Name;
762 (Data.Flags, "unit %% already belongs to project %%",
768 elsif not Source.Locally_Removed
769 and then not Data.Flags.Allow_Duplicate_Basenames
770 and then Lang_Id.Config.Kind = Unit_Based
771 and then Source.Language.Config.Kind = Unit_Based
773 Error_Msg_File_1 := File_Name;
774 Error_Msg_File_2 := File_Name_Type (Source.Project.Name);
777 "{ is already a source of project {", Location, Project);
779 -- Add the file anyway, to avoid further warnings like "language
792 Id := new Source_Data;
794 if Current_Verbosity = High then
796 Write_Str ("adding source File: ");
797 Write_Str (Get_Name_String (Display_File));
800 Write_Str (" at" & Index'Img);
803 if Lang_Id.Config.Kind = Unit_Based then
804 Write_Str (" Unit: ");
806 -- ??? in gprclean, it seems we sometimes pass an empty Unit name
807 -- (see test extended_projects).
809 if Unit /= No_Name then
810 Write_Str (Get_Name_String (Unit));
813 Write_Str (" Kind: ");
814 Write_Str (Source_Kind'Image (Kind));
820 Id.Project := Project;
821 Id.Location := Location;
822 Id.Source_Dir_Rank := Source_Dir_Rank;
823 Id.Language := Lang_Id;
825 Id.Alternate_Languages := Alternate_Languages;
826 Id.Locally_Removed := Locally_Removed;
828 Id.File := File_Name;
829 Id.Display_File := Display_File;
830 Id.Dep_Name := Dependency_Name
831 (File_Name, Lang_Id.Config.Dependency_Kind);
832 Id.Naming_Exception := Naming_Exception;
833 Id.Object := Object_Name
834 (File_Name, Config.Object_File_Suffix);
835 Id.Switches := Switches_Name (File_Name);
837 -- Add the source id to the Unit_Sources_HT hash table, if the unit name
840 if Unit /= No_Name then
842 -- Note: we might be creating a dummy unit here, when we in fact have
843 -- a separate. For instance, file file-bar.adb will initially be
844 -- assumed to be the IMPL of unit "file.bar". Only later on (in
845 -- Check_Object_Files) will we parse those units that only have an
846 -- impl and no spec to make sure whether we have a Separate in fact
847 -- (that significantly reduces the number of times we need to parse
848 -- the files, since we are then only interested in those with no
849 -- spec). We still need those dummy units in the table, since that's
850 -- the name we find in the ALI file
852 UData := Units_Htable.Get (Data.Tree.Units_HT, Unit);
854 if UData = No_Unit_Index then
855 UData := new Unit_Data;
857 Units_Htable.Set (Data.Tree.Units_HT, Unit, UData);
862 -- Note that this updates Unit information as well
864 Override_Kind (Id, Kind);
867 if Path /= No_Path_Information then
869 Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id);
872 Id.Next_With_File_Name :=
873 Source_Files_Htable.Get (Data.Tree.Source_Files_HT, File_Name);
874 Source_Files_Htable.Set (Data.Tree.Source_Files_HT, File_Name, Id);
877 Project.Has_Multi_Unit_Sources := True;
880 -- Add the source to the language list
882 Id.Next_In_Lang := Lang_Id.First_Source;
883 Lang_Id.First_Source := Id;
885 if Source_To_Replace /= No_Source then
886 Remove_Source (Data.Tree, Source_To_Replace, Id);
889 if Data.Tree.Replaced_Source_Number > 0 and then
890 Replaced_Source_HTable.Get (Data.Tree.Replaced_Sources, Id.File) /=
893 Replaced_Source_HTable.Remove (Data.Tree.Replaced_Sources, Id.File);
894 Data.Tree.Replaced_Source_Number :=
895 Data.Tree.Replaced_Source_Number - 1;
899 ------------------------------
900 -- Canonical_Case_File_Name --
901 ------------------------------
903 function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is
905 if Osint.File_Names_Case_Sensitive then
906 return File_Name_Type (Name);
908 Get_Name_String (Name);
909 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
912 end Canonical_Case_File_Name;
914 ---------------------------------
915 -- Process_Aggregated_Projects --
916 ---------------------------------
918 procedure Process_Aggregated_Projects
919 (Tree : Project_Tree_Ref;
920 Project : Project_Id;
921 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
922 Flags : Processing_Flags)
924 Data : Tree_Processing_Data :=
926 Node_Tree => Node_Tree,
929 Project_Files : constant Prj.Variable_Value :=
931 (Snames.Name_Project_Files,
932 Project.Decl.Attributes,
935 Project_Path_For_Aggregate : Prj.Env.Project_Search_Path;
937 procedure Found_Project_File (Path : Path_Information; Rank : Natural);
938 -- Called for each project file aggregated by Project
940 procedure Expand_Project_Files is
941 new Expand_Subdirectory_Pattern (Callback => Found_Project_File);
942 -- Search for all project files referenced by the patterns given in
943 -- parameter. Calls Found_Project_File for each of them.
945 ------------------------
946 -- Found_Project_File --
947 ------------------------
949 procedure Found_Project_File (Path : Path_Information; Rank : Natural) is
950 pragma Unreferenced (Rank);
953 if Path.Name /= Project.Path.Name then
954 Debug_Output ("aggregates: ", Name_Id (Path.Display_Name));
956 -- For usual "with" statement, this phase will have been done when
957 -- parsing the project itself. However, for aggregate projects, we
958 -- can only do this when processing the aggregate project, since
959 -- the exact list of project files or project directories can
960 -- depend on scenario variables.
962 -- We only load the projects explicitly here, but do not process
963 -- them. For the processing, Prj.Proc will take care of processing
964 -- them, within the same call to Recursive_Process (thus avoiding
965 -- the processing of a given project multiple times).
967 -- ??? We might already have loaded the project
969 Add_Aggregated_Project (Project, Path => Path.Name);
972 Debug_Output ("pattern returned the aggregate itself, ignored");
974 end Found_Project_File;
976 -- Start of processing for Check_Aggregate_Project
979 pragma Assert (Project.Qualifier = Aggregate);
981 if Project_Files.Default then
982 Error_Msg_Name_1 := Snames.Name_Project_Files;
985 "Attribute %% must be specified in aggregate project",
986 Project.Location, Project);
990 -- The aggregated projects are only searched relative to the directory
991 -- of the aggregate project, not in the default project path.
993 Initialize_Empty (Project_Path_For_Aggregate);
995 Free (Project.Aggregated_Projects);
997 -- Look for aggregated projects. For similarity with source files and
998 -- dirs, the aggregated project files are not searched for on the
999 -- project path, and are only found through the path specified in
1000 -- the Project_Files attribute.
1002 Expand_Project_Files
1003 (Project => Project,
1005 Patterns => Project_Files.Values,
1006 Ignore => Nil_String,
1007 Search_For => Search_Files,
1008 Resolve_Links => Opt.Follow_Links_For_Files);
1010 Free (Project_Path_For_Aggregate);
1011 end Process_Aggregated_Projects;
1013 ----------------------------
1014 -- Check_Abstract_Project --
1015 ----------------------------
1017 procedure Check_Abstract_Project
1018 (Project : Project_Id;
1019 Data : in out Tree_Processing_Data)
1021 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
1023 Source_Dirs : constant Variable_Value :=
1026 Project.Decl.Attributes, Shared);
1027 Source_Files : constant Variable_Value :=
1030 Project.Decl.Attributes, Shared);
1031 Source_List_File : constant Variable_Value :=
1033 (Name_Source_List_File,
1034 Project.Decl.Attributes, Shared);
1035 Languages : constant Variable_Value :=
1038 Project.Decl.Attributes, Shared);
1041 if Project.Source_Dirs /= Nil_String then
1042 if Source_Dirs.Values = Nil_String
1043 and then Source_Files.Values = Nil_String
1044 and then Languages.Values = Nil_String
1045 and then Source_List_File.Default
1047 Project.Source_Dirs := Nil_String;
1052 "at least one of Source_Files, Source_Dirs or Languages "
1053 & "must be declared empty for an abstract project",
1054 Project.Location, Project);
1057 end Check_Abstract_Project;
1064 (Project : Project_Id;
1065 Data : in out Tree_Processing_Data)
1067 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
1068 Prj_Data : Project_Processing_Data;
1071 Debug_Increase_Indent ("check", Project.Name);
1073 Initialize (Prj_Data, Project);
1075 Check_If_Externally_Built (Project, Data);
1077 if Project.Qualifier /= Aggregate then
1078 Get_Directories (Project, Data);
1079 Check_Programming_Languages (Project, Data);
1081 if Current_Verbosity = High then
1082 Show_Source_Dirs (Project, Shared);
1086 case Project.Qualifier is
1087 when Dry => Check_Abstract_Project (Project, Data);
1088 when others => null;
1091 -- Check configuration. This must be done even for gnatmake (even though
1092 -- no user configuration file was provided) since the default config we
1093 -- generate indicates whether libraries are supported for instance.
1095 Check_Configuration (Project, Data);
1097 if Project.Qualifier /= Aggregate then
1098 Check_Library_Attributes (Project, Data);
1099 Check_Package_Naming (Project, Data);
1100 Look_For_Sources (Prj_Data, Data);
1101 Check_Interfaces (Project, Data);
1103 if Project.Library then
1104 Check_Stand_Alone_Library (Project, Data);
1107 Get_Mains (Project, Data);
1112 Debug_Decrease_Indent ("done check");
1115 ---------------------
1116 -- Check_Unit_Name --
1117 ---------------------
1119 procedure Check_Unit_Name (Name : String; Unit : out Name_Id) is
1120 The_Name : String := Name;
1121 Real_Name : Name_Id;
1122 Need_Letter : Boolean := True;
1123 Last_Underscore : Boolean := False;
1124 OK : Boolean := The_Name'Length > 0;
1127 function Is_Reserved (Name : Name_Id) return Boolean;
1128 function Is_Reserved (S : String) return Boolean;
1129 -- Check that the given name is not an Ada 95 reserved word. The reason
1130 -- for the Ada 95 here is that we do not want to exclude the case of an
1131 -- Ada 95 unit called Interface (for example). In Ada 2005, such a unit
1132 -- name would be rejected anyway by the compiler. That means there is no
1133 -- requirement that the project file parser reject this.
1139 function Is_Reserved (S : String) return Boolean is
1142 Add_Str_To_Name_Buffer (S);
1143 return Is_Reserved (Name_Find);
1150 function Is_Reserved (Name : Name_Id) return Boolean is
1152 if Get_Name_Table_Byte (Name) /= 0
1153 and then Name /= Name_Project
1154 and then Name /= Name_Extends
1155 and then Name /= Name_External
1156 and then Name not in Ada_2005_Reserved_Words
1159 Debug_Output ("Ada reserved word: ", Name);
1167 -- Start of processing for Check_Unit_Name
1170 To_Lower (The_Name);
1172 Name_Len := The_Name'Length;
1173 Name_Buffer (1 .. Name_Len) := The_Name;
1175 -- Special cases of children of packages A, G, I and S on VMS
1177 if OpenVMS_On_Target
1178 and then Name_Len > 3
1179 and then Name_Buffer (2 .. 3) = "__"
1181 ((Name_Buffer (1) = 'a') or else
1182 (Name_Buffer (1) = 'g') or else
1183 (Name_Buffer (1) = 'i') or else
1184 (Name_Buffer (1) = 's'))
1186 Name_Buffer (2) := '.';
1187 Name_Buffer (3 .. Name_Len - 1) := Name_Buffer (4 .. Name_Len);
1188 Name_Len := Name_Len - 1;
1191 Real_Name := Name_Find;
1193 if Is_Reserved (Real_Name) then
1197 First := The_Name'First;
1199 for Index in The_Name'Range loop
1202 -- We need a letter (at the beginning, and following a dot),
1203 -- but we don't have one.
1205 if Is_Letter (The_Name (Index)) then
1206 Need_Letter := False;
1211 if Current_Verbosity = High then
1213 Write_Int (Types.Int (Index));
1215 Write_Char (The_Name (Index));
1216 Write_Line ("' is not a letter.");
1222 elsif Last_Underscore
1223 and then (The_Name (Index) = '_' or else The_Name (Index) = '.')
1225 -- Two underscores are illegal, and a dot cannot follow
1230 if Current_Verbosity = High then
1232 Write_Int (Types.Int (Index));
1234 Write_Char (The_Name (Index));
1235 Write_Line ("' is illegal here.");
1240 elsif The_Name (Index) = '.' then
1242 -- First, check if the name before the dot is not a reserved word
1244 if Is_Reserved (The_Name (First .. Index - 1)) then
1250 -- We need a letter after a dot
1252 Need_Letter := True;
1254 elsif The_Name (Index) = '_' then
1255 Last_Underscore := True;
1258 -- We need an letter or a digit
1260 Last_Underscore := False;
1262 if not Is_Alphanumeric (The_Name (Index)) then
1265 if Current_Verbosity = High then
1267 Write_Int (Types.Int (Index));
1269 Write_Char (The_Name (Index));
1270 Write_Line ("' is not alphanumeric.");
1278 -- Cannot end with an underscore or a dot
1280 OK := OK and then not Need_Letter and then not Last_Underscore;
1283 if First /= Name'First and then
1284 Is_Reserved (The_Name (First .. The_Name'Last))
1292 -- Signal a problem with No_Name
1296 end Check_Unit_Name;
1298 -------------------------
1299 -- Check_Configuration --
1300 -------------------------
1302 procedure Check_Configuration
1303 (Project : Project_Id;
1304 Data : in out Tree_Processing_Data)
1306 Shared : constant Shared_Project_Tree_Data_Access :=
1309 Dot_Replacement : File_Name_Type := No_File;
1310 Casing : Casing_Type := All_Lower_Case;
1311 Separate_Suffix : File_Name_Type := No_File;
1313 Lang_Index : Language_Ptr := No_Language_Index;
1314 -- The index of the language data being checked
1316 Prev_Index : Language_Ptr := No_Language_Index;
1317 -- The index of the previous language
1319 procedure Process_Project_Level_Simple_Attributes;
1320 -- Process the simple attributes at the project level
1322 procedure Process_Project_Level_Array_Attributes;
1323 -- Process the associate array attributes at the project level
1325 procedure Process_Packages;
1326 -- Read the packages of the project
1328 ----------------------
1329 -- Process_Packages --
1330 ----------------------
1332 procedure Process_Packages is
1333 Packages : Package_Id;
1334 Element : Package_Element;
1336 procedure Process_Binder (Arrays : Array_Id);
1337 -- Process the associate array attributes of package Binder
1339 procedure Process_Builder (Attributes : Variable_Id);
1340 -- Process the simple attributes of package Builder
1342 procedure Process_Compiler (Arrays : Array_Id);
1343 -- Process the associate array attributes of package Compiler
1345 procedure Process_Naming (Attributes : Variable_Id);
1346 -- Process the simple attributes of package Naming
1348 procedure Process_Naming (Arrays : Array_Id);
1349 -- Process the associate array attributes of package Naming
1351 procedure Process_Linker (Attributes : Variable_Id);
1352 -- Process the simple attributes of package Linker of a
1353 -- configuration project.
1355 --------------------
1356 -- Process_Binder --
1357 --------------------
1359 procedure Process_Binder (Arrays : Array_Id) is
1360 Current_Array_Id : Array_Id;
1361 Current_Array : Array_Data;
1362 Element_Id : Array_Element_Id;
1363 Element : Array_Element;
1366 -- Process the associative array attribute of package Binder
1368 Current_Array_Id := Arrays;
1369 while Current_Array_Id /= No_Array loop
1370 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1372 Element_Id := Current_Array.Value;
1373 while Element_Id /= No_Array_Element loop
1374 Element := Shared.Array_Elements.Table (Element_Id);
1376 if Element.Index /= All_Other_Names then
1378 -- Get the name of the language
1381 Get_Language_From_Name
1382 (Project, Get_Name_String (Element.Index));
1384 if Lang_Index /= No_Language_Index then
1385 case Current_Array.Name is
1388 -- Attribute Driver (<language>)
1390 Lang_Index.Config.Binder_Driver :=
1391 File_Name_Type (Element.Value.Value);
1393 when Name_Required_Switches =>
1396 Lang_Index.Config.Binder_Required_Switches,
1397 From_List => Element.Value.Values,
1398 In_Tree => Data.Tree);
1402 -- Attribute Prefix (<language>)
1404 Lang_Index.Config.Binder_Prefix :=
1405 Element.Value.Value;
1407 when Name_Objects_Path =>
1409 -- Attribute Objects_Path (<language>)
1411 Lang_Index.Config.Objects_Path :=
1412 Element.Value.Value;
1414 when Name_Objects_Path_File =>
1416 -- Attribute Objects_Path (<language>)
1418 Lang_Index.Config.Objects_Path_File :=
1419 Element.Value.Value;
1427 Element_Id := Element.Next;
1430 Current_Array_Id := Current_Array.Next;
1434 ---------------------
1435 -- Process_Builder --
1436 ---------------------
1438 procedure Process_Builder (Attributes : Variable_Id) is
1439 Attribute_Id : Variable_Id;
1440 Attribute : Variable;
1443 -- Process non associated array attribute from package Builder
1445 Attribute_Id := Attributes;
1446 while Attribute_Id /= No_Variable loop
1447 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1449 if not Attribute.Value.Default then
1450 if Attribute.Name = Name_Executable_Suffix then
1452 -- Attribute Executable_Suffix: the suffix of the
1455 Project.Config.Executable_Suffix :=
1456 Attribute.Value.Value;
1460 Attribute_Id := Attribute.Next;
1462 end Process_Builder;
1464 ----------------------
1465 -- Process_Compiler --
1466 ----------------------
1468 procedure Process_Compiler (Arrays : Array_Id) is
1469 Current_Array_Id : Array_Id;
1470 Current_Array : Array_Data;
1471 Element_Id : Array_Element_Id;
1472 Element : Array_Element;
1473 List : String_List_Id;
1476 -- Process the associative array attribute of package Compiler
1478 Current_Array_Id := Arrays;
1479 while Current_Array_Id /= No_Array loop
1480 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1482 Element_Id := Current_Array.Value;
1483 while Element_Id /= No_Array_Element loop
1484 Element := Shared.Array_Elements.Table (Element_Id);
1486 if Element.Index /= All_Other_Names then
1488 -- Get the name of the language
1490 Lang_Index := Get_Language_From_Name
1491 (Project, Get_Name_String (Element.Index));
1493 if Lang_Index /= No_Language_Index then
1494 case Current_Array.Name is
1495 when Name_Dependency_Kind =>
1497 -- Attribute Dependency_Kind (<language>)
1499 Get_Name_String (Element.Value.Value);
1502 Lang_Index.Config.Dependency_Kind :=
1503 Dependency_File_Kind'Value
1504 (Name_Buffer (1 .. Name_Len));
1507 when Constraint_Error =>
1510 "illegal value for Dependency_Kind",
1511 Element.Value.Location,
1515 when Name_Dependency_Switches =>
1517 -- Attribute Dependency_Switches (<language>)
1519 if Lang_Index.Config.Dependency_Kind = None then
1520 Lang_Index.Config.Dependency_Kind := Makefile;
1523 List := Element.Value.Values;
1525 if List /= Nil_String then
1527 Lang_Index.Config.Dependency_Option,
1529 In_Tree => Data.Tree);
1532 when Name_Dependency_Driver =>
1534 -- Attribute Dependency_Driver (<language>)
1536 if Lang_Index.Config.Dependency_Kind = None then
1537 Lang_Index.Config.Dependency_Kind := Makefile;
1540 List := Element.Value.Values;
1542 if List /= Nil_String then
1544 Lang_Index.Config.Compute_Dependency,
1546 In_Tree => Data.Tree);
1549 when Name_Language_Kind =>
1550 -- Attribute Language_Kind (<language>)
1552 Get_Name_String (Element.Value.Value);
1555 Lang_Index.Config.Kind :=
1557 (Name_Buffer (1 .. Name_Len));
1560 when Constraint_Error =>
1563 "illegal value for Language_Kind",
1564 Element.Value.Location,
1568 when Name_Include_Switches =>
1570 -- Attribute Include_Switches (<language>)
1572 List := Element.Value.Values;
1574 if List = Nil_String then
1576 (Data.Flags, "include option cannot be null",
1577 Element.Value.Location, Project);
1580 Put (Into_List => Lang_Index.Config.Include_Option,
1582 In_Tree => Data.Tree);
1584 when Name_Include_Path =>
1586 -- Attribute Include_Path (<language>)
1588 Lang_Index.Config.Include_Path :=
1589 Element.Value.Value;
1591 when Name_Include_Path_File =>
1593 -- Attribute Include_Path_File (<language>)
1595 Lang_Index.Config.Include_Path_File :=
1596 Element.Value.Value;
1600 -- Attribute Driver (<language>)
1602 Lang_Index.Config.Compiler_Driver :=
1603 File_Name_Type (Element.Value.Value);
1605 when Name_Required_Switches |
1606 Name_Leading_Required_Switches =>
1609 Compiler_Leading_Required_Switches,
1610 From_List => Element.Value.Values,
1611 In_Tree => Data.Tree);
1613 when Name_Trailing_Required_Switches =>
1616 Compiler_Trailing_Required_Switches,
1617 From_List => Element.Value.Values,
1618 In_Tree => Data.Tree);
1620 when Name_Multi_Unit_Switches =>
1622 Lang_Index.Config.Multi_Unit_Switches,
1623 From_List => Element.Value.Values,
1624 In_Tree => Data.Tree);
1626 when Name_Multi_Unit_Object_Separator =>
1627 Get_Name_String (Element.Value.Value);
1629 if Name_Len /= 1 then
1632 "multi-unit object separator must have " &
1633 "a single character",
1634 Element.Value.Location, Project);
1636 elsif Name_Buffer (1) = ' ' then
1639 "multi-unit object separator cannot be " &
1641 Element.Value.Location, Project);
1644 Lang_Index.Config.Multi_Unit_Object_Separator :=
1648 when Name_Path_Syntax =>
1650 Lang_Index.Config.Path_Syntax :=
1651 Path_Syntax_Kind'Value
1652 (Get_Name_String (Element.Value.Value));
1655 when Constraint_Error =>
1658 "invalid value for Path_Syntax",
1659 Element.Value.Location, Project);
1662 when Name_Object_File_Suffix =>
1663 if Get_Name_String (Element.Value.Value) = "" then
1666 "object file suffix cannot be empty",
1667 Element.Value.Location, Project);
1670 Lang_Index.Config.Object_File_Suffix :=
1671 Element.Value.Value;
1674 when Name_Object_File_Switches =>
1676 Lang_Index.Config.Object_File_Switches,
1677 From_List => Element.Value.Values,
1678 In_Tree => Data.Tree);
1680 when Name_Pic_Option =>
1682 -- Attribute Compiler_Pic_Option (<language>)
1684 List := Element.Value.Values;
1686 if List = Nil_String then
1689 "compiler PIC option cannot be null",
1690 Element.Value.Location, Project);
1694 Lang_Index.Config.Compilation_PIC_Option,
1696 In_Tree => Data.Tree);
1698 when Name_Mapping_File_Switches =>
1700 -- Attribute Mapping_File_Switches (<language>)
1702 List := Element.Value.Values;
1704 if List = Nil_String then
1707 "mapping file switches cannot be null",
1708 Element.Value.Location, Project);
1712 Lang_Index.Config.Mapping_File_Switches,
1714 In_Tree => Data.Tree);
1716 when Name_Mapping_Spec_Suffix =>
1718 -- Attribute Mapping_Spec_Suffix (<language>)
1720 Lang_Index.Config.Mapping_Spec_Suffix :=
1721 File_Name_Type (Element.Value.Value);
1723 when Name_Mapping_Body_Suffix =>
1725 -- Attribute Mapping_Body_Suffix (<language>)
1727 Lang_Index.Config.Mapping_Body_Suffix :=
1728 File_Name_Type (Element.Value.Value);
1730 when Name_Config_File_Switches =>
1732 -- Attribute Config_File_Switches (<language>)
1734 List := Element.Value.Values;
1736 if List = Nil_String then
1739 "config file switches cannot be null",
1740 Element.Value.Location, Project);
1744 Lang_Index.Config.Config_File_Switches,
1746 In_Tree => Data.Tree);
1748 when Name_Objects_Path =>
1750 -- Attribute Objects_Path (<language>)
1752 Lang_Index.Config.Objects_Path :=
1753 Element.Value.Value;
1755 when Name_Objects_Path_File =>
1757 -- Attribute Objects_Path_File (<language>)
1759 Lang_Index.Config.Objects_Path_File :=
1760 Element.Value.Value;
1762 when Name_Config_Body_File_Name =>
1764 -- Attribute Config_Body_File_Name (<language>)
1766 Lang_Index.Config.Config_Body :=
1767 Element.Value.Value;
1769 when Name_Config_Body_File_Name_Index =>
1771 -- Attribute Config_Body_File_Name_Index
1774 Lang_Index.Config.Config_Body_Index :=
1775 Element.Value.Value;
1777 when Name_Config_Body_File_Name_Pattern =>
1779 -- Attribute Config_Body_File_Name_Pattern
1782 Lang_Index.Config.Config_Body_Pattern :=
1783 Element.Value.Value;
1785 when Name_Config_Spec_File_Name =>
1787 -- Attribute Config_Spec_File_Name (<language>)
1789 Lang_Index.Config.Config_Spec :=
1790 Element.Value.Value;
1792 when Name_Config_Spec_File_Name_Index =>
1794 -- Attribute Config_Spec_File_Name_Index
1797 Lang_Index.Config.Config_Spec_Index :=
1798 Element.Value.Value;
1800 when Name_Config_Spec_File_Name_Pattern =>
1802 -- Attribute Config_Spec_File_Name_Pattern
1805 Lang_Index.Config.Config_Spec_Pattern :=
1806 Element.Value.Value;
1808 when Name_Config_File_Unique =>
1810 -- Attribute Config_File_Unique (<language>)
1813 Lang_Index.Config.Config_File_Unique :=
1815 (Get_Name_String (Element.Value.Value));
1817 when Constraint_Error =>
1820 "illegal value for Config_File_Unique",
1821 Element.Value.Location, Project);
1830 Element_Id := Element.Next;
1833 Current_Array_Id := Current_Array.Next;
1835 end Process_Compiler;
1837 --------------------
1838 -- Process_Naming --
1839 --------------------
1841 procedure Process_Naming (Attributes : Variable_Id) is
1842 Attribute_Id : Variable_Id;
1843 Attribute : Variable;
1846 -- Process non associated array attribute from package Naming
1848 Attribute_Id := Attributes;
1849 while Attribute_Id /= No_Variable loop
1850 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1852 if not Attribute.Value.Default then
1853 if Attribute.Name = Name_Separate_Suffix then
1855 -- Attribute Separate_Suffix
1857 Get_Name_String (Attribute.Value.Value);
1858 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1859 Separate_Suffix := Name_Find;
1861 elsif Attribute.Name = Name_Casing then
1867 Value (Get_Name_String (Attribute.Value.Value));
1870 when Constraint_Error =>
1873 "invalid value for Casing",
1874 Attribute.Value.Location, Project);
1877 elsif Attribute.Name = Name_Dot_Replacement then
1879 -- Attribute Dot_Replacement
1881 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1886 Attribute_Id := Attribute.Next;
1890 procedure Process_Naming (Arrays : Array_Id) is
1891 Current_Array_Id : Array_Id;
1892 Current_Array : Array_Data;
1893 Element_Id : Array_Element_Id;
1894 Element : Array_Element;
1897 -- Process the associative array attribute of package Naming
1899 Current_Array_Id := Arrays;
1900 while Current_Array_Id /= No_Array loop
1901 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1903 Element_Id := Current_Array.Value;
1904 while Element_Id /= No_Array_Element loop
1905 Element := Shared.Array_Elements.Table (Element_Id);
1907 -- Get the name of the language
1909 Lang_Index := Get_Language_From_Name
1910 (Project, Get_Name_String (Element.Index));
1912 if Lang_Index /= No_Language_Index then
1913 case Current_Array.Name is
1914 when Name_Spec_Suffix | Name_Specification_Suffix =>
1916 -- Attribute Spec_Suffix (<language>)
1918 Get_Name_String (Element.Value.Value);
1919 Canonical_Case_File_Name
1920 (Name_Buffer (1 .. Name_Len));
1921 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1924 when Name_Implementation_Suffix | Name_Body_Suffix =>
1926 Get_Name_String (Element.Value.Value);
1927 Canonical_Case_File_Name
1928 (Name_Buffer (1 .. Name_Len));
1930 -- Attribute Body_Suffix (<language>)
1932 Lang_Index.Config.Naming_Data.Body_Suffix :=
1934 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1935 Lang_Index.Config.Naming_Data.Body_Suffix;
1942 Element_Id := Element.Next;
1945 Current_Array_Id := Current_Array.Next;
1949 --------------------
1950 -- Process_Linker --
1951 --------------------
1953 procedure Process_Linker (Attributes : Variable_Id) is
1954 Attribute_Id : Variable_Id;
1955 Attribute : Variable;
1958 -- Process non associated array attribute from package Linker
1960 Attribute_Id := Attributes;
1961 while Attribute_Id /= No_Variable loop
1962 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1964 if not Attribute.Value.Default then
1965 if Attribute.Name = Name_Driver then
1967 -- Attribute Linker'Driver: the default linker to use
1969 Project.Config.Linker :=
1970 Path_Name_Type (Attribute.Value.Value);
1972 -- Linker'Driver is also used to link shared libraries
1973 -- if the obsolescent attribute Library_GCC has not been
1976 if Project.Config.Shared_Lib_Driver = No_File then
1977 Project.Config.Shared_Lib_Driver :=
1978 File_Name_Type (Attribute.Value.Value);
1981 elsif Attribute.Name = Name_Required_Switches then
1983 -- Attribute Required_Switches: the minimum trailing
1984 -- options to use when invoking the linker
1987 Project.Config.Trailing_Linker_Required_Switches,
1988 From_List => Attribute.Value.Values,
1989 In_Tree => Data.Tree);
1991 elsif Attribute.Name = Name_Map_File_Option then
1992 Project.Config.Map_File_Option := Attribute.Value.Value;
1994 elsif Attribute.Name = Name_Max_Command_Line_Length then
1996 Project.Config.Max_Command_Line_Length :=
1997 Natural'Value (Get_Name_String
1998 (Attribute.Value.Value));
2001 when Constraint_Error =>
2004 "value must be positive or equal to 0",
2005 Attribute.Value.Location, Project);
2008 elsif Attribute.Name = Name_Response_File_Format then
2013 Get_Name_String (Attribute.Value.Value);
2014 To_Lower (Name_Buffer (1 .. Name_Len));
2017 if Name = Name_None then
2018 Project.Config.Resp_File_Format := None;
2020 elsif Name = Name_Gnu then
2021 Project.Config.Resp_File_Format := GNU;
2023 elsif Name = Name_Object_List then
2024 Project.Config.Resp_File_Format := Object_List;
2026 elsif Name = Name_Option_List then
2027 Project.Config.Resp_File_Format := Option_List;
2029 elsif Name_Buffer (1 .. Name_Len) = "gcc" then
2030 Project.Config.Resp_File_Format := GCC;
2032 elsif Name_Buffer (1 .. Name_Len) = "gcc_gnu" then
2033 Project.Config.Resp_File_Format := GCC_GNU;
2036 Name_Buffer (1 .. Name_Len) = "gcc_option_list"
2038 Project.Config.Resp_File_Format := GCC_Option_List;
2041 Name_Buffer (1 .. Name_Len) = "gcc_object_list"
2043 Project.Config.Resp_File_Format := GCC_Object_List;
2048 "illegal response file format",
2049 Attribute.Value.Location, Project);
2053 elsif Attribute.Name = Name_Response_File_Switches then
2054 Put (Into_List => Project.Config.Resp_File_Options,
2055 From_List => Attribute.Value.Values,
2056 In_Tree => Data.Tree);
2060 Attribute_Id := Attribute.Next;
2064 -- Start of processing for Process_Packages
2067 Packages := Project.Decl.Packages;
2068 while Packages /= No_Package loop
2069 Element := Shared.Packages.Table (Packages);
2071 case Element.Name is
2074 -- Process attributes of package Binder
2076 Process_Binder (Element.Decl.Arrays);
2078 when Name_Builder =>
2080 -- Process attributes of package Builder
2082 Process_Builder (Element.Decl.Attributes);
2084 when Name_Compiler =>
2086 -- Process attributes of package Compiler
2088 Process_Compiler (Element.Decl.Arrays);
2092 -- Process attributes of package Linker
2094 Process_Linker (Element.Decl.Attributes);
2098 -- Process attributes of package Naming
2100 Process_Naming (Element.Decl.Attributes);
2101 Process_Naming (Element.Decl.Arrays);
2107 Packages := Element.Next;
2109 end Process_Packages;
2111 ---------------------------------------------
2112 -- Process_Project_Level_Simple_Attributes --
2113 ---------------------------------------------
2115 procedure Process_Project_Level_Simple_Attributes is
2116 Attribute_Id : Variable_Id;
2117 Attribute : Variable;
2118 List : String_List_Id;
2121 -- Process non associated array attribute at project level
2123 Attribute_Id := Project.Decl.Attributes;
2124 while Attribute_Id /= No_Variable loop
2125 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
2127 if not Attribute.Value.Default then
2128 if Attribute.Name = Name_Target then
2130 -- Attribute Target: the target specified
2132 Project.Config.Target := Attribute.Value.Value;
2134 elsif Attribute.Name = Name_Library_Builder then
2136 -- Attribute Library_Builder: the application to invoke
2137 -- to build libraries.
2139 Project.Config.Library_Builder :=
2140 Path_Name_Type (Attribute.Value.Value);
2142 elsif Attribute.Name = Name_Archive_Builder then
2144 -- Attribute Archive_Builder: the archive builder
2145 -- (usually "ar") and its minimum options (usually "cr").
2147 List := Attribute.Value.Values;
2149 if List = Nil_String then
2152 "archive builder cannot be null",
2153 Attribute.Value.Location, Project);
2156 Put (Into_List => Project.Config.Archive_Builder,
2158 In_Tree => Data.Tree);
2160 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
2162 -- Attribute Archive_Builder: the archive builder
2163 -- (usually "ar") and its minimum options (usually "cr").
2165 List := Attribute.Value.Values;
2167 if List /= Nil_String then
2170 Project.Config.Archive_Builder_Append_Option,
2172 In_Tree => Data.Tree);
2175 elsif Attribute.Name = Name_Archive_Indexer then
2177 -- Attribute Archive_Indexer: the optional archive
2178 -- indexer (usually "ranlib") with its minimum options
2181 List := Attribute.Value.Values;
2183 if List = Nil_String then
2186 "archive indexer cannot be null",
2187 Attribute.Value.Location, Project);
2190 Put (Into_List => Project.Config.Archive_Indexer,
2192 In_Tree => Data.Tree);
2194 elsif Attribute.Name = Name_Library_Partial_Linker then
2196 -- Attribute Library_Partial_Linker: the optional linker
2197 -- driver with its minimum options, to partially link
2200 List := Attribute.Value.Values;
2202 if List = Nil_String then
2205 "partial linker cannot be null",
2206 Attribute.Value.Location, Project);
2209 Put (Into_List => Project.Config.Lib_Partial_Linker,
2211 In_Tree => Data.Tree);
2213 elsif Attribute.Name = Name_Library_GCC then
2214 Project.Config.Shared_Lib_Driver :=
2215 File_Name_Type (Attribute.Value.Value);
2218 "?Library_'G'C'C is an obsolescent attribute, " &
2219 "use Linker''Driver instead",
2220 Attribute.Value.Location, Project);
2222 elsif Attribute.Name = Name_Archive_Suffix then
2223 Project.Config.Archive_Suffix :=
2224 File_Name_Type (Attribute.Value.Value);
2226 elsif Attribute.Name = Name_Linker_Executable_Option then
2228 -- Attribute Linker_Executable_Option: optional options
2229 -- to specify an executable name. Defaults to "-o".
2231 List := Attribute.Value.Values;
2233 if List = Nil_String then
2236 "linker executable option cannot be null",
2237 Attribute.Value.Location, Project);
2240 Put (Into_List => Project.Config.Linker_Executable_Option,
2242 In_Tree => Data.Tree);
2244 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2246 -- Attribute Linker_Lib_Dir_Option: optional options
2247 -- to specify a library search directory. Defaults to
2250 Get_Name_String (Attribute.Value.Value);
2252 if Name_Len = 0 then
2255 "linker library directory option cannot be empty",
2256 Attribute.Value.Location, Project);
2259 Project.Config.Linker_Lib_Dir_Option :=
2260 Attribute.Value.Value;
2262 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2264 -- Attribute Linker_Lib_Name_Option: optional options
2265 -- to specify the name of a library to be linked in.
2266 -- Defaults to "-l".
2268 Get_Name_String (Attribute.Value.Value);
2270 if Name_Len = 0 then
2273 "linker library name option cannot be empty",
2274 Attribute.Value.Location, Project);
2277 Project.Config.Linker_Lib_Name_Option :=
2278 Attribute.Value.Value;
2280 elsif Attribute.Name = Name_Run_Path_Option then
2282 -- Attribute Run_Path_Option: optional options to
2283 -- specify a path for libraries.
2285 List := Attribute.Value.Values;
2287 if List /= Nil_String then
2288 Put (Into_List => Project.Config.Run_Path_Option,
2290 In_Tree => Data.Tree);
2293 elsif Attribute.Name = Name_Run_Path_Origin then
2294 Get_Name_String (Attribute.Value.Value);
2296 if Name_Len = 0 then
2299 "run path origin cannot be empty",
2300 Attribute.Value.Location, Project);
2303 Project.Config.Run_Path_Origin := Attribute.Value.Value;
2305 elsif Attribute.Name = Name_Library_Install_Name_Option then
2306 Project.Config.Library_Install_Name_Option :=
2307 Attribute.Value.Value;
2309 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2311 pragma Unsuppress (All_Checks);
2313 Project.Config.Separate_Run_Path_Options :=
2314 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2316 when Constraint_Error =>
2319 "invalid value """ &
2320 Get_Name_String (Attribute.Value.Value) &
2321 """ for Separate_Run_Path_Options",
2322 Attribute.Value.Location, Project);
2325 elsif Attribute.Name = Name_Library_Support then
2327 pragma Unsuppress (All_Checks);
2329 Project.Config.Lib_Support :=
2330 Library_Support'Value (Get_Name_String
2331 (Attribute.Value.Value));
2333 when Constraint_Error =>
2336 "invalid value """ &
2337 Get_Name_String (Attribute.Value.Value) &
2338 """ for Library_Support",
2339 Attribute.Value.Location, Project);
2342 elsif Attribute.Name = Name_Shared_Library_Prefix then
2343 Project.Config.Shared_Lib_Prefix :=
2344 File_Name_Type (Attribute.Value.Value);
2346 elsif Attribute.Name = Name_Shared_Library_Suffix then
2347 Project.Config.Shared_Lib_Suffix :=
2348 File_Name_Type (Attribute.Value.Value);
2350 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2352 pragma Unsuppress (All_Checks);
2354 Project.Config.Symbolic_Link_Supported :=
2355 Boolean'Value (Get_Name_String
2356 (Attribute.Value.Value));
2358 when Constraint_Error =>
2362 & Get_Name_String (Attribute.Value.Value)
2363 & """ for Symbolic_Link_Supported",
2364 Attribute.Value.Location, Project);
2368 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2371 pragma Unsuppress (All_Checks);
2373 Project.Config.Lib_Maj_Min_Id_Supported :=
2374 Boolean'Value (Get_Name_String
2375 (Attribute.Value.Value));
2377 when Constraint_Error =>
2380 "invalid value """ &
2381 Get_Name_String (Attribute.Value.Value) &
2382 """ for Library_Major_Minor_Id_Supported",
2383 Attribute.Value.Location, Project);
2386 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2388 pragma Unsuppress (All_Checks);
2390 Project.Config.Auto_Init_Supported :=
2391 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2393 when Constraint_Error =>
2397 & Get_Name_String (Attribute.Value.Value)
2398 & """ for Library_Auto_Init_Supported",
2399 Attribute.Value.Location, Project);
2402 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2403 List := Attribute.Value.Values;
2405 if List /= Nil_String then
2406 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2408 In_Tree => Data.Tree);
2411 elsif Attribute.Name = Name_Library_Version_Switches then
2412 List := Attribute.Value.Values;
2414 if List /= Nil_String then
2415 Put (Into_List => Project.Config.Lib_Version_Options,
2417 In_Tree => Data.Tree);
2422 Attribute_Id := Attribute.Next;
2424 end Process_Project_Level_Simple_Attributes;
2426 --------------------------------------------
2427 -- Process_Project_Level_Array_Attributes --
2428 --------------------------------------------
2430 procedure Process_Project_Level_Array_Attributes is
2431 Current_Array_Id : Array_Id;
2432 Current_Array : Array_Data;
2433 Element_Id : Array_Element_Id;
2434 Element : Array_Element;
2435 List : String_List_Id;
2438 -- Process the associative array attributes at project level
2440 Current_Array_Id := Project.Decl.Arrays;
2441 while Current_Array_Id /= No_Array loop
2442 Current_Array := Shared.Arrays.Table (Current_Array_Id);
2444 Element_Id := Current_Array.Value;
2445 while Element_Id /= No_Array_Element loop
2446 Element := Shared.Array_Elements.Table (Element_Id);
2448 -- Get the name of the language
2451 Get_Language_From_Name
2452 (Project, Get_Name_String (Element.Index));
2454 if Lang_Index /= No_Language_Index then
2455 case Current_Array.Name is
2456 when Name_Inherit_Source_Path =>
2457 List := Element.Value.Values;
2459 if List /= Nil_String then
2462 Lang_Index.Config.Include_Compatible_Languages,
2464 In_Tree => Data.Tree,
2465 Lower_Case => True);
2468 when Name_Toolchain_Description =>
2470 -- Attribute Toolchain_Description (<language>)
2472 Lang_Index.Config.Toolchain_Description :=
2473 Element.Value.Value;
2475 when Name_Toolchain_Version =>
2477 -- Attribute Toolchain_Version (<language>)
2479 Lang_Index.Config.Toolchain_Version :=
2480 Element.Value.Value;
2482 -- For Ada, set proper checksum computation mode
2484 if Lang_Index.Name = Name_Ada then
2486 Vers : constant String :=
2487 Get_Name_String (Element.Value.Value);
2488 pragma Assert (Vers'First = 1);
2491 -- Version 6.3 or earlier
2494 and then Vers (1 .. 5) = "GNAT "
2495 and then Vers (7) = '.'
2499 (Vers (6) = '6' and then Vers (8) < '4'))
2501 Checksum_GNAT_6_3 := True;
2503 -- Version 5.03 or earlier
2506 or else (Vers (6) = '5'
2507 and then Vers (Vers'Last) < '4')
2509 Checksum_GNAT_5_03 := True;
2511 -- Version 5.02 or earlier
2514 or else Vers (Vers'Last) < '3'
2516 Checksum_Accumulate_Token_Checksum :=
2524 when Name_Runtime_Library_Dir =>
2526 -- Attribute Runtime_Library_Dir (<language>)
2528 Lang_Index.Config.Runtime_Library_Dir :=
2529 Element.Value.Value;
2531 when Name_Runtime_Source_Dir =>
2533 -- Attribute Runtime_Library_Dir (<language>)
2535 Lang_Index.Config.Runtime_Source_Dir :=
2536 Element.Value.Value;
2538 when Name_Object_Generated =>
2540 pragma Unsuppress (All_Checks);
2546 (Get_Name_String (Element.Value.Value));
2548 Lang_Index.Config.Object_Generated := Value;
2550 -- If no object is generated, no object may be
2554 Lang_Index.Config.Objects_Linked := False;
2558 when Constraint_Error =>
2562 & Get_Name_String (Element.Value.Value)
2563 & """ for Object_Generated",
2564 Element.Value.Location, Project);
2567 when Name_Objects_Linked =>
2569 pragma Unsuppress (All_Checks);
2575 (Get_Name_String (Element.Value.Value));
2577 -- No change if Object_Generated is False, as this
2578 -- forces Objects_Linked to be False too.
2580 if Lang_Index.Config.Object_Generated then
2581 Lang_Index.Config.Objects_Linked := Value;
2585 when Constraint_Error =>
2589 & Get_Name_String (Element.Value.Value)
2590 & """ for Objects_Linked",
2591 Element.Value.Location, Project);
2598 Element_Id := Element.Next;
2601 Current_Array_Id := Current_Array.Next;
2603 end Process_Project_Level_Array_Attributes;
2605 -- Start of processing for Check_Configuration
2608 Process_Project_Level_Simple_Attributes;
2609 Process_Project_Level_Array_Attributes;
2612 -- For unit based languages, set Casing, Dot_Replacement and
2613 -- Separate_Suffix in Naming_Data.
2615 Lang_Index := Project.Languages;
2616 while Lang_Index /= No_Language_Index loop
2617 if Lang_Index.Config.Kind = Unit_Based then
2618 Lang_Index.Config.Naming_Data.Casing := Casing;
2619 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2621 if Separate_Suffix /= No_File then
2622 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2629 Lang_Index := Lang_Index.Next;
2632 -- Give empty names to various prefixes/suffixes, if they have not
2633 -- been specified in the configuration.
2635 if Project.Config.Archive_Suffix = No_File then
2636 Project.Config.Archive_Suffix := Empty_File;
2639 if Project.Config.Shared_Lib_Prefix = No_File then
2640 Project.Config.Shared_Lib_Prefix := Empty_File;
2643 if Project.Config.Shared_Lib_Suffix = No_File then
2644 Project.Config.Shared_Lib_Suffix := Empty_File;
2647 Lang_Index := Project.Languages;
2648 while Lang_Index /= No_Language_Index loop
2650 -- For all languages, Compiler_Driver needs to be specified. This is
2651 -- only needed if we do intend to compile (not in GPS for instance).
2653 if Data.Flags.Compiler_Driver_Mandatory
2654 and then Lang_Index.Config.Compiler_Driver = No_File
2656 Error_Msg_Name_1 := Lang_Index.Display_Name;
2659 "?no compiler specified for language %%" &
2660 ", ignoring all its sources",
2661 No_Location, Project);
2663 if Lang_Index = Project.Languages then
2664 Project.Languages := Lang_Index.Next;
2666 Prev_Index.Next := Lang_Index.Next;
2669 elsif Lang_Index.Config.Kind = Unit_Based then
2670 Prev_Index := Lang_Index;
2672 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2673 -- Body_Suffix need to be specified.
2675 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2678 "Dot_Replacement not specified for " &
2679 Get_Name_String (Lang_Index.Name),
2680 No_Location, Project);
2683 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2686 "Spec_Suffix not specified for " &
2687 Get_Name_String (Lang_Index.Name),
2688 No_Location, Project);
2691 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2694 "Body_Suffix not specified for " &
2695 Get_Name_String (Lang_Index.Name),
2696 No_Location, Project);
2700 Prev_Index := Lang_Index;
2702 -- For file based languages, either Spec_Suffix or Body_Suffix
2703 -- need to be specified.
2705 if Data.Flags.Require_Sources_Other_Lang
2706 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2707 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2709 Error_Msg_Name_1 := Lang_Index.Display_Name;
2712 "no suffixes specified for %%",
2713 No_Location, Project);
2717 Lang_Index := Lang_Index.Next;
2719 end Check_Configuration;
2721 -------------------------------
2722 -- Check_If_Externally_Built --
2723 -------------------------------
2725 procedure Check_If_Externally_Built
2726 (Project : Project_Id;
2727 Data : in out Tree_Processing_Data)
2729 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2730 Externally_Built : constant Variable_Value :=
2732 (Name_Externally_Built,
2733 Project.Decl.Attributes, Shared);
2736 if not Externally_Built.Default then
2737 Get_Name_String (Externally_Built.Value);
2738 To_Lower (Name_Buffer (1 .. Name_Len));
2740 if Name_Buffer (1 .. Name_Len) = "true" then
2741 Project.Externally_Built := True;
2743 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2744 Error_Msg (Data.Flags,
2745 "Externally_Built may only be true or false",
2746 Externally_Built.Location, Project);
2750 -- A virtual project extending an externally built project is itself
2751 -- externally built.
2753 if Project.Virtual and then Project.Extends /= No_Project then
2754 Project.Externally_Built := Project.Extends.Externally_Built;
2757 if Project.Externally_Built then
2758 Debug_Output ("project is externally built");
2760 Debug_Output ("project is not externally built");
2762 end Check_If_Externally_Built;
2764 ----------------------
2765 -- Check_Interfaces --
2766 ----------------------
2768 procedure Check_Interfaces
2769 (Project : Project_Id;
2770 Data : in out Tree_Processing_Data)
2772 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2774 Interfaces : constant Prj.Variable_Value :=
2776 (Snames.Name_Interfaces,
2777 Project.Decl.Attributes,
2780 Library_Interface : constant Prj.Variable_Value :=
2782 (Snames.Name_Library_Interface,
2783 Project.Decl.Attributes,
2786 List : String_List_Id;
2787 Element : String_Element;
2788 Name : File_Name_Type;
2789 Iter : Source_Iterator;
2791 Project_2 : Project_Id;
2795 if not Interfaces.Default then
2797 -- Set In_Interfaces to False for all sources. It will be set to True
2798 -- later for the sources in the Interfaces list.
2800 Project_2 := Project;
2801 while Project_2 /= No_Project loop
2802 Iter := For_Each_Source (Data.Tree, Project_2);
2804 Source := Prj.Element (Iter);
2805 exit when Source = No_Source;
2806 Source.In_Interfaces := False;
2810 Project_2 := Project_2.Extends;
2813 List := Interfaces.Values;
2814 while List /= Nil_String loop
2815 Element := Shared.String_Elements.Table (List);
2816 Name := Canonical_Case_File_Name (Element.Value);
2818 Project_2 := Project;
2820 while Project_2 /= No_Project loop
2821 Iter := For_Each_Source (Data.Tree, Project_2);
2824 Source := Prj.Element (Iter);
2825 exit when Source = No_Source;
2827 if Source.File = Name then
2828 if not Source.Locally_Removed then
2829 Source.In_Interfaces := True;
2830 Source.Declared_In_Interfaces := True;
2832 Other := Other_Part (Source);
2834 if Other /= No_Source then
2835 Other.In_Interfaces := True;
2836 Other.Declared_In_Interfaces := True;
2840 ("interface: ", Name_Id (Source.Path.Name));
2849 Project_2 := Project_2.Extends;
2852 if Source = No_Source then
2853 Error_Msg_File_1 := File_Name_Type (Element.Value);
2854 Error_Msg_Name_1 := Project.Name;
2858 "{ cannot be an interface of project %% "
2859 & "as it is not one of its sources",
2860 Element.Location, Project);
2863 List := Element.Next;
2866 Project.Interfaces_Defined := True;
2868 elsif Project.Library and then not Library_Interface.Default then
2870 -- Set In_Interfaces to False for all sources. It will be set to True
2871 -- later for the sources in the Library_Interface list.
2873 Project_2 := Project;
2874 while Project_2 /= No_Project loop
2875 Iter := For_Each_Source (Data.Tree, Project_2);
2877 Source := Prj.Element (Iter);
2878 exit when Source = No_Source;
2879 Source.In_Interfaces := False;
2883 Project_2 := Project_2.Extends;
2886 List := Library_Interface.Values;
2887 while List /= Nil_String loop
2888 Element := Shared.String_Elements.Table (List);
2889 Get_Name_String (Element.Value);
2890 To_Lower (Name_Buffer (1 .. Name_Len));
2893 Project_2 := Project;
2895 while Project_2 /= No_Project loop
2896 Iter := For_Each_Source (Data.Tree, Project_2);
2899 Source := Prj.Element (Iter);
2900 exit when Source = No_Source;
2902 if Source.Unit /= No_Unit_Index and then
2903 Source.Unit.Name = Name_Id (Name)
2905 if not Source.Locally_Removed then
2906 Source.In_Interfaces := True;
2907 Source.Declared_In_Interfaces := True;
2909 Other := Other_Part (Source);
2911 if Other /= No_Source then
2912 Other.In_Interfaces := True;
2913 Other.Declared_In_Interfaces := True;
2917 ("interface: ", Name_Id (Source.Path.Name));
2926 Project_2 := Project_2.Extends;
2927 end loop Big_Loop_2;
2929 List := Element.Next;
2932 Project.Interfaces_Defined := True;
2934 elsif Project.Extends /= No_Project
2935 and then Project.Extends.Interfaces_Defined
2937 Project.Interfaces_Defined := True;
2939 Iter := For_Each_Source (Data.Tree, Project);
2941 Source := Prj.Element (Iter);
2942 exit when Source = No_Source;
2944 if not Source.Declared_In_Interfaces then
2945 Source.In_Interfaces := False;
2951 end Check_Interfaces;
2953 --------------------------
2954 -- Check_Package_Naming --
2955 --------------------------
2957 procedure Check_Package_Naming
2958 (Project : Project_Id;
2959 Data : in out Tree_Processing_Data)
2961 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2962 Naming_Id : constant Package_Id :=
2964 (Name_Naming, Project.Decl.Packages, Shared);
2965 Naming : Package_Element;
2967 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2969 procedure Check_Naming;
2970 -- Check the validity of the Naming package (suffixes valid, ...)
2972 procedure Check_Common
2973 (Dot_Replacement : in out File_Name_Type;
2974 Casing : in out Casing_Type;
2975 Casing_Defined : out Boolean;
2976 Separate_Suffix : in out File_Name_Type;
2977 Sep_Suffix_Loc : out Source_Ptr);
2978 -- Check attributes common
2980 procedure Process_Exceptions_File_Based
2981 (Lang_Id : Language_Ptr;
2982 Kind : Source_Kind);
2983 procedure Process_Exceptions_Unit_Based
2984 (Lang_Id : Language_Ptr;
2985 Kind : Source_Kind);
2986 -- Process the naming exceptions for the two types of languages
2988 procedure Initialize_Naming_Data;
2989 -- Initialize internal naming data for the various languages
2995 procedure Check_Common
2996 (Dot_Replacement : in out File_Name_Type;
2997 Casing : in out Casing_Type;
2998 Casing_Defined : out Boolean;
2999 Separate_Suffix : in out File_Name_Type;
3000 Sep_Suffix_Loc : out Source_Ptr)
3002 Dot_Repl : constant Variable_Value :=
3004 (Name_Dot_Replacement,
3005 Naming.Decl.Attributes,
3007 Casing_String : constant Variable_Value :=
3010 Naming.Decl.Attributes,
3012 Sep_Suffix : constant Variable_Value :=
3014 (Name_Separate_Suffix,
3015 Naming.Decl.Attributes,
3017 Dot_Repl_Loc : Source_Ptr;
3020 Sep_Suffix_Loc := No_Location;
3022 if not Dot_Repl.Default then
3024 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
3026 if Length_Of_Name (Dot_Repl.Value) = 0 then
3028 (Data.Flags, "Dot_Replacement cannot be empty",
3029 Dot_Repl.Location, Project);
3032 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
3033 Dot_Repl_Loc := Dot_Repl.Location;
3036 Repl : constant String := Get_Name_String (Dot_Replacement);
3039 -- Dot_Replacement cannot
3041 -- - start or end with an alphanumeric
3042 -- - be a single '_'
3043 -- - start with an '_' followed by an alphanumeric
3044 -- - contain a '.' except if it is "."
3047 or else Is_Alphanumeric (Repl (Repl'First))
3048 or else Is_Alphanumeric (Repl (Repl'Last))
3049 or else (Repl (Repl'First) = '_'
3053 Is_Alphanumeric (Repl (Repl'First + 1))))
3054 or else (Repl'Length > 1
3056 Index (Source => Repl, Pattern => ".") /= 0)
3061 """ is illegal for Dot_Replacement.",
3062 Dot_Repl_Loc, Project);
3067 if Dot_Replacement /= No_File then
3069 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
3072 Casing_Defined := False;
3074 if not Casing_String.Default then
3076 (Casing_String.Kind = Single, "Casing is not a string");
3079 Casing_Image : constant String :=
3080 Get_Name_String (Casing_String.Value);
3083 if Casing_Image'Length = 0 then
3086 "Casing cannot be an empty string",
3087 Casing_String.Location, Project);
3090 Casing := Value (Casing_Image);
3091 Casing_Defined := True;
3094 when Constraint_Error =>
3095 Name_Len := Casing_Image'Length;
3096 Name_Buffer (1 .. Name_Len) := Casing_Image;
3097 Err_Vars.Error_Msg_Name_1 := Name_Find;
3100 "%% is not a correct Casing",
3101 Casing_String.Location, Project);
3105 Write_Attr ("Casing", Image (Casing));
3107 if not Sep_Suffix.Default then
3108 if Length_Of_Name (Sep_Suffix.Value) = 0 then
3111 "Separate_Suffix cannot be empty",
3112 Sep_Suffix.Location, Project);
3115 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
3116 Sep_Suffix_Loc := Sep_Suffix.Location;
3118 Check_Illegal_Suffix
3119 (Project, Separate_Suffix,
3120 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
3125 if Separate_Suffix /= No_File then
3127 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
3131 -----------------------------------
3132 -- Process_Exceptions_File_Based --
3133 -----------------------------------
3135 procedure Process_Exceptions_File_Based
3136 (Lang_Id : Language_Ptr;
3139 Lang : constant Name_Id := Lang_Id.Name;
3140 Exceptions : Array_Element_Id;
3141 Exception_List : Variable_Value;
3142 Element_Id : String_List_Id;
3143 Element : String_Element;
3144 File_Name : File_Name_Type;
3152 (Name_Implementation_Exceptions,
3153 In_Arrays => Naming.Decl.Arrays,
3159 (Name_Specification_Exceptions,
3160 In_Arrays => Naming.Decl.Arrays,
3167 In_Array => Exceptions,
3170 if Exception_List /= Nil_Variable_Value then
3171 Element_Id := Exception_List.Values;
3172 while Element_Id /= Nil_String loop
3173 Element := Shared.String_Elements.Table (Element_Id);
3174 File_Name := Canonical_Case_File_Name (Element.Value);
3177 Source_Files_Htable.Get
3178 (Data.Tree.Source_Files_HT, File_Name);
3179 while Source /= No_Source
3180 and then Source.Project /= Project
3182 Source := Source.Next_With_File_Name;
3185 if Source = No_Source then
3190 Source_Dir_Rank => 0,
3193 File_Name => File_Name,
3194 Display_File => File_Name_Type (Element.Value),
3195 Naming_Exception => True,
3196 Location => Element.Location);
3199 -- Check if the file name is already recorded for another
3200 -- language or another kind.
3202 if Source.Language /= Lang_Id then
3205 "the same file cannot be a source of two languages",
3206 Element.Location, Project);
3208 elsif Source.Kind /= Kind then
3211 "the same file cannot be a source and a template",
3212 Element.Location, Project);
3215 -- If the file is already recorded for the same
3216 -- language and the same kind, it means that the file
3217 -- name appears several times in the *_Exceptions
3218 -- attribute; so there is nothing to do.
3221 Element_Id := Element.Next;
3224 end Process_Exceptions_File_Based;
3226 -----------------------------------
3227 -- Process_Exceptions_Unit_Based --
3228 -----------------------------------
3230 procedure Process_Exceptions_Unit_Based
3231 (Lang_Id : Language_Ptr;
3234 Exceptions : Array_Element_Id;
3235 Element : Array_Element;
3238 File_Name : File_Name_Type;
3247 In_Arrays => Naming.Decl.Arrays,
3250 if Exceptions = No_Array_Element then
3253 (Name_Implementation,
3254 In_Arrays => Naming.Decl.Arrays,
3262 In_Arrays => Naming.Decl.Arrays,
3265 if Exceptions = No_Array_Element then
3269 In_Arrays => Naming.Decl.Arrays,
3274 while Exceptions /= No_Array_Element loop
3275 Element := Shared.Array_Elements.Table (Exceptions);
3276 File_Name := Canonical_Case_File_Name (Element.Value.Value);
3278 Get_Name_String (Element.Index);
3279 To_Lower (Name_Buffer (1 .. Name_Len));
3280 Index := Element.Value.Index;
3282 -- Check if it is a valid unit name
3284 Get_Name_String (Element.Index);
3285 Check_Unit_Name (Name_Buffer (1 .. Name_Len), Unit);
3287 if Unit = No_Name then
3288 Err_Vars.Error_Msg_Name_1 := Element.Index;
3291 "%% is not a valid unit name.",
3292 Element.Value.Location, Project);
3295 if Unit /= No_Name then
3300 Source_Dir_Rank => 0,
3303 File_Name => File_Name,
3304 Display_File => File_Name_Type (Element.Value.Value),
3307 Location => Element.Value.Location,
3308 Naming_Exception => True);
3311 Exceptions := Element.Next;
3313 end Process_Exceptions_Unit_Based;
3319 procedure Check_Naming is
3320 Dot_Replacement : File_Name_Type :=
3322 (First_Name_Id + Character'Pos ('-'));
3323 Separate_Suffix : File_Name_Type := No_File;
3324 Casing : Casing_Type := All_Lower_Case;
3325 Casing_Defined : Boolean;
3326 Lang_Id : Language_Ptr;
3327 Sep_Suffix_Loc : Source_Ptr;
3328 Suffix : Variable_Value;
3333 (Dot_Replacement => Dot_Replacement,
3335 Casing_Defined => Casing_Defined,
3336 Separate_Suffix => Separate_Suffix,
3337 Sep_Suffix_Loc => Sep_Suffix_Loc);
3339 -- For all unit based languages, if any, set the specified value
3340 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3341 -- systematically overwrite, since the defaults come from the
3342 -- configuration file.
3344 if Dot_Replacement /= No_File
3345 or else Casing_Defined
3346 or else Separate_Suffix /= No_File
3348 Lang_Id := Project.Languages;
3349 while Lang_Id /= No_Language_Index loop
3350 if Lang_Id.Config.Kind = Unit_Based then
3351 if Dot_Replacement /= No_File then
3352 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3356 if Casing_Defined then
3357 Lang_Id.Config.Naming_Data.Casing := Casing;
3361 Lang_Id := Lang_Id.Next;
3365 -- Next, get the spec and body suffixes
3367 Lang_Id := Project.Languages;
3368 while Lang_Id /= No_Language_Index loop
3369 Lang := Lang_Id.Name;
3375 Attribute_Or_Array_Name => Name_Spec_Suffix,
3376 In_Package => Naming_Id,
3379 if Suffix = Nil_Variable_Value then
3382 Attribute_Or_Array_Name => Name_Specification_Suffix,
3383 In_Package => Naming_Id,
3387 if Suffix /= Nil_Variable_Value then
3388 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3389 File_Name_Type (Suffix.Value);
3391 Check_Illegal_Suffix
3393 Lang_Id.Config.Naming_Data.Spec_Suffix,
3394 Lang_Id.Config.Naming_Data.Dot_Replacement,
3395 "Spec_Suffix", Suffix.Location, Data);
3399 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3407 Attribute_Or_Array_Name => Name_Body_Suffix,
3408 In_Package => Naming_Id,
3411 if Suffix = Nil_Variable_Value then
3415 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3416 In_Package => Naming_Id,
3420 if Suffix /= Nil_Variable_Value then
3421 Lang_Id.Config.Naming_Data.Body_Suffix :=
3422 File_Name_Type (Suffix.Value);
3424 -- The default value of separate suffix should be the same as
3425 -- the body suffix, so we need to compute that first.
3427 if Separate_Suffix = No_File then
3428 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3429 Lang_Id.Config.Naming_Data.Body_Suffix;
3433 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3435 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3439 Check_Illegal_Suffix
3441 Lang_Id.Config.Naming_Data.Body_Suffix,
3442 Lang_Id.Config.Naming_Data.Dot_Replacement,
3443 "Body_Suffix", Suffix.Location, Data);
3447 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3449 elsif Separate_Suffix /= No_File then
3450 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3453 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3454 -- since that would cause a clear ambiguity. Note that we do allow
3455 -- a Spec_Suffix to have the same termination as one of these,
3456 -- which causes a potential ambiguity, but we resolve that by
3457 -- matching the longest possible suffix.
3459 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3460 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3461 Lang_Id.Config.Naming_Data.Body_Suffix
3466 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3467 & """) cannot be the same as Spec_Suffix.",
3468 Ada_Body_Suffix_Loc, Project);
3471 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3472 Lang_Id.Config.Naming_Data.Separate_Suffix
3473 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3474 Lang_Id.Config.Naming_Data.Separate_Suffix
3478 "Separate_Suffix ("""
3480 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3481 & """) cannot be the same as Spec_Suffix.",
3482 Sep_Suffix_Loc, Project);
3485 Lang_Id := Lang_Id.Next;
3488 -- Get the naming exceptions for all languages
3490 for Kind in Spec_Or_Body loop
3491 Lang_Id := Project.Languages;
3492 while Lang_Id /= No_Language_Index loop
3493 case Lang_Id.Config.Kind is
3495 Process_Exceptions_File_Based (Lang_Id, Kind);
3498 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3501 Lang_Id := Lang_Id.Next;
3506 ----------------------------
3507 -- Initialize_Naming_Data --
3508 ----------------------------
3510 procedure Initialize_Naming_Data is
3511 Specs : Array_Element_Id :=
3517 Impls : Array_Element_Id :=
3523 Lang : Language_Ptr;
3524 Lang_Name : Name_Id;
3525 Value : Variable_Value;
3526 Extended : Project_Id;
3529 -- At this stage, the project already contains the default extensions
3530 -- for the various languages. We now merge those suffixes read in the
3531 -- user project, and they override the default.
3533 while Specs /= No_Array_Element loop
3534 Lang_Name := Shared.Array_Elements.Table (Specs).Index;
3536 Get_Language_From_Name
3537 (Project, Name => Get_Name_String (Lang_Name));
3539 -- An extending project inherits its parent projects' languages
3540 -- so if needed we should create entries for those languages
3543 Extended := Project.Extends;
3544 while Extended /= null loop
3545 Lang := Get_Language_From_Name
3546 (Extended, Name => Get_Name_String (Lang_Name));
3547 exit when Lang /= null;
3549 Extended := Extended.Extends;
3552 if Lang /= null then
3553 Lang := new Language_Data'(Lang.all);
3554 Lang.First_Source := null;
3555 Lang.Next := Project.Languages;
3556 Project.Languages := Lang;
3560 -- If language was not found in project or the projects it extends
3564 ("ignoring spec naming data (lang. not in project): ",
3568 Value := Shared.Array_Elements.Table (Specs).Value;
3570 if Value.Kind = Single then
3571 Lang.Config.Naming_Data.Spec_Suffix :=
3572 Canonical_Case_File_Name (Value.Value);
3576 Specs := Shared.Array_Elements.Table (Specs).Next;
3579 while Impls /= No_Array_Element loop
3580 Lang_Name := Shared.Array_Elements.Table (Impls).Index;
3582 Get_Language_From_Name
3583 (Project, Name => Get_Name_String (Lang_Name));
3587 ("ignoring impl naming data (lang. not in project): ",
3590 Value := Shared.Array_Elements.Table (Impls).Value;
3592 if Lang.Name = Name_Ada then
3593 Ada_Body_Suffix_Loc := Value.Location;
3596 if Value.Kind = Single then
3597 Lang.Config.Naming_Data.Body_Suffix :=
3598 Canonical_Case_File_Name (Value.Value);
3602 Impls := Shared.Array_Elements.Table (Impls).Next;
3604 end Initialize_Naming_Data;
3606 -- Start of processing for Check_Naming_Schemes
3609 -- No Naming package or parsing a configuration file? nothing to do
3611 if Naming_Id /= No_Package
3612 and then Project.Qualifier /= Configuration
3614 Naming := Shared.Packages.Table (Naming_Id);
3615 Debug_Increase_Indent ("checking package Naming for ", Project.Name);
3616 Initialize_Naming_Data;
3618 Debug_Decrease_Indent ("done checking package naming");
3620 end Check_Package_Naming;
3622 ------------------------------
3623 -- Check_Library_Attributes --
3624 ------------------------------
3626 procedure Check_Library_Attributes
3627 (Project : Project_Id;
3628 Data : in out Tree_Processing_Data)
3630 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
3632 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3634 Lib_Dir : constant Prj.Variable_Value :=
3636 (Snames.Name_Library_Dir, Attributes, Shared);
3638 Lib_Name : constant Prj.Variable_Value :=
3640 (Snames.Name_Library_Name, Attributes, Shared);
3642 Lib_Version : constant Prj.Variable_Value :=
3644 (Snames.Name_Library_Version, Attributes, Shared);
3646 Lib_ALI_Dir : constant Prj.Variable_Value :=
3648 (Snames.Name_Library_Ali_Dir, Attributes, Shared);
3650 Lib_GCC : constant Prj.Variable_Value :=
3652 (Snames.Name_Library_GCC, Attributes, Shared);
3654 The_Lib_Kind : constant Prj.Variable_Value :=
3656 (Snames.Name_Library_Kind, Attributes, Shared);
3658 Imported_Project_List : Project_List;
3660 Continuation : String_Access := No_Continuation_String'Access;
3662 Support_For_Libraries : Library_Support;
3664 Library_Directory_Present : Boolean;
3666 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3667 -- Check if an imported or extended project if also a library project
3673 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3675 Iter : Source_Iterator;
3678 if Proj /= No_Project then
3679 if not Proj.Library then
3681 -- The only not library projects that are OK are those that
3682 -- have no sources. However, header files from non-Ada
3683 -- languages are OK, as there is nothing to compile.
3685 Iter := For_Each_Source (Data.Tree, Proj);
3687 Src_Id := Prj.Element (Iter);
3688 exit when Src_Id = No_Source
3689 or else Src_Id.Language.Config.Kind /= File_Based
3690 or else Src_Id.Kind /= Spec;
3694 if Src_Id /= No_Source then
3695 Error_Msg_Name_1 := Project.Name;
3696 Error_Msg_Name_2 := Proj.Name;
3699 if Project.Library_Kind /= Static then
3703 "shared library project %% cannot extend " &
3704 "project %% that is not a library project",
3705 Project.Location, Project);
3706 Continuation := Continuation_String'Access;
3709 elsif (not Unchecked_Shared_Lib_Imports)
3710 and then Project.Library_Kind /= Static
3715 "shared library project %% cannot import project %% " &
3716 "that is not a shared library project",
3717 Project.Location, Project);
3718 Continuation := Continuation_String'Access;
3722 elsif Project.Library_Kind /= Static and then
3723 Proj.Library_Kind = Static
3725 Error_Msg_Name_1 := Project.Name;
3726 Error_Msg_Name_2 := Proj.Name;
3732 "shared library project %% cannot extend static " &
3733 "library project %%",
3734 Project.Location, Project);
3735 Continuation := Continuation_String'Access;
3737 elsif not Unchecked_Shared_Lib_Imports then
3741 "shared library project %% cannot import static " &
3742 "library project %%",
3743 Project.Location, Project);
3744 Continuation := Continuation_String'Access;
3751 Dir_Exists : Boolean;
3753 -- Start of processing for Check_Library_Attributes
3756 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3758 -- Special case of extending project
3760 if Project.Extends /= No_Project then
3762 -- If the project extended is a library project, we inherit the
3763 -- library name, if it is not redefined; we check that the library
3764 -- directory is specified.
3766 if Project.Extends.Library then
3767 if Project.Qualifier = Standard then
3770 "a standard project cannot extend a library project",
3771 Project.Location, Project);
3774 if Lib_Name.Default then
3775 Project.Library_Name := Project.Extends.Library_Name;
3778 if Lib_Dir.Default then
3779 if not Project.Virtual then
3782 "a project extending a library project must " &
3783 "specify an attribute Library_Dir",
3784 Project.Location, Project);
3787 -- For a virtual project extending a library project,
3788 -- inherit library directory and library kind.
3790 Project.Library_Dir := Project.Extends.Library_Dir;
3791 Library_Directory_Present := True;
3792 Project.Library_Kind := Project.Extends.Library_Kind;
3799 pragma Assert (Lib_Name.Kind = Single);
3801 if Lib_Name.Value = Empty_String then
3802 if Current_Verbosity = High
3803 and then Project.Library_Name = No_Name
3806 Write_Line ("no library name");
3810 -- There is no restriction on the syntax of library names
3812 Project.Library_Name := Lib_Name.Value;
3815 if Project.Library_Name /= No_Name then
3816 if Current_Verbosity = High then
3817 Write_Attr ("Library name: ",
3818 Get_Name_String (Project.Library_Name));
3821 pragma Assert (Lib_Dir.Kind = Single);
3823 if not Library_Directory_Present then
3824 Debug_Output ("no library directory");
3827 -- Find path name (unless inherited), check that it is a directory
3829 if Project.Library_Dir = No_Path_Information then
3832 File_Name_Type (Lib_Dir.Value),
3833 Path => Project.Library_Dir,
3834 Dir_Exists => Dir_Exists,
3836 Create => "library",
3837 Must_Exist => False,
3838 Location => Lib_Dir.Location,
3839 Externally_Built => Project.Externally_Built);
3845 (Project.Library_Dir.Display_Name));
3848 if not Dir_Exists then
3850 -- Get the absolute name of the library directory that
3851 -- does not exist, to report an error.
3853 Err_Vars.Error_Msg_File_1 :=
3854 File_Name_Type (Project.Library_Dir.Display_Name);
3857 "library directory { does not exist",
3858 Lib_Dir.Location, Project);
3860 elsif not Project.Externally_Built then
3862 -- The library directory cannot be the same as the Object
3865 if Project.Library_Dir.Name = Project.Object_Directory.Name then
3868 "library directory cannot be the same " &
3869 "as object directory",
3870 Lib_Dir.Location, Project);
3871 Project.Library_Dir := No_Path_Information;
3875 OK : Boolean := True;
3876 Dirs_Id : String_List_Id;
3877 Dir_Elem : String_Element;
3881 -- The library directory cannot be the same as a source
3882 -- directory of the current project.
3884 Dirs_Id := Project.Source_Dirs;
3885 while Dirs_Id /= Nil_String loop
3886 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
3887 Dirs_Id := Dir_Elem.Next;
3889 if Project.Library_Dir.Name =
3890 Path_Name_Type (Dir_Elem.Value)
3892 Err_Vars.Error_Msg_File_1 :=
3893 File_Name_Type (Dir_Elem.Value);
3896 "library directory cannot be the same " &
3897 "as source directory {",
3898 Lib_Dir.Location, Project);
3906 -- The library directory cannot be the same as a
3907 -- source directory of another project either.
3909 Pid := Data.Tree.Projects;
3911 exit Project_Loop when Pid = null;
3913 if Pid.Project /= Project then
3914 Dirs_Id := Pid.Project.Source_Dirs;
3916 Dir_Loop : while Dirs_Id /= Nil_String loop
3918 Shared.String_Elements.Table (Dirs_Id);
3919 Dirs_Id := Dir_Elem.Next;
3921 if Project.Library_Dir.Name =
3922 Path_Name_Type (Dir_Elem.Value)
3924 Err_Vars.Error_Msg_File_1 :=
3925 File_Name_Type (Dir_Elem.Value);
3926 Err_Vars.Error_Msg_Name_1 :=
3931 "library directory cannot be the same" &
3932 " as source directory { of project %%",
3933 Lib_Dir.Location, Project);
3941 end loop Project_Loop;
3945 Project.Library_Dir := No_Path_Information;
3947 elsif Current_Verbosity = High then
3949 -- Display the Library directory in high verbosity
3952 ("Library directory",
3953 Get_Name_String (Project.Library_Dir.Display_Name));
3963 Project.Library_Dir /= No_Path_Information
3964 and then Project.Library_Name /= No_Name;
3966 if Project.Extends = No_Project then
3967 case Project.Qualifier is
3969 if Project.Library then
3972 "a standard project cannot be a library project",
3973 Lib_Name.Location, Project);
3977 if not Project.Library then
3978 if Project.Library_Name = No_Name then
3981 "attribute Library_Name not declared",
3982 Project.Location, Project);
3984 if not Library_Directory_Present then
3987 "\attribute Library_Dir not declared",
3988 Project.Location, Project);
3991 elsif Project.Library_Dir = No_Path_Information then
3994 "attribute Library_Dir not declared",
3995 Project.Location, Project);
4005 if Project.Library then
4006 Support_For_Libraries := Project.Config.Lib_Support;
4008 if Support_For_Libraries = Prj.None then
4011 "?libraries are not supported on this platform",
4012 Lib_Name.Location, Project);
4013 Project.Library := False;
4016 if Lib_ALI_Dir.Value = Empty_String then
4017 Debug_Output ("no library ALI directory specified");
4018 Project.Library_ALI_Dir := Project.Library_Dir;
4021 -- Find path name, check that it is a directory
4025 File_Name_Type (Lib_ALI_Dir.Value),
4026 Path => Project.Library_ALI_Dir,
4027 Create => "library ALI",
4028 Dir_Exists => Dir_Exists,
4030 Must_Exist => False,
4031 Location => Lib_ALI_Dir.Location,
4032 Externally_Built => Project.Externally_Built);
4034 if not Dir_Exists then
4036 -- Get the absolute name of the library ALI directory that
4037 -- does not exist, to report an error.
4039 Err_Vars.Error_Msg_File_1 :=
4040 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
4043 "library 'A'L'I directory { does not exist",
4044 Lib_ALI_Dir.Location, Project);
4047 if (not Project.Externally_Built) and then
4048 Project.Library_ALI_Dir /= Project.Library_Dir
4050 -- The library ALI directory cannot be the same as the
4051 -- Object directory.
4053 if Project.Library_ALI_Dir = Project.Object_Directory then
4056 "library 'A'L'I directory cannot be the same " &
4057 "as object directory",
4058 Lib_ALI_Dir.Location, Project);
4059 Project.Library_ALI_Dir := No_Path_Information;
4063 OK : Boolean := True;
4064 Dirs_Id : String_List_Id;
4065 Dir_Elem : String_Element;
4069 -- The library ALI directory cannot be the same as
4070 -- a source directory of the current project.
4072 Dirs_Id := Project.Source_Dirs;
4073 while Dirs_Id /= Nil_String loop
4074 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
4075 Dirs_Id := Dir_Elem.Next;
4077 if Project.Library_ALI_Dir.Name =
4078 Path_Name_Type (Dir_Elem.Value)
4080 Err_Vars.Error_Msg_File_1 :=
4081 File_Name_Type (Dir_Elem.Value);
4084 "library 'A'L'I directory cannot be " &
4085 "the same as source directory {",
4086 Lib_ALI_Dir.Location, Project);
4094 -- The library ALI directory cannot be the same as
4095 -- a source directory of another project either.
4097 Pid := Data.Tree.Projects;
4098 ALI_Project_Loop : loop
4099 exit ALI_Project_Loop when Pid = null;
4101 if Pid.Project /= Project then
4102 Dirs_Id := Pid.Project.Source_Dirs;
4105 while Dirs_Id /= Nil_String loop
4107 Shared.String_Elements.Table (Dirs_Id);
4108 Dirs_Id := Dir_Elem.Next;
4110 if Project.Library_ALI_Dir.Name =
4111 Path_Name_Type (Dir_Elem.Value)
4113 Err_Vars.Error_Msg_File_1 :=
4114 File_Name_Type (Dir_Elem.Value);
4115 Err_Vars.Error_Msg_Name_1 :=
4120 "library 'A'L'I directory cannot " &
4121 "be the same as source directory " &
4123 Lib_ALI_Dir.Location, Project);
4125 exit ALI_Project_Loop;
4127 end loop ALI_Dir_Loop;
4130 end loop ALI_Project_Loop;
4134 Project.Library_ALI_Dir := No_Path_Information;
4136 elsif Current_Verbosity = High then
4138 -- Display Library ALI directory in high verbosity
4143 (Project.Library_ALI_Dir.Display_Name));
4150 pragma Assert (Lib_Version.Kind = Single);
4152 if Lib_Version.Value = Empty_String then
4153 Debug_Output ("no library version specified");
4156 Project.Lib_Internal_Name := Lib_Version.Value;
4159 pragma Assert (The_Lib_Kind.Kind = Single);
4161 if The_Lib_Kind.Value = Empty_String then
4162 Debug_Output ("no library kind specified");
4165 Get_Name_String (The_Lib_Kind.Value);
4168 Kind_Name : constant String :=
4169 To_Lower (Name_Buffer (1 .. Name_Len));
4171 OK : Boolean := True;
4174 if Kind_Name = "static" then
4175 Project.Library_Kind := Static;
4177 elsif Kind_Name = "dynamic" then
4178 Project.Library_Kind := Dynamic;
4180 elsif Kind_Name = "relocatable" then
4181 Project.Library_Kind := Relocatable;
4186 "illegal value for Library_Kind",
4187 The_Lib_Kind.Location, Project);
4191 if Current_Verbosity = High and then OK then
4192 Write_Attr ("Library kind", Kind_Name);
4195 if Project.Library_Kind /= Static then
4196 if Support_For_Libraries = Prj.Static_Only then
4199 "only static libraries are supported " &
4201 The_Lib_Kind.Location, Project);
4202 Project.Library := False;
4205 -- Check if (obsolescent) attribute Library_GCC or
4206 -- Linker'Driver is declared.
4208 if Lib_GCC.Value /= Empty_String then
4211 "?Library_'G'C'C is an obsolescent attribute, " &
4212 "use Linker''Driver instead",
4213 Lib_GCC.Location, Project);
4214 Project.Config.Shared_Lib_Driver :=
4215 File_Name_Type (Lib_GCC.Value);
4219 Linker : constant Package_Id :=
4222 Project.Decl.Packages,
4224 Driver : constant Variable_Value :=
4227 Attribute_Or_Array_Name =>
4229 In_Package => Linker,
4233 if Driver /= Nil_Variable_Value
4234 and then Driver.Value /= Empty_String
4236 Project.Config.Shared_Lib_Driver :=
4237 File_Name_Type (Driver.Value);
4246 if Project.Library then
4247 Debug_Output ("this is a library project file");
4249 Check_Library (Project.Extends, Extends => True);
4251 Imported_Project_List := Project.Imported_Projects;
4252 while Imported_Project_List /= null loop
4254 (Imported_Project_List.Project,
4256 Imported_Project_List := Imported_Project_List.Next;
4263 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4264 -- Warn if they are declared, as it is a common error to think that
4265 -- library are "linked" with Linker switches.
4267 if Project.Library then
4269 Linker_Package_Id : constant Package_Id :=
4272 Project.Decl.Packages, Shared);
4273 Linker_Package : Package_Element;
4274 Switches : Array_Element_Id := No_Array_Element;
4277 if Linker_Package_Id /= No_Package then
4278 Linker_Package := Shared.Packages.Table (Linker_Package_Id);
4282 (Name => Name_Switches,
4283 In_Arrays => Linker_Package.Decl.Arrays,
4286 if Switches = No_Array_Element then
4289 (Name => Name_Default_Switches,
4290 In_Arrays => Linker_Package.Decl.Arrays,
4294 if Switches /= No_Array_Element then
4297 "?Linker switches not taken into account in library " &
4299 No_Location, Project);
4305 if Project.Extends /= No_Project and then Project.Extends.Library then
4307 -- Remove the library name from Lib_Data_Table
4309 for J in 1 .. Lib_Data_Table.Last loop
4310 if Lib_Data_Table.Table (J).Proj = Project.Extends then
4311 Lib_Data_Table.Table (J) :=
4312 Lib_Data_Table.Table (Lib_Data_Table.Last);
4313 Lib_Data_Table.Set_Last (Lib_Data_Table.Last - 1);
4319 if Project.Library and then not Lib_Name.Default then
4321 -- Check if the same library name is used in an other library project
4323 for J in 1 .. Lib_Data_Table.Last loop
4324 if Lib_Data_Table.Table (J).Name = Project.Library_Name then
4325 Error_Msg_Name_1 := Lib_Data_Table.Table (J).Proj.Name;
4328 "Library name cannot be the same as in project %%",
4329 Lib_Name.Location, Project);
4330 Project.Library := False;
4336 if Project.Library then
4338 -- Record the library name
4340 Lib_Data_Table.Append
4341 ((Name => Project.Library_Name, Proj => Project));
4343 end Check_Library_Attributes;
4345 ---------------------------------
4346 -- Check_Programming_Languages --
4347 ---------------------------------
4349 procedure Check_Programming_Languages
4350 (Project : Project_Id;
4351 Data : in out Tree_Processing_Data)
4353 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4355 Languages : Variable_Value := Nil_Variable_Value;
4356 Def_Lang : Variable_Value := Nil_Variable_Value;
4357 Def_Lang_Id : Name_Id;
4359 procedure Add_Language (Name, Display_Name : Name_Id);
4360 -- Add a new language to the list of languages for the project.
4361 -- Nothing is done if the language has already been defined
4367 procedure Add_Language (Name, Display_Name : Name_Id) is
4368 Lang : Language_Ptr;
4371 Lang := Project.Languages;
4372 while Lang /= No_Language_Index loop
4373 if Name = Lang.Name then
4380 Lang := new Language_Data'(No_Language_Data);
4381 Lang.Next := Project.Languages;
4382 Project.Languages := Lang;
4384 Lang.Display_Name := Display_Name;
4387 -- Start of processing for Check_Programming_Languages
4390 Project.Languages := null;
4392 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Shared);
4395 (Name_Default_Language, Project.Decl.Attributes, Shared);
4397 if Project.Source_Dirs /= Nil_String then
4399 -- Check if languages are specified in this project
4401 if Languages.Default then
4403 -- Fail if there is no default language defined
4405 if Def_Lang.Default then
4408 "no languages defined for this project",
4409 Project.Location, Project);
4410 Def_Lang_Id := No_Name;
4413 Get_Name_String (Def_Lang.Value);
4414 To_Lower (Name_Buffer (1 .. Name_Len));
4415 Def_Lang_Id := Name_Find;
4418 if Def_Lang_Id /= No_Name then
4419 Get_Name_String (Def_Lang_Id);
4420 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4422 (Name => Def_Lang_Id,
4423 Display_Name => Name_Find);
4428 Current : String_List_Id := Languages.Values;
4429 Element : String_Element;
4432 -- If there are no languages declared, there are no sources
4434 if Current = Nil_String then
4435 Project.Source_Dirs := Nil_String;
4437 if Project.Qualifier = Standard then
4440 "a standard project must have at least one language",
4441 Languages.Location, Project);
4445 -- Look through all the languages specified in attribute
4448 while Current /= Nil_String loop
4449 Element := Shared.String_Elements.Table (Current);
4450 Get_Name_String (Element.Value);
4451 To_Lower (Name_Buffer (1 .. Name_Len));
4455 Display_Name => Element.Value);
4457 Current := Element.Next;
4463 end Check_Programming_Languages;
4465 -------------------------------
4466 -- Check_Stand_Alone_Library --
4467 -------------------------------
4469 procedure Check_Stand_Alone_Library
4470 (Project : Project_Id;
4471 Data : in out Tree_Processing_Data)
4473 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4475 Lib_Interfaces : constant Prj.Variable_Value :=
4477 (Snames.Name_Library_Interface,
4478 Project.Decl.Attributes,
4481 Lib_Auto_Init : constant Prj.Variable_Value :=
4483 (Snames.Name_Library_Auto_Init,
4484 Project.Decl.Attributes,
4487 Lib_Src_Dir : constant Prj.Variable_Value :=
4489 (Snames.Name_Library_Src_Dir,
4490 Project.Decl.Attributes,
4493 Lib_Symbol_File : constant Prj.Variable_Value :=
4495 (Snames.Name_Library_Symbol_File,
4496 Project.Decl.Attributes,
4499 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4501 (Snames.Name_Library_Symbol_Policy,
4502 Project.Decl.Attributes,
4505 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4507 (Snames.Name_Library_Reference_Symbol_File,
4508 Project.Decl.Attributes,
4511 Auto_Init_Supported : Boolean;
4512 OK : Boolean := True;
4514 Next_Proj : Project_Id;
4515 Iter : Source_Iterator;
4518 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4520 pragma Assert (Lib_Interfaces.Kind = List);
4522 -- It is a stand-alone library project file if attribute
4523 -- Library_Interface is defined.
4525 if not Lib_Interfaces.Default then
4527 Interfaces : String_List_Id := Lib_Interfaces.Values;
4528 Interface_ALIs : String_List_Id := Nil_String;
4532 Project.Standalone_Library := True;
4534 -- Library_Interface cannot be an empty list
4536 if Interfaces = Nil_String then
4539 "Library_Interface cannot be an empty list",
4540 Lib_Interfaces.Location, Project);
4543 -- Process each unit name specified in the attribute
4544 -- Library_Interface.
4546 while Interfaces /= Nil_String loop
4548 (Shared.String_Elements.Table (Interfaces).Value);
4549 To_Lower (Name_Buffer (1 .. Name_Len));
4551 if Name_Len = 0 then
4554 "an interface cannot be an empty string",
4555 Shared.String_Elements.Table (Interfaces).Location,
4560 Error_Msg_Name_1 := Unit;
4562 Next_Proj := Project.Extends;
4563 Iter := For_Each_Source (Data.Tree, Project);
4565 while Prj.Element (Iter) /= No_Source
4567 (Prj.Element (Iter).Unit = null
4568 or else Prj.Element (Iter).Unit.Name /= Unit)
4573 Source := Prj.Element (Iter);
4574 exit when Source /= No_Source
4575 or else Next_Proj = No_Project;
4577 Iter := For_Each_Source (Data.Tree, Next_Proj);
4578 Next_Proj := Next_Proj.Extends;
4581 if Source /= No_Source then
4582 if Source.Kind = Sep then
4583 Source := No_Source;
4585 elsif Source.Kind = Spec
4586 and then Other_Part (Source) /= No_Source
4588 Source := Other_Part (Source);
4592 if Source /= No_Source then
4593 if Source.Project /= Project
4594 and then not Is_Extending (Project, Source.Project)
4596 Source := No_Source;
4600 if Source = No_Source then
4603 "%% is not a unit of this project",
4604 Shared.String_Elements.Table (Interfaces).Location,
4608 if Source.Kind = Spec
4609 and then Other_Part (Source) /= No_Source
4611 Source := Other_Part (Source);
4614 String_Element_Table.Increment_Last
4615 (Shared.String_Elements);
4617 Shared.String_Elements.Table
4618 (String_Element_Table.Last (Shared.String_Elements)) :=
4619 (Value => Name_Id (Source.Dep_Name),
4621 Display_Value => Name_Id (Source.Dep_Name),
4623 Shared.String_Elements.Table (Interfaces).Location,
4625 Next => Interface_ALIs);
4628 String_Element_Table.Last (Shared.String_Elements);
4632 Interfaces := Shared.String_Elements.Table (Interfaces).Next;
4635 -- Put the list of Interface ALIs in the project data
4637 Project.Lib_Interface_ALIs := Interface_ALIs;
4639 -- Check value of attribute Library_Auto_Init and set
4640 -- Lib_Auto_Init accordingly.
4642 if Lib_Auto_Init.Default then
4644 -- If no attribute Library_Auto_Init is declared, then set auto
4645 -- init only if it is supported.
4647 Project.Lib_Auto_Init := Auto_Init_Supported;
4650 Get_Name_String (Lib_Auto_Init.Value);
4651 To_Lower (Name_Buffer (1 .. Name_Len));
4653 if Name_Buffer (1 .. Name_Len) = "false" then
4654 Project.Lib_Auto_Init := False;
4656 elsif Name_Buffer (1 .. Name_Len) = "true" then
4657 if Auto_Init_Supported then
4658 Project.Lib_Auto_Init := True;
4661 -- Library_Auto_Init cannot be "true" if auto init is not
4666 "library auto init not supported " &
4668 Lib_Auto_Init.Location, Project);
4674 "invalid value for attribute Library_Auto_Init",
4675 Lib_Auto_Init.Location, Project);
4680 -- If attribute Library_Src_Dir is defined and not the empty string,
4681 -- check if the directory exist and is not the object directory or
4682 -- one of the source directories. This is the directory where copies
4683 -- of the interface sources will be copied. Note that this directory
4684 -- may be the library directory.
4686 if Lib_Src_Dir.Value /= Empty_String then
4688 Dir_Id : constant File_Name_Type :=
4689 File_Name_Type (Lib_Src_Dir.Value);
4690 Dir_Exists : Boolean;
4696 Path => Project.Library_Src_Dir,
4697 Dir_Exists => Dir_Exists,
4699 Must_Exist => False,
4700 Create => "library source copy",
4701 Location => Lib_Src_Dir.Location,
4702 Externally_Built => Project.Externally_Built);
4704 -- If directory does not exist, report an error
4706 if not Dir_Exists then
4708 -- Get the absolute name of the library directory that does
4709 -- not exist, to report an error.
4711 Err_Vars.Error_Msg_File_1 :=
4712 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4715 "Directory { does not exist",
4716 Lib_Src_Dir.Location, Project);
4718 -- Report error if it is the same as the object directory
4720 elsif Project.Library_Src_Dir = Project.Object_Directory then
4723 "directory to copy interfaces cannot be " &
4724 "the object directory",
4725 Lib_Src_Dir.Location, Project);
4726 Project.Library_Src_Dir := No_Path_Information;
4730 Src_Dirs : String_List_Id;
4731 Src_Dir : String_Element;
4735 -- Interface copy directory cannot be one of the source
4736 -- directory of the current project.
4738 Src_Dirs := Project.Source_Dirs;
4739 while Src_Dirs /= Nil_String loop
4740 Src_Dir := Shared.String_Elements.Table (Src_Dirs);
4742 -- Report error if it is one of the source directories
4744 if Project.Library_Src_Dir.Name =
4745 Path_Name_Type (Src_Dir.Value)
4749 "directory to copy interfaces cannot " &
4750 "be one of the source directories",
4751 Lib_Src_Dir.Location, Project);
4752 Project.Library_Src_Dir := No_Path_Information;
4756 Src_Dirs := Src_Dir.Next;
4759 if Project.Library_Src_Dir /= No_Path_Information then
4761 -- It cannot be a source directory of any other
4764 Pid := Data.Tree.Projects;
4766 exit Project_Loop when Pid = null;
4768 Src_Dirs := Pid.Project.Source_Dirs;
4769 Dir_Loop : while Src_Dirs /= Nil_String loop
4771 Shared.String_Elements.Table (Src_Dirs);
4773 -- Report error if it is one of the source
4776 if Project.Library_Src_Dir.Name =
4777 Path_Name_Type (Src_Dir.Value)
4780 File_Name_Type (Src_Dir.Value);
4781 Error_Msg_Name_1 := Pid.Project.Name;
4784 "directory to copy interfaces cannot " &
4785 "be the same as source directory { of " &
4787 Lib_Src_Dir.Location, Project);
4788 Project.Library_Src_Dir :=
4789 No_Path_Information;
4793 Src_Dirs := Src_Dir.Next;
4797 end loop Project_Loop;
4801 -- In high verbosity, if there is a valid Library_Src_Dir,
4802 -- display its path name.
4804 if Project.Library_Src_Dir /= No_Path_Information
4805 and then Current_Verbosity = High
4808 ("Directory to copy interfaces",
4809 Get_Name_String (Project.Library_Src_Dir.Name));
4815 -- Check the symbol related attributes
4817 -- First, the symbol policy
4819 if not Lib_Symbol_Policy.Default then
4821 Value : constant String :=
4823 (Get_Name_String (Lib_Symbol_Policy.Value));
4826 -- Symbol policy must hove one of a limited number of values
4828 if Value = "autonomous" or else Value = "default" then
4829 Project.Symbol_Data.Symbol_Policy := Autonomous;
4831 elsif Value = "compliant" then
4832 Project.Symbol_Data.Symbol_Policy := Compliant;
4834 elsif Value = "controlled" then
4835 Project.Symbol_Data.Symbol_Policy := Controlled;
4837 elsif Value = "restricted" then
4838 Project.Symbol_Data.Symbol_Policy := Restricted;
4840 elsif Value = "direct" then
4841 Project.Symbol_Data.Symbol_Policy := Direct;
4846 "illegal value for Library_Symbol_Policy",
4847 Lib_Symbol_Policy.Location, Project);
4852 -- If attribute Library_Symbol_File is not specified, symbol policy
4853 -- cannot be Restricted.
4855 if Lib_Symbol_File.Default then
4856 if Project.Symbol_Data.Symbol_Policy = Restricted then
4859 "Library_Symbol_File needs to be defined when " &
4860 "symbol policy is Restricted",
4861 Lib_Symbol_Policy.Location, Project);
4865 -- Library_Symbol_File is defined
4867 Project.Symbol_Data.Symbol_File :=
4868 Path_Name_Type (Lib_Symbol_File.Value);
4870 Get_Name_String (Lib_Symbol_File.Value);
4872 if Name_Len = 0 then
4875 "symbol file name cannot be an empty string",
4876 Lib_Symbol_File.Location, Project);
4879 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4882 for J in 1 .. Name_Len loop
4883 if Name_Buffer (J) = '/'
4884 or else Name_Buffer (J) = Directory_Separator
4893 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4896 "symbol file name { is illegal. " &
4897 "Name cannot include directory info.",
4898 Lib_Symbol_File.Location, Project);
4903 -- If attribute Library_Reference_Symbol_File is not defined,
4904 -- symbol policy cannot be Compliant or Controlled.
4906 if Lib_Ref_Symbol_File.Default then
4907 if Project.Symbol_Data.Symbol_Policy = Compliant
4908 or else Project.Symbol_Data.Symbol_Policy = Controlled
4912 "a reference symbol file needs to be defined",
4913 Lib_Symbol_Policy.Location, Project);
4917 -- Library_Reference_Symbol_File is defined, check file exists
4919 Project.Symbol_Data.Reference :=
4920 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4922 Get_Name_String (Lib_Ref_Symbol_File.Value);
4924 if Name_Len = 0 then
4927 "reference symbol file name cannot be an empty string",
4928 Lib_Symbol_File.Location, Project);
4931 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4933 Add_Str_To_Name_Buffer
4934 (Get_Name_String (Project.Directory.Name));
4935 Add_Str_To_Name_Buffer
4936 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4937 Project.Symbol_Data.Reference := Name_Find;
4940 if not Is_Regular_File
4941 (Get_Name_String (Project.Symbol_Data.Reference))
4944 File_Name_Type (Lib_Ref_Symbol_File.Value);
4946 -- For controlled and direct symbol policies, it is an error
4947 -- if the reference symbol file does not exist. For other
4948 -- symbol policies, this is just a warning
4951 Project.Symbol_Data.Symbol_Policy /= Controlled
4952 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4956 "<library reference symbol file { does not exist",
4957 Lib_Ref_Symbol_File.Location, Project);
4959 -- In addition in the non-controlled case, if symbol policy
4960 -- is Compliant, it is changed to Autonomous, because there
4961 -- is no reference to check against, and we don't want to
4962 -- fail in this case.
4964 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4965 if Project.Symbol_Data.Symbol_Policy = Compliant then
4966 Project.Symbol_Data.Symbol_Policy := Autonomous;
4971 -- If both the reference symbol file and the symbol file are
4972 -- defined, then check that they are not the same file.
4974 if Project.Symbol_Data.Symbol_File /= No_Path then
4975 Get_Name_String (Project.Symbol_Data.Symbol_File);
4977 if Name_Len > 0 then
4979 -- We do not need to pass a Directory to
4980 -- Normalize_Pathname, since the path_information
4981 -- already contains absolute information.
4983 Symb_Path : constant String :=
4986 (Project.Object_Directory.Name) &
4987 Name_Buffer (1 .. Name_Len),
4990 Opt.Follow_Links_For_Files);
4991 Ref_Path : constant String :=
4994 (Project.Symbol_Data.Reference),
4997 Opt.Follow_Links_For_Files);
4999 if Symb_Path = Ref_Path then
5002 "library reference symbol file and library" &
5003 " symbol file cannot be the same file",
5004 Lib_Ref_Symbol_File.Location, Project);
5012 end Check_Stand_Alone_Library;
5014 ----------------------------
5015 -- Compute_Directory_Last --
5016 ----------------------------
5018 function Compute_Directory_Last (Dir : String) return Natural is
5021 and then (Dir (Dir'Last - 1) = Directory_Separator
5023 Dir (Dir'Last - 1) = '/')
5025 return Dir'Last - 1;
5029 end Compute_Directory_Last;
5031 ---------------------
5032 -- Get_Directories --
5033 ---------------------
5035 procedure Get_Directories
5036 (Project : Project_Id;
5037 Data : in out Tree_Processing_Data)
5039 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5041 Object_Dir : constant Variable_Value :=
5043 (Name_Object_Dir, Project.Decl.Attributes, Shared);
5045 Exec_Dir : constant Variable_Value :=
5047 (Name_Exec_Dir, Project.Decl.Attributes, Shared);
5049 Source_Dirs : constant Variable_Value :=
5051 (Name_Source_Dirs, Project.Decl.Attributes, Shared);
5053 Ignore_Source_Sub_Dirs : constant Variable_Value :=
5055 (Name_Ignore_Source_Sub_Dirs,
5056 Project.Decl.Attributes,
5059 Excluded_Source_Dirs : constant Variable_Value :=
5061 (Name_Excluded_Source_Dirs,
5062 Project.Decl.Attributes,
5065 Source_Files : constant Variable_Value :=
5068 Project.Decl.Attributes, Shared);
5070 Last_Source_Dir : String_List_Id := Nil_String;
5071 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
5073 Languages : constant Variable_Value :=
5075 (Name_Languages, Project.Decl.Attributes, Shared);
5077 Remove_Source_Dirs : Boolean := False;
5079 procedure Add_To_Or_Remove_From_Source_Dirs
5080 (Path : Path_Information;
5082 -- When Removed = False, the directory Path_Id to the list of
5083 -- source_dirs if not already in the list. When Removed = True,
5084 -- removed directory Path_Id if in the list.
5086 procedure Find_Source_Dirs is new Expand_Subdirectory_Pattern
5087 (Add_To_Or_Remove_From_Source_Dirs);
5089 ---------------------------------------
5090 -- Add_To_Or_Remove_From_Source_Dirs --
5091 ---------------------------------------
5093 procedure Add_To_Or_Remove_From_Source_Dirs
5094 (Path : Path_Information;
5097 List : String_List_Id;
5098 Prev : String_List_Id;
5099 Rank_List : Number_List_Index;
5100 Prev_Rank : Number_List_Index;
5101 Element : String_Element;
5105 Prev_Rank := No_Number_List;
5106 List := Project.Source_Dirs;
5107 Rank_List := Project.Source_Dir_Ranks;
5108 while List /= Nil_String loop
5109 Element := Shared.String_Elements.Table (List);
5110 exit when Element.Value = Name_Id (Path.Name);
5112 List := Element.Next;
5113 Prev_Rank := Rank_List;
5114 Rank_List := Shared.Number_Lists.Table (Prev_Rank).Next;
5117 -- The directory is in the list if List is not Nil_String
5119 if not Remove_Source_Dirs and then List = Nil_String then
5120 Debug_Output ("adding source dir=", Name_Id (Path.Display_Name));
5122 String_Element_Table.Increment_Last (Shared.String_Elements);
5124 (Value => Name_Id (Path.Name),
5126 Display_Value => Name_Id (Path.Display_Name),
5127 Location => No_Location,
5129 Next => Nil_String);
5131 Number_List_Table.Increment_Last (Shared.Number_Lists);
5133 if Last_Source_Dir = Nil_String then
5135 -- This is the first source directory
5137 Project.Source_Dirs :=
5138 String_Element_Table.Last (Shared.String_Elements);
5139 Project.Source_Dir_Ranks :=
5140 Number_List_Table.Last (Shared.Number_Lists);
5143 -- We already have source directories, link the previous
5144 -- last to the new one.
5146 Shared.String_Elements.Table (Last_Source_Dir).Next :=
5147 String_Element_Table.Last (Shared.String_Elements);
5148 Shared.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
5149 Number_List_Table.Last (Shared.Number_Lists);
5152 -- And register this source directory as the new last
5155 String_Element_Table.Last (Shared.String_Elements);
5156 Shared.String_Elements.Table (Last_Source_Dir) := Element;
5157 Last_Src_Dir_Rank := Number_List_Table.Last (Shared.Number_Lists);
5158 Shared.Number_Lists.Table (Last_Src_Dir_Rank) :=
5159 (Number => Rank, Next => No_Number_List);
5161 elsif Remove_Source_Dirs and then List /= Nil_String then
5163 -- Remove source dir if present
5165 if Prev = Nil_String then
5166 Project.Source_Dirs := Shared.String_Elements.Table (List).Next;
5167 Project.Source_Dir_Ranks :=
5168 Shared.Number_Lists.Table (Rank_List).Next;
5171 Shared.String_Elements.Table (Prev).Next :=
5172 Shared.String_Elements.Table (List).Next;
5173 Shared.Number_Lists.Table (Prev_Rank).Next :=
5174 Shared.Number_Lists.Table (Rank_List).Next;
5177 end Add_To_Or_Remove_From_Source_Dirs;
5179 -- Local declarations
5181 Dir_Exists : Boolean;
5183 No_Sources : constant Boolean :=
5184 ((not Source_Files.Default
5185 and then Source_Files.Values = Nil_String)
5187 (not Source_Dirs.Default
5188 and then Source_Dirs.Values = Nil_String)
5190 (not Languages.Default
5191 and then Languages.Values = Nil_String))
5192 and then Project.Extends = No_Project;
5194 -- Start of processing for Get_Directories
5197 Debug_Output ("starting to look for directories");
5199 -- Set the object directory to its default which may be nil, if there
5200 -- is no sources in the project.
5203 Project.Object_Directory := No_Path_Information;
5205 Project.Object_Directory := Project.Directory;
5208 -- Check the object directory
5210 if Object_Dir.Value /= Empty_String then
5211 Get_Name_String (Object_Dir.Value);
5213 if Name_Len = 0 then
5216 "Object_Dir cannot be empty",
5217 Object_Dir.Location, Project);
5219 elsif not No_Sources then
5221 -- We check that the specified object directory does exist.
5222 -- However, even when it doesn't exist, we set it to a default
5223 -- value. This is for the benefit of tools that recover from
5224 -- errors; for example, these tools could create the non existent
5225 -- directory. We always return an absolute directory name though.
5229 File_Name_Type (Object_Dir.Value),
5230 Path => Project.Object_Directory,
5232 Dir_Exists => Dir_Exists,
5234 Location => Object_Dir.Location,
5235 Must_Exist => False,
5236 Externally_Built => Project.Externally_Built);
5239 and then not Project.Externally_Built
5241 -- The object directory does not exist, report an error if the
5242 -- project is not externally built.
5244 Err_Vars.Error_Msg_File_1 :=
5245 File_Name_Type (Object_Dir.Value);
5247 (Data.Flags, Data.Flags.Require_Obj_Dirs,
5248 "object directory { not found", Project.Location, Project);
5252 elsif not No_Sources and then Subdirs /= null then
5254 Name_Buffer (1) := '.';
5258 Path => Project.Object_Directory,
5260 Dir_Exists => Dir_Exists,
5262 Location => Object_Dir.Location,
5263 Externally_Built => Project.Externally_Built);
5266 if Current_Verbosity = High then
5267 if Project.Object_Directory = No_Path_Information then
5268 Debug_Output ("no object directory");
5271 ("Object directory",
5272 Get_Name_String (Project.Object_Directory.Display_Name));
5276 -- Check the exec directory
5278 -- We set the object directory to its default
5280 Project.Exec_Directory := Project.Object_Directory;
5282 if Exec_Dir.Value /= Empty_String then
5283 Get_Name_String (Exec_Dir.Value);
5285 if Name_Len = 0 then
5288 "Exec_Dir cannot be empty",
5289 Exec_Dir.Location, Project);
5291 elsif not No_Sources then
5293 -- We check that the specified exec directory does exist
5297 File_Name_Type (Exec_Dir.Value),
5298 Path => Project.Exec_Directory,
5299 Dir_Exists => Dir_Exists,
5302 Location => Exec_Dir.Location,
5303 Externally_Built => Project.Externally_Built);
5305 if not Dir_Exists then
5306 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5308 (Data.Flags, Data.Flags.Missing_Source_Files,
5309 "exec directory { not found", Project.Location, Project);
5314 if Current_Verbosity = High then
5315 if Project.Exec_Directory = No_Path_Information then
5316 Debug_Output ("no exec directory");
5319 ("exec directory: ",
5320 Name_Id (Project.Exec_Directory.Display_Name));
5324 -- Look for the source directories
5326 Debug_Output ("starting to look for source directories");
5328 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5330 if not Source_Files.Default
5331 and then Source_Files.Values = Nil_String
5333 Project.Source_Dirs := Nil_String;
5335 if Project.Qualifier = Standard then
5338 "a standard project cannot have no sources",
5339 Source_Files.Location, Project);
5342 elsif Source_Dirs.Default then
5344 -- No Source_Dirs specified: the single source directory is the one
5345 -- containing the project file.
5347 Remove_Source_Dirs := False;
5348 Add_To_Or_Remove_From_Source_Dirs
5349 (Path => (Name => Project.Directory.Name,
5350 Display_Name => Project.Directory.Display_Name),
5354 Remove_Source_Dirs := False;
5356 (Project => Project,
5358 Patterns => Source_Dirs.Values,
5359 Ignore => Ignore_Source_Sub_Dirs.Values,
5360 Search_For => Search_Directories,
5361 Resolve_Links => Opt.Follow_Links_For_Dirs);
5363 if Project.Source_Dirs = Nil_String
5364 and then Project.Qualifier = Standard
5368 "a standard project cannot have no source directories",
5369 Source_Dirs.Location, Project);
5373 if not Excluded_Source_Dirs.Default
5374 and then Excluded_Source_Dirs.Values /= Nil_String
5376 Remove_Source_Dirs := True;
5378 (Project => Project,
5380 Patterns => Excluded_Source_Dirs.Values,
5381 Ignore => Nil_String,
5382 Search_For => Search_Directories,
5383 Resolve_Links => Opt.Follow_Links_For_Dirs);
5386 Debug_Output ("putting source directories in canonical cases");
5389 Current : String_List_Id := Project.Source_Dirs;
5390 Element : String_Element;
5393 while Current /= Nil_String loop
5394 Element := Shared.String_Elements.Table (Current);
5395 if Element.Value /= No_Name then
5397 Name_Id (Canonical_Case_File_Name (Element.Value));
5398 Shared.String_Elements.Table (Current) := Element;
5401 Current := Element.Next;
5404 end Get_Directories;
5411 (Project : Project_Id;
5412 Data : in out Tree_Processing_Data)
5414 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5416 Mains : constant Variable_Value :=
5418 (Name_Main, Project.Decl.Attributes, Shared);
5419 List : String_List_Id;
5420 Elem : String_Element;
5423 Project.Mains := Mains.Values;
5425 -- If no Mains were specified, and if we are an extending project,
5426 -- inherit the Mains from the project we are extending.
5428 if Mains.Default then
5429 if not Project.Library and then Project.Extends /= No_Project then
5430 Project.Mains := Project.Extends.Mains;
5433 -- In a library project file, Main cannot be specified
5435 elsif Project.Library then
5438 "a library project file cannot have Main specified",
5439 Mains.Location, Project);
5442 List := Mains.Values;
5443 while List /= Nil_String loop
5444 Elem := Shared.String_Elements.Table (List);
5446 if Length_Of_Name (Elem.Value) = 0 then
5449 "?a main cannot have an empty name",
5450 Elem.Location, Project);
5459 ---------------------------
5460 -- Get_Sources_From_File --
5461 ---------------------------
5463 procedure Get_Sources_From_File
5465 Location : Source_Ptr;
5466 Project : in out Project_Processing_Data;
5467 Data : in out Tree_Processing_Data)
5469 File : Prj.Util.Text_File;
5470 Line : String (1 .. 250);
5472 Source_Name : File_Name_Type;
5473 Name_Loc : Name_Location;
5476 if Current_Verbosity = High then
5477 Debug_Output ("opening """ & Path & '"');
5482 Prj.Util.Open (File, Path);
5484 if not Prj.Util.Is_Valid (File) then
5486 (Data.Flags, "file does not exist", Location, Project.Project);
5489 -- Read the lines one by one
5491 while not Prj.Util.End_Of_File (File) loop
5492 Prj.Util.Get_Line (File, Line, Last);
5494 -- A non empty, non comment line should contain a file name
5497 and then (Last = 1 or else Line (1 .. 2) /= "--")
5500 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5501 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5502 Source_Name := Name_Find;
5504 -- Check that there is no directory information
5506 for J in 1 .. Last loop
5507 if Line (J) = '/' or else Line (J) = Directory_Separator then
5508 Error_Msg_File_1 := Source_Name;
5511 "file name cannot include directory information ({)",
5512 Location, Project.Project);
5517 Name_Loc := Source_Names_Htable.Get
5518 (Project.Source_Names, Source_Name);
5520 if Name_Loc = No_Name_Location then
5522 (Name => Source_Name,
5523 Location => Location,
5524 Source => No_Source,
5529 Name_Loc.Listed := True;
5532 Source_Names_Htable.Set
5533 (Project.Source_Names, Source_Name, Name_Loc);
5537 Prj.Util.Close (File);
5540 end Get_Sources_From_File;
5546 function No_Space_Img (N : Natural) return String is
5547 Image : constant String := N'Img;
5549 return Image (2 .. Image'Last);
5552 -----------------------
5553 -- Compute_Unit_Name --
5554 -----------------------
5556 procedure Compute_Unit_Name
5557 (File_Name : File_Name_Type;
5558 Naming : Lang_Naming_Data;
5559 Kind : out Source_Kind;
5561 Project : Project_Processing_Data;
5562 In_Tree : Project_Tree_Ref)
5564 Filename : constant String := Get_Name_String (File_Name);
5565 Last : Integer := Filename'Last;
5570 Unit_Except : Unit_Exception;
5571 Masked : Boolean := False;
5577 if Naming.Separate_Suffix = No_File
5578 or else Naming.Body_Suffix = No_File
5579 or else Naming.Spec_Suffix = No_File
5584 if Naming.Dot_Replacement = No_File then
5585 Debug_Output ("no dot_replacement specified");
5589 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5590 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5591 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5593 -- Choose the longest suffix that matches. If there are several matches,
5594 -- give priority to specs, then bodies, then separates.
5596 if Naming.Separate_Suffix /= Naming.Body_Suffix
5597 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5599 Last := Filename'Last - Sep_Len;
5603 if Filename'Last - Body_Len <= Last
5604 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5606 Last := Natural'Min (Last, Filename'Last - Body_Len);
5610 if Filename'Last - Spec_Len <= Last
5611 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5613 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5617 if Last = Filename'Last then
5618 Debug_Output ("no matching suffix");
5622 -- Check that the casing matches
5624 if File_Names_Case_Sensitive then
5625 case Naming.Casing is
5626 when All_Lower_Case =>
5627 for J in Filename'First .. Last loop
5628 if Is_Letter (Filename (J))
5629 and then not Is_Lower (Filename (J))
5631 Debug_Output ("invalid casing");
5636 when All_Upper_Case =>
5637 for J in Filename'First .. Last loop
5638 if Is_Letter (Filename (J))
5639 and then not Is_Upper (Filename (J))
5641 Debug_Output ("invalid casing");
5646 when Mixed_Case | Unknown =>
5651 -- If Dot_Replacement is not a single dot, then there should not
5652 -- be any dot in the name.
5655 Dot_Repl : constant String :=
5656 Get_Name_String (Naming.Dot_Replacement);
5659 if Dot_Repl /= "." then
5660 for Index in Filename'First .. Last loop
5661 if Filename (Index) = '.' then
5662 Debug_Output ("invalid name, contains dot");
5667 Replace_Into_Name_Buffer
5668 (Filename (Filename'First .. Last), Dot_Repl, '.');
5671 Name_Len := Last - Filename'First + 1;
5672 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5674 (Source => Name_Buffer (1 .. Name_Len),
5675 Mapping => Lower_Case_Map);
5679 -- In the standard GNAT naming scheme, check for special cases: children
5680 -- or separates of A, G, I or S, and run time sources.
5682 if Is_Standard_GNAT_Naming (Naming)
5683 and then Name_Len >= 3
5686 S1 : constant Character := Name_Buffer (1);
5687 S2 : constant Character := Name_Buffer (2);
5688 S3 : constant Character := Name_Buffer (3);
5696 -- Children or separates of packages A, G, I or S. These names
5697 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5698 -- versions (x__... and x~...) are allowed in all platforms,
5699 -- because it is not possible to know the platform before
5700 -- processing of the project files.
5702 if S2 = '_' and then S3 = '_' then
5703 Name_Buffer (2) := '.';
5704 Name_Buffer (3 .. Name_Len - 1) :=
5705 Name_Buffer (4 .. Name_Len);
5706 Name_Len := Name_Len - 1;
5709 Name_Buffer (2) := '.';
5713 -- If it is potentially a run time source
5721 -- Name_Buffer contains the name of the unit in lower-cases. Check
5722 -- that this is a valid unit name
5724 Check_Unit_Name (Name_Buffer (1 .. Name_Len), Unit);
5726 -- If there is a naming exception for the same unit, the file is not
5727 -- a source for the unit.
5729 if Unit /= No_Name then
5731 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5734 Masked := Unit_Except.Spec /= No_File
5736 Unit_Except.Spec /= File_Name;
5738 Masked := Unit_Except.Impl /= No_File
5740 Unit_Except.Impl /= File_Name;
5744 if Current_Verbosity = High then
5746 Write_Str (" """ & Filename & """ contains the ");
5749 Write_Str ("spec of a unit found in """);
5750 Write_Str (Get_Name_String (Unit_Except.Spec));
5752 Write_Str ("body of a unit found in """);
5753 Write_Str (Get_Name_String (Unit_Except.Impl));
5756 Write_Line (""" (ignored)");
5764 and then Current_Verbosity = High
5767 when Spec => Debug_Output ("spec of", Unit);
5768 when Impl => Debug_Output ("body of", Unit);
5769 when Sep => Debug_Output ("sep of", Unit);
5772 end Compute_Unit_Name;
5774 --------------------------
5775 -- Check_Illegal_Suffix --
5776 --------------------------
5778 procedure Check_Illegal_Suffix
5779 (Project : Project_Id;
5780 Suffix : File_Name_Type;
5781 Dot_Replacement : File_Name_Type;
5782 Attribute_Name : String;
5783 Location : Source_Ptr;
5784 Data : in out Tree_Processing_Data)
5786 Suffix_Str : constant String := Get_Name_String (Suffix);
5789 if Suffix_Str'Length = 0 then
5795 elsif Index (Suffix_Str, ".") = 0 then
5796 Err_Vars.Error_Msg_File_1 := Suffix;
5799 "{ is illegal for " & Attribute_Name & ": must have a dot",
5804 -- Case of dot replacement is a single dot, and first character of
5805 -- suffix is also a dot.
5807 if Dot_Replacement /= No_File
5808 and then Get_Name_String (Dot_Replacement) = "."
5809 and then Suffix_Str (Suffix_Str'First) = '.'
5811 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5813 -- If there are multiple dots in the name
5815 if Suffix_Str (Index) = '.' then
5817 -- It is illegal to have a letter following the initial dot
5819 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5820 Err_Vars.Error_Msg_File_1 := Suffix;
5823 "{ is illegal for " & Attribute_Name
5824 & ": ambiguous prefix when Dot_Replacement is a dot",
5831 end Check_Illegal_Suffix;
5833 ----------------------
5834 -- Locate_Directory --
5835 ----------------------
5837 procedure Locate_Directory
5838 (Project : Project_Id;
5839 Name : File_Name_Type;
5840 Path : out Path_Information;
5841 Dir_Exists : out Boolean;
5842 Data : in out Tree_Processing_Data;
5843 Create : String := "";
5844 Location : Source_Ptr := No_Location;
5845 Must_Exist : Boolean := True;
5846 Externally_Built : Boolean := False)
5848 Parent : constant Path_Name_Type :=
5849 Project.Directory.Display_Name;
5850 The_Parent : constant String :=
5851 Get_Name_String (Parent);
5852 The_Parent_Last : constant Natural :=
5853 Compute_Directory_Last (The_Parent);
5854 Full_Name : File_Name_Type;
5855 The_Name : File_Name_Type;
5858 Get_Name_String (Name);
5860 -- Add Subdirs.all if it is a directory that may be created and
5861 -- Subdirs is not null;
5863 if Create /= "" and then Subdirs /= null then
5864 if Name_Buffer (Name_Len) /= Directory_Separator then
5865 Add_Char_To_Name_Buffer (Directory_Separator);
5868 Add_Str_To_Name_Buffer (Subdirs.all);
5871 -- Convert '/' to directory separator (for Windows)
5873 for J in 1 .. Name_Len loop
5874 if Name_Buffer (J) = '/' then
5875 Name_Buffer (J) := Directory_Separator;
5879 The_Name := Name_Find;
5881 if Current_Verbosity = High then
5883 Write_Str ("Locate_Directory (""");
5884 Write_Str (Get_Name_String (The_Name));
5885 Write_Str (""", in """);
5886 Write_Str (The_Parent);
5890 Path := No_Path_Information;
5891 Dir_Exists := False;
5893 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5894 Full_Name := The_Name;
5898 Add_Str_To_Name_Buffer
5899 (The_Parent (The_Parent'First .. The_Parent_Last));
5900 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5901 Full_Name := Name_Find;
5905 Full_Path_Name : String_Access :=
5906 new String'(Get_Name_String (Full_Name));
5909 if (Setup_Projects or else Subdirs /= null)
5910 and then Create'Length > 0
5912 if not Is_Directory (Full_Path_Name.all) then
5914 -- If project is externally built, do not create a subdir,
5915 -- use the specified directory, without the subdir.
5917 if Externally_Built then
5918 if Is_Absolute_Path (Get_Name_String (Name)) then
5919 Get_Name_String (Name);
5923 Add_Str_To_Name_Buffer
5924 (The_Parent (The_Parent'First .. The_Parent_Last));
5925 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5928 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5932 Create_Path (Full_Path_Name.all);
5934 if not Quiet_Output then
5936 Write_Str (" directory """);
5937 Write_Str (Full_Path_Name.all);
5938 Write_Str (""" created for project ");
5939 Write_Line (Get_Name_String (Project.Name));
5946 "could not create " & Create &
5947 " directory " & Full_Path_Name.all,
5954 Dir_Exists := Is_Directory (Full_Path_Name.all);
5956 if not Must_Exist or else Dir_Exists then
5958 Normed : constant String :=
5960 (Full_Path_Name.all,
5962 The_Parent (The_Parent'First .. The_Parent_Last),
5963 Resolve_Links => False,
5964 Case_Sensitive => True);
5966 Canonical_Path : constant String :=
5971 (The_Parent'First .. The_Parent_Last),
5973 Opt.Follow_Links_For_Dirs,
5974 Case_Sensitive => False);
5977 Name_Len := Normed'Length;
5978 Name_Buffer (1 .. Name_Len) := Normed;
5980 -- Directories should always end with a directory separator
5982 if Name_Buffer (Name_Len) /= Directory_Separator then
5983 Add_Char_To_Name_Buffer (Directory_Separator);
5986 Path.Display_Name := Name_Find;
5988 Name_Len := Canonical_Path'Length;
5989 Name_Buffer (1 .. Name_Len) := Canonical_Path;
5991 if Name_Buffer (Name_Len) /= Directory_Separator then
5992 Add_Char_To_Name_Buffer (Directory_Separator);
5995 Path.Name := Name_Find;
5999 Free (Full_Path_Name);
6001 end Locate_Directory;
6003 ---------------------------
6004 -- Find_Excluded_Sources --
6005 ---------------------------
6007 procedure Find_Excluded_Sources
6008 (Project : in out Project_Processing_Data;
6009 Data : in out Tree_Processing_Data)
6011 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6013 Excluded_Source_List_File : constant Variable_Value :=
6015 (Name_Excluded_Source_List_File,
6016 Project.Project.Decl.Attributes,
6018 Excluded_Sources : Variable_Value := Util.Value_Of
6019 (Name_Excluded_Source_Files,
6020 Project.Project.Decl.Attributes,
6023 Current : String_List_Id;
6024 Element : String_Element;
6025 Location : Source_Ptr;
6026 Name : File_Name_Type;
6027 File : Prj.Util.Text_File;
6028 Line : String (1 .. 300);
6030 Locally_Removed : Boolean := False;
6033 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6035 if Excluded_Sources.Default then
6036 Locally_Removed := True;
6039 (Name_Locally_Removed_Files,
6040 Project.Project.Decl.Attributes, Shared);
6043 -- If there are excluded sources, put them in the table
6045 if not Excluded_Sources.Default then
6046 if not Excluded_Source_List_File.Default then
6047 if Locally_Removed then
6050 "?both attributes Locally_Removed_Files and " &
6051 "Excluded_Source_List_File are present",
6052 Excluded_Source_List_File.Location, Project.Project);
6056 "?both attributes Excluded_Source_Files and " &
6057 "Excluded_Source_List_File are present",
6058 Excluded_Source_List_File.Location, Project.Project);
6062 Current := Excluded_Sources.Values;
6063 while Current /= Nil_String loop
6064 Element := Shared.String_Elements.Table (Current);
6065 Name := Canonical_Case_File_Name (Element.Value);
6067 -- If the element has no location, then use the location of
6068 -- Excluded_Sources to report possible errors.
6070 if Element.Location = No_Location then
6071 Location := Excluded_Sources.Location;
6073 Location := Element.Location;
6076 Excluded_Sources_Htable.Set
6077 (Project.Excluded, Name,
6078 (Name, No_File, 0, False, Location));
6079 Current := Element.Next;
6082 elsif not Excluded_Source_List_File.Default then
6083 Location := Excluded_Source_List_File.Location;
6086 Source_File_Name : constant File_Name_Type :=
6088 (Excluded_Source_List_File.Value);
6089 Source_File_Line : Natural := 0;
6091 Source_File_Path_Name : constant String :=
6094 Project.Project.Directory.Name);
6097 if Source_File_Path_Name'Length = 0 then
6098 Err_Vars.Error_Msg_File_1 :=
6099 File_Name_Type (Excluded_Source_List_File.Value);
6102 "file with excluded sources { does not exist",
6103 Excluded_Source_List_File.Location, Project.Project);
6108 Prj.Util.Open (File, Source_File_Path_Name);
6110 if not Prj.Util.Is_Valid (File) then
6112 (Data.Flags, "file does not exist",
6113 Location, Project.Project);
6115 -- Read the lines one by one
6117 while not Prj.Util.End_Of_File (File) loop
6118 Prj.Util.Get_Line (File, Line, Last);
6119 Source_File_Line := Source_File_Line + 1;
6121 -- Non empty, non comment line should contain a file name
6124 and then (Last = 1 or else Line (1 .. 2) /= "--")
6127 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6128 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6131 -- Check that there is no directory information
6133 for J in 1 .. Last loop
6135 or else Line (J) = Directory_Separator
6137 Error_Msg_File_1 := Name;
6140 "file name cannot include " &
6141 "directory information ({)",
6142 Location, Project.Project);
6147 Excluded_Sources_Htable.Set
6150 (Name, Source_File_Name, Source_File_Line,
6155 Prj.Util.Close (File);
6160 end Find_Excluded_Sources;
6166 procedure Find_Sources
6167 (Project : in out Project_Processing_Data;
6168 Data : in out Tree_Processing_Data)
6170 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6172 Sources : constant Variable_Value :=
6175 Project.Project.Decl.Attributes,
6178 Source_List_File : constant Variable_Value :=
6180 (Name_Source_List_File,
6181 Project.Project.Decl.Attributes,
6184 Name_Loc : Name_Location;
6185 Has_Explicit_Sources : Boolean;
6188 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6190 (Source_List_File.Kind = Single,
6191 "Source_List_File is not a single string");
6193 Project.Source_List_File_Location := Source_List_File.Location;
6195 -- If the user has specified a Source_Files attribute
6197 if not Sources.Default then
6198 if not Source_List_File.Default then
6201 "?both attributes source_files and " &
6202 "source_list_file are present",
6203 Source_List_File.Location, Project.Project);
6206 -- Sources is a list of file names
6209 Current : String_List_Id := Sources.Values;
6210 Element : String_Element;
6211 Location : Source_Ptr;
6212 Name : File_Name_Type;
6215 if Current = Nil_String then
6216 Project.Project.Languages := No_Language_Index;
6218 -- This project contains no source. For projects that don't
6219 -- extend other projects, this also means that there is no
6220 -- need for an object directory, if not specified.
6222 if Project.Project.Extends = No_Project
6223 and then Project.Project.Object_Directory =
6224 Project.Project.Directory
6226 Project.Project.Object_Directory := No_Path_Information;
6230 while Current /= Nil_String loop
6231 Element := Shared.String_Elements.Table (Current);
6232 Name := Canonical_Case_File_Name (Element.Value);
6233 Get_Name_String (Element.Value);
6235 -- If the element has no location, then use the location of
6236 -- Sources to report possible errors.
6238 if Element.Location = No_Location then
6239 Location := Sources.Location;
6241 Location := Element.Location;
6244 -- Check that there is no directory information
6246 for J in 1 .. Name_Len loop
6247 if Name_Buffer (J) = '/'
6248 or else Name_Buffer (J) = Directory_Separator
6250 Error_Msg_File_1 := Name;
6253 "file name cannot include directory " &
6255 Location, Project.Project);
6260 -- Check whether the file is already there: the same file name
6261 -- may be in the list. If the source is missing, the error will
6262 -- be on the first mention of the source file name.
6264 Name_Loc := Source_Names_Htable.Get
6265 (Project.Source_Names, Name);
6267 if Name_Loc = No_Name_Location then
6270 Location => Location,
6271 Source => No_Source,
6276 Name_Loc.Listed := True;
6279 Source_Names_Htable.Set
6280 (Project.Source_Names, Name, Name_Loc);
6282 Current := Element.Next;
6285 Has_Explicit_Sources := True;
6288 -- If we have no Source_Files attribute, check the Source_List_File
6291 elsif not Source_List_File.Default then
6293 -- Source_List_File is the name of the file that contains the source
6297 Source_File_Path_Name : constant String :=
6299 (File_Name_Type (Source_List_File.Value),
6300 Project.Project.Directory.Display_Name);
6303 Has_Explicit_Sources := True;
6305 if Source_File_Path_Name'Length = 0 then
6306 Err_Vars.Error_Msg_File_1 :=
6307 File_Name_Type (Source_List_File.Value);
6310 "file with sources { does not exist",
6311 Source_List_File.Location, Project.Project);
6314 Get_Sources_From_File
6315 (Source_File_Path_Name, Source_List_File.Location,
6321 -- Neither Source_Files nor Source_List_File has been specified. Find
6322 -- all the files that satisfy the naming scheme in all the source
6325 Has_Explicit_Sources := False;
6328 -- Remove any exception that is not in the specified list of sources
6330 if Has_Explicit_Sources then
6333 Iter : Source_Iterator;
6340 Iter := For_Each_Source (Data.Tree, Project.Project);
6344 Source := Prj.Element (Iter);
6345 exit Source_Loop when Source = No_Source;
6347 if Source.Naming_Exception then
6348 NL := Source_Names_Htable.Get
6349 (Project.Source_Names, Source.File);
6351 if NL /= No_Name_Location and then not NL.Listed then
6352 -- Remove the exception
6353 Source_Names_Htable.Set
6354 (Project.Source_Names,
6357 Remove_Source (Data.Tree, Source, No_Source);
6359 Error_Msg_Name_1 := Name_Id (Source.File);
6362 "? unknown source file %%",
6372 end loop Source_Loop;
6374 exit Iter_Loop when not Again;
6382 For_All_Sources => Sources.Default and then Source_List_File.Default);
6384 -- Check if all exceptions have been found
6388 Iter : Source_Iterator;
6389 Found : Boolean := False;
6392 Iter := For_Each_Source (Data.Tree, Project.Project);
6394 Source := Prj.Element (Iter);
6395 exit when Source = No_Source;
6397 -- If the full source path is unknown for this source_id, there
6398 -- could be several reasons:
6399 -- * we simply did not find the file itself, this is an error
6400 -- * we have a multi-unit source file. Another Source_Id from
6401 -- the same file has received the full path, so we need to
6404 if Source.Naming_Exception
6405 and then Source.Path = No_Path_Information
6407 if Source.Unit /= No_Unit_Index then
6410 if Source.Index /= 0 then -- Only multi-unit files
6413 Source_Files_Htable.Get
6414 (Data.Tree.Source_Files_HT, Source.File);
6416 while S /= null loop
6417 if S.Path /= No_Path_Information then
6418 Source.Path := S.Path;
6421 if Current_Verbosity = High then
6423 ("setting full path for "
6424 & Get_Name_String (Source.File)
6425 & " at" & Source.Index'Img
6427 & Get_Name_String (Source.Path.Name));
6433 S := S.Next_With_File_Name;
6439 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6440 Error_Msg_Name_2 := Source.Unit.Name;
6442 (Data.Flags, Data.Flags.Missing_Source_Files,
6443 "source file %% for unit %% not found",
6444 No_Location, Project.Project);
6448 if Source.Path = No_Path_Information then
6449 Remove_Source (Data.Tree, Source, No_Source);
6457 -- It is an error if a source file name in a source list or in a source
6458 -- list file is not found.
6460 if Has_Explicit_Sources then
6463 First_Error : Boolean;
6466 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6467 First_Error := True;
6468 while NL /= No_Name_Location loop
6469 if not NL.Found then
6470 Err_Vars.Error_Msg_File_1 := NL.Name;
6473 (Data.Flags, Data.Flags.Missing_Source_Files,
6474 "source file { not found",
6475 NL.Location, Project.Project);
6476 First_Error := False;
6479 (Data.Flags, Data.Flags.Missing_Source_Files,
6480 "\source file { not found",
6481 NL.Location, Project.Project);
6485 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6495 procedure Initialize
6496 (Data : out Tree_Processing_Data;
6497 Tree : Project_Tree_Ref;
6498 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
6499 Flags : Prj.Processing_Flags)
6503 Data.Node_Tree := Node_Tree;
6504 Data.Flags := Flags;
6511 procedure Free (Data : in out Tree_Processing_Data) is
6512 pragma Unreferenced (Data);
6521 procedure Initialize
6522 (Data : in out Project_Processing_Data;
6523 Project : Project_Id)
6526 Data.Project := Project;
6533 procedure Free (Data : in out Project_Processing_Data) is
6535 Source_Names_Htable.Reset (Data.Source_Names);
6536 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6537 Excluded_Sources_Htable.Reset (Data.Excluded);
6540 -------------------------------
6541 -- Check_File_Naming_Schemes --
6542 -------------------------------
6544 procedure Check_File_Naming_Schemes
6545 (In_Tree : Project_Tree_Ref;
6546 Project : Project_Processing_Data;
6547 File_Name : File_Name_Type;
6548 Alternate_Languages : out Language_List;
6549 Language : out Language_Ptr;
6550 Display_Language_Name : out Name_Id;
6552 Lang_Kind : out Language_Kind;
6553 Kind : out Source_Kind)
6555 Filename : constant String := Get_Name_String (File_Name);
6556 Config : Language_Config;
6557 Tmp_Lang : Language_Ptr;
6559 Header_File : Boolean := False;
6560 -- True if we found at least one language for which the file is a header
6561 -- In such a case, we search for all possible languages where this is
6562 -- also a header (C and C++ for instance), since the file might be used
6563 -- for several such languages.
6565 procedure Check_File_Based_Lang;
6566 -- Does the naming scheme test for file-based languages. For those,
6567 -- there is no Unit. Just check if the file name has the implementation
6568 -- or, if it is specified, the template suffix of the language.
6570 -- Returns True if the file belongs to the current language and we
6571 -- should stop searching for matching languages. Not that a given header
6572 -- file could belong to several languages (C and C++ for instance). Thus
6573 -- if we found a header we'll check whether it matches other languages.
6575 ---------------------------
6576 -- Check_File_Based_Lang --
6577 ---------------------------
6579 procedure Check_File_Based_Lang is
6582 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6586 Language := Tmp_Lang;
6589 ("implementation of language ", Display_Language_Name);
6591 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6593 ("header of language ", Display_Language_Name);
6596 Alternate_Languages := new Language_List_Element'
6597 (Language => Language,
6598 Next => Alternate_Languages);
6601 Header_File := True;
6604 Language := Tmp_Lang;
6607 end Check_File_Based_Lang;
6609 -- Start of processing for Check_File_Naming_Schemes
6612 Language := No_Language_Index;
6613 Alternate_Languages := null;
6614 Display_Language_Name := No_Name;
6616 Lang_Kind := File_Based;
6619 Tmp_Lang := Project.Project.Languages;
6620 while Tmp_Lang /= No_Language_Index loop
6621 if Current_Verbosity = High then
6623 ("testing language "
6624 & Get_Name_String (Tmp_Lang.Name)
6625 & " Header_File=" & Header_File'Img);
6628 Display_Language_Name := Tmp_Lang.Display_Name;
6629 Config := Tmp_Lang.Config;
6630 Lang_Kind := Config.Kind;
6634 Check_File_Based_Lang;
6635 exit when Kind = Impl;
6639 -- We know it belongs to a least a file_based language, no
6640 -- need to check unit-based ones.
6642 if not Header_File then
6644 (File_Name => File_Name,
6645 Naming => Config.Naming_Data,
6649 In_Tree => In_Tree);
6651 if Unit /= No_Name then
6652 Language := Tmp_Lang;
6658 Tmp_Lang := Tmp_Lang.Next;
6661 if Language = No_Language_Index then
6662 Debug_Output ("not a source of any language");
6664 end Check_File_Naming_Schemes;
6670 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6672 -- If the file was previously already associated with a unit, change it
6674 if Source.Unit /= null
6675 and then Source.Kind in Spec_Or_Body
6676 and then Source.Unit.File_Names (Source.Kind) /= null
6678 -- If we had another file referencing the same unit (for instance it
6679 -- was in an extended project), that source file is in fact invisible
6680 -- from now on, and in particular doesn't belong to the same unit.
6682 if Source.Unit.File_Names (Source.Kind) /= Source then
6683 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6686 Source.Unit.File_Names (Source.Kind) := null;
6689 Source.Kind := Kind;
6691 if Current_Verbosity = High
6692 and then Source.File /= No_File
6694 Debug_Output ("override kind for "
6695 & Get_Name_String (Source.File)
6696 & " idx=" & Source.Index'Img
6697 & " kind=" & Source.Kind'Img);
6700 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6701 Source.Unit.File_Names (Source.Kind) := Source;
6709 procedure Check_File
6710 (Project : in out Project_Processing_Data;
6711 Data : in out Tree_Processing_Data;
6712 Source_Dir_Rank : Natural;
6713 Path : Path_Name_Type;
6714 Display_Path : Path_Name_Type;
6715 File_Name : File_Name_Type;
6716 Display_File_Name : File_Name_Type;
6717 Locally_Removed : Boolean;
6718 For_All_Sources : Boolean)
6720 Name_Loc : Name_Location :=
6721 Source_Names_Htable.Get
6722 (Project.Source_Names, File_Name);
6723 Check_Name : Boolean := False;
6724 Alternate_Languages : Language_List;
6725 Language : Language_Ptr;
6727 Src_Ind : Source_File_Index;
6729 Display_Language_Name : Name_Id;
6730 Lang_Kind : Language_Kind;
6731 Kind : Source_Kind := Spec;
6734 if Current_Verbosity = High then
6735 Debug_Increase_Indent
6736 ("checking file (rank=" & Source_Dir_Rank'Img & ")",
6737 Name_Id (Display_Path));
6740 if Name_Loc = No_Name_Location then
6741 Check_Name := For_All_Sources;
6744 if Name_Loc.Found then
6746 -- Check if it is OK to have the same file name in several
6747 -- source directories.
6749 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6750 Error_Msg_File_1 := File_Name;
6753 "{ is found in several source directories",
6754 Name_Loc.Location, Project.Project);
6758 Name_Loc.Found := True;
6760 Source_Names_Htable.Set
6761 (Project.Source_Names, File_Name, Name_Loc);
6763 if Name_Loc.Source = No_Source then
6767 -- Set the full path for the source_id (which might have been
6768 -- created when parsing the naming exceptions, and therefore
6769 -- might not have the full path).
6770 -- We only set this for this source_id, but not for other
6771 -- source_id in the same file (case of multi-unit source files)
6772 -- For the latter, they will be set in Find_Sources when we
6773 -- check that all source_id have known full paths.
6774 -- Doing this later saves one htable lookup per file in the
6775 -- common case where the user is not using multi-unit files.
6777 Name_Loc.Source.Path := (Path, Display_Path);
6779 Source_Paths_Htable.Set
6780 (Data.Tree.Source_Paths_HT, Path, Name_Loc.Source);
6782 -- Check if this is a subunit
6784 if Name_Loc.Source.Unit /= No_Unit_Index
6785 and then Name_Loc.Source.Kind = Impl
6787 Src_Ind := Sinput.P.Load_Project_File
6788 (Get_Name_String (Display_Path));
6790 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6791 Override_Kind (Name_Loc.Source, Sep);
6799 Check_File_Naming_Schemes
6800 (In_Tree => Data.Tree,
6802 File_Name => File_Name,
6803 Alternate_Languages => Alternate_Languages,
6804 Language => Language,
6805 Display_Language_Name => Display_Language_Name,
6807 Lang_Kind => Lang_Kind,
6810 if Language = No_Language_Index then
6812 -- A file name in a list must be a source of a language
6814 if Data.Flags.Error_On_Unknown_Language
6815 and then Name_Loc.Found
6817 Error_Msg_File_1 := File_Name;
6820 "language unknown for {",
6821 Name_Loc.Location, Project.Project);
6827 Project => Project.Project,
6828 Source_Dir_Rank => Source_Dir_Rank,
6829 Lang_Id => Language,
6832 Alternate_Languages => Alternate_Languages,
6833 File_Name => File_Name,
6834 Display_File => Display_File_Name,
6836 Locally_Removed => Locally_Removed,
6837 Path => (Path, Display_Path));
6839 -- If it is a source specified in a list, update the entry in
6840 -- the Source_Names table.
6842 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6843 Name_Loc.Source := Source;
6844 Source_Names_Htable.Set
6845 (Project.Source_Names, File_Name, Name_Loc);
6850 Debug_Decrease_Indent;
6853 ---------------------------------
6854 -- Expand_Subdirectory_Pattern --
6855 ---------------------------------
6857 procedure Expand_Subdirectory_Pattern
6858 (Project : Project_Id;
6859 Data : in out Tree_Processing_Data;
6860 Patterns : String_List_Id;
6861 Ignore : String_List_Id;
6862 Search_For : Search_Type;
6863 Resolve_Links : Boolean)
6865 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6867 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
6868 (Header_Num => Header_Num,
6870 No_Element => False,
6871 Key => Path_Name_Type,
6874 -- Hash table stores recursive source directories, to avoid looking
6875 -- several times, and to avoid cycles that may be introduced by symbolic
6878 File_Pattern : GNAT.Regexp.Regexp;
6879 -- Pattern to use when matching file names.
6881 Visited : Recursive_Dirs.Instance;
6883 procedure Find_Pattern
6884 (Pattern_Id : Name_Id;
6886 Location : Source_Ptr);
6887 -- Find a specific pattern
6889 function Recursive_Find_Dirs
6890 (Path : Path_Information;
6891 Rank : Natural) return Boolean;
6892 -- Search all the subdirectories (recursively) of Path.
6893 -- Return True if at least one file or directory was processed
6895 function Subdirectory_Matches
6896 (Path : Path_Information;
6897 Rank : Natural) return Boolean;
6898 -- Called when a matching directory was found. If the user is in fact
6899 -- searching for files, we then search for those files matching the
6900 -- pattern within the directory.
6901 -- Return True if at least one file or directory was processed
6903 --------------------------
6904 -- Subdirectory_Matches --
6905 --------------------------
6907 function Subdirectory_Matches
6908 (Path : Path_Information;
6909 Rank : Natural) return Boolean
6912 Name : String (1 .. 250);
6914 Found : Path_Information;
6915 Success : Boolean := False;
6919 when Search_Directories =>
6920 Callback (Path, Rank);
6923 when Search_Files =>
6924 Open (Dir, Get_Name_String (Path.Display_Name));
6926 Read (Dir, Name, Last);
6929 if Name (Name'First .. Last) /= "."
6930 and then Name (Name'First .. Last) /= ".."
6931 and then Match (Name (Name'First .. Last), File_Pattern)
6933 Get_Name_String (Path.Display_Name);
6934 Add_Str_To_Name_Buffer (Name (Name'First .. Last));
6936 Found.Display_Name := Name_Find;
6937 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6938 Found.Name := Name_Find;
6940 Callback (Found, Rank);
6949 end Subdirectory_Matches;
6951 -------------------------
6952 -- Recursive_Find_Dirs --
6953 -------------------------
6955 function Recursive_Find_Dirs
6956 (Path : Path_Information;
6957 Rank : Natural) return Boolean
6959 Path_Str : constant String := Get_Name_String (Path.Display_Name);
6961 Name : String (1 .. 250);
6963 Success : Boolean := False;
6966 Debug_Output ("looking for subdirs of ", Name_Id (Path.Display_Name));
6968 if Recursive_Dirs.Get (Visited, Path.Name) then
6972 Recursive_Dirs.Set (Visited, Path.Name, True);
6974 Success := Subdirectory_Matches (Path, Rank) or Success;
6976 Open (Dir, Path_Str);
6979 Read (Dir, Name, Last);
6982 if Name (1 .. Last) /= "."
6983 and then Name (1 .. Last) /= ".."
6986 Path_Name : constant String :=
6988 (Name => Name (1 .. Last),
6989 Directory => Path_Str,
6990 Resolve_Links => Resolve_Links)
6991 & Directory_Separator;
6992 Path2 : Path_Information;
6993 OK : Boolean := True;
6996 if Is_Directory (Path_Name) then
6997 if Ignore /= Nil_String then
6999 Dir_Name : String := Name (1 .. Last);
7000 List : String_List_Id := Ignore;
7003 Canonical_Case_File_Name (Dir_Name);
7005 while List /= Nil_String loop
7007 (Shared.String_Elements.Table (List).Value);
7008 Canonical_Case_File_Name
7009 (Name_Buffer (1 .. Name_Len));
7010 OK := Name_Buffer (1 .. Name_Len) /= Dir_Name;
7012 List := Shared.String_Elements.Table (List).Next;
7019 Add_Str_To_Name_Buffer (Path_Name);
7020 Path2.Display_Name := Name_Find;
7022 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
7023 Path2.Name := Name_Find;
7026 Recursive_Find_Dirs (Path2, Rank) or Success;
7038 when Directory_Error =>
7040 end Recursive_Find_Dirs;
7046 procedure Find_Pattern
7047 (Pattern_Id : Name_Id;
7049 Location : Source_Ptr)
7051 Pattern : constant String := Get_Name_String (Pattern_Id);
7052 Pattern_End : Natural := Pattern'Last;
7053 Recursive : Boolean;
7054 Dir : File_Name_Type;
7055 Path_Name : Path_Information;
7056 Dir_Exists : Boolean;
7057 Has_Error : Boolean := False;
7061 Debug_Increase_Indent ("Find_Pattern", Pattern_Id);
7063 -- If we are looking for files, find the pattern for the files
7065 if Search_For = Search_Files then
7066 while Pattern_End >= Pattern'First
7067 and then Pattern (Pattern_End) /= '/'
7068 and then Pattern (Pattern_End) /= Directory_Separator
7070 Pattern_End := Pattern_End - 1;
7073 if Pattern_End = Pattern'Last then
7074 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7076 (Data.Flags, Data.Flags.Missing_Source_Files,
7077 "Missing file name or pattern in {", Location, Project);
7081 if Current_Verbosity = High then
7083 Write_Str ("file_pattern=");
7084 Write_Str (Pattern (Pattern_End + 1 .. Pattern'Last));
7085 Write_Str (" dir_pattern=");
7086 Write_Line (Pattern (Pattern'First .. Pattern_End));
7089 File_Pattern := Compile
7090 (Pattern (Pattern_End + 1 .. Pattern'Last),
7092 Case_Sensitive => File_Names_Case_Sensitive);
7094 -- If we had just "*.gpr", this is equivalent to "./*.gpr"
7096 if Pattern_End > Pattern'First then
7097 Pattern_End := Pattern_End - 1; -- Skip directory separator
7102 Pattern_End - 1 >= Pattern'First
7103 and then Pattern (Pattern_End - 1 .. Pattern_End) = "**"
7104 and then (Pattern_End - 1 = Pattern'First
7105 or else Pattern (Pattern_End - 2) = '/'
7106 or else Pattern (Pattern_End - 2) = Directory_Separator);
7109 Pattern_End := Pattern_End - 2;
7110 if Pattern_End > Pattern'First then
7111 Pattern_End := Pattern_End - 1; -- Skip '/'
7115 Name_Len := Pattern_End - Pattern'First + 1;
7116 Name_Buffer (1 .. Name_Len) := Pattern (Pattern'First .. Pattern_End);
7120 (Project => Project,
7123 Dir_Exists => Dir_Exists,
7125 Must_Exist => False);
7127 if not Dir_Exists then
7128 Err_Vars.Error_Msg_File_1 := Dir;
7130 (Data.Flags, Data.Flags.Missing_Source_Files,
7131 "{ is not a valid directory", Location, Project);
7132 Has_Error := Data.Flags.Missing_Source_Files = Error;
7135 if not Has_Error then
7136 -- Links have been resolved if necessary, and Path_Name
7137 -- always ends with a directory separator.
7140 Success := Recursive_Find_Dirs (Path_Name, Rank);
7142 Success := Subdirectory_Matches (Path_Name, Rank);
7147 when Search_Directories =>
7148 null; -- Error can't occur
7150 when Search_Files =>
7151 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7153 (Data.Flags, Data.Flags.Missing_Source_Files,
7154 "file { not found", Location, Project);
7159 Debug_Decrease_Indent ("done Find_Pattern");
7164 Pattern_Id : String_List_Id := Patterns;
7165 Element : String_Element;
7166 Rank : Natural := 1;
7168 -- Start of processing for Expand_Subdirectory_Pattern
7171 while Pattern_Id /= Nil_String loop
7172 Element := Shared.String_Elements.Table (Pattern_Id);
7173 Find_Pattern (Element.Value, Rank, Element.Location);
7175 Pattern_Id := Element.Next;
7178 Recursive_Dirs.Reset (Visited);
7179 end Expand_Subdirectory_Pattern;
7181 ------------------------
7182 -- Search_Directories --
7183 ------------------------
7185 procedure Search_Directories
7186 (Project : in out Project_Processing_Data;
7187 Data : in out Tree_Processing_Data;
7188 For_All_Sources : Boolean)
7190 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
7192 Source_Dir : String_List_Id;
7193 Element : String_Element;
7194 Src_Dir_Rank : Number_List_Index;
7195 Num_Nod : Number_Node;
7197 Name : String (1 .. 1_000);
7199 File_Name : File_Name_Type;
7200 Display_File_Name : File_Name_Type;
7203 Debug_Increase_Indent ("looking for sources of", Project.Project.Name);
7205 -- Loop through subdirectories
7207 Source_Dir := Project.Project.Source_Dirs;
7208 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
7209 while Source_Dir /= Nil_String loop
7211 Num_Nod := Shared.Number_Lists.Table (Src_Dir_Rank);
7212 Element := Shared.String_Elements.Table (Source_Dir);
7214 -- Use Element.Value in this test, not Display_Value, because we
7215 -- want the symbolic links to be resolved when appropriate.
7217 if Element.Value /= No_Name then
7219 Source_Directory : constant String :=
7220 Get_Name_String (Element.Value)
7221 & Directory_Separator;
7223 Dir_Last : constant Natural :=
7224 Compute_Directory_Last (Source_Directory);
7226 Display_Source_Directory : constant String :=
7228 (Element.Display_Value)
7229 & Directory_Separator;
7230 -- Display_Source_Directory is to allow us to open a UTF-8
7231 -- encoded directory on Windows.
7234 if Current_Verbosity = High then
7235 Debug_Increase_Indent
7236 ("Source_Dir (node=" & Num_Nod.Number'Img & ") """
7237 & Source_Directory (Source_Directory'First .. Dir_Last)
7241 -- We look to every entry in the source directory
7243 Open (Dir, Display_Source_Directory);
7246 Read (Dir, Name, Last);
7250 -- In fast project loading mode (without -eL), the user
7251 -- guarantees that no directory has a name which is a
7252 -- valid source name, so we can avoid doing a system call
7253 -- here. This provides a very significant speed up on
7254 -- slow file systems (remote files for instance).
7256 if not Opt.Follow_Links_For_Files
7257 or else Is_Regular_File
7258 (Display_Source_Directory & Name (1 .. Last))
7261 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7262 Display_File_Name := Name_Find;
7264 if Osint.File_Names_Case_Sensitive then
7265 File_Name := Display_File_Name;
7267 Canonical_Case_File_Name
7268 (Name_Buffer (1 .. Name_Len));
7269 File_Name := Name_Find;
7273 Path_Name : constant String :=
7278 (Source_Directory'First ..
7281 Opt.Follow_Links_For_Files,
7282 Case_Sensitive => True);
7284 Path : Path_Name_Type;
7286 Excluded_Sources_Htable.Get
7287 (Project.Excluded, File_Name);
7288 To_Remove : Boolean := False;
7291 Name_Len := Path_Name'Length;
7292 Name_Buffer (1 .. Name_Len) := Path_Name;
7294 if Osint.File_Names_Case_Sensitive then
7297 Canonical_Case_File_Name
7298 (Name_Buffer (1 .. Name_Len));
7302 if FF /= No_File_Found then
7303 if not FF.Found then
7305 Excluded_Sources_Htable.Set
7306 (Project.Excluded, File_Name, FF);
7309 ("excluded source ",
7310 Name_Id (Display_File_Name));
7312 -- Will mark the file as removed, but we
7313 -- still need to add it to the list: if we
7314 -- don't, the file will not appear in the
7315 -- mapping file and will cause the compiler
7322 -- Preserve the user's original casing and use of
7323 -- links. The display_value (a directory) already
7324 -- ends with a directory separator by construction,
7325 -- so no need to add one.
7327 Get_Name_String (Element.Display_Value);
7328 Get_Name_String_And_Append (Display_File_Name);
7331 (Project => Project,
7332 Source_Dir_Rank => Num_Nod.Number,
7335 Display_Path => Name_Find,
7336 File_Name => File_Name,
7337 Locally_Removed => To_Remove,
7338 Display_File_Name => Display_File_Name,
7339 For_All_Sources => For_All_Sources);
7343 if Current_Verbosity = High then
7344 Debug_Output ("ignore " & Name (1 .. Last));
7349 Debug_Decrease_Indent;
7355 when Directory_Error =>
7359 Source_Dir := Element.Next;
7360 Src_Dir_Rank := Num_Nod.Next;
7363 Debug_Decrease_Indent ("end looking for sources.");
7364 end Search_Directories;
7366 ----------------------------
7367 -- Load_Naming_Exceptions --
7368 ----------------------------
7370 procedure Load_Naming_Exceptions
7371 (Project : in out Project_Processing_Data;
7372 Data : in out Tree_Processing_Data)
7375 Iter : Source_Iterator;
7378 Iter := For_Each_Source (Data.Tree, Project.Project);
7380 Source := Prj.Element (Iter);
7381 exit when Source = No_Source;
7383 -- An excluded file cannot also be an exception file name
7385 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
7388 Error_Msg_File_1 := Source.File;
7391 "{ cannot be both excluded and an exception file name",
7392 No_Location, Project.Project);
7396 ("naming exception: adding source file to source_Names: ",
7397 Name_Id (Source.File));
7399 Source_Names_Htable.Set
7400 (Project.Source_Names,
7403 (Name => Source.File,
7404 Location => Source.Location,
7409 -- If this is an Ada exception, record in table Unit_Exceptions
7411 if Source.Unit /= No_Unit_Index then
7413 Unit_Except : Unit_Exception :=
7414 Unit_Exceptions_Htable.Get
7415 (Project.Unit_Exceptions, Source.Unit.Name);
7418 Unit_Except.Name := Source.Unit.Name;
7420 if Source.Kind = Spec then
7421 Unit_Except.Spec := Source.File;
7423 Unit_Except.Impl := Source.File;
7426 Unit_Exceptions_Htable.Set
7427 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7433 end Load_Naming_Exceptions;
7435 ----------------------
7436 -- Look_For_Sources --
7437 ----------------------
7439 procedure Look_For_Sources
7440 (Project : in out Project_Processing_Data;
7441 Data : in out Tree_Processing_Data)
7443 Object_Files : Object_File_Names_Htable.Instance;
7444 Iter : Source_Iterator;
7447 procedure Check_Object (Src : Source_Id);
7448 -- Check if object file name of Src is already used in the project tree,
7449 -- and report an error if so.
7451 procedure Check_Object_Files;
7452 -- Check that no two sources of this project have the same object file
7454 procedure Mark_Excluded_Sources;
7455 -- Mark as such the sources that are declared as excluded
7457 procedure Check_Missing_Sources;
7458 -- Check whether one of the languages has no sources, and report an
7459 -- error when appropriate
7461 procedure Get_Sources_From_Source_Info;
7462 -- Get the source information from the tables that were created when a
7463 -- source info file was read.
7465 ---------------------------
7466 -- Check_Missing_Sources --
7467 ---------------------------
7469 procedure Check_Missing_Sources is
7470 Extending : constant Boolean :=
7471 Project.Project.Extends /= No_Project;
7472 Language : Language_Ptr;
7474 Alt_Lang : Language_List;
7475 Continuation : Boolean := False;
7476 Iter : Source_Iterator;
7478 if not Project.Project.Externally_Built
7479 and then not Extending
7481 Language := Project.Project.Languages;
7482 while Language /= No_Language_Index loop
7484 -- If there are no sources for this language, check if there
7485 -- are sources for which this is an alternate language.
7487 if Language.First_Source = No_Source
7488 and then (Data.Flags.Require_Sources_Other_Lang
7489 or else Language.Name = Name_Ada)
7491 Iter := For_Each_Source (In_Tree => Data.Tree,
7492 Project => Project.Project);
7494 Source := Element (Iter);
7495 exit Source_Loop when Source = No_Source
7496 or else Source.Language = Language;
7498 Alt_Lang := Source.Alternate_Languages;
7499 while Alt_Lang /= null loop
7500 exit Source_Loop when Alt_Lang.Language = Language;
7501 Alt_Lang := Alt_Lang.Next;
7505 end loop Source_Loop;
7507 if Source = No_Source then
7510 Get_Name_String (Language.Display_Name),
7512 Project.Source_List_File_Location,
7514 Continuation := True;
7518 Language := Language.Next;
7521 end Check_Missing_Sources;
7527 procedure Check_Object (Src : Source_Id) is
7531 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7533 -- We cannot just check on "Source /= Src", since we might have
7534 -- two different entries for the same file (and since that's
7535 -- the same file it is expected that it has the same object)
7537 if Source /= No_Source
7538 and then Source.Path /= Src.Path
7540 Error_Msg_File_1 := Src.File;
7541 Error_Msg_File_2 := Source.File;
7544 "{ and { have the same object file name",
7545 No_Location, Project.Project);
7548 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7552 ---------------------------
7553 -- Mark_Excluded_Sources --
7554 ---------------------------
7556 procedure Mark_Excluded_Sources is
7557 Source : Source_Id := No_Source;
7558 Excluded : File_Found;
7562 -- Minor optimization: if there are no excluded files, no need to
7563 -- traverse the list of sources. We cannot however also check whether
7564 -- the existing exceptions have ".Found" set to True (indicating we
7565 -- found them before) because we need to do some final processing on
7566 -- them in any case.
7568 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7571 Proj := Project.Project;
7572 while Proj /= No_Project loop
7573 Iter := For_Each_Source (Data.Tree, Proj);
7574 while Prj.Element (Iter) /= No_Source loop
7575 Source := Prj.Element (Iter);
7576 Excluded := Excluded_Sources_Htable.Get
7577 (Project.Excluded, Source.File);
7579 if Excluded /= No_File_Found then
7580 Source.Locally_Removed := True;
7581 Source.In_Interfaces := False;
7583 if Current_Verbosity = High then
7585 Write_Str ("removing file ");
7587 (Get_Name_String (Excluded.File)
7588 & " " & Get_Name_String (Source.Project.Name));
7591 Excluded_Sources_Htable.Remove
7592 (Project.Excluded, Source.File);
7598 Proj := Proj.Extends;
7602 -- If we have any excluded element left, that means we did not find
7605 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7606 while Excluded /= No_File_Found loop
7607 if not Excluded.Found then
7609 -- Check if the file belongs to another imported project to
7610 -- provide a better error message.
7613 (In_Tree => Data.Tree,
7614 Project => Project.Project,
7615 In_Imported_Only => True,
7616 Base_Name => Excluded.File);
7618 Err_Vars.Error_Msg_File_1 := Excluded.File;
7620 if Src = No_Source then
7621 if Excluded.Excl_File = No_File then
7624 "unknown file {", Excluded.Location, Project.Project);
7630 Get_Name_String (Excluded.Excl_File) & ":" &
7631 No_Space_Img (Excluded.Excl_Line) &
7632 ": unknown file {", Excluded.Location, Project.Project);
7636 if Excluded.Excl_File = No_File then
7639 "cannot remove a source from an imported project: {",
7640 Excluded.Location, Project.Project);
7646 Get_Name_String (Excluded.Excl_File) & ":" &
7647 No_Space_Img (Excluded.Excl_Line) &
7648 ": cannot remove a source from an imported project: {",
7649 Excluded.Location, Project.Project);
7654 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7656 end Mark_Excluded_Sources;
7658 ------------------------
7659 -- Check_Object_Files --
7660 ------------------------
7662 procedure Check_Object_Files is
7663 Iter : Source_Iterator;
7665 Src_Ind : Source_File_Index;
7668 Iter := For_Each_Source (Data.Tree);
7670 Src_Id := Prj.Element (Iter);
7671 exit when Src_Id = No_Source;
7673 if Is_Compilable (Src_Id)
7674 and then Src_Id.Language.Config.Object_Generated
7675 and then Is_Extending (Project.Project, Src_Id.Project)
7677 if Src_Id.Unit = No_Unit_Index then
7678 if Src_Id.Kind = Impl then
7679 Check_Object (Src_Id);
7685 if Other_Part (Src_Id) = No_Source then
7686 Check_Object (Src_Id);
7693 if Other_Part (Src_Id) /= No_Source then
7694 Check_Object (Src_Id);
7697 -- Check if it is a subunit
7700 Sinput.P.Load_Project_File
7701 (Get_Name_String (Src_Id.Path.Display_Name));
7703 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7704 Override_Kind (Src_Id, Sep);
7706 Check_Object (Src_Id);
7715 end Check_Object_Files;
7717 ----------------------------------
7718 -- Get_Sources_From_Source_Info --
7719 ----------------------------------
7721 procedure Get_Sources_From_Source_Info is
7722 Iter : Source_Info_Iterator;
7725 Lang_Id : Language_Ptr;
7727 Initialize (Iter, Project.Project.Name);
7730 Src := Source_Info_Of (Iter);
7732 exit when Src = No_Source_Info;
7734 Id := new Source_Data;
7736 Id.Project := Project.Project;
7738 Lang_Id := Project.Project.Languages;
7739 while Lang_Id /= No_Language_Index and then
7740 Lang_Id.Name /= Src.Language
7742 Lang_Id := Lang_Id.Next;
7745 if Lang_Id = No_Language_Index then
7747 ("unknown language " &
7748 Get_Name_String (Src.Language) &
7750 Get_Name_String (Src.Project) &
7751 " in source info file");
7754 Id.Language := Lang_Id;
7755 Id.Kind := Src.Kind;
7756 Id.Index := Src.Index;
7759 (Path_Name_Type (Src.Display_Path_Name),
7760 Path_Name_Type (Src.Path_Name));
7763 Add_Str_To_Name_Buffer
7764 (Ada.Directories.Simple_Name
7765 (Get_Name_String (Src.Path_Name)));
7766 Id.File := Name_Find;
7768 Id.Next_With_File_Name :=
7769 Source_Files_Htable.Get (Data.Tree.Source_Files_HT, Id.File);
7770 Source_Files_Htable.Set (Data.Tree.Source_Files_HT, Id.File, Id);
7773 Add_Str_To_Name_Buffer
7774 (Ada.Directories.Simple_Name
7775 (Get_Name_String (Src.Display_Path_Name)));
7776 Id.Display_File := Name_Find;
7778 Id.Dep_Name := Dependency_Name
7779 (Id.File, Id.Language.Config.Dependency_Kind);
7780 Id.Naming_Exception := Src.Naming_Exception;
7781 Id.Object := Object_Name
7782 (Id.File, Id.Language.Config.Object_File_Suffix);
7783 Id.Switches := Switches_Name (Id.File);
7785 -- Add the source id to the Unit_Sources_HT hash table, if the
7786 -- unit name is not null.
7788 if Src.Kind /= Sep and then Src.Unit_Name /= No_Name then
7791 UData : Unit_Index :=
7792 Units_Htable.Get (Data.Tree.Units_HT, Src.Unit_Name);
7794 if UData = No_Unit_Index then
7795 UData := new Unit_Data;
7796 UData.Name := Src.Unit_Name;
7798 (Data.Tree.Units_HT, Src.Unit_Name, UData);
7804 -- Note that this updates Unit information as well
7806 Override_Kind (Id, Id.Kind);
7809 if Src.Index /= 0 then
7810 Project.Project.Has_Multi_Unit_Sources := True;
7813 -- Add the source to the language list
7815 Id.Next_In_Lang := Id.Language.First_Source;
7816 Id.Language.First_Source := Id;
7820 end Get_Sources_From_Source_Info;
7822 -- Start of processing for Look_For_Sources
7825 if Data.Tree.Source_Info_File_Exists then
7826 Get_Sources_From_Source_Info;
7829 if Project.Project.Source_Dirs /= Nil_String then
7830 Find_Excluded_Sources (Project, Data);
7832 if Project.Project.Languages /= No_Language_Index then
7833 Load_Naming_Exceptions (Project, Data);
7834 Find_Sources (Project, Data);
7835 Mark_Excluded_Sources;
7837 Check_Missing_Sources;
7841 Object_File_Names_Htable.Reset (Object_Files);
7843 end Look_For_Sources;
7849 function Path_Name_Of
7850 (File_Name : File_Name_Type;
7851 Directory : Path_Name_Type) return String
7853 Result : String_Access;
7854 The_Directory : constant String := Get_Name_String (Directory);
7857 Debug_Output ("Path_Name_Of file name=", Name_Id (File_Name));
7858 Debug_Output ("Path_Name_Of directory=", Name_Id (Directory));
7859 Get_Name_String (File_Name);
7862 (File_Name => Name_Buffer (1 .. Name_Len),
7863 Path => The_Directory);
7865 if Result = null then
7869 R : constant String := Result.all;
7881 procedure Remove_Source
7882 (Tree : Project_Tree_Ref;
7884 Replaced_By : Source_Id)
7889 if Current_Verbosity = High then
7891 Write_Str ("removing source ");
7892 Write_Str (Get_Name_String (Id.File));
7894 if Id.Index /= 0 then
7895 Write_Str (" at" & Id.Index'Img);
7901 if Replaced_By /= No_Source then
7902 Id.Replaced_By := Replaced_By;
7903 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7905 if Id.File /= Replaced_By.File then
7907 Replacement : constant File_Name_Type :=
7908 Replaced_Source_HTable.Get
7909 (Tree.Replaced_Sources, Id.File);
7912 Replaced_Source_HTable.Set
7913 (Tree.Replaced_Sources, Id.File, Replaced_By.File);
7915 if Replacement = No_File then
7916 Tree.Replaced_Source_Number :=
7917 Tree.Replaced_Source_Number + 1;
7923 Id.In_Interfaces := False;
7924 Id.Locally_Removed := True;
7926 -- ??? Should we remove the source from the unit ? The file is not used,
7927 -- so probably should not be referenced from the unit. On the other hand
7928 -- it might give useful additional info
7929 -- if Id.Unit /= null then
7930 -- Id.Unit.File_Names (Id.Kind) := null;
7933 Source := Id.Language.First_Source;
7936 Id.Language.First_Source := Id.Next_In_Lang;
7939 while Source.Next_In_Lang /= Id loop
7940 Source := Source.Next_In_Lang;
7943 Source.Next_In_Lang := Id.Next_In_Lang;
7947 -----------------------
7948 -- Report_No_Sources --
7949 -----------------------
7951 procedure Report_No_Sources
7952 (Project : Project_Id;
7954 Data : Tree_Processing_Data;
7955 Location : Source_Ptr;
7956 Continuation : Boolean := False)
7959 case Data.Flags.When_No_Sources is
7963 when Warning | Error =>
7965 Msg : constant String :=
7968 " sources in this project";
7971 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7973 if Continuation then
7974 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7976 Error_Msg (Data.Flags, Msg, Location, Project);
7980 end Report_No_Sources;
7982 ----------------------
7983 -- Show_Source_Dirs --
7984 ----------------------
7986 procedure Show_Source_Dirs
7987 (Project : Project_Id;
7988 Shared : Shared_Project_Tree_Data_Access)
7990 Current : String_List_Id;
7991 Element : String_Element;
7994 if Project.Source_Dirs = Nil_String then
7995 Debug_Output ("no Source_Dirs");
7997 Debug_Increase_Indent ("Source_Dirs:");
7999 Current := Project.Source_Dirs;
8000 while Current /= Nil_String loop
8001 Element := Shared.String_Elements.Table (Current);
8002 Debug_Output (Get_Name_String (Element.Display_Value));
8003 Current := Element.Next;
8006 Debug_Decrease_Indent ("end Source_Dirs.");
8008 end Show_Source_Dirs;
8010 ---------------------------
8011 -- Process_Naming_Scheme --
8012 ---------------------------
8014 procedure Process_Naming_Scheme
8015 (Tree : Project_Tree_Ref;
8016 Root_Project : Project_Id;
8017 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
8018 Flags : Processing_Flags)
8020 procedure Recursive_Check
8021 (Project : Project_Id;
8022 Prj_Tree : Project_Tree_Ref;
8023 Data : in out Tree_Processing_Data);
8024 -- Check_Naming_Scheme for the project
8026 ---------------------
8027 -- Recursive_Check --
8028 ---------------------
8030 procedure Recursive_Check
8031 (Project : Project_Id;
8032 Prj_Tree : Project_Tree_Ref;
8033 Data : in out Tree_Processing_Data) is
8035 if Current_Verbosity = High then
8036 Debug_Increase_Indent
8037 ("Processing_Naming_Scheme for project", Project.Name);
8040 Data.Tree := Prj_Tree;
8041 Prj.Nmsc.Check (Project, Data);
8043 if Current_Verbosity = High then
8044 Debug_Decrease_Indent ("done Processing_Naming_Scheme");
8046 end Recursive_Check;
8048 procedure Check_All_Projects is new
8049 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
8051 Data : Tree_Processing_Data;
8053 -- Start of processing for Process_Naming_Scheme
8055 Lib_Data_Table.Init;
8056 Initialize (Data, Tree => Tree, Node_Tree => Node_Tree, Flags => Flags);
8057 Check_All_Projects (Root_Project, Tree, Data, Imported_First => True);
8060 -- Adjust language configs for projects that are extended
8063 List : Project_List;
8066 Lang : Language_Ptr;
8067 Elng : Language_Ptr;
8070 List := Tree.Projects;
8071 while List /= null loop
8072 Proj := List.Project;
8074 while Exte.Extended_By /= No_Project loop
8075 Exte := Exte.Extended_By;
8078 if Exte /= Proj then
8079 Lang := Proj.Languages;
8081 if Lang /= No_Language_Index then
8083 Elng := Get_Language_From_Name
8084 (Exte, Get_Name_String (Lang.Name));
8085 exit when Elng /= No_Language_Index;
8086 Exte := Exte.Extends;
8089 if Elng /= Lang then
8090 Lang.Config := Elng.Config;
8098 end Process_Naming_Scheme;