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_Ada_Name (Name : String; Unit : out Name_Id);
285 -- Check that a name is a valid Ada 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_Ada_Name --
1117 --------------------
1119 procedure Check_Ada_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_Ada_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
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_Switches =>
1497 -- Attribute Dependency_Switches (<language>)
1499 if Lang_Index.Config.Dependency_Kind = None then
1500 Lang_Index.Config.Dependency_Kind := Makefile;
1503 List := Element.Value.Values;
1505 if List /= Nil_String then
1507 Lang_Index.Config.Dependency_Option,
1509 In_Tree => Data.Tree);
1512 when Name_Dependency_Driver =>
1514 -- Attribute Dependency_Driver (<language>)
1516 if Lang_Index.Config.Dependency_Kind = None then
1517 Lang_Index.Config.Dependency_Kind := Makefile;
1520 List := Element.Value.Values;
1522 if List /= Nil_String then
1524 Lang_Index.Config.Compute_Dependency,
1526 In_Tree => Data.Tree);
1529 when Name_Include_Switches =>
1531 -- Attribute Include_Switches (<language>)
1533 List := Element.Value.Values;
1535 if List = Nil_String then
1537 (Data.Flags, "include option cannot be null",
1538 Element.Value.Location, Project);
1541 Put (Into_List => Lang_Index.Config.Include_Option,
1543 In_Tree => Data.Tree);
1545 when Name_Include_Path =>
1547 -- Attribute Include_Path (<language>)
1549 Lang_Index.Config.Include_Path :=
1550 Element.Value.Value;
1552 when Name_Include_Path_File =>
1554 -- Attribute Include_Path_File (<language>)
1556 Lang_Index.Config.Include_Path_File :=
1557 Element.Value.Value;
1561 -- Attribute Driver (<language>)
1563 Lang_Index.Config.Compiler_Driver :=
1564 File_Name_Type (Element.Value.Value);
1566 when Name_Required_Switches |
1567 Name_Leading_Required_Switches =>
1570 Compiler_Leading_Required_Switches,
1571 From_List => Element.Value.Values,
1572 In_Tree => Data.Tree);
1574 when Name_Trailing_Required_Switches =>
1577 Compiler_Trailing_Required_Switches,
1578 From_List => Element.Value.Values,
1579 In_Tree => Data.Tree);
1581 when Name_Multi_Unit_Switches =>
1583 Lang_Index.Config.Multi_Unit_Switches,
1584 From_List => Element.Value.Values,
1585 In_Tree => Data.Tree);
1587 when Name_Multi_Unit_Object_Separator =>
1588 Get_Name_String (Element.Value.Value);
1590 if Name_Len /= 1 then
1593 "multi-unit object separator must have " &
1594 "a single character",
1595 Element.Value.Location, Project);
1597 elsif Name_Buffer (1) = ' ' then
1600 "multi-unit object separator cannot be " &
1602 Element.Value.Location, Project);
1605 Lang_Index.Config.Multi_Unit_Object_Separator :=
1609 when Name_Path_Syntax =>
1611 Lang_Index.Config.Path_Syntax :=
1612 Path_Syntax_Kind'Value
1613 (Get_Name_String (Element.Value.Value));
1616 when Constraint_Error =>
1619 "invalid value for Path_Syntax",
1620 Element.Value.Location, Project);
1623 when Name_Object_File_Suffix =>
1624 if Get_Name_String (Element.Value.Value) = "" then
1627 "object file suffix cannot be empty",
1628 Element.Value.Location, Project);
1631 Lang_Index.Config.Object_File_Suffix :=
1632 Element.Value.Value;
1635 when Name_Object_File_Switches =>
1637 Lang_Index.Config.Object_File_Switches,
1638 From_List => Element.Value.Values,
1639 In_Tree => Data.Tree);
1641 when Name_Pic_Option =>
1643 -- Attribute Compiler_Pic_Option (<language>)
1645 List := Element.Value.Values;
1647 if List = Nil_String then
1650 "compiler PIC option cannot be null",
1651 Element.Value.Location, Project);
1655 Lang_Index.Config.Compilation_PIC_Option,
1657 In_Tree => Data.Tree);
1659 when Name_Mapping_File_Switches =>
1661 -- Attribute Mapping_File_Switches (<language>)
1663 List := Element.Value.Values;
1665 if List = Nil_String then
1668 "mapping file switches cannot be null",
1669 Element.Value.Location, Project);
1673 Lang_Index.Config.Mapping_File_Switches,
1675 In_Tree => Data.Tree);
1677 when Name_Mapping_Spec_Suffix =>
1679 -- Attribute Mapping_Spec_Suffix (<language>)
1681 Lang_Index.Config.Mapping_Spec_Suffix :=
1682 File_Name_Type (Element.Value.Value);
1684 when Name_Mapping_Body_Suffix =>
1686 -- Attribute Mapping_Body_Suffix (<language>)
1688 Lang_Index.Config.Mapping_Body_Suffix :=
1689 File_Name_Type (Element.Value.Value);
1691 when Name_Config_File_Switches =>
1693 -- Attribute Config_File_Switches (<language>)
1695 List := Element.Value.Values;
1697 if List = Nil_String then
1700 "config file switches cannot be null",
1701 Element.Value.Location, Project);
1705 Lang_Index.Config.Config_File_Switches,
1707 In_Tree => Data.Tree);
1709 when Name_Objects_Path =>
1711 -- Attribute Objects_Path (<language>)
1713 Lang_Index.Config.Objects_Path :=
1714 Element.Value.Value;
1716 when Name_Objects_Path_File =>
1718 -- Attribute Objects_Path_File (<language>)
1720 Lang_Index.Config.Objects_Path_File :=
1721 Element.Value.Value;
1723 when Name_Config_Body_File_Name =>
1725 -- Attribute Config_Body_File_Name (<language>)
1727 Lang_Index.Config.Config_Body :=
1728 Element.Value.Value;
1730 when Name_Config_Body_File_Name_Index =>
1732 -- Attribute Config_Body_File_Name_Index
1735 Lang_Index.Config.Config_Body_Index :=
1736 Element.Value.Value;
1738 when Name_Config_Body_File_Name_Pattern =>
1740 -- Attribute Config_Body_File_Name_Pattern
1743 Lang_Index.Config.Config_Body_Pattern :=
1744 Element.Value.Value;
1746 when Name_Config_Spec_File_Name =>
1748 -- Attribute Config_Spec_File_Name (<language>)
1750 Lang_Index.Config.Config_Spec :=
1751 Element.Value.Value;
1753 when Name_Config_Spec_File_Name_Index =>
1755 -- Attribute Config_Spec_File_Name_Index
1758 Lang_Index.Config.Config_Spec_Index :=
1759 Element.Value.Value;
1761 when Name_Config_Spec_File_Name_Pattern =>
1763 -- Attribute Config_Spec_File_Name_Pattern
1766 Lang_Index.Config.Config_Spec_Pattern :=
1767 Element.Value.Value;
1769 when Name_Config_File_Unique =>
1771 -- Attribute Config_File_Unique (<language>)
1774 Lang_Index.Config.Config_File_Unique :=
1776 (Get_Name_String (Element.Value.Value));
1778 when Constraint_Error =>
1781 "illegal value for Config_File_Unique",
1782 Element.Value.Location, Project);
1791 Element_Id := Element.Next;
1794 Current_Array_Id := Current_Array.Next;
1796 end Process_Compiler;
1798 --------------------
1799 -- Process_Naming --
1800 --------------------
1802 procedure Process_Naming (Attributes : Variable_Id) is
1803 Attribute_Id : Variable_Id;
1804 Attribute : Variable;
1807 -- Process non associated array attribute from package Naming
1809 Attribute_Id := Attributes;
1810 while Attribute_Id /= No_Variable loop
1811 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1813 if not Attribute.Value.Default then
1814 if Attribute.Name = Name_Separate_Suffix then
1816 -- Attribute Separate_Suffix
1818 Get_Name_String (Attribute.Value.Value);
1819 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1820 Separate_Suffix := Name_Find;
1822 elsif Attribute.Name = Name_Casing then
1828 Value (Get_Name_String (Attribute.Value.Value));
1831 when Constraint_Error =>
1834 "invalid value for Casing",
1835 Attribute.Value.Location, Project);
1838 elsif Attribute.Name = Name_Dot_Replacement then
1840 -- Attribute Dot_Replacement
1842 Dot_Replacement := File_Name_Type (Attribute.Value.Value);
1847 Attribute_Id := Attribute.Next;
1851 procedure Process_Naming (Arrays : Array_Id) is
1852 Current_Array_Id : Array_Id;
1853 Current_Array : Array_Data;
1854 Element_Id : Array_Element_Id;
1855 Element : Array_Element;
1858 -- Process the associative array attribute of package Naming
1860 Current_Array_Id := Arrays;
1861 while Current_Array_Id /= No_Array loop
1862 Current_Array := Shared.Arrays.Table (Current_Array_Id);
1864 Element_Id := Current_Array.Value;
1865 while Element_Id /= No_Array_Element loop
1866 Element := Shared.Array_Elements.Table (Element_Id);
1868 -- Get the name of the language
1870 Lang_Index := Get_Language_From_Name
1871 (Project, Get_Name_String (Element.Index));
1873 if Lang_Index /= No_Language_Index then
1874 case Current_Array.Name is
1875 when Name_Spec_Suffix | Name_Specification_Suffix =>
1877 -- Attribute Spec_Suffix (<language>)
1879 Get_Name_String (Element.Value.Value);
1880 Canonical_Case_File_Name
1881 (Name_Buffer (1 .. Name_Len));
1882 Lang_Index.Config.Naming_Data.Spec_Suffix :=
1885 when Name_Implementation_Suffix | Name_Body_Suffix =>
1887 Get_Name_String (Element.Value.Value);
1888 Canonical_Case_File_Name
1889 (Name_Buffer (1 .. Name_Len));
1891 -- Attribute Body_Suffix (<language>)
1893 Lang_Index.Config.Naming_Data.Body_Suffix :=
1895 Lang_Index.Config.Naming_Data.Separate_Suffix :=
1896 Lang_Index.Config.Naming_Data.Body_Suffix;
1903 Element_Id := Element.Next;
1906 Current_Array_Id := Current_Array.Next;
1910 --------------------
1911 -- Process_Linker --
1912 --------------------
1914 procedure Process_Linker (Attributes : Variable_Id) is
1915 Attribute_Id : Variable_Id;
1916 Attribute : Variable;
1919 -- Process non associated array attribute from package Linker
1921 Attribute_Id := Attributes;
1922 while Attribute_Id /= No_Variable loop
1923 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
1925 if not Attribute.Value.Default then
1926 if Attribute.Name = Name_Driver then
1928 -- Attribute Linker'Driver: the default linker to use
1930 Project.Config.Linker :=
1931 Path_Name_Type (Attribute.Value.Value);
1933 -- Linker'Driver is also used to link shared libraries
1934 -- if the obsolescent attribute Library_GCC has not been
1937 if Project.Config.Shared_Lib_Driver = No_File then
1938 Project.Config.Shared_Lib_Driver :=
1939 File_Name_Type (Attribute.Value.Value);
1942 elsif Attribute.Name = Name_Required_Switches then
1944 -- Attribute Required_Switches: the minimum trailing
1945 -- options to use when invoking the linker
1948 Project.Config.Trailing_Linker_Required_Switches,
1949 From_List => Attribute.Value.Values,
1950 In_Tree => Data.Tree);
1952 elsif Attribute.Name = Name_Map_File_Option then
1953 Project.Config.Map_File_Option := Attribute.Value.Value;
1955 elsif Attribute.Name = Name_Max_Command_Line_Length then
1957 Project.Config.Max_Command_Line_Length :=
1958 Natural'Value (Get_Name_String
1959 (Attribute.Value.Value));
1962 when Constraint_Error =>
1965 "value must be positive or equal to 0",
1966 Attribute.Value.Location, Project);
1969 elsif Attribute.Name = Name_Response_File_Format then
1974 Get_Name_String (Attribute.Value.Value);
1975 To_Lower (Name_Buffer (1 .. Name_Len));
1978 if Name = Name_None then
1979 Project.Config.Resp_File_Format := None;
1981 elsif Name = Name_Gnu then
1982 Project.Config.Resp_File_Format := GNU;
1984 elsif Name = Name_Object_List then
1985 Project.Config.Resp_File_Format := Object_List;
1987 elsif Name = Name_Option_List then
1988 Project.Config.Resp_File_Format := Option_List;
1990 elsif Name_Buffer (1 .. Name_Len) = "gcc" then
1991 Project.Config.Resp_File_Format := GCC;
1993 elsif Name_Buffer (1 .. Name_Len) = "gcc_gnu" then
1994 Project.Config.Resp_File_Format := GCC_GNU;
1997 Name_Buffer (1 .. Name_Len) = "gcc_option_list"
1999 Project.Config.Resp_File_Format := GCC_Option_List;
2002 Name_Buffer (1 .. Name_Len) = "gcc_object_list"
2004 Project.Config.Resp_File_Format := GCC_Object_List;
2009 "illegal response file format",
2010 Attribute.Value.Location, Project);
2014 elsif Attribute.Name = Name_Response_File_Switches then
2015 Put (Into_List => Project.Config.Resp_File_Options,
2016 From_List => Attribute.Value.Values,
2017 In_Tree => Data.Tree);
2021 Attribute_Id := Attribute.Next;
2025 -- Start of processing for Process_Packages
2028 Packages := Project.Decl.Packages;
2029 while Packages /= No_Package loop
2030 Element := Shared.Packages.Table (Packages);
2032 case Element.Name is
2035 -- Process attributes of package Binder
2037 Process_Binder (Element.Decl.Arrays);
2039 when Name_Builder =>
2041 -- Process attributes of package Builder
2043 Process_Builder (Element.Decl.Attributes);
2045 when Name_Compiler =>
2047 -- Process attributes of package Compiler
2049 Process_Compiler (Element.Decl.Arrays);
2053 -- Process attributes of package Linker
2055 Process_Linker (Element.Decl.Attributes);
2059 -- Process attributes of package Naming
2061 Process_Naming (Element.Decl.Attributes);
2062 Process_Naming (Element.Decl.Arrays);
2068 Packages := Element.Next;
2070 end Process_Packages;
2072 ---------------------------------------------
2073 -- Process_Project_Level_Simple_Attributes --
2074 ---------------------------------------------
2076 procedure Process_Project_Level_Simple_Attributes is
2077 Attribute_Id : Variable_Id;
2078 Attribute : Variable;
2079 List : String_List_Id;
2082 -- Process non associated array attribute at project level
2084 Attribute_Id := Project.Decl.Attributes;
2085 while Attribute_Id /= No_Variable loop
2086 Attribute := Shared.Variable_Elements.Table (Attribute_Id);
2088 if not Attribute.Value.Default then
2089 if Attribute.Name = Name_Target then
2091 -- Attribute Target: the target specified
2093 Project.Config.Target := Attribute.Value.Value;
2095 elsif Attribute.Name = Name_Library_Builder then
2097 -- Attribute Library_Builder: the application to invoke
2098 -- to build libraries.
2100 Project.Config.Library_Builder :=
2101 Path_Name_Type (Attribute.Value.Value);
2103 elsif Attribute.Name = Name_Archive_Builder then
2105 -- Attribute Archive_Builder: the archive builder
2106 -- (usually "ar") and its minimum options (usually "cr").
2108 List := Attribute.Value.Values;
2110 if List = Nil_String then
2113 "archive builder cannot be null",
2114 Attribute.Value.Location, Project);
2117 Put (Into_List => Project.Config.Archive_Builder,
2119 In_Tree => Data.Tree);
2121 elsif Attribute.Name = Name_Archive_Builder_Append_Option then
2123 -- Attribute Archive_Builder: the archive builder
2124 -- (usually "ar") and its minimum options (usually "cr").
2126 List := Attribute.Value.Values;
2128 if List /= Nil_String then
2131 Project.Config.Archive_Builder_Append_Option,
2133 In_Tree => Data.Tree);
2136 elsif Attribute.Name = Name_Archive_Indexer then
2138 -- Attribute Archive_Indexer: the optional archive
2139 -- indexer (usually "ranlib") with its minimum options
2142 List := Attribute.Value.Values;
2144 if List = Nil_String then
2147 "archive indexer cannot be null",
2148 Attribute.Value.Location, Project);
2151 Put (Into_List => Project.Config.Archive_Indexer,
2153 In_Tree => Data.Tree);
2155 elsif Attribute.Name = Name_Library_Partial_Linker then
2157 -- Attribute Library_Partial_Linker: the optional linker
2158 -- driver with its minimum options, to partially link
2161 List := Attribute.Value.Values;
2163 if List = Nil_String then
2166 "partial linker cannot be null",
2167 Attribute.Value.Location, Project);
2170 Put (Into_List => Project.Config.Lib_Partial_Linker,
2172 In_Tree => Data.Tree);
2174 elsif Attribute.Name = Name_Library_GCC then
2175 Project.Config.Shared_Lib_Driver :=
2176 File_Name_Type (Attribute.Value.Value);
2179 "?Library_'G'C'C is an obsolescent attribute, " &
2180 "use Linker''Driver instead",
2181 Attribute.Value.Location, Project);
2183 elsif Attribute.Name = Name_Archive_Suffix then
2184 Project.Config.Archive_Suffix :=
2185 File_Name_Type (Attribute.Value.Value);
2187 elsif Attribute.Name = Name_Linker_Executable_Option then
2189 -- Attribute Linker_Executable_Option: optional options
2190 -- to specify an executable name. Defaults to "-o".
2192 List := Attribute.Value.Values;
2194 if List = Nil_String then
2197 "linker executable option cannot be null",
2198 Attribute.Value.Location, Project);
2201 Put (Into_List => Project.Config.Linker_Executable_Option,
2203 In_Tree => Data.Tree);
2205 elsif Attribute.Name = Name_Linker_Lib_Dir_Option then
2207 -- Attribute Linker_Lib_Dir_Option: optional options
2208 -- to specify a library search directory. Defaults to
2211 Get_Name_String (Attribute.Value.Value);
2213 if Name_Len = 0 then
2216 "linker library directory option cannot be empty",
2217 Attribute.Value.Location, Project);
2220 Project.Config.Linker_Lib_Dir_Option :=
2221 Attribute.Value.Value;
2223 elsif Attribute.Name = Name_Linker_Lib_Name_Option then
2225 -- Attribute Linker_Lib_Name_Option: optional options
2226 -- to specify the name of a library to be linked in.
2227 -- Defaults to "-l".
2229 Get_Name_String (Attribute.Value.Value);
2231 if Name_Len = 0 then
2234 "linker library name option cannot be empty",
2235 Attribute.Value.Location, Project);
2238 Project.Config.Linker_Lib_Name_Option :=
2239 Attribute.Value.Value;
2241 elsif Attribute.Name = Name_Run_Path_Option then
2243 -- Attribute Run_Path_Option: optional options to
2244 -- specify a path for libraries.
2246 List := Attribute.Value.Values;
2248 if List /= Nil_String then
2249 Put (Into_List => Project.Config.Run_Path_Option,
2251 In_Tree => Data.Tree);
2254 elsif Attribute.Name = Name_Run_Path_Origin then
2255 Get_Name_String (Attribute.Value.Value);
2257 if Name_Len = 0 then
2260 "run path origin cannot be empty",
2261 Attribute.Value.Location, Project);
2264 Project.Config.Run_Path_Origin := Attribute.Value.Value;
2266 elsif Attribute.Name = Name_Library_Install_Name_Option then
2267 Project.Config.Library_Install_Name_Option :=
2268 Attribute.Value.Value;
2270 elsif Attribute.Name = Name_Separate_Run_Path_Options then
2272 pragma Unsuppress (All_Checks);
2274 Project.Config.Separate_Run_Path_Options :=
2275 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2277 when Constraint_Error =>
2280 "invalid value """ &
2281 Get_Name_String (Attribute.Value.Value) &
2282 """ for Separate_Run_Path_Options",
2283 Attribute.Value.Location, Project);
2286 elsif Attribute.Name = Name_Library_Support then
2288 pragma Unsuppress (All_Checks);
2290 Project.Config.Lib_Support :=
2291 Library_Support'Value (Get_Name_String
2292 (Attribute.Value.Value));
2294 when Constraint_Error =>
2297 "invalid value """ &
2298 Get_Name_String (Attribute.Value.Value) &
2299 """ for Library_Support",
2300 Attribute.Value.Location, Project);
2303 elsif Attribute.Name = Name_Shared_Library_Prefix then
2304 Project.Config.Shared_Lib_Prefix :=
2305 File_Name_Type (Attribute.Value.Value);
2307 elsif Attribute.Name = Name_Shared_Library_Suffix then
2308 Project.Config.Shared_Lib_Suffix :=
2309 File_Name_Type (Attribute.Value.Value);
2311 elsif Attribute.Name = Name_Symbolic_Link_Supported then
2313 pragma Unsuppress (All_Checks);
2315 Project.Config.Symbolic_Link_Supported :=
2316 Boolean'Value (Get_Name_String
2317 (Attribute.Value.Value));
2319 when Constraint_Error =>
2323 & Get_Name_String (Attribute.Value.Value)
2324 & """ for Symbolic_Link_Supported",
2325 Attribute.Value.Location, Project);
2329 Attribute.Name = Name_Library_Major_Minor_Id_Supported
2332 pragma Unsuppress (All_Checks);
2334 Project.Config.Lib_Maj_Min_Id_Supported :=
2335 Boolean'Value (Get_Name_String
2336 (Attribute.Value.Value));
2338 when Constraint_Error =>
2341 "invalid value """ &
2342 Get_Name_String (Attribute.Value.Value) &
2343 """ for Library_Major_Minor_Id_Supported",
2344 Attribute.Value.Location, Project);
2347 elsif Attribute.Name = Name_Library_Auto_Init_Supported then
2349 pragma Unsuppress (All_Checks);
2351 Project.Config.Auto_Init_Supported :=
2352 Boolean'Value (Get_Name_String (Attribute.Value.Value));
2354 when Constraint_Error =>
2358 & Get_Name_String (Attribute.Value.Value)
2359 & """ for Library_Auto_Init_Supported",
2360 Attribute.Value.Location, Project);
2363 elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then
2364 List := Attribute.Value.Values;
2366 if List /= Nil_String then
2367 Put (Into_List => Project.Config.Shared_Lib_Min_Options,
2369 In_Tree => Data.Tree);
2372 elsif Attribute.Name = Name_Library_Version_Switches then
2373 List := Attribute.Value.Values;
2375 if List /= Nil_String then
2376 Put (Into_List => Project.Config.Lib_Version_Options,
2378 In_Tree => Data.Tree);
2383 Attribute_Id := Attribute.Next;
2385 end Process_Project_Level_Simple_Attributes;
2387 --------------------------------------------
2388 -- Process_Project_Level_Array_Attributes --
2389 --------------------------------------------
2391 procedure Process_Project_Level_Array_Attributes is
2392 Current_Array_Id : Array_Id;
2393 Current_Array : Array_Data;
2394 Element_Id : Array_Element_Id;
2395 Element : Array_Element;
2396 List : String_List_Id;
2399 -- Process the associative array attributes at project level
2401 Current_Array_Id := Project.Decl.Arrays;
2402 while Current_Array_Id /= No_Array loop
2403 Current_Array := Shared.Arrays.Table (Current_Array_Id);
2405 Element_Id := Current_Array.Value;
2406 while Element_Id /= No_Array_Element loop
2407 Element := Shared.Array_Elements.Table (Element_Id);
2409 -- Get the name of the language
2412 Get_Language_From_Name
2413 (Project, Get_Name_String (Element.Index));
2415 if Lang_Index /= No_Language_Index then
2416 case Current_Array.Name is
2417 when Name_Inherit_Source_Path =>
2418 List := Element.Value.Values;
2420 if List /= Nil_String then
2423 Lang_Index.Config.Include_Compatible_Languages,
2425 In_Tree => Data.Tree,
2426 Lower_Case => True);
2429 when Name_Toolchain_Description =>
2431 -- Attribute Toolchain_Description (<language>)
2433 Lang_Index.Config.Toolchain_Description :=
2434 Element.Value.Value;
2436 when Name_Toolchain_Version =>
2438 -- Attribute Toolchain_Version (<language>)
2440 Lang_Index.Config.Toolchain_Version :=
2441 Element.Value.Value;
2443 -- For Ada, set proper checksum computation mode
2445 if Lang_Index.Name = Name_Ada then
2447 Vers : constant String :=
2448 Get_Name_String (Element.Value.Value);
2449 pragma Assert (Vers'First = 1);
2452 -- Version 6.3 or earlier
2455 and then Vers (1 .. 5) = "GNAT "
2456 and then Vers (7) = '.'
2460 (Vers (6) = '6' and then Vers (8) < '4'))
2462 Checksum_GNAT_6_3 := True;
2464 -- Version 5.03 or earlier
2467 or else (Vers (6) = '5'
2468 and then Vers (Vers'Last) < '4')
2470 Checksum_GNAT_5_03 := True;
2472 -- Version 5.02 or earlier
2475 or else Vers (Vers'Last) < '3'
2477 Checksum_Accumulate_Token_Checksum :=
2485 when Name_Runtime_Library_Dir =>
2487 -- Attribute Runtime_Library_Dir (<language>)
2489 Lang_Index.Config.Runtime_Library_Dir :=
2490 Element.Value.Value;
2492 when Name_Runtime_Source_Dir =>
2494 -- Attribute Runtime_Library_Dir (<language>)
2496 Lang_Index.Config.Runtime_Source_Dir :=
2497 Element.Value.Value;
2499 when Name_Object_Generated =>
2501 pragma Unsuppress (All_Checks);
2507 (Get_Name_String (Element.Value.Value));
2509 Lang_Index.Config.Object_Generated := Value;
2511 -- If no object is generated, no object may be
2515 Lang_Index.Config.Objects_Linked := False;
2519 when Constraint_Error =>
2523 & Get_Name_String (Element.Value.Value)
2524 & """ for Object_Generated",
2525 Element.Value.Location, Project);
2528 when Name_Objects_Linked =>
2530 pragma Unsuppress (All_Checks);
2536 (Get_Name_String (Element.Value.Value));
2538 -- No change if Object_Generated is False, as this
2539 -- forces Objects_Linked to be False too.
2541 if Lang_Index.Config.Object_Generated then
2542 Lang_Index.Config.Objects_Linked := Value;
2546 when Constraint_Error =>
2550 & Get_Name_String (Element.Value.Value)
2551 & """ for Objects_Linked",
2552 Element.Value.Location, Project);
2559 Element_Id := Element.Next;
2562 Current_Array_Id := Current_Array.Next;
2564 end Process_Project_Level_Array_Attributes;
2566 -- Start of processing for Check_Configuration
2569 Process_Project_Level_Simple_Attributes;
2570 Process_Project_Level_Array_Attributes;
2573 -- For unit based languages, set Casing, Dot_Replacement and
2574 -- Separate_Suffix in Naming_Data.
2576 Lang_Index := Project.Languages;
2577 while Lang_Index /= No_Language_Index loop
2578 if Lang_Index.Name = Name_Ada then
2579 Lang_Index.Config.Naming_Data.Casing := Casing;
2580 Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement;
2582 if Separate_Suffix /= No_File then
2583 Lang_Index.Config.Naming_Data.Separate_Suffix :=
2590 Lang_Index := Lang_Index.Next;
2593 -- Give empty names to various prefixes/suffixes, if they have not
2594 -- been specified in the configuration.
2596 if Project.Config.Archive_Suffix = No_File then
2597 Project.Config.Archive_Suffix := Empty_File;
2600 if Project.Config.Shared_Lib_Prefix = No_File then
2601 Project.Config.Shared_Lib_Prefix := Empty_File;
2604 if Project.Config.Shared_Lib_Suffix = No_File then
2605 Project.Config.Shared_Lib_Suffix := Empty_File;
2608 Lang_Index := Project.Languages;
2609 while Lang_Index /= No_Language_Index loop
2611 -- For all languages, Compiler_Driver needs to be specified. This is
2612 -- only needed if we do intend to compile (not in GPS for instance).
2614 if Data.Flags.Compiler_Driver_Mandatory
2615 and then Lang_Index.Config.Compiler_Driver = No_File
2617 Error_Msg_Name_1 := Lang_Index.Display_Name;
2620 "?no compiler specified for language %%" &
2621 ", ignoring all its sources",
2622 No_Location, Project);
2624 if Lang_Index = Project.Languages then
2625 Project.Languages := Lang_Index.Next;
2627 Prev_Index.Next := Lang_Index.Next;
2630 elsif Lang_Index.Name = Name_Ada then
2631 Prev_Index := Lang_Index;
2633 -- For unit based languages, Dot_Replacement, Spec_Suffix and
2634 -- Body_Suffix need to be specified.
2636 if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then
2639 "Dot_Replacement not specified for Ada",
2640 No_Location, Project);
2643 if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then
2646 "Spec_Suffix not specified for Ada",
2647 No_Location, Project);
2650 if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then
2653 "Body_Suffix not specified for Ada",
2654 No_Location, Project);
2658 Prev_Index := Lang_Index;
2660 -- For file based languages, either Spec_Suffix or Body_Suffix
2661 -- need to be specified.
2663 if Data.Flags.Require_Sources_Other_Lang
2664 and then Lang_Index.Config.Naming_Data.Spec_Suffix = No_File
2665 and then Lang_Index.Config.Naming_Data.Body_Suffix = No_File
2667 Error_Msg_Name_1 := Lang_Index.Display_Name;
2670 "no suffixes specified for %%",
2671 No_Location, Project);
2675 Lang_Index := Lang_Index.Next;
2677 end Check_Configuration;
2679 -------------------------------
2680 -- Check_If_Externally_Built --
2681 -------------------------------
2683 procedure Check_If_Externally_Built
2684 (Project : Project_Id;
2685 Data : in out Tree_Processing_Data)
2687 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2688 Externally_Built : constant Variable_Value :=
2690 (Name_Externally_Built,
2691 Project.Decl.Attributes, Shared);
2694 if not Externally_Built.Default then
2695 Get_Name_String (Externally_Built.Value);
2696 To_Lower (Name_Buffer (1 .. Name_Len));
2698 if Name_Buffer (1 .. Name_Len) = "true" then
2699 Project.Externally_Built := True;
2701 elsif Name_Buffer (1 .. Name_Len) /= "false" then
2702 Error_Msg (Data.Flags,
2703 "Externally_Built may only be true or false",
2704 Externally_Built.Location, Project);
2708 -- A virtual project extending an externally built project is itself
2709 -- externally built.
2711 if Project.Virtual and then Project.Extends /= No_Project then
2712 Project.Externally_Built := Project.Extends.Externally_Built;
2715 if Project.Externally_Built then
2716 Debug_Output ("project is externally built");
2718 Debug_Output ("project is not externally built");
2720 end Check_If_Externally_Built;
2722 ----------------------
2723 -- Check_Interfaces --
2724 ----------------------
2726 procedure Check_Interfaces
2727 (Project : Project_Id;
2728 Data : in out Tree_Processing_Data)
2730 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2732 Interfaces : constant Prj.Variable_Value :=
2734 (Snames.Name_Interfaces,
2735 Project.Decl.Attributes,
2738 Library_Interface : constant Prj.Variable_Value :=
2740 (Snames.Name_Library_Interface,
2741 Project.Decl.Attributes,
2744 List : String_List_Id;
2745 Element : String_Element;
2746 Name : File_Name_Type;
2747 Iter : Source_Iterator;
2749 Project_2 : Project_Id;
2753 if not Interfaces.Default then
2755 -- Set In_Interfaces to False for all sources. It will be set to True
2756 -- later for the sources in the Interfaces list.
2758 Project_2 := Project;
2759 while Project_2 /= No_Project loop
2760 Iter := For_Each_Source (Data.Tree, Project_2);
2762 Source := Prj.Element (Iter);
2763 exit when Source = No_Source;
2764 Source.In_Interfaces := False;
2768 Project_2 := Project_2.Extends;
2771 List := Interfaces.Values;
2772 while List /= Nil_String loop
2773 Element := Shared.String_Elements.Table (List);
2774 Name := Canonical_Case_File_Name (Element.Value);
2776 Project_2 := Project;
2778 while Project_2 /= No_Project loop
2779 Iter := For_Each_Source (Data.Tree, Project_2);
2782 Source := Prj.Element (Iter);
2783 exit when Source = No_Source;
2785 if Source.File = Name then
2786 if not Source.Locally_Removed then
2787 Source.In_Interfaces := True;
2788 Source.Declared_In_Interfaces := True;
2790 Other := Other_Part (Source);
2792 if Other /= No_Source then
2793 Other.In_Interfaces := True;
2794 Other.Declared_In_Interfaces := True;
2798 ("interface: ", Name_Id (Source.Path.Name));
2807 Project_2 := Project_2.Extends;
2810 if Source = No_Source then
2811 Error_Msg_File_1 := File_Name_Type (Element.Value);
2812 Error_Msg_Name_1 := Project.Name;
2816 "{ cannot be an interface of project %% "
2817 & "as it is not one of its sources",
2818 Element.Location, Project);
2821 List := Element.Next;
2824 Project.Interfaces_Defined := True;
2826 elsif Project.Library and then not Library_Interface.Default then
2828 -- Set In_Interfaces to False for all sources. It will be set to True
2829 -- later for the sources in the Library_Interface list.
2831 Project_2 := Project;
2832 while Project_2 /= No_Project loop
2833 Iter := For_Each_Source (Data.Tree, Project_2);
2835 Source := Prj.Element (Iter);
2836 exit when Source = No_Source;
2837 Source.In_Interfaces := False;
2841 Project_2 := Project_2.Extends;
2844 List := Library_Interface.Values;
2845 while List /= Nil_String loop
2846 Element := Shared.String_Elements.Table (List);
2847 Get_Name_String (Element.Value);
2848 To_Lower (Name_Buffer (1 .. Name_Len));
2851 Project_2 := Project;
2853 while Project_2 /= No_Project loop
2854 Iter := For_Each_Source (Data.Tree, Project_2);
2857 Source := Prj.Element (Iter);
2858 exit when Source = No_Source;
2860 if Source.Unit /= No_Unit_Index and then
2861 Source.Unit.Name = Name_Id (Name)
2863 if not Source.Locally_Removed then
2864 Source.In_Interfaces := True;
2865 Source.Declared_In_Interfaces := True;
2867 Other := Other_Part (Source);
2869 if Other /= No_Source then
2870 Other.In_Interfaces := True;
2871 Other.Declared_In_Interfaces := True;
2875 ("interface: ", Name_Id (Source.Path.Name));
2884 Project_2 := Project_2.Extends;
2885 end loop Big_Loop_2;
2887 List := Element.Next;
2890 Project.Interfaces_Defined := True;
2892 elsif Project.Extends /= No_Project
2893 and then Project.Extends.Interfaces_Defined
2895 Project.Interfaces_Defined := True;
2897 Iter := For_Each_Source (Data.Tree, Project);
2899 Source := Prj.Element (Iter);
2900 exit when Source = No_Source;
2902 if not Source.Declared_In_Interfaces then
2903 Source.In_Interfaces := False;
2909 end Check_Interfaces;
2911 --------------------------
2912 -- Check_Package_Naming --
2913 --------------------------
2915 procedure Check_Package_Naming
2916 (Project : Project_Id;
2917 Data : in out Tree_Processing_Data)
2919 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
2920 Naming_Id : constant Package_Id :=
2922 (Name_Naming, Project.Decl.Packages, Shared);
2923 Naming : Package_Element;
2925 Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
2927 procedure Check_Naming;
2928 -- Check the validity of the Naming package (suffixes valid, ...)
2930 procedure Check_Common
2931 (Dot_Replacement : in out File_Name_Type;
2932 Casing : in out Casing_Type;
2933 Casing_Defined : out Boolean;
2934 Separate_Suffix : in out File_Name_Type;
2935 Sep_Suffix_Loc : out Source_Ptr);
2936 -- Check attributes common
2938 procedure Process_Exceptions_File_Based
2939 (Lang_Id : Language_Ptr;
2940 Kind : Source_Kind);
2941 procedure Process_Exceptions_Unit_Based
2942 (Lang_Id : Language_Ptr;
2943 Kind : Source_Kind);
2944 -- Process the naming exceptions for the two types of languages
2946 procedure Initialize_Naming_Data;
2947 -- Initialize internal naming data for the various languages
2953 procedure Check_Common
2954 (Dot_Replacement : in out File_Name_Type;
2955 Casing : in out Casing_Type;
2956 Casing_Defined : out Boolean;
2957 Separate_Suffix : in out File_Name_Type;
2958 Sep_Suffix_Loc : out Source_Ptr)
2960 Dot_Repl : constant Variable_Value :=
2962 (Name_Dot_Replacement,
2963 Naming.Decl.Attributes,
2965 Casing_String : constant Variable_Value :=
2968 Naming.Decl.Attributes,
2970 Sep_Suffix : constant Variable_Value :=
2972 (Name_Separate_Suffix,
2973 Naming.Decl.Attributes,
2975 Dot_Repl_Loc : Source_Ptr;
2978 Sep_Suffix_Loc := No_Location;
2980 if not Dot_Repl.Default then
2982 (Dot_Repl.Kind = Single, "Dot_Replacement is not a string");
2984 if Length_Of_Name (Dot_Repl.Value) = 0 then
2986 (Data.Flags, "Dot_Replacement cannot be empty",
2987 Dot_Repl.Location, Project);
2990 Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value);
2991 Dot_Repl_Loc := Dot_Repl.Location;
2994 Repl : constant String := Get_Name_String (Dot_Replacement);
2997 -- Dot_Replacement cannot
2999 -- - start or end with an alphanumeric
3000 -- - be a single '_'
3001 -- - start with an '_' followed by an alphanumeric
3002 -- - contain a '.' except if it is "."
3005 or else Is_Alphanumeric (Repl (Repl'First))
3006 or else Is_Alphanumeric (Repl (Repl'Last))
3007 or else (Repl (Repl'First) = '_'
3011 Is_Alphanumeric (Repl (Repl'First + 1))))
3012 or else (Repl'Length > 1
3014 Index (Source => Repl, Pattern => ".") /= 0)
3019 """ is illegal for Dot_Replacement.",
3020 Dot_Repl_Loc, Project);
3025 if Dot_Replacement /= No_File then
3027 ("Dot_Replacement", Get_Name_String (Dot_Replacement));
3030 Casing_Defined := False;
3032 if not Casing_String.Default then
3034 (Casing_String.Kind = Single, "Casing is not a string");
3037 Casing_Image : constant String :=
3038 Get_Name_String (Casing_String.Value);
3041 if Casing_Image'Length = 0 then
3044 "Casing cannot be an empty string",
3045 Casing_String.Location, Project);
3048 Casing := Value (Casing_Image);
3049 Casing_Defined := True;
3052 when Constraint_Error =>
3053 Name_Len := Casing_Image'Length;
3054 Name_Buffer (1 .. Name_Len) := Casing_Image;
3055 Err_Vars.Error_Msg_Name_1 := Name_Find;
3058 "%% is not a correct Casing",
3059 Casing_String.Location, Project);
3063 Write_Attr ("Casing", Image (Casing));
3065 if not Sep_Suffix.Default then
3066 if Length_Of_Name (Sep_Suffix.Value) = 0 then
3069 "Separate_Suffix cannot be empty",
3070 Sep_Suffix.Location, Project);
3073 Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value);
3074 Sep_Suffix_Loc := Sep_Suffix.Location;
3076 Check_Illegal_Suffix
3077 (Project, Separate_Suffix,
3078 Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location,
3083 if Separate_Suffix /= No_File then
3085 ("Separate_Suffix", Get_Name_String (Separate_Suffix));
3089 -----------------------------------
3090 -- Process_Exceptions_File_Based --
3091 -----------------------------------
3093 procedure Process_Exceptions_File_Based
3094 (Lang_Id : Language_Ptr;
3097 Lang : constant Name_Id := Lang_Id.Name;
3098 Exceptions : Array_Element_Id;
3099 Exception_List : Variable_Value;
3100 Element_Id : String_List_Id;
3101 Element : String_Element;
3102 File_Name : File_Name_Type;
3110 (Name_Implementation_Exceptions,
3111 In_Arrays => Naming.Decl.Arrays,
3117 (Name_Specification_Exceptions,
3118 In_Arrays => Naming.Decl.Arrays,
3125 In_Array => Exceptions,
3128 if Exception_List /= Nil_Variable_Value then
3129 Element_Id := Exception_List.Values;
3130 while Element_Id /= Nil_String loop
3131 Element := Shared.String_Elements.Table (Element_Id);
3132 File_Name := Canonical_Case_File_Name (Element.Value);
3135 Source_Files_Htable.Get
3136 (Data.Tree.Source_Files_HT, File_Name);
3137 while Source /= No_Source
3138 and then Source.Project /= Project
3140 Source := Source.Next_With_File_Name;
3143 if Source = No_Source then
3148 Source_Dir_Rank => 0,
3151 File_Name => File_Name,
3152 Display_File => File_Name_Type (Element.Value),
3153 Naming_Exception => True,
3154 Location => Element.Location);
3157 -- Check if the file name is already recorded for another
3158 -- language or another kind.
3160 if Source.Language /= Lang_Id then
3163 "the same file cannot be a source of two languages",
3164 Element.Location, Project);
3166 elsif Source.Kind /= Kind then
3169 "the same file cannot be a source and a template",
3170 Element.Location, Project);
3173 -- If the file is already recorded for the same
3174 -- language and the same kind, it means that the file
3175 -- name appears several times in the *_Exceptions
3176 -- attribute; so there is nothing to do.
3179 Element_Id := Element.Next;
3182 end Process_Exceptions_File_Based;
3184 -----------------------------------
3185 -- Process_Exceptions_Unit_Based --
3186 -----------------------------------
3188 procedure Process_Exceptions_Unit_Based
3189 (Lang_Id : Language_Ptr;
3192 Lang : constant Name_Id := Lang_Id.Name;
3193 Exceptions : Array_Element_Id;
3194 Element : Array_Element;
3197 File_Name : File_Name_Type;
3206 In_Arrays => Naming.Decl.Arrays,
3209 if Exceptions = No_Array_Element then
3212 (Name_Implementation,
3213 In_Arrays => Naming.Decl.Arrays,
3221 In_Arrays => Naming.Decl.Arrays,
3224 if Exceptions = No_Array_Element then
3228 In_Arrays => Naming.Decl.Arrays,
3233 while Exceptions /= No_Array_Element loop
3234 Element := Shared.Array_Elements.Table (Exceptions);
3235 File_Name := Canonical_Case_File_Name (Element.Value.Value);
3237 Get_Name_String (Element.Index);
3238 To_Lower (Name_Buffer (1 .. Name_Len));
3240 Index := Element.Value.Index;
3242 -- For Ada, check if it is a valid unit name
3244 if Lang = Name_Ada then
3245 Get_Name_String (Element.Index);
3246 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
3248 if Unit = No_Name then
3249 Err_Vars.Error_Msg_Name_1 := Element.Index;
3252 "%% is not a valid unit name.",
3253 Element.Value.Location, Project);
3257 if Unit /= No_Name then
3262 Source_Dir_Rank => 0,
3265 File_Name => File_Name,
3266 Display_File => File_Name_Type (Element.Value.Value),
3269 Location => Element.Value.Location,
3270 Naming_Exception => True);
3273 Exceptions := Element.Next;
3275 end Process_Exceptions_Unit_Based;
3281 procedure Check_Naming is
3282 Dot_Replacement : File_Name_Type :=
3284 (First_Name_Id + Character'Pos ('-'));
3285 Separate_Suffix : File_Name_Type := No_File;
3286 Casing : Casing_Type := All_Lower_Case;
3287 Casing_Defined : Boolean;
3288 Lang_Id : Language_Ptr;
3289 Sep_Suffix_Loc : Source_Ptr;
3290 Suffix : Variable_Value;
3295 (Dot_Replacement => Dot_Replacement,
3297 Casing_Defined => Casing_Defined,
3298 Separate_Suffix => Separate_Suffix,
3299 Sep_Suffix_Loc => Sep_Suffix_Loc);
3301 -- For all unit based languages, if any, set the specified value
3302 -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
3303 -- systematically overwrite, since the defaults come from the
3304 -- configuration file.
3306 if Dot_Replacement /= No_File
3307 or else Casing_Defined
3308 or else Separate_Suffix /= No_File
3310 Lang_Id := Project.Languages;
3311 while Lang_Id /= No_Language_Index loop
3312 if Lang_Id.Config.Kind = Unit_Based then
3313 if Dot_Replacement /= No_File then
3314 Lang_Id.Config.Naming_Data.Dot_Replacement :=
3318 if Casing_Defined then
3319 Lang_Id.Config.Naming_Data.Casing := Casing;
3323 Lang_Id := Lang_Id.Next;
3327 -- Next, get the spec and body suffixes
3329 Lang_Id := Project.Languages;
3330 while Lang_Id /= No_Language_Index loop
3331 Lang := Lang_Id.Name;
3337 Attribute_Or_Array_Name => Name_Spec_Suffix,
3338 In_Package => Naming_Id,
3341 if Suffix = Nil_Variable_Value then
3344 Attribute_Or_Array_Name => Name_Specification_Suffix,
3345 In_Package => Naming_Id,
3349 if Suffix /= Nil_Variable_Value then
3350 Lang_Id.Config.Naming_Data.Spec_Suffix :=
3351 File_Name_Type (Suffix.Value);
3353 Check_Illegal_Suffix
3355 Lang_Id.Config.Naming_Data.Spec_Suffix,
3356 Lang_Id.Config.Naming_Data.Dot_Replacement,
3357 "Spec_Suffix", Suffix.Location, Data);
3361 Get_Name_String (Lang_Id.Config.Naming_Data.Spec_Suffix));
3369 Attribute_Or_Array_Name => Name_Body_Suffix,
3370 In_Package => Naming_Id,
3373 if Suffix = Nil_Variable_Value then
3377 Attribute_Or_Array_Name => Name_Implementation_Suffix,
3378 In_Package => Naming_Id,
3382 if Suffix /= Nil_Variable_Value then
3383 Lang_Id.Config.Naming_Data.Body_Suffix :=
3384 File_Name_Type (Suffix.Value);
3386 -- The default value of separate suffix should be the same as
3387 -- the body suffix, so we need to compute that first.
3389 if Separate_Suffix = No_File then
3390 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3391 Lang_Id.Config.Naming_Data.Body_Suffix;
3395 (Lang_Id.Config.Naming_Data.Separate_Suffix));
3397 Lang_Id.Config.Naming_Data.Separate_Suffix :=
3401 Check_Illegal_Suffix
3403 Lang_Id.Config.Naming_Data.Body_Suffix,
3404 Lang_Id.Config.Naming_Data.Dot_Replacement,
3405 "Body_Suffix", Suffix.Location, Data);
3409 Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix));
3411 elsif Separate_Suffix /= No_File then
3412 Lang_Id.Config.Naming_Data.Separate_Suffix := Separate_Suffix;
3415 -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
3416 -- since that would cause a clear ambiguity. Note that we do allow
3417 -- a Spec_Suffix to have the same termination as one of these,
3418 -- which causes a potential ambiguity, but we resolve that by
3419 -- matching the longest possible suffix.
3421 if Lang_Id.Config.Naming_Data.Spec_Suffix /= No_File
3422 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3423 Lang_Id.Config.Naming_Data.Body_Suffix
3428 & Get_Name_String (Lang_Id.Config.Naming_Data.Body_Suffix)
3429 & """) cannot be the same as Spec_Suffix.",
3430 Ada_Body_Suffix_Loc, Project);
3433 if Lang_Id.Config.Naming_Data.Body_Suffix /=
3434 Lang_Id.Config.Naming_Data.Separate_Suffix
3435 and then Lang_Id.Config.Naming_Data.Spec_Suffix =
3436 Lang_Id.Config.Naming_Data.Separate_Suffix
3440 "Separate_Suffix ("""
3442 (Lang_Id.Config.Naming_Data.Separate_Suffix)
3443 & """) cannot be the same as Spec_Suffix.",
3444 Sep_Suffix_Loc, Project);
3447 Lang_Id := Lang_Id.Next;
3450 -- Get the naming exceptions for all languages
3452 for Kind in Spec_Or_Body loop
3453 Lang_Id := Project.Languages;
3454 while Lang_Id /= No_Language_Index loop
3455 case Lang_Id.Config.Kind is
3457 Process_Exceptions_File_Based (Lang_Id, Kind);
3460 Process_Exceptions_Unit_Based (Lang_Id, Kind);
3463 Lang_Id := Lang_Id.Next;
3468 ----------------------------
3469 -- Initialize_Naming_Data --
3470 ----------------------------
3472 procedure Initialize_Naming_Data is
3473 Specs : Array_Element_Id :=
3479 Impls : Array_Element_Id :=
3485 Lang : Language_Ptr;
3486 Lang_Name : Name_Id;
3487 Value : Variable_Value;
3488 Extended : Project_Id;
3491 -- At this stage, the project already contains the default extensions
3492 -- for the various languages. We now merge those suffixes read in the
3493 -- user project, and they override the default.
3495 while Specs /= No_Array_Element loop
3496 Lang_Name := Shared.Array_Elements.Table (Specs).Index;
3498 Get_Language_From_Name
3499 (Project, Name => Get_Name_String (Lang_Name));
3501 -- An extending project inherits its parent projects' languages
3502 -- so if needed we should create entries for those languages
3505 Extended := Project.Extends;
3506 while Extended /= null loop
3507 Lang := Get_Language_From_Name
3508 (Extended, Name => Get_Name_String (Lang_Name));
3509 exit when Lang /= null;
3511 Extended := Extended.Extends;
3514 if Lang /= null then
3515 Lang := new Language_Data'(Lang.all);
3516 Lang.First_Source := null;
3517 Lang.Next := Project.Languages;
3518 Project.Languages := Lang;
3522 -- If language was not found in project or the projects it extends
3526 ("ignoring spec naming data (lang. not in project): ",
3530 Value := Shared.Array_Elements.Table (Specs).Value;
3532 if Value.Kind = Single then
3533 Lang.Config.Naming_Data.Spec_Suffix :=
3534 Canonical_Case_File_Name (Value.Value);
3538 Specs := Shared.Array_Elements.Table (Specs).Next;
3541 while Impls /= No_Array_Element loop
3542 Lang_Name := Shared.Array_Elements.Table (Impls).Index;
3544 Get_Language_From_Name
3545 (Project, Name => Get_Name_String (Lang_Name));
3549 ("ignoring impl naming data (lang. not in project): ",
3552 Value := Shared.Array_Elements.Table (Impls).Value;
3554 if Lang.Name = Name_Ada then
3555 Ada_Body_Suffix_Loc := Value.Location;
3558 if Value.Kind = Single then
3559 Lang.Config.Naming_Data.Body_Suffix :=
3560 Canonical_Case_File_Name (Value.Value);
3564 Impls := Shared.Array_Elements.Table (Impls).Next;
3566 end Initialize_Naming_Data;
3568 -- Start of processing for Check_Naming_Schemes
3571 -- No Naming package or parsing a configuration file? nothing to do
3573 if Naming_Id /= No_Package
3574 and then Project.Qualifier /= Configuration
3576 Naming := Shared.Packages.Table (Naming_Id);
3577 Debug_Increase_Indent ("checking package Naming for ", Project.Name);
3578 Initialize_Naming_Data;
3580 Debug_Decrease_Indent ("done checking package naming");
3582 end Check_Package_Naming;
3584 ------------------------------
3585 -- Check_Library_Attributes --
3586 ------------------------------
3588 procedure Check_Library_Attributes
3589 (Project : Project_Id;
3590 Data : in out Tree_Processing_Data)
3592 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
3594 Attributes : constant Prj.Variable_Id := Project.Decl.Attributes;
3596 Lib_Dir : constant Prj.Variable_Value :=
3598 (Snames.Name_Library_Dir, Attributes, Shared);
3600 Lib_Name : constant Prj.Variable_Value :=
3602 (Snames.Name_Library_Name, Attributes, Shared);
3604 Lib_Version : constant Prj.Variable_Value :=
3606 (Snames.Name_Library_Version, Attributes, Shared);
3608 Lib_ALI_Dir : constant Prj.Variable_Value :=
3610 (Snames.Name_Library_Ali_Dir, Attributes, Shared);
3612 Lib_GCC : constant Prj.Variable_Value :=
3614 (Snames.Name_Library_GCC, Attributes, Shared);
3616 The_Lib_Kind : constant Prj.Variable_Value :=
3618 (Snames.Name_Library_Kind, Attributes, Shared);
3620 Imported_Project_List : Project_List;
3622 Continuation : String_Access := No_Continuation_String'Access;
3624 Support_For_Libraries : Library_Support;
3626 Library_Directory_Present : Boolean;
3628 procedure Check_Library (Proj : Project_Id; Extends : Boolean);
3629 -- Check if an imported or extended project if also a library project
3635 procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
3637 Iter : Source_Iterator;
3640 if Proj /= No_Project then
3641 if not Proj.Library then
3643 -- The only not library projects that are OK are those that
3644 -- have no sources. However, header files from non-Ada
3645 -- languages are OK, as there is nothing to compile.
3647 Iter := For_Each_Source (Data.Tree, Proj);
3649 Src_Id := Prj.Element (Iter);
3650 exit when Src_Id = No_Source
3651 or else Src_Id.Language.Config.Kind /= File_Based
3652 or else Src_Id.Kind /= Spec;
3656 if Src_Id /= No_Source then
3657 Error_Msg_Name_1 := Project.Name;
3658 Error_Msg_Name_2 := Proj.Name;
3661 if Project.Library_Kind /= Static then
3665 "shared library project %% cannot extend " &
3666 "project %% that is not a library project",
3667 Project.Location, Project);
3668 Continuation := Continuation_String'Access;
3671 elsif (not Unchecked_Shared_Lib_Imports)
3672 and then Project.Library_Kind /= Static
3677 "shared library project %% cannot import project %% " &
3678 "that is not a shared library project",
3679 Project.Location, Project);
3680 Continuation := Continuation_String'Access;
3684 elsif Project.Library_Kind /= Static and then
3685 Proj.Library_Kind = Static
3687 Error_Msg_Name_1 := Project.Name;
3688 Error_Msg_Name_2 := Proj.Name;
3694 "shared library project %% cannot extend static " &
3695 "library project %%",
3696 Project.Location, Project);
3697 Continuation := Continuation_String'Access;
3699 elsif not Unchecked_Shared_Lib_Imports then
3703 "shared library project %% cannot import static " &
3704 "library project %%",
3705 Project.Location, Project);
3706 Continuation := Continuation_String'Access;
3713 Dir_Exists : Boolean;
3715 -- Start of processing for Check_Library_Attributes
3718 Library_Directory_Present := Lib_Dir.Value /= Empty_String;
3720 -- Special case of extending project
3722 if Project.Extends /= No_Project then
3724 -- If the project extended is a library project, we inherit the
3725 -- library name, if it is not redefined; we check that the library
3726 -- directory is specified.
3728 if Project.Extends.Library then
3729 if Project.Qualifier = Standard then
3732 "a standard project cannot extend a library project",
3733 Project.Location, Project);
3736 if Lib_Name.Default then
3737 Project.Library_Name := Project.Extends.Library_Name;
3740 if Lib_Dir.Default then
3741 if not Project.Virtual then
3744 "a project extending a library project must " &
3745 "specify an attribute Library_Dir",
3746 Project.Location, Project);
3749 -- For a virtual project extending a library project,
3750 -- inherit library directory and library kind.
3752 Project.Library_Dir := Project.Extends.Library_Dir;
3753 Library_Directory_Present := True;
3754 Project.Library_Kind := Project.Extends.Library_Kind;
3761 pragma Assert (Lib_Name.Kind = Single);
3763 if Lib_Name.Value = Empty_String then
3764 if Current_Verbosity = High
3765 and then Project.Library_Name = No_Name
3768 Write_Line ("no library name");
3772 -- There is no restriction on the syntax of library names
3774 Project.Library_Name := Lib_Name.Value;
3777 if Project.Library_Name /= No_Name then
3778 if Current_Verbosity = High then
3779 Write_Attr ("Library name: ",
3780 Get_Name_String (Project.Library_Name));
3783 pragma Assert (Lib_Dir.Kind = Single);
3785 if not Library_Directory_Present then
3786 Debug_Output ("no library directory");
3789 -- Find path name (unless inherited), check that it is a directory
3791 if Project.Library_Dir = No_Path_Information then
3794 File_Name_Type (Lib_Dir.Value),
3795 Path => Project.Library_Dir,
3796 Dir_Exists => Dir_Exists,
3798 Create => "library",
3799 Must_Exist => False,
3800 Location => Lib_Dir.Location,
3801 Externally_Built => Project.Externally_Built);
3807 (Project.Library_Dir.Display_Name));
3810 if not Dir_Exists then
3812 -- Get the absolute name of the library directory that
3813 -- does not exist, to report an error.
3815 Err_Vars.Error_Msg_File_1 :=
3816 File_Name_Type (Project.Library_Dir.Display_Name);
3819 "library directory { does not exist",
3820 Lib_Dir.Location, Project);
3822 elsif not Project.Externally_Built then
3824 -- The library directory cannot be the same as the Object
3827 if Project.Library_Dir.Name = Project.Object_Directory.Name then
3830 "library directory cannot be the same " &
3831 "as object directory",
3832 Lib_Dir.Location, Project);
3833 Project.Library_Dir := No_Path_Information;
3837 OK : Boolean := True;
3838 Dirs_Id : String_List_Id;
3839 Dir_Elem : String_Element;
3843 -- The library directory cannot be the same as a source
3844 -- directory of the current project.
3846 Dirs_Id := Project.Source_Dirs;
3847 while Dirs_Id /= Nil_String loop
3848 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
3849 Dirs_Id := Dir_Elem.Next;
3851 if Project.Library_Dir.Name =
3852 Path_Name_Type (Dir_Elem.Value)
3854 Err_Vars.Error_Msg_File_1 :=
3855 File_Name_Type (Dir_Elem.Value);
3858 "library directory cannot be the same " &
3859 "as source directory {",
3860 Lib_Dir.Location, Project);
3868 -- The library directory cannot be the same as a
3869 -- source directory of another project either.
3871 Pid := Data.Tree.Projects;
3873 exit Project_Loop when Pid = null;
3875 if Pid.Project /= Project then
3876 Dirs_Id := Pid.Project.Source_Dirs;
3878 Dir_Loop : while Dirs_Id /= Nil_String loop
3880 Shared.String_Elements.Table (Dirs_Id);
3881 Dirs_Id := Dir_Elem.Next;
3883 if Project.Library_Dir.Name =
3884 Path_Name_Type (Dir_Elem.Value)
3886 Err_Vars.Error_Msg_File_1 :=
3887 File_Name_Type (Dir_Elem.Value);
3888 Err_Vars.Error_Msg_Name_1 :=
3893 "library directory cannot be the same" &
3894 " as source directory { of project %%",
3895 Lib_Dir.Location, Project);
3903 end loop Project_Loop;
3907 Project.Library_Dir := No_Path_Information;
3909 elsif Current_Verbosity = High then
3911 -- Display the Library directory in high verbosity
3914 ("Library directory",
3915 Get_Name_String (Project.Library_Dir.Display_Name));
3925 Project.Library_Dir /= No_Path_Information
3926 and then Project.Library_Name /= No_Name;
3928 if Project.Extends = No_Project then
3929 case Project.Qualifier is
3931 if Project.Library then
3934 "a standard project cannot be a library project",
3935 Lib_Name.Location, Project);
3939 if not Project.Library then
3940 if Project.Library_Name = No_Name then
3943 "attribute Library_Name not declared",
3944 Project.Location, Project);
3946 if not Library_Directory_Present then
3949 "\attribute Library_Dir not declared",
3950 Project.Location, Project);
3953 elsif Project.Library_Dir = No_Path_Information then
3956 "attribute Library_Dir not declared",
3957 Project.Location, Project);
3967 if Project.Library then
3968 Support_For_Libraries := Project.Config.Lib_Support;
3970 if Support_For_Libraries = Prj.None then
3973 "?libraries are not supported on this platform",
3974 Lib_Name.Location, Project);
3975 Project.Library := False;
3978 if Lib_ALI_Dir.Value = Empty_String then
3979 Debug_Output ("no library ALI directory specified");
3980 Project.Library_ALI_Dir := Project.Library_Dir;
3983 -- Find path name, check that it is a directory
3987 File_Name_Type (Lib_ALI_Dir.Value),
3988 Path => Project.Library_ALI_Dir,
3989 Create => "library ALI",
3990 Dir_Exists => Dir_Exists,
3992 Must_Exist => False,
3993 Location => Lib_ALI_Dir.Location,
3994 Externally_Built => Project.Externally_Built);
3996 if not Dir_Exists then
3998 -- Get the absolute name of the library ALI directory that
3999 -- does not exist, to report an error.
4001 Err_Vars.Error_Msg_File_1 :=
4002 File_Name_Type (Project.Library_ALI_Dir.Display_Name);
4005 "library 'A'L'I directory { does not exist",
4006 Lib_ALI_Dir.Location, Project);
4009 if (not Project.Externally_Built) and then
4010 Project.Library_ALI_Dir /= Project.Library_Dir
4012 -- The library ALI directory cannot be the same as the
4013 -- Object directory.
4015 if Project.Library_ALI_Dir = Project.Object_Directory then
4018 "library 'A'L'I directory cannot be the same " &
4019 "as object directory",
4020 Lib_ALI_Dir.Location, Project);
4021 Project.Library_ALI_Dir := No_Path_Information;
4025 OK : Boolean := True;
4026 Dirs_Id : String_List_Id;
4027 Dir_Elem : String_Element;
4031 -- The library ALI directory cannot be the same as
4032 -- a source directory of the current project.
4034 Dirs_Id := Project.Source_Dirs;
4035 while Dirs_Id /= Nil_String loop
4036 Dir_Elem := Shared.String_Elements.Table (Dirs_Id);
4037 Dirs_Id := Dir_Elem.Next;
4039 if Project.Library_ALI_Dir.Name =
4040 Path_Name_Type (Dir_Elem.Value)
4042 Err_Vars.Error_Msg_File_1 :=
4043 File_Name_Type (Dir_Elem.Value);
4046 "library 'A'L'I directory cannot be " &
4047 "the same as source directory {",
4048 Lib_ALI_Dir.Location, Project);
4056 -- The library ALI directory cannot be the same as
4057 -- a source directory of another project either.
4059 Pid := Data.Tree.Projects;
4060 ALI_Project_Loop : loop
4061 exit ALI_Project_Loop when Pid = null;
4063 if Pid.Project /= Project then
4064 Dirs_Id := Pid.Project.Source_Dirs;
4067 while Dirs_Id /= Nil_String loop
4069 Shared.String_Elements.Table (Dirs_Id);
4070 Dirs_Id := Dir_Elem.Next;
4072 if Project.Library_ALI_Dir.Name =
4073 Path_Name_Type (Dir_Elem.Value)
4075 Err_Vars.Error_Msg_File_1 :=
4076 File_Name_Type (Dir_Elem.Value);
4077 Err_Vars.Error_Msg_Name_1 :=
4082 "library 'A'L'I directory cannot " &
4083 "be the same as source directory " &
4085 Lib_ALI_Dir.Location, Project);
4087 exit ALI_Project_Loop;
4089 end loop ALI_Dir_Loop;
4092 end loop ALI_Project_Loop;
4096 Project.Library_ALI_Dir := No_Path_Information;
4098 elsif Current_Verbosity = High then
4100 -- Display Library ALI directory in high verbosity
4105 (Project.Library_ALI_Dir.Display_Name));
4112 pragma Assert (Lib_Version.Kind = Single);
4114 if Lib_Version.Value = Empty_String then
4115 Debug_Output ("no library version specified");
4118 Project.Lib_Internal_Name := Lib_Version.Value;
4121 pragma Assert (The_Lib_Kind.Kind = Single);
4123 if The_Lib_Kind.Value = Empty_String then
4124 Debug_Output ("no library kind specified");
4127 Get_Name_String (The_Lib_Kind.Value);
4130 Kind_Name : constant String :=
4131 To_Lower (Name_Buffer (1 .. Name_Len));
4133 OK : Boolean := True;
4136 if Kind_Name = "static" then
4137 Project.Library_Kind := Static;
4139 elsif Kind_Name = "dynamic" then
4140 Project.Library_Kind := Dynamic;
4142 elsif Kind_Name = "relocatable" then
4143 Project.Library_Kind := Relocatable;
4148 "illegal value for Library_Kind",
4149 The_Lib_Kind.Location, Project);
4153 if Current_Verbosity = High and then OK then
4154 Write_Attr ("Library kind", Kind_Name);
4157 if Project.Library_Kind /= Static then
4158 if Support_For_Libraries = Prj.Static_Only then
4161 "only static libraries are supported " &
4163 The_Lib_Kind.Location, Project);
4164 Project.Library := False;
4167 -- Check if (obsolescent) attribute Library_GCC or
4168 -- Linker'Driver is declared.
4170 if Lib_GCC.Value /= Empty_String then
4173 "?Library_'G'C'C is an obsolescent attribute, " &
4174 "use Linker''Driver instead",
4175 Lib_GCC.Location, Project);
4176 Project.Config.Shared_Lib_Driver :=
4177 File_Name_Type (Lib_GCC.Value);
4181 Linker : constant Package_Id :=
4184 Project.Decl.Packages,
4186 Driver : constant Variable_Value :=
4189 Attribute_Or_Array_Name =>
4191 In_Package => Linker,
4195 if Driver /= Nil_Variable_Value
4196 and then Driver.Value /= Empty_String
4198 Project.Config.Shared_Lib_Driver :=
4199 File_Name_Type (Driver.Value);
4208 if Project.Library then
4209 Debug_Output ("this is a library project file");
4211 Check_Library (Project.Extends, Extends => True);
4213 Imported_Project_List := Project.Imported_Projects;
4214 while Imported_Project_List /= null loop
4216 (Imported_Project_List.Project,
4218 Imported_Project_List := Imported_Project_List.Next;
4225 -- Check if Linker'Switches or Linker'Default_Switches are declared.
4226 -- Warn if they are declared, as it is a common error to think that
4227 -- library are "linked" with Linker switches.
4229 if Project.Library then
4231 Linker_Package_Id : constant Package_Id :=
4234 Project.Decl.Packages, Shared);
4235 Linker_Package : Package_Element;
4236 Switches : Array_Element_Id := No_Array_Element;
4239 if Linker_Package_Id /= No_Package then
4240 Linker_Package := Shared.Packages.Table (Linker_Package_Id);
4244 (Name => Name_Switches,
4245 In_Arrays => Linker_Package.Decl.Arrays,
4248 if Switches = No_Array_Element then
4251 (Name => Name_Default_Switches,
4252 In_Arrays => Linker_Package.Decl.Arrays,
4256 if Switches /= No_Array_Element then
4259 "?Linker switches not taken into account in library " &
4261 No_Location, Project);
4267 if Project.Extends /= No_Project and then Project.Extends.Library then
4269 -- Remove the library name from Lib_Data_Table
4271 for J in 1 .. Lib_Data_Table.Last loop
4272 if Lib_Data_Table.Table (J).Proj = Project.Extends then
4273 Lib_Data_Table.Table (J) :=
4274 Lib_Data_Table.Table (Lib_Data_Table.Last);
4275 Lib_Data_Table.Set_Last (Lib_Data_Table.Last - 1);
4281 if Project.Library and then not Lib_Name.Default then
4283 -- Check if the same library name is used in an other library project
4285 for J in 1 .. Lib_Data_Table.Last loop
4286 if Lib_Data_Table.Table (J).Name = Project.Library_Name then
4287 Error_Msg_Name_1 := Lib_Data_Table.Table (J).Proj.Name;
4290 "Library name cannot be the same as in project %%",
4291 Lib_Name.Location, Project);
4292 Project.Library := False;
4298 if Project.Library then
4300 -- Record the library name
4302 Lib_Data_Table.Append
4303 ((Name => Project.Library_Name, Proj => Project));
4305 end Check_Library_Attributes;
4307 ---------------------------------
4308 -- Check_Programming_Languages --
4309 ---------------------------------
4311 procedure Check_Programming_Languages
4312 (Project : Project_Id;
4313 Data : in out Tree_Processing_Data)
4315 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4317 Languages : Variable_Value := Nil_Variable_Value;
4318 Def_Lang : Variable_Value := Nil_Variable_Value;
4319 Def_Lang_Id : Name_Id;
4321 procedure Add_Language (Name, Display_Name : Name_Id);
4322 -- Add a new language to the list of languages for the project.
4323 -- Nothing is done if the language has already been defined
4329 procedure Add_Language (Name, Display_Name : Name_Id) is
4330 Lang : Language_Ptr;
4333 Lang := Project.Languages;
4334 while Lang /= No_Language_Index loop
4335 if Name = Lang.Name then
4342 Lang := new Language_Data'(No_Language_Data);
4343 Lang.Next := Project.Languages;
4344 Project.Languages := Lang;
4346 Lang.Display_Name := Display_Name;
4348 if Name = Name_Ada then
4349 Lang.Config.Kind := Unit_Based;
4350 Lang.Config.Dependency_Kind := ALI_File;
4352 Lang.Config.Kind := File_Based;
4356 -- Start of processing for Check_Programming_Languages
4359 Project.Languages := null;
4361 Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, Shared);
4364 (Name_Default_Language, Project.Decl.Attributes, Shared);
4366 if Project.Source_Dirs /= Nil_String then
4368 -- Check if languages are specified in this project
4370 if Languages.Default then
4372 -- Fail if there is no default language defined
4374 if Def_Lang.Default then
4377 "no languages defined for this project",
4378 Project.Location, Project);
4379 Def_Lang_Id := No_Name;
4382 Get_Name_String (Def_Lang.Value);
4383 To_Lower (Name_Buffer (1 .. Name_Len));
4384 Def_Lang_Id := Name_Find;
4387 if Def_Lang_Id /= No_Name then
4388 Get_Name_String (Def_Lang_Id);
4389 Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
4391 (Name => Def_Lang_Id,
4392 Display_Name => Name_Find);
4397 Current : String_List_Id := Languages.Values;
4398 Element : String_Element;
4401 -- If there are no languages declared, there are no sources
4403 if Current = Nil_String then
4404 Project.Source_Dirs := Nil_String;
4406 if Project.Qualifier = Standard then
4409 "a standard project must have at least one language",
4410 Languages.Location, Project);
4414 -- Look through all the languages specified in attribute
4417 while Current /= Nil_String loop
4418 Element := Shared.String_Elements.Table (Current);
4419 Get_Name_String (Element.Value);
4420 To_Lower (Name_Buffer (1 .. Name_Len));
4424 Display_Name => Element.Value);
4426 Current := Element.Next;
4432 end Check_Programming_Languages;
4434 -------------------------------
4435 -- Check_Stand_Alone_Library --
4436 -------------------------------
4438 procedure Check_Stand_Alone_Library
4439 (Project : Project_Id;
4440 Data : in out Tree_Processing_Data)
4442 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
4444 Lib_Interfaces : constant Prj.Variable_Value :=
4446 (Snames.Name_Library_Interface,
4447 Project.Decl.Attributes,
4450 Lib_Auto_Init : constant Prj.Variable_Value :=
4452 (Snames.Name_Library_Auto_Init,
4453 Project.Decl.Attributes,
4456 Lib_Src_Dir : constant Prj.Variable_Value :=
4458 (Snames.Name_Library_Src_Dir,
4459 Project.Decl.Attributes,
4462 Lib_Symbol_File : constant Prj.Variable_Value :=
4464 (Snames.Name_Library_Symbol_File,
4465 Project.Decl.Attributes,
4468 Lib_Symbol_Policy : constant Prj.Variable_Value :=
4470 (Snames.Name_Library_Symbol_Policy,
4471 Project.Decl.Attributes,
4474 Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
4476 (Snames.Name_Library_Reference_Symbol_File,
4477 Project.Decl.Attributes,
4480 Auto_Init_Supported : Boolean;
4481 OK : Boolean := True;
4483 Next_Proj : Project_Id;
4484 Iter : Source_Iterator;
4487 Auto_Init_Supported := Project.Config.Auto_Init_Supported;
4489 pragma Assert (Lib_Interfaces.Kind = List);
4491 -- It is a stand-alone library project file if attribute
4492 -- Library_Interface is defined.
4494 if not Lib_Interfaces.Default then
4496 Interfaces : String_List_Id := Lib_Interfaces.Values;
4497 Interface_ALIs : String_List_Id := Nil_String;
4501 Project.Standalone_Library := True;
4503 -- Library_Interface cannot be an empty list
4505 if Interfaces = Nil_String then
4508 "Library_Interface cannot be an empty list",
4509 Lib_Interfaces.Location, Project);
4512 -- Process each unit name specified in the attribute
4513 -- Library_Interface.
4515 while Interfaces /= Nil_String loop
4517 (Shared.String_Elements.Table (Interfaces).Value);
4518 To_Lower (Name_Buffer (1 .. Name_Len));
4520 if Name_Len = 0 then
4523 "an interface cannot be an empty string",
4524 Shared.String_Elements.Table (Interfaces).Location,
4529 Error_Msg_Name_1 := Unit;
4531 Next_Proj := Project.Extends;
4532 Iter := For_Each_Source (Data.Tree, Project);
4534 while Prj.Element (Iter) /= No_Source
4536 (Prj.Element (Iter).Unit = null
4537 or else Prj.Element (Iter).Unit.Name /= Unit)
4542 Source := Prj.Element (Iter);
4543 exit when Source /= No_Source
4544 or else Next_Proj = No_Project;
4546 Iter := For_Each_Source (Data.Tree, Next_Proj);
4547 Next_Proj := Next_Proj.Extends;
4550 if Source /= No_Source then
4551 if Source.Kind = Sep then
4552 Source := No_Source;
4554 elsif Source.Kind = Spec
4555 and then Other_Part (Source) /= No_Source
4557 Source := Other_Part (Source);
4561 if Source /= No_Source then
4562 if Source.Project /= Project
4563 and then not Is_Extending (Project, Source.Project)
4565 Source := No_Source;
4569 if Source = No_Source then
4572 "%% is not a unit of this project",
4573 Shared.String_Elements.Table (Interfaces).Location,
4577 if Source.Kind = Spec
4578 and then Other_Part (Source) /= No_Source
4580 Source := Other_Part (Source);
4583 String_Element_Table.Increment_Last
4584 (Shared.String_Elements);
4586 Shared.String_Elements.Table
4587 (String_Element_Table.Last (Shared.String_Elements)) :=
4588 (Value => Name_Id (Source.Dep_Name),
4590 Display_Value => Name_Id (Source.Dep_Name),
4592 Shared.String_Elements.Table (Interfaces).Location,
4594 Next => Interface_ALIs);
4597 String_Element_Table.Last (Shared.String_Elements);
4601 Interfaces := Shared.String_Elements.Table (Interfaces).Next;
4604 -- Put the list of Interface ALIs in the project data
4606 Project.Lib_Interface_ALIs := Interface_ALIs;
4608 -- Check value of attribute Library_Auto_Init and set
4609 -- Lib_Auto_Init accordingly.
4611 if Lib_Auto_Init.Default then
4613 -- If no attribute Library_Auto_Init is declared, then set auto
4614 -- init only if it is supported.
4616 Project.Lib_Auto_Init := Auto_Init_Supported;
4619 Get_Name_String (Lib_Auto_Init.Value);
4620 To_Lower (Name_Buffer (1 .. Name_Len));
4622 if Name_Buffer (1 .. Name_Len) = "false" then
4623 Project.Lib_Auto_Init := False;
4625 elsif Name_Buffer (1 .. Name_Len) = "true" then
4626 if Auto_Init_Supported then
4627 Project.Lib_Auto_Init := True;
4630 -- Library_Auto_Init cannot be "true" if auto init is not
4635 "library auto init not supported " &
4637 Lib_Auto_Init.Location, Project);
4643 "invalid value for attribute Library_Auto_Init",
4644 Lib_Auto_Init.Location, Project);
4649 -- If attribute Library_Src_Dir is defined and not the empty string,
4650 -- check if the directory exist and is not the object directory or
4651 -- one of the source directories. This is the directory where copies
4652 -- of the interface sources will be copied. Note that this directory
4653 -- may be the library directory.
4655 if Lib_Src_Dir.Value /= Empty_String then
4657 Dir_Id : constant File_Name_Type :=
4658 File_Name_Type (Lib_Src_Dir.Value);
4659 Dir_Exists : Boolean;
4665 Path => Project.Library_Src_Dir,
4666 Dir_Exists => Dir_Exists,
4668 Must_Exist => False,
4669 Create => "library source copy",
4670 Location => Lib_Src_Dir.Location,
4671 Externally_Built => Project.Externally_Built);
4673 -- If directory does not exist, report an error
4675 if not Dir_Exists then
4677 -- Get the absolute name of the library directory that does
4678 -- not exist, to report an error.
4680 Err_Vars.Error_Msg_File_1 :=
4681 File_Name_Type (Project.Library_Src_Dir.Display_Name);
4684 "Directory { does not exist",
4685 Lib_Src_Dir.Location, Project);
4687 -- Report error if it is the same as the object directory
4689 elsif Project.Library_Src_Dir = Project.Object_Directory then
4692 "directory to copy interfaces cannot be " &
4693 "the object directory",
4694 Lib_Src_Dir.Location, Project);
4695 Project.Library_Src_Dir := No_Path_Information;
4699 Src_Dirs : String_List_Id;
4700 Src_Dir : String_Element;
4704 -- Interface copy directory cannot be one of the source
4705 -- directory of the current project.
4707 Src_Dirs := Project.Source_Dirs;
4708 while Src_Dirs /= Nil_String loop
4709 Src_Dir := Shared.String_Elements.Table (Src_Dirs);
4711 -- Report error if it is one of the source directories
4713 if Project.Library_Src_Dir.Name =
4714 Path_Name_Type (Src_Dir.Value)
4718 "directory to copy interfaces cannot " &
4719 "be one of the source directories",
4720 Lib_Src_Dir.Location, Project);
4721 Project.Library_Src_Dir := No_Path_Information;
4725 Src_Dirs := Src_Dir.Next;
4728 if Project.Library_Src_Dir /= No_Path_Information then
4730 -- It cannot be a source directory of any other
4733 Pid := Data.Tree.Projects;
4735 exit Project_Loop when Pid = null;
4737 Src_Dirs := Pid.Project.Source_Dirs;
4738 Dir_Loop : while Src_Dirs /= Nil_String loop
4740 Shared.String_Elements.Table (Src_Dirs);
4742 -- Report error if it is one of the source
4745 if Project.Library_Src_Dir.Name =
4746 Path_Name_Type (Src_Dir.Value)
4749 File_Name_Type (Src_Dir.Value);
4750 Error_Msg_Name_1 := Pid.Project.Name;
4753 "directory to copy interfaces cannot " &
4754 "be the same as source directory { of " &
4756 Lib_Src_Dir.Location, Project);
4757 Project.Library_Src_Dir :=
4758 No_Path_Information;
4762 Src_Dirs := Src_Dir.Next;
4766 end loop Project_Loop;
4770 -- In high verbosity, if there is a valid Library_Src_Dir,
4771 -- display its path name.
4773 if Project.Library_Src_Dir /= No_Path_Information
4774 and then Current_Verbosity = High
4777 ("Directory to copy interfaces",
4778 Get_Name_String (Project.Library_Src_Dir.Name));
4784 -- Check the symbol related attributes
4786 -- First, the symbol policy
4788 if not Lib_Symbol_Policy.Default then
4790 Value : constant String :=
4792 (Get_Name_String (Lib_Symbol_Policy.Value));
4795 -- Symbol policy must hove one of a limited number of values
4797 if Value = "autonomous" or else Value = "default" then
4798 Project.Symbol_Data.Symbol_Policy := Autonomous;
4800 elsif Value = "compliant" then
4801 Project.Symbol_Data.Symbol_Policy := Compliant;
4803 elsif Value = "controlled" then
4804 Project.Symbol_Data.Symbol_Policy := Controlled;
4806 elsif Value = "restricted" then
4807 Project.Symbol_Data.Symbol_Policy := Restricted;
4809 elsif Value = "direct" then
4810 Project.Symbol_Data.Symbol_Policy := Direct;
4815 "illegal value for Library_Symbol_Policy",
4816 Lib_Symbol_Policy.Location, Project);
4821 -- If attribute Library_Symbol_File is not specified, symbol policy
4822 -- cannot be Restricted.
4824 if Lib_Symbol_File.Default then
4825 if Project.Symbol_Data.Symbol_Policy = Restricted then
4828 "Library_Symbol_File needs to be defined when " &
4829 "symbol policy is Restricted",
4830 Lib_Symbol_Policy.Location, Project);
4834 -- Library_Symbol_File is defined
4836 Project.Symbol_Data.Symbol_File :=
4837 Path_Name_Type (Lib_Symbol_File.Value);
4839 Get_Name_String (Lib_Symbol_File.Value);
4841 if Name_Len = 0 then
4844 "symbol file name cannot be an empty string",
4845 Lib_Symbol_File.Location, Project);
4848 OK := not Is_Absolute_Path (Name_Buffer (1 .. Name_Len));
4851 for J in 1 .. Name_Len loop
4852 if Name_Buffer (J) = '/'
4853 or else Name_Buffer (J) = Directory_Separator
4862 Error_Msg_File_1 := File_Name_Type (Lib_Symbol_File.Value);
4865 "symbol file name { is illegal. " &
4866 "Name cannot include directory info.",
4867 Lib_Symbol_File.Location, Project);
4872 -- If attribute Library_Reference_Symbol_File is not defined,
4873 -- symbol policy cannot be Compliant or Controlled.
4875 if Lib_Ref_Symbol_File.Default then
4876 if Project.Symbol_Data.Symbol_Policy = Compliant
4877 or else Project.Symbol_Data.Symbol_Policy = Controlled
4881 "a reference symbol file needs to be defined",
4882 Lib_Symbol_Policy.Location, Project);
4886 -- Library_Reference_Symbol_File is defined, check file exists
4888 Project.Symbol_Data.Reference :=
4889 Path_Name_Type (Lib_Ref_Symbol_File.Value);
4891 Get_Name_String (Lib_Ref_Symbol_File.Value);
4893 if Name_Len = 0 then
4896 "reference symbol file name cannot be an empty string",
4897 Lib_Symbol_File.Location, Project);
4900 if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
4902 Add_Str_To_Name_Buffer
4903 (Get_Name_String (Project.Directory.Name));
4904 Add_Str_To_Name_Buffer
4905 (Get_Name_String (Lib_Ref_Symbol_File.Value));
4906 Project.Symbol_Data.Reference := Name_Find;
4909 if not Is_Regular_File
4910 (Get_Name_String (Project.Symbol_Data.Reference))
4913 File_Name_Type (Lib_Ref_Symbol_File.Value);
4915 -- For controlled and direct symbol policies, it is an error
4916 -- if the reference symbol file does not exist. For other
4917 -- symbol policies, this is just a warning
4920 Project.Symbol_Data.Symbol_Policy /= Controlled
4921 and then Project.Symbol_Data.Symbol_Policy /= Direct;
4925 "<library reference symbol file { does not exist",
4926 Lib_Ref_Symbol_File.Location, Project);
4928 -- In addition in the non-controlled case, if symbol policy
4929 -- is Compliant, it is changed to Autonomous, because there
4930 -- is no reference to check against, and we don't want to
4931 -- fail in this case.
4933 if Project.Symbol_Data.Symbol_Policy /= Controlled then
4934 if Project.Symbol_Data.Symbol_Policy = Compliant then
4935 Project.Symbol_Data.Symbol_Policy := Autonomous;
4940 -- If both the reference symbol file and the symbol file are
4941 -- defined, then check that they are not the same file.
4943 if Project.Symbol_Data.Symbol_File /= No_Path then
4944 Get_Name_String (Project.Symbol_Data.Symbol_File);
4946 if Name_Len > 0 then
4948 -- We do not need to pass a Directory to
4949 -- Normalize_Pathname, since the path_information
4950 -- already contains absolute information.
4952 Symb_Path : constant String :=
4955 (Project.Object_Directory.Name) &
4956 Name_Buffer (1 .. Name_Len),
4959 Opt.Follow_Links_For_Files);
4960 Ref_Path : constant String :=
4963 (Project.Symbol_Data.Reference),
4966 Opt.Follow_Links_For_Files);
4968 if Symb_Path = Ref_Path then
4971 "library reference symbol file and library" &
4972 " symbol file cannot be the same file",
4973 Lib_Ref_Symbol_File.Location, Project);
4981 end Check_Stand_Alone_Library;
4983 ----------------------------
4984 -- Compute_Directory_Last --
4985 ----------------------------
4987 function Compute_Directory_Last (Dir : String) return Natural is
4990 and then (Dir (Dir'Last - 1) = Directory_Separator
4992 Dir (Dir'Last - 1) = '/')
4994 return Dir'Last - 1;
4998 end Compute_Directory_Last;
5000 ---------------------
5001 -- Get_Directories --
5002 ---------------------
5004 procedure Get_Directories
5005 (Project : Project_Id;
5006 Data : in out Tree_Processing_Data)
5008 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5010 Object_Dir : constant Variable_Value :=
5012 (Name_Object_Dir, Project.Decl.Attributes, Shared);
5014 Exec_Dir : constant Variable_Value :=
5016 (Name_Exec_Dir, Project.Decl.Attributes, Shared);
5018 Source_Dirs : constant Variable_Value :=
5020 (Name_Source_Dirs, Project.Decl.Attributes, Shared);
5022 Ignore_Source_Sub_Dirs : constant Variable_Value :=
5024 (Name_Ignore_Source_Sub_Dirs,
5025 Project.Decl.Attributes,
5028 Excluded_Source_Dirs : constant Variable_Value :=
5030 (Name_Excluded_Source_Dirs,
5031 Project.Decl.Attributes,
5034 Source_Files : constant Variable_Value :=
5037 Project.Decl.Attributes, Shared);
5039 Last_Source_Dir : String_List_Id := Nil_String;
5040 Last_Src_Dir_Rank : Number_List_Index := No_Number_List;
5042 Languages : constant Variable_Value :=
5044 (Name_Languages, Project.Decl.Attributes, Shared);
5046 Remove_Source_Dirs : Boolean := False;
5048 procedure Add_To_Or_Remove_From_Source_Dirs
5049 (Path : Path_Information;
5051 -- When Removed = False, the directory Path_Id to the list of
5052 -- source_dirs if not already in the list. When Removed = True,
5053 -- removed directory Path_Id if in the list.
5055 procedure Find_Source_Dirs is new Expand_Subdirectory_Pattern
5056 (Add_To_Or_Remove_From_Source_Dirs);
5058 ---------------------------------------
5059 -- Add_To_Or_Remove_From_Source_Dirs --
5060 ---------------------------------------
5062 procedure Add_To_Or_Remove_From_Source_Dirs
5063 (Path : Path_Information;
5066 List : String_List_Id;
5067 Prev : String_List_Id;
5068 Rank_List : Number_List_Index;
5069 Prev_Rank : Number_List_Index;
5070 Element : String_Element;
5074 Prev_Rank := No_Number_List;
5075 List := Project.Source_Dirs;
5076 Rank_List := Project.Source_Dir_Ranks;
5077 while List /= Nil_String loop
5078 Element := Shared.String_Elements.Table (List);
5079 exit when Element.Value = Name_Id (Path.Name);
5081 List := Element.Next;
5082 Prev_Rank := Rank_List;
5083 Rank_List := Shared.Number_Lists.Table (Prev_Rank).Next;
5086 -- The directory is in the list if List is not Nil_String
5088 if not Remove_Source_Dirs and then List = Nil_String then
5089 Debug_Output ("adding source dir=", Name_Id (Path.Display_Name));
5091 String_Element_Table.Increment_Last (Shared.String_Elements);
5093 (Value => Name_Id (Path.Name),
5095 Display_Value => Name_Id (Path.Display_Name),
5096 Location => No_Location,
5098 Next => Nil_String);
5100 Number_List_Table.Increment_Last (Shared.Number_Lists);
5102 if Last_Source_Dir = Nil_String then
5104 -- This is the first source directory
5106 Project.Source_Dirs :=
5107 String_Element_Table.Last (Shared.String_Elements);
5108 Project.Source_Dir_Ranks :=
5109 Number_List_Table.Last (Shared.Number_Lists);
5112 -- We already have source directories, link the previous
5113 -- last to the new one.
5115 Shared.String_Elements.Table (Last_Source_Dir).Next :=
5116 String_Element_Table.Last (Shared.String_Elements);
5117 Shared.Number_Lists.Table (Last_Src_Dir_Rank).Next :=
5118 Number_List_Table.Last (Shared.Number_Lists);
5121 -- And register this source directory as the new last
5124 String_Element_Table.Last (Shared.String_Elements);
5125 Shared.String_Elements.Table (Last_Source_Dir) := Element;
5126 Last_Src_Dir_Rank := Number_List_Table.Last (Shared.Number_Lists);
5127 Shared.Number_Lists.Table (Last_Src_Dir_Rank) :=
5128 (Number => Rank, Next => No_Number_List);
5130 elsif Remove_Source_Dirs and then List /= Nil_String then
5132 -- Remove source dir if present
5134 if Prev = Nil_String then
5135 Project.Source_Dirs := Shared.String_Elements.Table (List).Next;
5136 Project.Source_Dir_Ranks :=
5137 Shared.Number_Lists.Table (Rank_List).Next;
5140 Shared.String_Elements.Table (Prev).Next :=
5141 Shared.String_Elements.Table (List).Next;
5142 Shared.Number_Lists.Table (Prev_Rank).Next :=
5143 Shared.Number_Lists.Table (Rank_List).Next;
5146 end Add_To_Or_Remove_From_Source_Dirs;
5148 -- Local declarations
5150 Dir_Exists : Boolean;
5152 No_Sources : constant Boolean :=
5153 ((not Source_Files.Default
5154 and then Source_Files.Values = Nil_String)
5156 (not Source_Dirs.Default
5157 and then Source_Dirs.Values = Nil_String)
5159 (not Languages.Default
5160 and then Languages.Values = Nil_String))
5161 and then Project.Extends = No_Project;
5163 -- Start of processing for Get_Directories
5166 Debug_Output ("starting to look for directories");
5168 -- Set the object directory to its default which may be nil, if there
5169 -- is no sources in the project.
5172 Project.Object_Directory := No_Path_Information;
5174 Project.Object_Directory := Project.Directory;
5177 -- Check the object directory
5179 if Object_Dir.Value /= Empty_String then
5180 Get_Name_String (Object_Dir.Value);
5182 if Name_Len = 0 then
5185 "Object_Dir cannot be empty",
5186 Object_Dir.Location, Project);
5188 elsif not No_Sources then
5190 -- We check that the specified object directory does exist.
5191 -- However, even when it doesn't exist, we set it to a default
5192 -- value. This is for the benefit of tools that recover from
5193 -- errors; for example, these tools could create the non existent
5194 -- directory. We always return an absolute directory name though.
5198 File_Name_Type (Object_Dir.Value),
5199 Path => Project.Object_Directory,
5201 Dir_Exists => Dir_Exists,
5203 Location => Object_Dir.Location,
5204 Must_Exist => False,
5205 Externally_Built => Project.Externally_Built);
5208 and then not Project.Externally_Built
5210 -- The object directory does not exist, report an error if the
5211 -- project is not externally built.
5213 Err_Vars.Error_Msg_File_1 :=
5214 File_Name_Type (Object_Dir.Value);
5216 (Data.Flags, Data.Flags.Require_Obj_Dirs,
5217 "object directory { not found", Project.Location, Project);
5221 elsif not No_Sources and then Subdirs /= null then
5223 Name_Buffer (1) := '.';
5227 Path => Project.Object_Directory,
5229 Dir_Exists => Dir_Exists,
5231 Location => Object_Dir.Location,
5232 Externally_Built => Project.Externally_Built);
5235 if Current_Verbosity = High then
5236 if Project.Object_Directory = No_Path_Information then
5237 Debug_Output ("no object directory");
5240 ("Object directory",
5241 Get_Name_String (Project.Object_Directory.Display_Name));
5245 -- Check the exec directory
5247 -- We set the object directory to its default
5249 Project.Exec_Directory := Project.Object_Directory;
5251 if Exec_Dir.Value /= Empty_String then
5252 Get_Name_String (Exec_Dir.Value);
5254 if Name_Len = 0 then
5257 "Exec_Dir cannot be empty",
5258 Exec_Dir.Location, Project);
5260 elsif not No_Sources then
5262 -- We check that the specified exec directory does exist
5266 File_Name_Type (Exec_Dir.Value),
5267 Path => Project.Exec_Directory,
5268 Dir_Exists => Dir_Exists,
5271 Location => Exec_Dir.Location,
5272 Externally_Built => Project.Externally_Built);
5274 if not Dir_Exists then
5275 Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
5277 (Data.Flags, Data.Flags.Missing_Source_Files,
5278 "exec directory { not found", Project.Location, Project);
5283 if Current_Verbosity = High then
5284 if Project.Exec_Directory = No_Path_Information then
5285 Debug_Output ("no exec directory");
5288 ("exec directory: ",
5289 Name_Id (Project.Exec_Directory.Display_Name));
5293 -- Look for the source directories
5295 Debug_Output ("starting to look for source directories");
5297 pragma Assert (Source_Dirs.Kind = List, "Source_Dirs is not a list");
5299 if not Source_Files.Default
5300 and then Source_Files.Values = Nil_String
5302 Project.Source_Dirs := Nil_String;
5304 if Project.Qualifier = Standard then
5307 "a standard project cannot have no sources",
5308 Source_Files.Location, Project);
5311 elsif Source_Dirs.Default then
5313 -- No Source_Dirs specified: the single source directory is the one
5314 -- containing the project file.
5316 Remove_Source_Dirs := False;
5317 Add_To_Or_Remove_From_Source_Dirs
5318 (Path => (Name => Project.Directory.Name,
5319 Display_Name => Project.Directory.Display_Name),
5323 Remove_Source_Dirs := False;
5325 (Project => Project,
5327 Patterns => Source_Dirs.Values,
5328 Ignore => Ignore_Source_Sub_Dirs.Values,
5329 Search_For => Search_Directories,
5330 Resolve_Links => Opt.Follow_Links_For_Dirs);
5332 if Project.Source_Dirs = Nil_String
5333 and then Project.Qualifier = Standard
5337 "a standard project cannot have no source directories",
5338 Source_Dirs.Location, Project);
5342 if not Excluded_Source_Dirs.Default
5343 and then Excluded_Source_Dirs.Values /= Nil_String
5345 Remove_Source_Dirs := True;
5347 (Project => Project,
5349 Patterns => Excluded_Source_Dirs.Values,
5350 Ignore => Nil_String,
5351 Search_For => Search_Directories,
5352 Resolve_Links => Opt.Follow_Links_For_Dirs);
5355 Debug_Output ("putting source directories in canonical cases");
5358 Current : String_List_Id := Project.Source_Dirs;
5359 Element : String_Element;
5362 while Current /= Nil_String loop
5363 Element := Shared.String_Elements.Table (Current);
5364 if Element.Value /= No_Name then
5366 Name_Id (Canonical_Case_File_Name (Element.Value));
5367 Shared.String_Elements.Table (Current) := Element;
5370 Current := Element.Next;
5373 end Get_Directories;
5380 (Project : Project_Id;
5381 Data : in out Tree_Processing_Data)
5383 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5385 Mains : constant Variable_Value :=
5387 (Name_Main, Project.Decl.Attributes, Shared);
5388 List : String_List_Id;
5389 Elem : String_Element;
5392 Project.Mains := Mains.Values;
5394 -- If no Mains were specified, and if we are an extending project,
5395 -- inherit the Mains from the project we are extending.
5397 if Mains.Default then
5398 if not Project.Library and then Project.Extends /= No_Project then
5399 Project.Mains := Project.Extends.Mains;
5402 -- In a library project file, Main cannot be specified
5404 elsif Project.Library then
5407 "a library project file cannot have Main specified",
5408 Mains.Location, Project);
5411 List := Mains.Values;
5412 while List /= Nil_String loop
5413 Elem := Shared.String_Elements.Table (List);
5415 if Length_Of_Name (Elem.Value) = 0 then
5418 "?a main cannot have an empty name",
5419 Elem.Location, Project);
5428 ---------------------------
5429 -- Get_Sources_From_File --
5430 ---------------------------
5432 procedure Get_Sources_From_File
5434 Location : Source_Ptr;
5435 Project : in out Project_Processing_Data;
5436 Data : in out Tree_Processing_Data)
5438 File : Prj.Util.Text_File;
5439 Line : String (1 .. 250);
5441 Source_Name : File_Name_Type;
5442 Name_Loc : Name_Location;
5445 if Current_Verbosity = High then
5446 Debug_Output ("opening """ & Path & '"');
5451 Prj.Util.Open (File, Path);
5453 if not Prj.Util.Is_Valid (File) then
5455 (Data.Flags, "file does not exist", Location, Project.Project);
5458 -- Read the lines one by one
5460 while not Prj.Util.End_Of_File (File) loop
5461 Prj.Util.Get_Line (File, Line, Last);
5463 -- A non empty, non comment line should contain a file name
5466 and then (Last = 1 or else Line (1 .. 2) /= "--")
5469 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
5470 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
5471 Source_Name := Name_Find;
5473 -- Check that there is no directory information
5475 for J in 1 .. Last loop
5476 if Line (J) = '/' or else Line (J) = Directory_Separator then
5477 Error_Msg_File_1 := Source_Name;
5480 "file name cannot include directory information ({)",
5481 Location, Project.Project);
5486 Name_Loc := Source_Names_Htable.Get
5487 (Project.Source_Names, Source_Name);
5489 if Name_Loc = No_Name_Location then
5491 (Name => Source_Name,
5492 Location => Location,
5493 Source => No_Source,
5498 Name_Loc.Listed := True;
5501 Source_Names_Htable.Set
5502 (Project.Source_Names, Source_Name, Name_Loc);
5506 Prj.Util.Close (File);
5509 end Get_Sources_From_File;
5515 function No_Space_Img (N : Natural) return String is
5516 Image : constant String := N'Img;
5518 return Image (2 .. Image'Last);
5521 -----------------------
5522 -- Compute_Unit_Name --
5523 -----------------------
5525 procedure Compute_Unit_Name
5526 (File_Name : File_Name_Type;
5527 Naming : Lang_Naming_Data;
5528 Kind : out Source_Kind;
5530 Project : Project_Processing_Data;
5531 In_Tree : Project_Tree_Ref)
5533 Filename : constant String := Get_Name_String (File_Name);
5534 Last : Integer := Filename'Last;
5539 Unit_Except : Unit_Exception;
5540 Masked : Boolean := False;
5546 if Naming.Separate_Suffix = No_File
5547 or else Naming.Body_Suffix = No_File
5548 or else Naming.Spec_Suffix = No_File
5553 if Naming.Dot_Replacement = No_File then
5554 Debug_Output ("no dot_replacement specified");
5558 Sep_Len := Integer (Length_Of_Name (Naming.Separate_Suffix));
5559 Spec_Len := Integer (Length_Of_Name (Naming.Spec_Suffix));
5560 Body_Len := Integer (Length_Of_Name (Naming.Body_Suffix));
5562 -- Choose the longest suffix that matches. If there are several matches,
5563 -- give priority to specs, then bodies, then separates.
5565 if Naming.Separate_Suffix /= Naming.Body_Suffix
5566 and then Suffix_Matches (Filename, Naming.Separate_Suffix)
5568 Last := Filename'Last - Sep_Len;
5572 if Filename'Last - Body_Len <= Last
5573 and then Suffix_Matches (Filename, Naming.Body_Suffix)
5575 Last := Natural'Min (Last, Filename'Last - Body_Len);
5579 if Filename'Last - Spec_Len <= Last
5580 and then Suffix_Matches (Filename, Naming.Spec_Suffix)
5582 Last := Natural'Min (Last, Filename'Last - Spec_Len);
5586 if Last = Filename'Last then
5587 Debug_Output ("no matching suffix");
5591 -- Check that the casing matches
5593 if File_Names_Case_Sensitive then
5594 case Naming.Casing is
5595 when All_Lower_Case =>
5596 for J in Filename'First .. Last loop
5597 if Is_Letter (Filename (J))
5598 and then not Is_Lower (Filename (J))
5600 Debug_Output ("invalid casing");
5605 when All_Upper_Case =>
5606 for J in Filename'First .. Last loop
5607 if Is_Letter (Filename (J))
5608 and then not Is_Upper (Filename (J))
5610 Debug_Output ("invalid casing");
5615 when Mixed_Case | Unknown =>
5620 -- If Dot_Replacement is not a single dot, then there should not
5621 -- be any dot in the name.
5624 Dot_Repl : constant String :=
5625 Get_Name_String (Naming.Dot_Replacement);
5628 if Dot_Repl /= "." then
5629 for Index in Filename'First .. Last loop
5630 if Filename (Index) = '.' then
5631 Debug_Output ("invalid name, contains dot");
5636 Replace_Into_Name_Buffer
5637 (Filename (Filename'First .. Last), Dot_Repl, '.');
5640 Name_Len := Last - Filename'First + 1;
5641 Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
5643 (Source => Name_Buffer (1 .. Name_Len),
5644 Mapping => Lower_Case_Map);
5648 -- In the standard GNAT naming scheme, check for special cases: children
5649 -- or separates of A, G, I or S, and run time sources.
5651 if Is_Standard_GNAT_Naming (Naming)
5652 and then Name_Len >= 3
5655 S1 : constant Character := Name_Buffer (1);
5656 S2 : constant Character := Name_Buffer (2);
5657 S3 : constant Character := Name_Buffer (3);
5665 -- Children or separates of packages A, G, I or S. These names
5666 -- are x__ ... or x~... (where x is a, g, i, or s). Both
5667 -- versions (x__... and x~...) are allowed in all platforms,
5668 -- because it is not possible to know the platform before
5669 -- processing of the project files.
5671 if S2 = '_' and then S3 = '_' then
5672 Name_Buffer (2) := '.';
5673 Name_Buffer (3 .. Name_Len - 1) :=
5674 Name_Buffer (4 .. Name_Len);
5675 Name_Len := Name_Len - 1;
5678 Name_Buffer (2) := '.';
5682 -- If it is potentially a run time source
5690 -- Name_Buffer contains the name of the unit in lower-cases. Check
5691 -- that this is a valid unit name
5693 Check_Ada_Name (Name_Buffer (1 .. Name_Len), Unit);
5695 -- If there is a naming exception for the same unit, the file is not
5696 -- a source for the unit.
5698 if Unit /= No_Name then
5700 Unit_Exceptions_Htable.Get (Project.Unit_Exceptions, Unit);
5703 Masked := Unit_Except.Spec /= No_File
5705 Unit_Except.Spec /= File_Name;
5707 Masked := Unit_Except.Impl /= No_File
5709 Unit_Except.Impl /= File_Name;
5713 if Current_Verbosity = High then
5715 Write_Str (" """ & Filename & """ contains the ");
5718 Write_Str ("spec of a unit found in """);
5719 Write_Str (Get_Name_String (Unit_Except.Spec));
5721 Write_Str ("body of a unit found in """);
5722 Write_Str (Get_Name_String (Unit_Except.Impl));
5725 Write_Line (""" (ignored)");
5733 and then Current_Verbosity = High
5736 when Spec => Debug_Output ("spec of", Unit);
5737 when Impl => Debug_Output ("body of", Unit);
5738 when Sep => Debug_Output ("sep of", Unit);
5741 end Compute_Unit_Name;
5743 --------------------------
5744 -- Check_Illegal_Suffix --
5745 --------------------------
5747 procedure Check_Illegal_Suffix
5748 (Project : Project_Id;
5749 Suffix : File_Name_Type;
5750 Dot_Replacement : File_Name_Type;
5751 Attribute_Name : String;
5752 Location : Source_Ptr;
5753 Data : in out Tree_Processing_Data)
5755 Suffix_Str : constant String := Get_Name_String (Suffix);
5758 if Suffix_Str'Length = 0 then
5764 elsif Index (Suffix_Str, ".") = 0 then
5765 Err_Vars.Error_Msg_File_1 := Suffix;
5768 "{ is illegal for " & Attribute_Name & ": must have a dot",
5773 -- Case of dot replacement is a single dot, and first character of
5774 -- suffix is also a dot.
5776 if Dot_Replacement /= No_File
5777 and then Get_Name_String (Dot_Replacement) = "."
5778 and then Suffix_Str (Suffix_Str'First) = '.'
5780 for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
5782 -- If there are multiple dots in the name
5784 if Suffix_Str (Index) = '.' then
5786 -- It is illegal to have a letter following the initial dot
5788 if Is_Letter (Suffix_Str (Suffix_Str'First + 1)) then
5789 Err_Vars.Error_Msg_File_1 := Suffix;
5792 "{ is illegal for " & Attribute_Name
5793 & ": ambiguous prefix when Dot_Replacement is a dot",
5800 end Check_Illegal_Suffix;
5802 ----------------------
5803 -- Locate_Directory --
5804 ----------------------
5806 procedure Locate_Directory
5807 (Project : Project_Id;
5808 Name : File_Name_Type;
5809 Path : out Path_Information;
5810 Dir_Exists : out Boolean;
5811 Data : in out Tree_Processing_Data;
5812 Create : String := "";
5813 Location : Source_Ptr := No_Location;
5814 Must_Exist : Boolean := True;
5815 Externally_Built : Boolean := False)
5817 Parent : constant Path_Name_Type :=
5818 Project.Directory.Display_Name;
5819 The_Parent : constant String :=
5820 Get_Name_String (Parent);
5821 The_Parent_Last : constant Natural :=
5822 Compute_Directory_Last (The_Parent);
5823 Full_Name : File_Name_Type;
5824 The_Name : File_Name_Type;
5827 Get_Name_String (Name);
5829 -- Add Subdirs.all if it is a directory that may be created and
5830 -- Subdirs is not null;
5832 if Create /= "" and then Subdirs /= null then
5833 if Name_Buffer (Name_Len) /= Directory_Separator then
5834 Add_Char_To_Name_Buffer (Directory_Separator);
5837 Add_Str_To_Name_Buffer (Subdirs.all);
5840 -- Convert '/' to directory separator (for Windows)
5842 for J in 1 .. Name_Len loop
5843 if Name_Buffer (J) = '/' then
5844 Name_Buffer (J) := Directory_Separator;
5848 The_Name := Name_Find;
5850 if Current_Verbosity = High then
5852 Write_Str ("Locate_Directory (""");
5853 Write_Str (Get_Name_String (The_Name));
5854 Write_Str (""", in """);
5855 Write_Str (The_Parent);
5859 Path := No_Path_Information;
5860 Dir_Exists := False;
5862 if Is_Absolute_Path (Get_Name_String (The_Name)) then
5863 Full_Name := The_Name;
5867 Add_Str_To_Name_Buffer
5868 (The_Parent (The_Parent'First .. The_Parent_Last));
5869 Add_Str_To_Name_Buffer (Get_Name_String (The_Name));
5870 Full_Name := Name_Find;
5874 Full_Path_Name : String_Access :=
5875 new String'(Get_Name_String (Full_Name));
5878 if (Setup_Projects or else Subdirs /= null)
5879 and then Create'Length > 0
5881 if not Is_Directory (Full_Path_Name.all) then
5883 -- If project is externally built, do not create a subdir,
5884 -- use the specified directory, without the subdir.
5886 if Externally_Built then
5887 if Is_Absolute_Path (Get_Name_String (Name)) then
5888 Get_Name_String (Name);
5892 Add_Str_To_Name_Buffer
5893 (The_Parent (The_Parent'First .. The_Parent_Last));
5894 Add_Str_To_Name_Buffer (Get_Name_String (Name));
5897 Full_Path_Name := new String'(Name_Buffer (1 .. Name_Len));
5901 Create_Path (Full_Path_Name.all);
5903 if not Quiet_Output then
5905 Write_Str (" directory """);
5906 Write_Str (Full_Path_Name.all);
5907 Write_Str (""" created for project ");
5908 Write_Line (Get_Name_String (Project.Name));
5915 "could not create " & Create &
5916 " directory " & Full_Path_Name.all,
5923 Dir_Exists := Is_Directory (Full_Path_Name.all);
5925 if not Must_Exist or else Dir_Exists then
5927 Normed : constant String :=
5929 (Full_Path_Name.all,
5931 The_Parent (The_Parent'First .. The_Parent_Last),
5932 Resolve_Links => False,
5933 Case_Sensitive => True);
5935 Canonical_Path : constant String :=
5940 (The_Parent'First .. The_Parent_Last),
5942 Opt.Follow_Links_For_Dirs,
5943 Case_Sensitive => False);
5946 Name_Len := Normed'Length;
5947 Name_Buffer (1 .. Name_Len) := Normed;
5949 -- Directories should always end with a directory separator
5951 if Name_Buffer (Name_Len) /= Directory_Separator then
5952 Add_Char_To_Name_Buffer (Directory_Separator);
5955 Path.Display_Name := Name_Find;
5957 Name_Len := Canonical_Path'Length;
5958 Name_Buffer (1 .. Name_Len) := Canonical_Path;
5960 if Name_Buffer (Name_Len) /= Directory_Separator then
5961 Add_Char_To_Name_Buffer (Directory_Separator);
5964 Path.Name := Name_Find;
5968 Free (Full_Path_Name);
5970 end Locate_Directory;
5972 ---------------------------
5973 -- Find_Excluded_Sources --
5974 ---------------------------
5976 procedure Find_Excluded_Sources
5977 (Project : in out Project_Processing_Data;
5978 Data : in out Tree_Processing_Data)
5980 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
5982 Excluded_Source_List_File : constant Variable_Value :=
5984 (Name_Excluded_Source_List_File,
5985 Project.Project.Decl.Attributes,
5987 Excluded_Sources : Variable_Value := Util.Value_Of
5988 (Name_Excluded_Source_Files,
5989 Project.Project.Decl.Attributes,
5992 Current : String_List_Id;
5993 Element : String_Element;
5994 Location : Source_Ptr;
5995 Name : File_Name_Type;
5996 File : Prj.Util.Text_File;
5997 Line : String (1 .. 300);
5999 Locally_Removed : Boolean := False;
6002 -- If Excluded_Source_Files is not declared, check Locally_Removed_Files
6004 if Excluded_Sources.Default then
6005 Locally_Removed := True;
6008 (Name_Locally_Removed_Files,
6009 Project.Project.Decl.Attributes, Shared);
6012 -- If there are excluded sources, put them in the table
6014 if not Excluded_Sources.Default then
6015 if not Excluded_Source_List_File.Default then
6016 if Locally_Removed then
6019 "?both attributes Locally_Removed_Files and " &
6020 "Excluded_Source_List_File are present",
6021 Excluded_Source_List_File.Location, Project.Project);
6025 "?both attributes Excluded_Source_Files and " &
6026 "Excluded_Source_List_File are present",
6027 Excluded_Source_List_File.Location, Project.Project);
6031 Current := Excluded_Sources.Values;
6032 while Current /= Nil_String loop
6033 Element := Shared.String_Elements.Table (Current);
6034 Name := Canonical_Case_File_Name (Element.Value);
6036 -- If the element has no location, then use the location of
6037 -- Excluded_Sources to report possible errors.
6039 if Element.Location = No_Location then
6040 Location := Excluded_Sources.Location;
6042 Location := Element.Location;
6045 Excluded_Sources_Htable.Set
6046 (Project.Excluded, Name,
6047 (Name, No_File, 0, False, Location));
6048 Current := Element.Next;
6051 elsif not Excluded_Source_List_File.Default then
6052 Location := Excluded_Source_List_File.Location;
6055 Source_File_Name : constant File_Name_Type :=
6057 (Excluded_Source_List_File.Value);
6058 Source_File_Line : Natural := 0;
6060 Source_File_Path_Name : constant String :=
6063 Project.Project.Directory.Name);
6066 if Source_File_Path_Name'Length = 0 then
6067 Err_Vars.Error_Msg_File_1 :=
6068 File_Name_Type (Excluded_Source_List_File.Value);
6071 "file with excluded sources { does not exist",
6072 Excluded_Source_List_File.Location, Project.Project);
6077 Prj.Util.Open (File, Source_File_Path_Name);
6079 if not Prj.Util.Is_Valid (File) then
6081 (Data.Flags, "file does not exist",
6082 Location, Project.Project);
6084 -- Read the lines one by one
6086 while not Prj.Util.End_Of_File (File) loop
6087 Prj.Util.Get_Line (File, Line, Last);
6088 Source_File_Line := Source_File_Line + 1;
6090 -- Non empty, non comment line should contain a file name
6093 and then (Last = 1 or else Line (1 .. 2) /= "--")
6096 Name_Buffer (1 .. Name_Len) := Line (1 .. Last);
6097 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6100 -- Check that there is no directory information
6102 for J in 1 .. Last loop
6104 or else Line (J) = Directory_Separator
6106 Error_Msg_File_1 := Name;
6109 "file name cannot include " &
6110 "directory information ({)",
6111 Location, Project.Project);
6116 Excluded_Sources_Htable.Set
6119 (Name, Source_File_Name, Source_File_Line,
6124 Prj.Util.Close (File);
6129 end Find_Excluded_Sources;
6135 procedure Find_Sources
6136 (Project : in out Project_Processing_Data;
6137 Data : in out Tree_Processing_Data)
6139 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6141 Sources : constant Variable_Value :=
6144 Project.Project.Decl.Attributes,
6147 Source_List_File : constant Variable_Value :=
6149 (Name_Source_List_File,
6150 Project.Project.Decl.Attributes,
6153 Name_Loc : Name_Location;
6154 Has_Explicit_Sources : Boolean;
6157 pragma Assert (Sources.Kind = List, "Source_Files is not a list");
6159 (Source_List_File.Kind = Single,
6160 "Source_List_File is not a single string");
6162 Project.Source_List_File_Location := Source_List_File.Location;
6164 -- If the user has specified a Source_Files attribute
6166 if not Sources.Default then
6167 if not Source_List_File.Default then
6170 "?both attributes source_files and " &
6171 "source_list_file are present",
6172 Source_List_File.Location, Project.Project);
6175 -- Sources is a list of file names
6178 Current : String_List_Id := Sources.Values;
6179 Element : String_Element;
6180 Location : Source_Ptr;
6181 Name : File_Name_Type;
6184 if Current = Nil_String then
6185 Project.Project.Languages := No_Language_Index;
6187 -- This project contains no source. For projects that don't
6188 -- extend other projects, this also means that there is no
6189 -- need for an object directory, if not specified.
6191 if Project.Project.Extends = No_Project
6192 and then Project.Project.Object_Directory =
6193 Project.Project.Directory
6195 Project.Project.Object_Directory := No_Path_Information;
6199 while Current /= Nil_String loop
6200 Element := Shared.String_Elements.Table (Current);
6201 Name := Canonical_Case_File_Name (Element.Value);
6202 Get_Name_String (Element.Value);
6204 -- If the element has no location, then use the location of
6205 -- Sources to report possible errors.
6207 if Element.Location = No_Location then
6208 Location := Sources.Location;
6210 Location := Element.Location;
6213 -- Check that there is no directory information
6215 for J in 1 .. Name_Len loop
6216 if Name_Buffer (J) = '/'
6217 or else Name_Buffer (J) = Directory_Separator
6219 Error_Msg_File_1 := Name;
6222 "file name cannot include directory " &
6224 Location, Project.Project);
6229 -- Check whether the file is already there: the same file name
6230 -- may be in the list. If the source is missing, the error will
6231 -- be on the first mention of the source file name.
6233 Name_Loc := Source_Names_Htable.Get
6234 (Project.Source_Names, Name);
6236 if Name_Loc = No_Name_Location then
6239 Location => Location,
6240 Source => No_Source,
6245 Name_Loc.Listed := True;
6248 Source_Names_Htable.Set
6249 (Project.Source_Names, Name, Name_Loc);
6251 Current := Element.Next;
6254 Has_Explicit_Sources := True;
6257 -- If we have no Source_Files attribute, check the Source_List_File
6260 elsif not Source_List_File.Default then
6262 -- Source_List_File is the name of the file that contains the source
6266 Source_File_Path_Name : constant String :=
6268 (File_Name_Type (Source_List_File.Value),
6269 Project.Project.Directory.Display_Name);
6272 Has_Explicit_Sources := True;
6274 if Source_File_Path_Name'Length = 0 then
6275 Err_Vars.Error_Msg_File_1 :=
6276 File_Name_Type (Source_List_File.Value);
6279 "file with sources { does not exist",
6280 Source_List_File.Location, Project.Project);
6283 Get_Sources_From_File
6284 (Source_File_Path_Name, Source_List_File.Location,
6290 -- Neither Source_Files nor Source_List_File has been specified. Find
6291 -- all the files that satisfy the naming scheme in all the source
6294 Has_Explicit_Sources := False;
6297 -- Remove any exception that is not in the specified list of sources
6299 if Has_Explicit_Sources then
6302 Iter : Source_Iterator;
6309 Iter := For_Each_Source (Data.Tree, Project.Project);
6313 Source := Prj.Element (Iter);
6314 exit Source_Loop when Source = No_Source;
6316 if Source.Naming_Exception then
6317 NL := Source_Names_Htable.Get
6318 (Project.Source_Names, Source.File);
6320 if NL /= No_Name_Location and then not NL.Listed then
6321 -- Remove the exception
6322 Source_Names_Htable.Set
6323 (Project.Source_Names,
6326 Remove_Source (Data.Tree, Source, No_Source);
6328 Error_Msg_Name_1 := Name_Id (Source.File);
6331 "? unknown source file %%",
6341 end loop Source_Loop;
6343 exit Iter_Loop when not Again;
6351 For_All_Sources => Sources.Default and then Source_List_File.Default);
6353 -- Check if all exceptions have been found
6357 Iter : Source_Iterator;
6358 Found : Boolean := False;
6361 Iter := For_Each_Source (Data.Tree, Project.Project);
6363 Source := Prj.Element (Iter);
6364 exit when Source = No_Source;
6366 -- If the full source path is unknown for this source_id, there
6367 -- could be several reasons:
6368 -- * we simply did not find the file itself, this is an error
6369 -- * we have a multi-unit source file. Another Source_Id from
6370 -- the same file has received the full path, so we need to
6373 if Source.Naming_Exception
6374 and then Source.Path = No_Path_Information
6376 if Source.Unit /= No_Unit_Index then
6379 if Source.Index /= 0 then -- Only multi-unit files
6382 Source_Files_Htable.Get
6383 (Data.Tree.Source_Files_HT, Source.File);
6385 while S /= null loop
6386 if S.Path /= No_Path_Information then
6387 Source.Path := S.Path;
6390 if Current_Verbosity = High then
6392 ("setting full path for "
6393 & Get_Name_String (Source.File)
6394 & " at" & Source.Index'Img
6396 & Get_Name_String (Source.Path.Name));
6402 S := S.Next_With_File_Name;
6408 Error_Msg_Name_1 := Name_Id (Source.Display_File);
6409 Error_Msg_Name_2 := Source.Unit.Name;
6411 (Data.Flags, Data.Flags.Missing_Source_Files,
6412 "source file %% for unit %% not found",
6413 No_Location, Project.Project);
6417 if Source.Path = No_Path_Information then
6418 Remove_Source (Data.Tree, Source, No_Source);
6426 -- It is an error if a source file name in a source list or in a source
6427 -- list file is not found.
6429 if Has_Explicit_Sources then
6432 First_Error : Boolean;
6435 NL := Source_Names_Htable.Get_First (Project.Source_Names);
6436 First_Error := True;
6437 while NL /= No_Name_Location loop
6438 if not NL.Found then
6439 Err_Vars.Error_Msg_File_1 := NL.Name;
6442 (Data.Flags, Data.Flags.Missing_Source_Files,
6443 "source file { not found",
6444 NL.Location, Project.Project);
6445 First_Error := False;
6448 (Data.Flags, Data.Flags.Missing_Source_Files,
6449 "\source file { not found",
6450 NL.Location, Project.Project);
6454 NL := Source_Names_Htable.Get_Next (Project.Source_Names);
6464 procedure Initialize
6465 (Data : out Tree_Processing_Data;
6466 Tree : Project_Tree_Ref;
6467 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
6468 Flags : Prj.Processing_Flags)
6472 Data.Node_Tree := Node_Tree;
6473 Data.Flags := Flags;
6480 procedure Free (Data : in out Tree_Processing_Data) is
6481 pragma Unreferenced (Data);
6490 procedure Initialize
6491 (Data : in out Project_Processing_Data;
6492 Project : Project_Id)
6495 Data.Project := Project;
6502 procedure Free (Data : in out Project_Processing_Data) is
6504 Source_Names_Htable.Reset (Data.Source_Names);
6505 Unit_Exceptions_Htable.Reset (Data.Unit_Exceptions);
6506 Excluded_Sources_Htable.Reset (Data.Excluded);
6509 -------------------------------
6510 -- Check_File_Naming_Schemes --
6511 -------------------------------
6513 procedure Check_File_Naming_Schemes
6514 (In_Tree : Project_Tree_Ref;
6515 Project : Project_Processing_Data;
6516 File_Name : File_Name_Type;
6517 Alternate_Languages : out Language_List;
6518 Language : out Language_Ptr;
6519 Display_Language_Name : out Name_Id;
6521 Lang_Kind : out Language_Kind;
6522 Kind : out Source_Kind)
6524 Filename : constant String := Get_Name_String (File_Name);
6525 Config : Language_Config;
6526 Tmp_Lang : Language_Ptr;
6528 Header_File : Boolean := False;
6529 -- True if we found at least one language for which the file is a header
6530 -- In such a case, we search for all possible languages where this is
6531 -- also a header (C and C++ for instance), since the file might be used
6532 -- for several such languages.
6534 procedure Check_File_Based_Lang;
6535 -- Does the naming scheme test for file-based languages. For those,
6536 -- there is no Unit. Just check if the file name has the implementation
6537 -- or, if it is specified, the template suffix of the language.
6539 -- Returns True if the file belongs to the current language and we
6540 -- should stop searching for matching languages. Not that a given header
6541 -- file could belong to several languages (C and C++ for instance). Thus
6542 -- if we found a header we'll check whether it matches other languages.
6544 ---------------------------
6545 -- Check_File_Based_Lang --
6546 ---------------------------
6548 procedure Check_File_Based_Lang is
6551 and then Suffix_Matches (Filename, Config.Naming_Data.Body_Suffix)
6555 Language := Tmp_Lang;
6558 ("implementation of language ", Display_Language_Name);
6560 elsif Suffix_Matches (Filename, Config.Naming_Data.Spec_Suffix) then
6562 ("header of language ", Display_Language_Name);
6565 Alternate_Languages := new Language_List_Element'
6566 (Language => Language,
6567 Next => Alternate_Languages);
6570 Header_File := True;
6573 Language := Tmp_Lang;
6576 end Check_File_Based_Lang;
6578 -- Start of processing for Check_File_Naming_Schemes
6581 Language := No_Language_Index;
6582 Alternate_Languages := null;
6583 Display_Language_Name := No_Name;
6585 Lang_Kind := File_Based;
6588 Tmp_Lang := Project.Project.Languages;
6589 while Tmp_Lang /= No_Language_Index loop
6590 if Current_Verbosity = High then
6592 ("testing language "
6593 & Get_Name_String (Tmp_Lang.Name)
6594 & " Header_File=" & Header_File'Img);
6597 Display_Language_Name := Tmp_Lang.Display_Name;
6598 Config := Tmp_Lang.Config;
6599 Lang_Kind := Config.Kind;
6603 Check_File_Based_Lang;
6604 exit when Kind = Impl;
6608 -- We know it belongs to a least a file_based language, no
6609 -- need to check unit-based ones.
6611 if not Header_File then
6613 (File_Name => File_Name,
6614 Naming => Config.Naming_Data,
6618 In_Tree => In_Tree);
6620 if Unit /= No_Name then
6621 Language := Tmp_Lang;
6627 Tmp_Lang := Tmp_Lang.Next;
6630 if Language = No_Language_Index then
6631 Debug_Output ("not a source of any language");
6633 end Check_File_Naming_Schemes;
6639 procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
6641 -- If the file was previously already associated with a unit, change it
6643 if Source.Unit /= null
6644 and then Source.Kind in Spec_Or_Body
6645 and then Source.Unit.File_Names (Source.Kind) /= null
6647 -- If we had another file referencing the same unit (for instance it
6648 -- was in an extended project), that source file is in fact invisible
6649 -- from now on, and in particular doesn't belong to the same unit.
6651 if Source.Unit.File_Names (Source.Kind) /= Source then
6652 Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
6655 Source.Unit.File_Names (Source.Kind) := null;
6658 Source.Kind := Kind;
6660 if Current_Verbosity = High
6661 and then Source.File /= No_File
6663 Debug_Output ("override kind for "
6664 & Get_Name_String (Source.File)
6665 & " idx=" & Source.Index'Img
6666 & " kind=" & Source.Kind'Img);
6669 if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
6670 Source.Unit.File_Names (Source.Kind) := Source;
6678 procedure Check_File
6679 (Project : in out Project_Processing_Data;
6680 Data : in out Tree_Processing_Data;
6681 Source_Dir_Rank : Natural;
6682 Path : Path_Name_Type;
6683 Display_Path : Path_Name_Type;
6684 File_Name : File_Name_Type;
6685 Display_File_Name : File_Name_Type;
6686 Locally_Removed : Boolean;
6687 For_All_Sources : Boolean)
6689 Name_Loc : Name_Location :=
6690 Source_Names_Htable.Get
6691 (Project.Source_Names, File_Name);
6692 Check_Name : Boolean := False;
6693 Alternate_Languages : Language_List;
6694 Language : Language_Ptr;
6696 Src_Ind : Source_File_Index;
6698 Display_Language_Name : Name_Id;
6699 Lang_Kind : Language_Kind;
6700 Kind : Source_Kind := Spec;
6703 if Current_Verbosity = High then
6704 Debug_Increase_Indent
6705 ("checking file (rank=" & Source_Dir_Rank'Img & ")",
6706 Name_Id (Display_Path));
6709 if Name_Loc = No_Name_Location then
6710 Check_Name := For_All_Sources;
6713 if Name_Loc.Found then
6715 -- Check if it is OK to have the same file name in several
6716 -- source directories.
6718 if Source_Dir_Rank = Name_Loc.Source.Source_Dir_Rank then
6719 Error_Msg_File_1 := File_Name;
6722 "{ is found in several source directories",
6723 Name_Loc.Location, Project.Project);
6727 Name_Loc.Found := True;
6729 Source_Names_Htable.Set
6730 (Project.Source_Names, File_Name, Name_Loc);
6732 if Name_Loc.Source = No_Source then
6736 -- Set the full path for the source_id (which might have been
6737 -- created when parsing the naming exceptions, and therefore
6738 -- might not have the full path).
6739 -- We only set this for this source_id, but not for other
6740 -- source_id in the same file (case of multi-unit source files)
6741 -- For the latter, they will be set in Find_Sources when we
6742 -- check that all source_id have known full paths.
6743 -- Doing this later saves one htable lookup per file in the
6744 -- common case where the user is not using multi-unit files.
6746 Name_Loc.Source.Path := (Path, Display_Path);
6748 Source_Paths_Htable.Set
6749 (Data.Tree.Source_Paths_HT, Path, Name_Loc.Source);
6751 -- Check if this is a subunit
6753 if Name_Loc.Source.Unit /= No_Unit_Index
6754 and then Name_Loc.Source.Kind = Impl
6756 Src_Ind := Sinput.P.Load_Project_File
6757 (Get_Name_String (Display_Path));
6759 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6760 Override_Kind (Name_Loc.Source, Sep);
6768 Check_File_Naming_Schemes
6769 (In_Tree => Data.Tree,
6771 File_Name => File_Name,
6772 Alternate_Languages => Alternate_Languages,
6773 Language => Language,
6774 Display_Language_Name => Display_Language_Name,
6776 Lang_Kind => Lang_Kind,
6779 if Language = No_Language_Index then
6781 -- A file name in a list must be a source of a language
6783 if Data.Flags.Error_On_Unknown_Language
6784 and then Name_Loc.Found
6786 Error_Msg_File_1 := File_Name;
6789 "language unknown for {",
6790 Name_Loc.Location, Project.Project);
6796 Project => Project.Project,
6797 Source_Dir_Rank => Source_Dir_Rank,
6798 Lang_Id => Language,
6801 Alternate_Languages => Alternate_Languages,
6802 File_Name => File_Name,
6803 Display_File => Display_File_Name,
6805 Locally_Removed => Locally_Removed,
6806 Path => (Path, Display_Path));
6808 -- If it is a source specified in a list, update the entry in
6809 -- the Source_Names table.
6811 if Name_Loc.Found and then Name_Loc.Source = No_Source then
6812 Name_Loc.Source := Source;
6813 Source_Names_Htable.Set
6814 (Project.Source_Names, File_Name, Name_Loc);
6819 Debug_Decrease_Indent;
6822 ---------------------------------
6823 -- Expand_Subdirectory_Pattern --
6824 ---------------------------------
6826 procedure Expand_Subdirectory_Pattern
6827 (Project : Project_Id;
6828 Data : in out Tree_Processing_Data;
6829 Patterns : String_List_Id;
6830 Ignore : String_List_Id;
6831 Search_For : Search_Type;
6832 Resolve_Links : Boolean)
6834 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
6836 package Recursive_Dirs is new GNAT.Dynamic_HTables.Simple_HTable
6837 (Header_Num => Header_Num,
6839 No_Element => False,
6840 Key => Path_Name_Type,
6843 -- Hash table stores recursive source directories, to avoid looking
6844 -- several times, and to avoid cycles that may be introduced by symbolic
6847 File_Pattern : GNAT.Regexp.Regexp;
6848 -- Pattern to use when matching file names.
6850 Visited : Recursive_Dirs.Instance;
6852 procedure Find_Pattern
6853 (Pattern_Id : Name_Id;
6855 Location : Source_Ptr);
6856 -- Find a specific pattern
6858 function Recursive_Find_Dirs
6859 (Path : Path_Information;
6860 Rank : Natural) return Boolean;
6861 -- Search all the subdirectories (recursively) of Path.
6862 -- Return True if at least one file or directory was processed
6864 function Subdirectory_Matches
6865 (Path : Path_Information;
6866 Rank : Natural) return Boolean;
6867 -- Called when a matching directory was found. If the user is in fact
6868 -- searching for files, we then search for those files matching the
6869 -- pattern within the directory.
6870 -- Return True if at least one file or directory was processed
6872 --------------------------
6873 -- Subdirectory_Matches --
6874 --------------------------
6876 function Subdirectory_Matches
6877 (Path : Path_Information;
6878 Rank : Natural) return Boolean
6881 Name : String (1 .. 250);
6883 Found : Path_Information;
6884 Success : Boolean := False;
6888 when Search_Directories =>
6889 Callback (Path, Rank);
6892 when Search_Files =>
6893 Open (Dir, Get_Name_String (Path.Display_Name));
6895 Read (Dir, Name, Last);
6898 if Name (Name'First .. Last) /= "."
6899 and then Name (Name'First .. Last) /= ".."
6900 and then Match (Name (Name'First .. Last), File_Pattern)
6902 Get_Name_String (Path.Display_Name);
6903 Add_Str_To_Name_Buffer (Name (Name'First .. Last));
6905 Found.Display_Name := Name_Find;
6906 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6907 Found.Name := Name_Find;
6909 Callback (Found, Rank);
6918 end Subdirectory_Matches;
6920 -------------------------
6921 -- Recursive_Find_Dirs --
6922 -------------------------
6924 function Recursive_Find_Dirs
6925 (Path : Path_Information;
6926 Rank : Natural) return Boolean
6928 Path_Str : constant String := Get_Name_String (Path.Display_Name);
6930 Name : String (1 .. 250);
6932 Success : Boolean := False;
6935 Debug_Output ("looking for subdirs of ", Name_Id (Path.Display_Name));
6937 if Recursive_Dirs.Get (Visited, Path.Name) then
6941 Recursive_Dirs.Set (Visited, Path.Name, True);
6943 Success := Subdirectory_Matches (Path, Rank) or Success;
6945 Open (Dir, Path_Str);
6948 Read (Dir, Name, Last);
6951 if Name (1 .. Last) /= "."
6952 and then Name (1 .. Last) /= ".."
6955 Path_Name : constant String :=
6957 (Name => Name (1 .. Last),
6958 Directory => Path_Str,
6959 Resolve_Links => Resolve_Links)
6960 & Directory_Separator;
6961 Path2 : Path_Information;
6962 OK : Boolean := True;
6965 if Is_Directory (Path_Name) then
6966 if Ignore /= Nil_String then
6968 Dir_Name : String := Name (1 .. Last);
6969 List : String_List_Id := Ignore;
6972 Canonical_Case_File_Name (Dir_Name);
6974 while List /= Nil_String loop
6976 (Shared.String_Elements.Table (List).Value);
6977 Canonical_Case_File_Name
6978 (Name_Buffer (1 .. Name_Len));
6979 OK := Name_Buffer (1 .. Name_Len) /= Dir_Name;
6981 List := Shared.String_Elements.Table (List).Next;
6988 Add_Str_To_Name_Buffer (Path_Name);
6989 Path2.Display_Name := Name_Find;
6991 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
6992 Path2.Name := Name_Find;
6995 Recursive_Find_Dirs (Path2, Rank) or Success;
7007 when Directory_Error =>
7009 end Recursive_Find_Dirs;
7015 procedure Find_Pattern
7016 (Pattern_Id : Name_Id;
7018 Location : Source_Ptr)
7020 Pattern : constant String := Get_Name_String (Pattern_Id);
7021 Pattern_End : Natural := Pattern'Last;
7022 Recursive : Boolean;
7023 Dir : File_Name_Type;
7024 Path_Name : Path_Information;
7025 Dir_Exists : Boolean;
7026 Has_Error : Boolean := False;
7030 Debug_Increase_Indent ("Find_Pattern", Pattern_Id);
7032 -- If we are looking for files, find the pattern for the files
7034 if Search_For = Search_Files then
7035 while Pattern_End >= Pattern'First
7036 and then Pattern (Pattern_End) /= '/'
7037 and then Pattern (Pattern_End) /= Directory_Separator
7039 Pattern_End := Pattern_End - 1;
7042 if Pattern_End = Pattern'Last then
7043 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7045 (Data.Flags, Data.Flags.Missing_Source_Files,
7046 "Missing file name or pattern in {", Location, Project);
7050 if Current_Verbosity = High then
7052 Write_Str ("file_pattern=");
7053 Write_Str (Pattern (Pattern_End + 1 .. Pattern'Last));
7054 Write_Str (" dir_pattern=");
7055 Write_Line (Pattern (Pattern'First .. Pattern_End));
7058 File_Pattern := Compile
7059 (Pattern (Pattern_End + 1 .. Pattern'Last),
7061 Case_Sensitive => File_Names_Case_Sensitive);
7063 -- If we had just "*.gpr", this is equivalent to "./*.gpr"
7065 if Pattern_End > Pattern'First then
7066 Pattern_End := Pattern_End - 1; -- Skip directory separator
7071 Pattern_End - 1 >= Pattern'First
7072 and then Pattern (Pattern_End - 1 .. Pattern_End) = "**"
7073 and then (Pattern_End - 1 = Pattern'First
7074 or else Pattern (Pattern_End - 2) = '/'
7075 or else Pattern (Pattern_End - 2) = Directory_Separator);
7078 Pattern_End := Pattern_End - 2;
7079 if Pattern_End > Pattern'First then
7080 Pattern_End := Pattern_End - 1; -- Skip '/'
7084 Name_Len := Pattern_End - Pattern'First + 1;
7085 Name_Buffer (1 .. Name_Len) := Pattern (Pattern'First .. Pattern_End);
7089 (Project => Project,
7092 Dir_Exists => Dir_Exists,
7094 Must_Exist => False);
7096 if not Dir_Exists then
7097 Err_Vars.Error_Msg_File_1 := Dir;
7099 (Data.Flags, Data.Flags.Missing_Source_Files,
7100 "{ is not a valid directory", Location, Project);
7101 Has_Error := Data.Flags.Missing_Source_Files = Error;
7104 if not Has_Error then
7105 -- Links have been resolved if necessary, and Path_Name
7106 -- always ends with a directory separator.
7109 Success := Recursive_Find_Dirs (Path_Name, Rank);
7111 Success := Subdirectory_Matches (Path_Name, Rank);
7116 when Search_Directories =>
7117 null; -- Error can't occur
7119 when Search_Files =>
7120 Err_Vars.Error_Msg_File_1 := File_Name_Type (Pattern_Id);
7122 (Data.Flags, Data.Flags.Missing_Source_Files,
7123 "file { not found", Location, Project);
7128 Debug_Decrease_Indent ("done Find_Pattern");
7133 Pattern_Id : String_List_Id := Patterns;
7134 Element : String_Element;
7135 Rank : Natural := 1;
7137 -- Start of processing for Expand_Subdirectory_Pattern
7140 while Pattern_Id /= Nil_String loop
7141 Element := Shared.String_Elements.Table (Pattern_Id);
7142 Find_Pattern (Element.Value, Rank, Element.Location);
7144 Pattern_Id := Element.Next;
7147 Recursive_Dirs.Reset (Visited);
7148 end Expand_Subdirectory_Pattern;
7150 ------------------------
7151 -- Search_Directories --
7152 ------------------------
7154 procedure Search_Directories
7155 (Project : in out Project_Processing_Data;
7156 Data : in out Tree_Processing_Data;
7157 For_All_Sources : Boolean)
7159 Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
7161 Source_Dir : String_List_Id;
7162 Element : String_Element;
7163 Src_Dir_Rank : Number_List_Index;
7164 Num_Nod : Number_Node;
7166 Name : String (1 .. 1_000);
7168 File_Name : File_Name_Type;
7169 Display_File_Name : File_Name_Type;
7172 Debug_Increase_Indent ("looking for sources of", Project.Project.Name);
7174 -- Loop through subdirectories
7176 Source_Dir := Project.Project.Source_Dirs;
7177 Src_Dir_Rank := Project.Project.Source_Dir_Ranks;
7178 while Source_Dir /= Nil_String loop
7180 Num_Nod := Shared.Number_Lists.Table (Src_Dir_Rank);
7181 Element := Shared.String_Elements.Table (Source_Dir);
7183 -- Use Element.Value in this test, not Display_Value, because we
7184 -- want the symbolic links to be resolved when appropriate.
7186 if Element.Value /= No_Name then
7188 Source_Directory : constant String :=
7189 Get_Name_String (Element.Value)
7190 & Directory_Separator;
7192 Dir_Last : constant Natural :=
7193 Compute_Directory_Last (Source_Directory);
7195 Display_Source_Directory : constant String :=
7197 (Element.Display_Value)
7198 & Directory_Separator;
7199 -- Display_Source_Directory is to allow us to open a UTF-8
7200 -- encoded directory on Windows.
7203 if Current_Verbosity = High then
7204 Debug_Increase_Indent
7205 ("Source_Dir (node=" & Num_Nod.Number'Img & ") """
7206 & Source_Directory (Source_Directory'First .. Dir_Last)
7210 -- We look to every entry in the source directory
7212 Open (Dir, Display_Source_Directory);
7215 Read (Dir, Name, Last);
7219 -- In fast project loading mode (without -eL), the user
7220 -- guarantees that no directory has a name which is a
7221 -- valid source name, so we can avoid doing a system call
7222 -- here. This provides a very significant speed up on
7223 -- slow file systems (remote files for instance).
7225 if not Opt.Follow_Links_For_Files
7226 or else Is_Regular_File
7227 (Display_Source_Directory & Name (1 .. Last))
7230 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7231 Display_File_Name := Name_Find;
7233 if Osint.File_Names_Case_Sensitive then
7234 File_Name := Display_File_Name;
7236 Canonical_Case_File_Name
7237 (Name_Buffer (1 .. Name_Len));
7238 File_Name := Name_Find;
7242 Path_Name : constant String :=
7247 (Source_Directory'First ..
7250 Opt.Follow_Links_For_Files,
7251 Case_Sensitive => True);
7253 Path : Path_Name_Type;
7255 Excluded_Sources_Htable.Get
7256 (Project.Excluded, File_Name);
7257 To_Remove : Boolean := False;
7260 Name_Len := Path_Name'Length;
7261 Name_Buffer (1 .. Name_Len) := Path_Name;
7263 if Osint.File_Names_Case_Sensitive then
7266 Canonical_Case_File_Name
7267 (Name_Buffer (1 .. Name_Len));
7271 if FF /= No_File_Found then
7272 if not FF.Found then
7274 Excluded_Sources_Htable.Set
7275 (Project.Excluded, File_Name, FF);
7278 ("excluded source ",
7279 Name_Id (Display_File_Name));
7281 -- Will mark the file as removed, but we
7282 -- still need to add it to the list: if we
7283 -- don't, the file will not appear in the
7284 -- mapping file and will cause the compiler
7291 -- Preserve the user's original casing and use of
7292 -- links. The display_value (a directory) already
7293 -- ends with a directory separator by construction,
7294 -- so no need to add one.
7296 Get_Name_String (Element.Display_Value);
7297 Get_Name_String_And_Append (Display_File_Name);
7300 (Project => Project,
7301 Source_Dir_Rank => Num_Nod.Number,
7304 Display_Path => Name_Find,
7305 File_Name => File_Name,
7306 Locally_Removed => To_Remove,
7307 Display_File_Name => Display_File_Name,
7308 For_All_Sources => For_All_Sources);
7312 if Current_Verbosity = High then
7313 Debug_Output ("ignore " & Name (1 .. Last));
7318 Debug_Decrease_Indent;
7324 when Directory_Error =>
7328 Source_Dir := Element.Next;
7329 Src_Dir_Rank := Num_Nod.Next;
7332 Debug_Decrease_Indent ("end looking for sources.");
7333 end Search_Directories;
7335 ----------------------------
7336 -- Load_Naming_Exceptions --
7337 ----------------------------
7339 procedure Load_Naming_Exceptions
7340 (Project : in out Project_Processing_Data;
7341 Data : in out Tree_Processing_Data)
7344 Iter : Source_Iterator;
7347 Iter := For_Each_Source (Data.Tree, Project.Project);
7349 Source := Prj.Element (Iter);
7350 exit when Source = No_Source;
7352 -- An excluded file cannot also be an exception file name
7354 if Excluded_Sources_Htable.Get (Project.Excluded, Source.File) /=
7357 Error_Msg_File_1 := Source.File;
7360 "{ cannot be both excluded and an exception file name",
7361 No_Location, Project.Project);
7365 ("naming exception: adding source file to source_Names: ",
7366 Name_Id (Source.File));
7368 Source_Names_Htable.Set
7369 (Project.Source_Names,
7372 (Name => Source.File,
7373 Location => Source.Location,
7378 -- If this is an Ada exception, record in table Unit_Exceptions
7380 if Source.Unit /= No_Unit_Index then
7382 Unit_Except : Unit_Exception :=
7383 Unit_Exceptions_Htable.Get
7384 (Project.Unit_Exceptions, Source.Unit.Name);
7387 Unit_Except.Name := Source.Unit.Name;
7389 if Source.Kind = Spec then
7390 Unit_Except.Spec := Source.File;
7392 Unit_Except.Impl := Source.File;
7395 Unit_Exceptions_Htable.Set
7396 (Project.Unit_Exceptions, Source.Unit.Name, Unit_Except);
7402 end Load_Naming_Exceptions;
7404 ----------------------
7405 -- Look_For_Sources --
7406 ----------------------
7408 procedure Look_For_Sources
7409 (Project : in out Project_Processing_Data;
7410 Data : in out Tree_Processing_Data)
7412 Object_Files : Object_File_Names_Htable.Instance;
7413 Iter : Source_Iterator;
7416 procedure Check_Object (Src : Source_Id);
7417 -- Check if object file name of Src is already used in the project tree,
7418 -- and report an error if so.
7420 procedure Check_Object_Files;
7421 -- Check that no two sources of this project have the same object file
7423 procedure Mark_Excluded_Sources;
7424 -- Mark as such the sources that are declared as excluded
7426 procedure Check_Missing_Sources;
7427 -- Check whether one of the languages has no sources, and report an
7428 -- error when appropriate
7430 procedure Get_Sources_From_Source_Info;
7431 -- Get the source information from the tables that were created when a
7432 -- source info file was read.
7434 ---------------------------
7435 -- Check_Missing_Sources --
7436 ---------------------------
7438 procedure Check_Missing_Sources is
7439 Extending : constant Boolean :=
7440 Project.Project.Extends /= No_Project;
7441 Language : Language_Ptr;
7443 Alt_Lang : Language_List;
7444 Continuation : Boolean := False;
7445 Iter : Source_Iterator;
7447 if not Project.Project.Externally_Built
7448 and then not Extending
7450 Language := Project.Project.Languages;
7451 while Language /= No_Language_Index loop
7453 -- If there are no sources for this language, check if there
7454 -- are sources for which this is an alternate language.
7456 if Language.First_Source = No_Source
7457 and then (Data.Flags.Require_Sources_Other_Lang
7458 or else Language.Name = Name_Ada)
7460 Iter := For_Each_Source (In_Tree => Data.Tree,
7461 Project => Project.Project);
7463 Source := Element (Iter);
7464 exit Source_Loop when Source = No_Source
7465 or else Source.Language = Language;
7467 Alt_Lang := Source.Alternate_Languages;
7468 while Alt_Lang /= null loop
7469 exit Source_Loop when Alt_Lang.Language = Language;
7470 Alt_Lang := Alt_Lang.Next;
7474 end loop Source_Loop;
7476 if Source = No_Source then
7479 Get_Name_String (Language.Display_Name),
7481 Project.Source_List_File_Location,
7483 Continuation := True;
7487 Language := Language.Next;
7490 end Check_Missing_Sources;
7496 procedure Check_Object (Src : Source_Id) is
7500 Source := Object_File_Names_Htable.Get (Object_Files, Src.Object);
7502 -- We cannot just check on "Source /= Src", since we might have
7503 -- two different entries for the same file (and since that's
7504 -- the same file it is expected that it has the same object)
7506 if Source /= No_Source
7507 and then Source.Path /= Src.Path
7509 Error_Msg_File_1 := Src.File;
7510 Error_Msg_File_2 := Source.File;
7513 "{ and { have the same object file name",
7514 No_Location, Project.Project);
7517 Object_File_Names_Htable.Set (Object_Files, Src.Object, Src);
7521 ---------------------------
7522 -- Mark_Excluded_Sources --
7523 ---------------------------
7525 procedure Mark_Excluded_Sources is
7526 Source : Source_Id := No_Source;
7527 Excluded : File_Found;
7531 -- Minor optimization: if there are no excluded files, no need to
7532 -- traverse the list of sources. We cannot however also check whether
7533 -- the existing exceptions have ".Found" set to True (indicating we
7534 -- found them before) because we need to do some final processing on
7535 -- them in any case.
7537 if Excluded_Sources_Htable.Get_First (Project.Excluded) /=
7540 Proj := Project.Project;
7541 while Proj /= No_Project loop
7542 Iter := For_Each_Source (Data.Tree, Proj);
7543 while Prj.Element (Iter) /= No_Source loop
7544 Source := Prj.Element (Iter);
7545 Excluded := Excluded_Sources_Htable.Get
7546 (Project.Excluded, Source.File);
7548 if Excluded /= No_File_Found then
7549 Source.Locally_Removed := True;
7550 Source.In_Interfaces := False;
7552 if Current_Verbosity = High then
7554 Write_Str ("removing file ");
7556 (Get_Name_String (Excluded.File)
7557 & " " & Get_Name_String (Source.Project.Name));
7560 Excluded_Sources_Htable.Remove
7561 (Project.Excluded, Source.File);
7567 Proj := Proj.Extends;
7571 -- If we have any excluded element left, that means we did not find
7574 Excluded := Excluded_Sources_Htable.Get_First (Project.Excluded);
7575 while Excluded /= No_File_Found loop
7576 if not Excluded.Found then
7578 -- Check if the file belongs to another imported project to
7579 -- provide a better error message.
7582 (In_Tree => Data.Tree,
7583 Project => Project.Project,
7584 In_Imported_Only => True,
7585 Base_Name => Excluded.File);
7587 Err_Vars.Error_Msg_File_1 := Excluded.File;
7589 if Src = No_Source then
7590 if Excluded.Excl_File = No_File then
7593 "unknown file {", Excluded.Location, Project.Project);
7599 Get_Name_String (Excluded.Excl_File) & ":" &
7600 No_Space_Img (Excluded.Excl_Line) &
7601 ": unknown file {", Excluded.Location, Project.Project);
7605 if Excluded.Excl_File = No_File then
7608 "cannot remove a source from an imported project: {",
7609 Excluded.Location, Project.Project);
7615 Get_Name_String (Excluded.Excl_File) & ":" &
7616 No_Space_Img (Excluded.Excl_Line) &
7617 ": cannot remove a source from an imported project: {",
7618 Excluded.Location, Project.Project);
7623 Excluded := Excluded_Sources_Htable.Get_Next (Project.Excluded);
7625 end Mark_Excluded_Sources;
7627 ------------------------
7628 -- Check_Object_Files --
7629 ------------------------
7631 procedure Check_Object_Files is
7632 Iter : Source_Iterator;
7634 Src_Ind : Source_File_Index;
7637 Iter := For_Each_Source (Data.Tree);
7639 Src_Id := Prj.Element (Iter);
7640 exit when Src_Id = No_Source;
7642 if Is_Compilable (Src_Id)
7643 and then Src_Id.Language.Config.Object_Generated
7644 and then Is_Extending (Project.Project, Src_Id.Project)
7646 if Src_Id.Unit = No_Unit_Index then
7647 if Src_Id.Kind = Impl then
7648 Check_Object (Src_Id);
7654 if Other_Part (Src_Id) = No_Source then
7655 Check_Object (Src_Id);
7662 if Other_Part (Src_Id) /= No_Source then
7663 Check_Object (Src_Id);
7666 -- Check if it is a subunit
7669 Sinput.P.Load_Project_File
7670 (Get_Name_String (Src_Id.Path.Display_Name));
7672 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7673 Override_Kind (Src_Id, Sep);
7675 Check_Object (Src_Id);
7684 end Check_Object_Files;
7686 ----------------------------------
7687 -- Get_Sources_From_Source_Info --
7688 ----------------------------------
7690 procedure Get_Sources_From_Source_Info is
7691 Iter : Source_Info_Iterator;
7694 Lang_Id : Language_Ptr;
7696 Initialize (Iter, Project.Project.Name);
7699 Src := Source_Info_Of (Iter);
7701 exit when Src = No_Source_Info;
7703 Id := new Source_Data;
7705 Id.Project := Project.Project;
7707 Lang_Id := Project.Project.Languages;
7708 while Lang_Id /= No_Language_Index and then
7709 Lang_Id.Name /= Src.Language
7711 Lang_Id := Lang_Id.Next;
7714 if Lang_Id = No_Language_Index then
7716 ("unknown language " &
7717 Get_Name_String (Src.Language) &
7719 Get_Name_String (Src.Project) &
7720 " in source info file");
7723 Id.Language := Lang_Id;
7724 Id.Kind := Src.Kind;
7725 Id.Index := Src.Index;
7728 (Path_Name_Type (Src.Display_Path_Name),
7729 Path_Name_Type (Src.Path_Name));
7732 Add_Str_To_Name_Buffer
7733 (Ada.Directories.Simple_Name
7734 (Get_Name_String (Src.Path_Name)));
7735 Id.File := Name_Find;
7737 Id.Next_With_File_Name :=
7738 Source_Files_Htable.Get (Data.Tree.Source_Files_HT, Id.File);
7739 Source_Files_Htable.Set (Data.Tree.Source_Files_HT, Id.File, Id);
7742 Add_Str_To_Name_Buffer
7743 (Ada.Directories.Simple_Name
7744 (Get_Name_String (Src.Display_Path_Name)));
7745 Id.Display_File := Name_Find;
7747 Id.Dep_Name := Dependency_Name
7748 (Id.File, Id.Language.Config.Dependency_Kind);
7749 Id.Naming_Exception := Src.Naming_Exception;
7750 Id.Object := Object_Name
7751 (Id.File, Id.Language.Config.Object_File_Suffix);
7752 Id.Switches := Switches_Name (Id.File);
7754 -- Add the source id to the Unit_Sources_HT hash table, if the
7755 -- unit name is not null.
7757 if Src.Kind /= Sep and then Src.Unit_Name /= No_Name then
7760 UData : Unit_Index :=
7761 Units_Htable.Get (Data.Tree.Units_HT, Src.Unit_Name);
7763 if UData = No_Unit_Index then
7764 UData := new Unit_Data;
7765 UData.Name := Src.Unit_Name;
7767 (Data.Tree.Units_HT, Src.Unit_Name, UData);
7773 -- Note that this updates Unit information as well
7775 Override_Kind (Id, Id.Kind);
7778 if Src.Index /= 0 then
7779 Project.Project.Has_Multi_Unit_Sources := True;
7782 -- Add the source to the language list
7784 Id.Next_In_Lang := Id.Language.First_Source;
7785 Id.Language.First_Source := Id;
7789 end Get_Sources_From_Source_Info;
7791 -- Start of processing for Look_For_Sources
7794 if Data.Tree.Source_Info_File_Exists then
7795 Get_Sources_From_Source_Info;
7798 if Project.Project.Source_Dirs /= Nil_String then
7799 Find_Excluded_Sources (Project, Data);
7801 if Project.Project.Languages /= No_Language_Index then
7802 Load_Naming_Exceptions (Project, Data);
7803 Find_Sources (Project, Data);
7804 Mark_Excluded_Sources;
7806 Check_Missing_Sources;
7810 Object_File_Names_Htable.Reset (Object_Files);
7812 end Look_For_Sources;
7818 function Path_Name_Of
7819 (File_Name : File_Name_Type;
7820 Directory : Path_Name_Type) return String
7822 Result : String_Access;
7823 The_Directory : constant String := Get_Name_String (Directory);
7826 Debug_Output ("Path_Name_Of file name=", Name_Id (File_Name));
7827 Debug_Output ("Path_Name_Of directory=", Name_Id (Directory));
7828 Get_Name_String (File_Name);
7831 (File_Name => Name_Buffer (1 .. Name_Len),
7832 Path => The_Directory);
7834 if Result = null then
7838 R : constant String := Result.all;
7850 procedure Remove_Source
7851 (Tree : Project_Tree_Ref;
7853 Replaced_By : Source_Id)
7858 if Current_Verbosity = High then
7860 Write_Str ("removing source ");
7861 Write_Str (Get_Name_String (Id.File));
7863 if Id.Index /= 0 then
7864 Write_Str (" at" & Id.Index'Img);
7870 if Replaced_By /= No_Source then
7871 Id.Replaced_By := Replaced_By;
7872 Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
7874 if Id.File /= Replaced_By.File then
7876 Replacement : constant File_Name_Type :=
7877 Replaced_Source_HTable.Get
7878 (Tree.Replaced_Sources, Id.File);
7881 Replaced_Source_HTable.Set
7882 (Tree.Replaced_Sources, Id.File, Replaced_By.File);
7884 if Replacement = No_File then
7885 Tree.Replaced_Source_Number :=
7886 Tree.Replaced_Source_Number + 1;
7892 Id.In_Interfaces := False;
7893 Id.Locally_Removed := True;
7895 -- ??? Should we remove the source from the unit ? The file is not used,
7896 -- so probably should not be referenced from the unit. On the other hand
7897 -- it might give useful additional info
7898 -- if Id.Unit /= null then
7899 -- Id.Unit.File_Names (Id.Kind) := null;
7902 Source := Id.Language.First_Source;
7905 Id.Language.First_Source := Id.Next_In_Lang;
7908 while Source.Next_In_Lang /= Id loop
7909 Source := Source.Next_In_Lang;
7912 Source.Next_In_Lang := Id.Next_In_Lang;
7916 -----------------------
7917 -- Report_No_Sources --
7918 -----------------------
7920 procedure Report_No_Sources
7921 (Project : Project_Id;
7923 Data : Tree_Processing_Data;
7924 Location : Source_Ptr;
7925 Continuation : Boolean := False)
7928 case Data.Flags.When_No_Sources is
7932 when Warning | Error =>
7934 Msg : constant String :=
7937 " sources in this project";
7940 Error_Msg_Warn := Data.Flags.When_No_Sources = Warning;
7942 if Continuation then
7943 Error_Msg (Data.Flags, "\" & Msg, Location, Project);
7945 Error_Msg (Data.Flags, Msg, Location, Project);
7949 end Report_No_Sources;
7951 ----------------------
7952 -- Show_Source_Dirs --
7953 ----------------------
7955 procedure Show_Source_Dirs
7956 (Project : Project_Id;
7957 Shared : Shared_Project_Tree_Data_Access)
7959 Current : String_List_Id;
7960 Element : String_Element;
7963 if Project.Source_Dirs = Nil_String then
7964 Debug_Output ("no Source_Dirs");
7966 Debug_Increase_Indent ("Source_Dirs:");
7968 Current := Project.Source_Dirs;
7969 while Current /= Nil_String loop
7970 Element := Shared.String_Elements.Table (Current);
7971 Debug_Output (Get_Name_String (Element.Display_Value));
7972 Current := Element.Next;
7975 Debug_Decrease_Indent ("end Source_Dirs.");
7977 end Show_Source_Dirs;
7979 ---------------------------
7980 -- Process_Naming_Scheme --
7981 ---------------------------
7983 procedure Process_Naming_Scheme
7984 (Tree : Project_Tree_Ref;
7985 Root_Project : Project_Id;
7986 Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
7987 Flags : Processing_Flags)
7989 procedure Recursive_Check
7990 (Project : Project_Id;
7991 Prj_Tree : Project_Tree_Ref;
7992 Data : in out Tree_Processing_Data);
7993 -- Check_Naming_Scheme for the project
7995 ---------------------
7996 -- Recursive_Check --
7997 ---------------------
7999 procedure Recursive_Check
8000 (Project : Project_Id;
8001 Prj_Tree : Project_Tree_Ref;
8002 Data : in out Tree_Processing_Data) is
8004 if Current_Verbosity = High then
8005 Debug_Increase_Indent
8006 ("Processing_Naming_Scheme for project", Project.Name);
8009 Data.Tree := Prj_Tree;
8010 Prj.Nmsc.Check (Project, Data);
8012 if Current_Verbosity = High then
8013 Debug_Decrease_Indent ("done Processing_Naming_Scheme");
8015 end Recursive_Check;
8017 procedure Check_All_Projects is new
8018 For_Every_Project_Imported (Tree_Processing_Data, Recursive_Check);
8020 Data : Tree_Processing_Data;
8022 -- Start of processing for Process_Naming_Scheme
8024 Lib_Data_Table.Init;
8025 Initialize (Data, Tree => Tree, Node_Tree => Node_Tree, Flags => Flags);
8026 Check_All_Projects (Root_Project, Tree, Data, Imported_First => True);
8029 -- Adjust language configs for projects that are extended
8032 List : Project_List;
8035 Lang : Language_Ptr;
8036 Elng : Language_Ptr;
8039 List := Tree.Projects;
8040 while List /= null loop
8041 Proj := List.Project;
8043 while Exte.Extended_By /= No_Project loop
8044 Exte := Exte.Extended_By;
8047 if Exte /= Proj then
8048 Lang := Proj.Languages;
8050 if Lang /= No_Language_Index then
8052 Elng := Get_Language_From_Name
8053 (Exte, Get_Name_String (Lang.Name));
8054 exit when Elng /= No_Language_Index;
8055 Exte := Exte.Extends;
8058 if Elng /= Lang then
8059 Lang.Config := Elng.Config;
8067 end Process_Naming_Scheme;